summaryrefslogtreecommitdiff
path: root/tests/unittests/net/test_init.py
Commit message (Collapse)AuthorAgeFilesLines
* net: purge blacklist_drivers across net and azure (#2160)Chris Patterson2023-05-101-5/+19
| | | | | | | | | | It was only used by Hyper-V which now has a filtering mechanism that does not require the use of a denylist. This exposed some issues with tests misspelling "hv_netvsc" and using unmatched mac addresses. This fixes those to work with the current filter that does not rely on the driver name. Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
* Cleanup ephemeral IP routes on exception (#2100)sxt10012023-04-031-0/+73
| | | | | If an exception occurs during EphemeralIPv4Network setup, any routes that were setup need to be torn down. This wasn't happening, and this commit adds the teardown.
* tests: Drop httpretty in favor of responses (#1720)Alberto Contreras2022-09-191-5/+5
|
* net: Implement link-local ephemeral ipv6Brett Holman2022-06-101-8/+24
| | | | | | | | | | | | | | | | | | | Also refactor network context managers into net.ephemeral Currently EC2 is the only IMDS to make use of this. IPv6 requires a link local address on interfaces. A link local address is sufficient for the EC2 IMDS, so no dhcp6 assignment is required for early boot IMDS queries. The kernel assigns this address using RFC 4291 [1] during link initialization, so all cloud-init needs to do is ensure that link is up. This means that even if dhcp4 fails, an ipv6-enabled instance may still succeed at crawling metadata. [1] https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.6
* cloudinit.net refactor: apply_network_config_names (#1388)Alberto Contreras2022-04-261-101/+0
| | | | | | Remove `apply_network_config_names` from `cloudinit.net` and `Distro` classes so it is only accessible via the networking attribute. LP: #1884602
* Network functions refactor and bugfixes (#1383)Brett Holman2022-04-151-1/+32
| | | | | | | | - replace common functionality with standard library implementations - add is_ip_network() for validating addresses in form: "192.168.1.1/24" - add validation to _normalize_net_keys - fix eni tests that formerly tested invalid ipv6 addresses (caught by stricter validation) - other refactorization and name standardization
* net: introduce find_candidate_nics() (#1313)Chris Patterson2022-03-111-0/+159
| | | | | | | | | | | | | | | | | find_fallback_nic_on_linux(), etc. provides valuable filtering of network interfaces in an effort to determine the best candidate for the fallback interface. Expose this logic with a new set of methods for finding the candidate network interfaces. These methods can be used by data sources which cannot rely on the fallback interface being the correct choice. Note that the MAC address filtering is now part of find_candidate_nics_on_linux(). This should be consistent behavior as find_fallback_nic_on_linux() never selected an interface without a MAC. find_fallback_nic_on_linux() continues to prefer eth0, but we make no such distinction in the candidate search. Signed-off-by: Chris Patterson cpatterson@microsoft.com
* Fix IPv6 netmask format for sysconfig (#1215)Harald2022-02-081-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change converts the IPv6 netmask from the network_data.json[1] format to the CIDR style, <IPv6_addr>/<prefix>. Using an IPv6 address like ffff:ffff:ffff:ffff:: does not work with NetworkManager, nor networkscripts. NetworkManager will ignore the route, logging: ifcfg-rh: ignoring invalid route at \ "::/:: via fd00:fd00:fd00:2::fffe dev $DEV" \ (/etc/sysconfig/network-scripts/route6-$DEV:3): \ Argument for "::/::" is not ADDR/PREFIX format Similarly if using networkscripts, ip route fail with error: Error: inet6 prefix is expected rather than \ "fd00:fd00:fd00::/ffff:ffff:ffff:ffff::". Also a bit of refactoring ... cloudinit.net.sysconfig.Route.to_string: * Move a couple of lines around to reduce repeated code. * if "ADDRESS" not in key -> continute, so that the code block following it can be de-indented. cloudinit.net.network_state: * Refactors the ipv4_mask_to_net_prefix, ipv6_mask_to_net_prefix removes mask_to_net_prefix methods. Utilize ipaddress library to do some of the heavy lifting. LP: #1959148
* Adopt Black and isort (SC-700) (#1157)James Falcon2021-12-151-519/+849
| | | | | Applied Black and isort, fixed any linting issues, updated tox.ini and CI.
* cloudinit/net: handle two different routes for the same ip (#1124)Emanuele Giuseppe Esposito2021-12-061-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | If we set a dhcp server side like this: $ cat /var/tmp/cloud-init/cloud-init-dhcp-f0rie5tm/dhcp.leases lease { ... option classless-static-routes 31.169.254.169.254 0.0.0.0,31.169.254.169.254 10.112.143.127,22.10.112.140 0.0.0.0,0 10.112.140.1; ... } cloud-init fails to configure the routes via 'ip route add' because to there are two different routes for 169.254.169.254: $ ip -4 route add 192.168.1.1/32 via 0.0.0.0 dev eth0 $ ip -4 route add 192.168.1.1/32 via 10.112.140.248 dev eth0 But NetworkManager can handle such scenario successfully as it uses "ip route append". So change cloud-init to also use "ip route append" to fix the issue: $ ip -4 route append 192.168.1.1/32 via 0.0.0.0 dev eth0 $ ip -4 route append 192.168.1.1/32 via 10.112.140.248 dev eth0 Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> RHBZ: #2003231
* Reorganize unit test locations under tests/unittests (#1126)Brett Holman2021-12-031-0/+1402
This attempts to standardize unit test file location under test/unittests/ such that any source file located at cloudinit/path/to/file.py may have a corresponding unit test file at test/unittests/path/to/test_file.py. Noteworthy Comments: ==================== Four different duplicate test files existed: test_{gpg,util,cc_mounts,cc_resolv_conf}.py Each of these duplicate file pairs has been merged together. This is a break in git history for these files. The test suite appears to have a dependency on test order. Changing test order causes some tests to fail. This should be rectified, but for now some tests have been modified in tests/unittests/config/test_set_passwords.py. A helper class name starts with "Test" which causes pytest to try executing it as a test case, which then throws warnings "due to Class having __init__()". Silence by changing the name of the class. # helpers.py is imported in many test files, import paths change cloudinit/tests/helpers.py -> tests/unittests/helpers.py # Move directories: cloudinit/distros/tests -> tests/unittests/distros cloudinit/cmd/devel/tests -> tests/unittests/cmd/devel cloudinit/cmd/tests -> tests/unittests/cmd/ cloudinit/sources/helpers/tests -> tests/unittests/sources/helpers cloudinit/sources/tests -> tests/unittests/sources cloudinit/net/tests -> tests/unittests/net cloudinit/config/tests -> tests/unittests/config cloudinit/analyze/tests/ -> tests/unittests/analyze/ # Standardize tests already in tests/unittests/ test_datasource -> sources test_distros -> distros test_vmware -> sources/vmware test_handler -> config # this contains cloudconfig module tests test_runs -> runs