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