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