Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Tomáš Pecka <tomas.pecka@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "trompeloeil_doctest.h" |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 9 | #include <filesystem> |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 10 | #include <sysrepo-cpp/utils/exception.hpp> |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 11 | #include "pretty_printers.h" |
| 12 | #include "system/IETFInterfaces.h" |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 13 | #include "system/IETFInterfacesConfig.h" |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 14 | #include "test_log_setup.h" |
| 15 | #include "test_sysrepo_helpers.h" |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 16 | #include "tests/configure.cmake.h" |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 17 | #include "tests/mock/system.h" |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 18 | #include "utils/io.h" |
Tomáš Pecka | f10b930 | 2021-02-23 19:02:02 +0100 | [diff] [blame] | 19 | |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 20 | using namespace std::string_literals; |
| 21 | |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 22 | struct FakeNetworkReload { |
| 23 | public: |
| 24 | MAKE_CONST_MOCK1(cb, void(const std::vector<std::string>&)); |
| 25 | }; |
| 26 | |
| 27 | TEST_CASE("Config data in ietf-interfaces") |
| 28 | { |
| 29 | TEST_SYSREPO_INIT_LOGS; |
| 30 | TEST_SYSREPO_INIT; |
| 31 | TEST_SYSREPO_INIT_CLIENT; |
| 32 | trompeloeil::sequence seq1; |
| 33 | |
Tomáš Pecka | 9cb218c | 2022-06-13 11:48:20 +0200 | [diff] [blame] | 34 | sysrepo::Connection{}.sessionStart(sysrepo::Datastore::Running).copyConfig(sysrepo::Datastore::Startup, "ietf-interfaces"); |
| 35 | |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 36 | auto fake = FakeNetworkReload(); |
| 37 | |
| 38 | const auto fakeConfigDir = std::filesystem::path(CMAKE_CURRENT_BINARY_DIR) / "tests/network/"s; |
| 39 | std::filesystem::remove_all(fakeConfigDir); |
| 40 | std::filesystem::create_directories(fakeConfigDir); |
| 41 | |
Jan Kundrát | 80113ed | 2022-04-27 18:10:52 +0200 | [diff] [blame] | 42 | REQUIRE_CALL(fake, cb(std::vector<std::string>{})).IN_SEQUENCE(seq1); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 43 | auto network = std::make_shared<velia::system::IETFInterfacesConfig>(srSess, fakeConfigDir, std::vector<std::string>{"br0", "eth0", "eth1"}, [&fake](const std::vector<std::string>& updatedInterfaces) { fake.cb(updatedInterfaces); }); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 44 | |
| 45 | SECTION("Link changes disabled") |
| 46 | { |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 47 | SECTION("Only specified link names can appear in configurable datastore") |
| 48 | { |
| 49 | for (const auto& [name, type] : {std::pair<const char*, const char*>{"eth0", "iana-if-type:ethernetCsmacd"}, |
| 50 | {"eth1", "iana-if-type:ethernetCsmacd"}, |
| 51 | {"br0", "iana-if-type:bridge"}, |
| 52 | {"osc", "iana-if-type:ethernetCsmacd"}, |
| 53 | {"oscW", "iana-if-type:ethernetCsmacd"}, |
| 54 | {"oscE", "iana-if-type:ethernetCsmacd"}}) { |
Jan Kundrát | b3e9998 | 2022-03-18 17:38:20 +0100 | [diff] [blame] | 55 | client.setItem("/ietf-interfaces:interfaces/interface[name='"s + name + "']/type", type); |
| 56 | client.setItem("/ietf-interfaces:interfaces/interface[name='"s + name + "']/enabled", "false"); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 57 | } |
Tomáš Pecka | 9cb218c | 2022-06-13 11:48:20 +0200 | [diff] [blame] | 58 | |
| 59 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0", "eth1"})).IN_SEQUENCE(seq1); // only these are monitored by the test |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 60 | client.applyChanges(); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | SECTION("Invalid type for a valid link") |
| 64 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 65 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:softwareLoopback"); |
| 66 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | SECTION("Invalid name") |
| 70 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 71 | client.setItem("/ietf-interfaces:interfaces/interface[name='blah0']/type", "iana-if-type:ethernetCsmacd"); |
| 72 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | 71a98b0 | 2021-05-17 15:59:40 +0200 | [diff] [blame] | 73 | } |
| 74 | } |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 75 | |
| 76 | SECTION("There must always be enabled protocol or the interface must be explicitely disabled") |
| 77 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 78 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 79 | |
| 80 | SECTION("Disabled protocols; enabled link") |
| 81 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 82 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 83 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 84 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
| 85 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | SECTION("Active protocols; disabled link") |
| 89 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 90 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "false"); |
| 91 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 92 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 93 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 94 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 95 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | SECTION("IPv4 only; enabled link") |
| 99 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 100 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 101 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 102 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 103 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 104 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 105 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | SECTION("Every active protocol must have at least one IP address assigned") |
| 110 | { |
Tomáš Pecka | 9cb218c | 2022-06-13 11:48:20 +0200 | [diff] [blame] | 111 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 112 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "false"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 113 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1).TIMES(AT_MOST(1)); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 114 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 115 | |
| 116 | SECTION("Enabled IPv4 protocol with some IPs assigned is valid") |
| 117 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 118 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 119 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 120 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 121 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.2']/ietf-ip:prefix-length", "24"); |
| 122 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 123 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 124 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | SECTION("Enabled IPv6 protocol with some IPs assigned is valid") |
| 128 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 129 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 130 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 131 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 132 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | 4c7ff2a | 2021-08-06 15:05:54 +0200 | [diff] [blame] | 133 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 134 | client.applyChanges(); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 135 | } |
| 136 | |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 137 | SECTION("Enabled IPv4 protocol must have at least one IP or the autoconfiguration must be on") |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 138 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 139 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 140 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 141 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 142 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
| 143 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 146 | SECTION("Enabled IPv6 protocol must have at least one IP or the autoconfiguration must be on") |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 147 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 148 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/enabled", "true"); |
| 149 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 150 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 151 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "false"); |
| 152 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | de0ef2f | 2021-07-08 13:23:50 +0200 | [diff] [blame] | 153 | } |
| 154 | } |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 155 | |
| 156 | std::string expectedContents; |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 157 | |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 158 | SECTION("Setting IPs to eth0") |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 159 | { |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 160 | const auto expectedFilePath = fakeConfigDir / "eth0.network"; |
| 161 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 162 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 163 | |
| 164 | SECTION("Single IPv4 address") |
| 165 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 166 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/description", "Hello world"); |
| 167 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 168 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 169 | expectedContents = R"([Match] |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 170 | Name=eth0 |
| 171 | |
| 172 | [Network] |
| 173 | Description=Hello world |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 174 | Address=192.0.2.1/24 |
| 175 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 176 | IPv6AcceptRA=false |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 177 | DHCP=no |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 178 | LLDP=true |
| 179 | EmitLLDP=nearest-bridge |
| 180 | )"; |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 181 | } |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 182 | |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 183 | SECTION("Two IPv4 addresses") |
| 184 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 185 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 186 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.2']/ietf-ip:prefix-length", "24"); |
| 187 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 188 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 189 | expectedContents = R"([Match] |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 190 | Name=eth0 |
| 191 | |
| 192 | [Network] |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 193 | Address=192.0.2.1/24 |
| 194 | Address=192.0.2.2/24 |
| 195 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 196 | IPv6AcceptRA=false |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 197 | DHCP=no |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 198 | LLDP=true |
| 199 | EmitLLDP=nearest-bridge |
| 200 | )"; |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | SECTION("IPv4 and IPv6 addresses") |
| 204 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 205 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 206 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
| 207 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 208 | expectedContents = R"([Match] |
| 209 | Name=eth0 |
| 210 | |
| 211 | [Network] |
| 212 | Address=192.0.2.1/24 |
| 213 | Address=2001:db8::1/32 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 214 | IPv6AcceptRA=true |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 215 | DHCP=no |
| 216 | LLDP=true |
| 217 | EmitLLDP=nearest-bridge |
| 218 | )"; |
| 219 | } |
| 220 | |
| 221 | SECTION("IPv4 and IPv6 addresses but IPv6 disabled") |
| 222 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 223 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 224 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
| 225 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 226 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/enabled", "false"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 227 | expectedContents = R"([Match] |
| 228 | Name=eth0 |
| 229 | |
| 230 | [Network] |
| 231 | Address=192.0.2.1/24 |
| 232 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 233 | IPv6AcceptRA=false |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 234 | DHCP=no |
| 235 | LLDP=true |
| 236 | EmitLLDP=nearest-bridge |
| 237 | )"; |
| 238 | } |
| 239 | |
| 240 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 241 | client.applyChanges(); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 242 | REQUIRE(std::filesystem::exists(expectedFilePath)); |
| 243 | REQUIRE(velia::utils::readFileToString(expectedFilePath) == expectedContents); |
| 244 | |
| 245 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 246 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 247 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 248 | client.applyChanges(); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 249 | REQUIRE(!std::filesystem::exists(expectedFilePath)); |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 250 | } |
| 251 | |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 252 | SECTION("Two links") |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 253 | { |
| 254 | const auto expectedFilePathEth0 = fakeConfigDir / "eth0.network"; |
| 255 | const auto expectedFilePathEth1 = fakeConfigDir / "eth1.network"; |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 256 | |
| 257 | std::string expectedContentsEth0 = R"([Match] |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 258 | Name=eth0 |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 259 | |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 260 | [Network] |
| 261 | Address=192.0.2.1/24 |
| 262 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 263 | IPv6AcceptRA=false |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 264 | DHCP=no |
| 265 | LLDP=true |
| 266 | EmitLLDP=nearest-bridge |
| 267 | )"; |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 268 | std::string expectedContentsEth1 = R"([Match] |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 269 | Name=eth1 |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 270 | |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 271 | [Network] |
| 272 | Address=2001:db8::1/32 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 273 | IPv6AcceptRA=true |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 274 | DHCP=no |
| 275 | LLDP=true |
| 276 | EmitLLDP=nearest-bridge |
| 277 | )"; |
| 278 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 279 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
| 280 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 281 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 282 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/type", "iana-if-type:ethernetCsmacd"); |
| 283 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 284 | |
| 285 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0", "eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 286 | client.applyChanges(); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 287 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 288 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 289 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 290 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 291 | |
| 292 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 293 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
| 294 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth1']"); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 295 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0", "eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 296 | client.applyChanges(); |
Tomáš Pecka | 85f7775 | 2021-06-03 10:09:58 +0200 | [diff] [blame] | 297 | REQUIRE(!std::filesystem::exists(expectedFilePathEth0)); |
| 298 | REQUIRE(!std::filesystem::exists(expectedFilePathEth1)); |
| 299 | } |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 300 | |
| 301 | SECTION("Setup a bridge br0 over eth0 and eth1") |
| 302 | { |
| 303 | const auto expectedFilePathBr0 = fakeConfigDir / "br0.network"; |
| 304 | const auto expectedFilePathEth0 = fakeConfigDir / "eth0.network"; |
| 305 | const auto expectedFilePathEth1 = fakeConfigDir / "eth1.network"; |
| 306 | |
| 307 | std::string expectedContentsBr0 = R"([Match] |
| 308 | Name=br0 |
| 309 | |
| 310 | [Network] |
| 311 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 312 | IPv6AcceptRA=false |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 313 | DHCP=no |
| 314 | LLDP=true |
| 315 | EmitLLDP=nearest-bridge |
| 316 | )"; |
| 317 | |
| 318 | std::string expectedContentsEth0 = R"([Match] |
| 319 | Name=eth0 |
| 320 | |
| 321 | [Network] |
| 322 | Bridge=br0 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 323 | IPv6AcceptRA=false |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 324 | DHCP=no |
| 325 | LLDP=true |
| 326 | EmitLLDP=nearest-bridge |
| 327 | )"; |
| 328 | |
| 329 | std::string expectedContentsEth1 = R"([Match] |
| 330 | Name=eth1 |
| 331 | |
| 332 | [Network] |
| 333 | Bridge=br0 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 334 | IPv6AcceptRA=false |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 335 | DHCP=no |
| 336 | LLDP=true |
| 337 | EmitLLDP=nearest-bridge |
| 338 | )"; |
| 339 | |
| 340 | // create br0 bridge over eth0 and eth1 with no IP |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 341 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/enabled", "false"); |
| 342 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/type", "iana-if-type:bridge"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 343 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 344 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
| 345 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/czechlight-network:bridge", "br0"); |
| 346 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
| 347 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 348 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 349 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/type", "iana-if-type:ethernetCsmacd"); |
| 350 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/czechlight-network:bridge", "br0"); |
| 351 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 352 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv6"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 353 | |
| 354 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0", "eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 355 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 356 | REQUIRE(std::filesystem::exists(expectedFilePathBr0)); |
| 357 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 358 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 359 | REQUIRE(velia::utils::readFileToString(expectedFilePathBr0) == expectedContentsBr0); |
| 360 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 361 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 362 | |
| 363 | // assign an IPv4 address to br0 |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 364 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/enabled", "true"); |
| 365 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 366 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 367 | expectedContentsBr0 = R"([Match] |
| 368 | Name=br0 |
| 369 | |
| 370 | [Network] |
| 371 | Address=192.0.2.1/24 |
| 372 | LinkLocalAddressing=no |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 373 | IPv6AcceptRA=false |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 374 | DHCP=no |
| 375 | LLDP=true |
| 376 | EmitLLDP=nearest-bridge |
| 377 | )"; |
| 378 | |
| 379 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 380 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 381 | REQUIRE(std::filesystem::exists(expectedFilePathBr0)); |
| 382 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 383 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 384 | REQUIRE(velia::utils::readFileToString(expectedFilePathBr0) == expectedContentsBr0); |
| 385 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 386 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 387 | |
| 388 | // assign also an IPv6 address to br0 |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 389 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 390 | expectedContentsBr0 = R"([Match] |
| 391 | Name=br0 |
| 392 | |
| 393 | [Network] |
| 394 | Address=192.0.2.1/24 |
| 395 | Address=2001:db8::1/32 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 396 | IPv6AcceptRA=true |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 397 | DHCP=no |
| 398 | LLDP=true |
| 399 | EmitLLDP=nearest-bridge |
| 400 | )"; |
| 401 | |
| 402 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 403 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 404 | REQUIRE(std::filesystem::exists(expectedFilePathBr0)); |
| 405 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 406 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 407 | REQUIRE(velia::utils::readFileToString(expectedFilePathBr0) == expectedContentsBr0); |
| 408 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 409 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 410 | |
| 411 | // remove eth1 from bridge |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 412 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth1']/czechlight-network:bridge"); |
| 413 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::2']/ietf-ip:prefix-length", "32"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 414 | |
| 415 | expectedContentsEth1 = R"([Match] |
| 416 | Name=eth1 |
| 417 | |
| 418 | [Network] |
| 419 | Address=2001:db8::2/32 |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 420 | IPv6AcceptRA=true |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 421 | DHCP=no |
| 422 | LLDP=true |
| 423 | EmitLLDP=nearest-bridge |
| 424 | )"; |
| 425 | |
| 426 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 427 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 428 | REQUIRE(std::filesystem::exists(expectedFilePathBr0)); |
| 429 | REQUIRE(std::filesystem::exists(expectedFilePathEth0)); |
| 430 | REQUIRE(std::filesystem::exists(expectedFilePathEth1)); |
| 431 | REQUIRE(velia::utils::readFileToString(expectedFilePathBr0) == expectedContentsBr0); |
| 432 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth0) == expectedContentsEth0); |
| 433 | REQUIRE(velia::utils::readFileToString(expectedFilePathEth1) == expectedContentsEth1); |
| 434 | |
| 435 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 436 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='br0']"); |
| 437 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
| 438 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth1']"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 439 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0", "eth1"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 440 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 441 | REQUIRE(!std::filesystem::exists(expectedFilePathBr0)); |
| 442 | REQUIRE(!std::filesystem::exists(expectedFilePathEth0)); |
| 443 | REQUIRE(!std::filesystem::exists(expectedFilePathEth1)); |
| 444 | } |
| 445 | |
| 446 | SECTION("Slave interface and enabled/disabled IP protocols") |
| 447 | { |
| 448 | const auto expectedFilePathBr0 = fakeConfigDir / "br0.network"; |
| 449 | const auto expectedFilePathEth0 = fakeConfigDir / "eth0.network"; |
| 450 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 451 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/type", "iana-if-type:bridge"); |
| 452 | client.setItem("/ietf-interfaces:interfaces/interface[name='br0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 453 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
| 454 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/czechlight-network:bridge", "br0"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 455 | |
| 456 | SECTION("Can't be a slave when IPv4 enabled") |
| 457 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 458 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 459 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | SECTION("Can't be a slave when IPv6 enabled") |
| 463 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 464 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth1']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
| 465 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | SECTION("Can't be a slave when both IPv4 and IPv6 enabled") |
| 469 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 470 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 471 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/ietf-ip:prefix-length", "32"); |
| 472 | REQUIRE_THROWS_AS(client.applyChanges(), sysrepo::ErrorWithCode); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | SECTION("Can be a slave when addresses present but protocol is disabled") |
| 476 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 477 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); |
| 478 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/enabled", "false"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 479 | |
| 480 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 481 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 482 | |
| 483 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 484 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='br0']"); |
| 485 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 486 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"br0", "eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 487 | client.applyChanges(); |
Tomáš Pecka | c2929a6 | 2021-06-05 17:21:03 +0200 | [diff] [blame] | 488 | REQUIRE(!std::filesystem::exists(expectedFilePathBr0)); |
| 489 | REQUIRE(!std::filesystem::exists(expectedFilePathEth0)); |
| 490 | } |
| 491 | } |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 492 | |
| 493 | SECTION("Network autoconfiguration") |
| 494 | { |
| 495 | const auto expectedFilePath = fakeConfigDir / "eth0.network"; |
| 496 | |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 497 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/type", "iana-if-type:ethernetCsmacd"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 498 | |
| 499 | SECTION("IPv4 on with address, IPv6 disabled, DHCPv4 off, RA off") |
| 500 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 501 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 502 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); // in case DHCP is disabled an IP must be present |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 503 | |
| 504 | expectedContents = R"([Match] |
| 505 | Name=eth0 |
| 506 | |
| 507 | [Network] |
| 508 | Address=192.0.2.1/24 |
| 509 | LinkLocalAddressing=no |
| 510 | IPv6AcceptRA=false |
| 511 | DHCP=no |
| 512 | LLDP=true |
| 513 | EmitLLDP=nearest-bridge |
| 514 | )"; |
| 515 | } |
| 516 | |
| 517 | SECTION("IPv4 on with address, IPv6 disabled, DHCPv4 on, RA on") |
| 518 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 519 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "true"); |
| 520 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/ietf-ip:prefix-length", "24"); // in case DHCP is disabled an IP must be present |
| 521 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "false"); |
| 522 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "true"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 523 | |
| 524 | expectedContents = R"([Match] |
| 525 | Name=eth0 |
| 526 | |
| 527 | [Network] |
| 528 | Address=192.0.2.1/24 |
| 529 | LinkLocalAddressing=no |
| 530 | IPv6AcceptRA=false |
| 531 | DHCP=ipv4 |
| 532 | LLDP=true |
| 533 | EmitLLDP=nearest-bridge |
| 534 | )"; |
| 535 | } |
| 536 | |
| 537 | SECTION("IPv4 disabled, IPv6 enabled, DHCPv4 on, RA on") |
| 538 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 539 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "false"); |
| 540 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "true"); |
| 541 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 542 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "true"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 543 | |
| 544 | expectedContents = R"([Match] |
| 545 | Name=eth0 |
| 546 | |
| 547 | [Network] |
| 548 | IPv6AcceptRA=true |
| 549 | DHCP=no |
| 550 | LLDP=true |
| 551 | EmitLLDP=nearest-bridge |
| 552 | )"; |
| 553 | } |
| 554 | |
| 555 | SECTION("IPv4 enabled, IPv6 enabled, DHCPv4 on, RA on") |
| 556 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 557 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 558 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "true"); |
| 559 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 560 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "true"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 561 | |
| 562 | expectedContents = R"([Match] |
| 563 | Name=eth0 |
| 564 | |
| 565 | [Network] |
| 566 | IPv6AcceptRA=true |
| 567 | DHCP=ipv4 |
| 568 | LLDP=true |
| 569 | EmitLLDP=nearest-bridge |
| 570 | )"; |
| 571 | } |
| 572 | |
| 573 | SECTION("IPv4 enabled, IPv6 enabled, DHCPv4 off, RA on") |
| 574 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 575 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:enabled", "true"); |
| 576 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/prefix-length", "24"); |
| 577 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 578 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:enabled", "true"); |
| 579 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "true"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 580 | |
| 581 | expectedContents = R"([Match] |
| 582 | Name=eth0 |
| 583 | |
| 584 | [Network] |
| 585 | Address=192.0.2.1/24 |
| 586 | IPv6AcceptRA=true |
| 587 | DHCP=no |
| 588 | LLDP=true |
| 589 | EmitLLDP=nearest-bridge |
| 590 | )"; |
| 591 | } |
| 592 | |
| 593 | SECTION("IPv4 disabled, IPv6 disabled, DHCPv4 off, RA off") |
| 594 | { |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 595 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ietf-ip:address[ip='192.0.2.1']/prefix-length", "24"); |
| 596 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/czechlight-network:dhcp-client", "false"); |
| 597 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:address[ip='2001:db8::1']/prefix-length", "32"); |
| 598 | client.setItem("/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv6/ietf-ip:autoconf/ietf-ip:create-global-addresses", "false"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 599 | |
| 600 | expectedContents = R"([Match] |
| 601 | Name=eth0 |
| 602 | |
| 603 | [Network] |
| 604 | Address=192.0.2.1/24 |
| 605 | Address=2001:db8::1/32 |
| 606 | IPv6AcceptRA=false |
| 607 | DHCP=no |
| 608 | LLDP=true |
| 609 | EmitLLDP=nearest-bridge |
| 610 | )"; |
| 611 | } |
| 612 | |
| 613 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 614 | client.applyChanges(); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 615 | REQUIRE(std::filesystem::exists(expectedFilePath)); |
| 616 | REQUIRE(velia::utils::readFileToString(expectedFilePath) == expectedContents); |
| 617 | |
| 618 | // reset the contents |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 619 | client.deleteItem("/ietf-interfaces:interfaces/interface[name='eth0']"); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 620 | REQUIRE_CALL(fake, cb(std::vector<std::string>{"eth0"})).IN_SEQUENCE(seq1); |
Václav Kubernát | 7efd6d5 | 2021-11-09 01:31:11 +0100 | [diff] [blame] | 621 | client.applyChanges(); |
Tomáš Pecka | bd43a94 | 2021-08-04 10:12:49 +0200 | [diff] [blame] | 622 | REQUIRE(!std::filesystem::exists(expectedFilePath)); |
| 623 | } |
Tomáš Pecka | 39bbb51 | 2021-05-23 22:07:22 +0200 | [diff] [blame] | 624 | } |