summaryrefslogtreecommitdiff
path: root/tests/unittests/test_net.py
AgeCommit message (Collapse)Author
2019-02-07netplan: Don't render yaml aliases when dumping netplanRyan Harper
Cloud-init rendered netplan with duplicate aliases if a network config included "global" nameserver/search values. Netplan uses can read yaml files which do use aliaes but cloud-init did not render a single yaml dictionary, instead it combined yaml sections into a single document which sometimes resulted in duplicate aliases being present. This branch introduces a yaml SafeDumper class which can set the 'ignore_aliases' attribute. This is not enabled by default but callers to util.yaml_dumps can pass a boolean to toggle this. The netplan render uses noalias=True and the resulting yaml output does not contain any aliases. LP: #1815051
2019-01-28sysconfig: On SUSE, use STARTMODE instead of ONBOOTRobert Schweikert
ONBOOT is not recognized on openSUSE and SUSE Linux Enterprise, add the STARTMODE setting LP: #1799540
2019-01-23net/sysconfig: do not write a resolv.conf file with only the header.Robert Schweikert
Writing the file with no dns information may prevent distro tools from writing a resolv.conf file with dns information obtained from a dhcp server.
2019-01-18net: Make sysconfig renderer compatible with Network Manager.Eduardo Otubo
The 'sysconfig' renderer is activated if, and only if, there's ifup and ifdown commands present in its search dictonary or the network-scripts configuration files are found. This patch adds a check for Network- Manager configuration file as well. This solution is based on the use of the plugin 'ifcfg-rh' present in Network-Manager and is designed to support Fedora 29 or other distributions that also replaced network-scripts by Network-Manager.
2018-12-11net: render 'metric' values in per-subnet routesRyan Harper
It is possible to have a metric value in a per-subnet route. This is currently missing in all renderers. Update each renderer to emit the correct metric value from the config. LP: #1805871
2018-10-09net: ignore nics that have "zero" mac address.Scott Moser
Previously we explicitly excluded mac address '00:00:00:00:00:00'. But then some nics (tunl0 and sit0) ended up having a mac address like '00:00:00:00'. The change here just ignores all 00[:00[:00...]]. LP: #1796917
2018-09-26Add support for Infiniband network interfaces (IPoIB).Mark Goddard
OpenStack ironic references Infiniband interfaces via a 6 byte 'MAC address' formed from bytes 13-15 and 18-20 of interface's hardware address. This address is used as the ethernet_mac_address of Infiniband links in network_data.json in configdrives generated by OpenStack nova. We can use this address to map links in network_data.json to their corresponding interface names. When generating interface configuration files, we need to use the interface's full hardware address as the HWADDR, rather than the 6 byte MAC address provided by network_data.json. This change allows IB interfaces to be referenced in this dual mode - by MAC address and hardware address, depending on the context. Support TYPE=InfiniBand for sysconfig configuration of IB interfaces.
2018-09-05tests: Disallow use of util.subp except for where needed.Scott Moser
In many cases, cloud-init uses 'util.subp' to run a subprocess. This is not really desirable in our unit tests as it makes the tests dependent upon existance of those utilities. The change here is to modify the base test case class (CiTestCase) to raise exception any time subp is called. Then, fix all callers. For cases where subp is necessary or actually desired, we can use it via   a.) context hander CiTestCase.allow_subp(value)   b.) class level self.allowed_subp = value Both cases the value is a list of acceptable executable names that will be called (essentially argv[0]). Some cleanups in AltCloud were done as the code was being updated.
2018-09-05sysconfig: refactor sysconfig to accept distro specific templates pathsRyan Harper
Multiple distros use sysconfig format but have different content and paths to certain files. Update distros to specify these template paths in their renderer_configs dictionary.
2018-08-06netplan: Correctly render macaddress on a bonds and bridges when provided.Scott Moser
When converting network config v1 to netplan, we were not correctly rendering the 'macaddress' key on a bond. Not that the difference in spelling between v1 'mac_address' and v2 'macaddress' is intentional. Also fixed here is rendering of the macaddress for bridges. LP: #1784699
2018-06-12netplan: fix mtu if provided by network config for all rendered typesChad Smith
When network configuration for any interface defines maximum transmission values (MTU) the netplan, eni and sysconfig renders will take into account any device-level, or subnet-level mtu values. When network configuration has conflicting device-level and ipv4 subnet mtu values, the subnet-specific value is honored and a warning will be logged about any ignored device-level setting. LP: #1774666
2018-05-09tests: do not rely on host /proc/cmdline in test_net.pyLars Kellogg-Stedman
Make test_net.TestGenerateFallbackConfig.test_unstable_names mock the value of /proc/cmdline in the same way as the existing test_unstable_names_disabled test. LP: #1769952
2018-05-09SmartOS: fix get_interfaces for nics that do not have addr_assign_type.Scott Moser
When attempting to apply network configuration for SmartOS's container platform, cloud-init would not identify nics. The nics on provided in this container service do not have 'addr_assign_type'. That was being interpreted as being a "stolen" mac, and would be filtered out by get_interfaces.
2018-04-26net: detect unstable network names and trigger a settle if neededRyan Harper
The cloud-init-local.service expects that any network device name changes have already been completed by the kernel or udev daemon. In some situations we've found that the renaming of interfaces from kernel names (eth0, eth1, etc) to their persistent names (eno1, ens3, enp0s1, etc) may happen after cloud-init-local has started where it reads values from sysfs about what network devices are present, and which device to use as a fallback nic. Subsequently, cloud-init-local would write out network configuration for a kernel device name which would no longer be present by the time that networking services start to bring up the devices. The result is that the instance does not get networking configured. Prior to use of systemd-networkd, the Ubuntu 'networking.service' unit included a call to udevadm settle which is why this race is not seen on a Xenial system. This change adds the ability to detect if an interface has a stable name, if if we find one without stable names and stable names have not been disabled (net.ifnames=0 in /proc/cmdline), then cloud-init will invoke udevadm settle. LP: #1766287
2018-04-25sysconfig: dhcp6 subnet type should not imply dhcpv4Vitaly Kuznetsov
BOOTPROTO=dhcp in sysconfig enables DHCPv4 and we should not do this implicitly when 'dhcp6' subnet is specified. In case both dhcpv4 and dhcpv6 are needed users should specify both: subnets: - type: dhcp6 - type: dhcp Fix the current code and add a dhcpv6 only test. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
2018-03-22Handle global dns entries in netplanRyan Harper
In network config v1 format, there are dns values which are not bound to a specific interface and do not map to the per-interface format in netplan. To handle this case we render netplan configuration that duplicates the DNS configuration on any interface that has a static network config. We avoiding interfaces which have DHCP configuration which may provide conflicting DNS values. LP: #1750884
2018-03-16net: recognize iscsi root cases without ip= on kernel command line.Scott Moser
When 'ip=' or 'ip6=' is found on the kernel command line, cloud-init will consider read network config from /run/net-*.conf files. There are some iscsi-root scenarios where initramfs configures networking but the ip= parameter is not present. 2 such cases are:  a.) static config in /etc/iscsi/iscsi.initramfs (copied into the initramfs)  b.) iBft This changes cloud-init to consider initramfs provided networking information if:  * there are /run/net-* files and  * (ip= or ip6 is on the command line) or open-iscsi.interface file exists. LP: #1752391
2018-03-16netplan: render bridge port-priority valuesRyan Harper
Update netplan renderer to write out bridge port-priority values now that netplan supports the feature. LP: #1735821
2018-01-24Azure VM Preprovisioning support.Douglas Jordan
This change will enable azure vms to report provisioning has completed twice, first to tell the fabric it has completed then a second time to enable customer settings. The datasource for the second provisioning is the Instance Metadata Service (IMDS),and the VM will poll indefinitely for the new ovf-env.xml from IMDS. This branch introduces EphemeralDHCPv4 which encapsulates common logic used by both DataSourceEc2 an DataSourceAzure for temporary DHCP interactions without side-effects. LP: #1734991
2018-01-24OpenNebula: Improve network configuration support.Akihiko Ota
Network configuration in OpenNebula would only work if the host correctly guessed the names of the devices in the guest. OpenNebula provided data in its context.sh like 'ETH0_NETWORK', but if the guest named devices differently then results were not predictable. This would occur with Predictable Network Interface Names. To address this, newer versions (of OpenNebula provide the mac address ETH0_MAC. This function is present in 4.14 and documented officially in 5.0 docs. This provides support for reading the mac addresses from the context.sh. It also fixes cases where context.sh provided a field (ETH0_NETWORK or ETH0_MASK) with a empty string. Previously the empty string would be used rather than falling back to the default. LP: #1719157, #1716397, #1736750
2017-11-21sysconfig: Correctly render dns and dns search info.Ryan McCabe
Currently when dns and dns search info is provided, it is not rendered when outputting to sysconfig format. This patch causes the DNS and DOMAIN lines to be written out rendering sysconfig. LP: #1705804
2017-10-05net: Handle bridge stp values of 0 and convert to boolean typeChad Smith
Update unit tests to pass a 0 instead of 'off' to validate that network state is properly written.
2017-10-05network: bridge_stp value not always correctRyan Harper
Update network_state to store the bridge_stp value as a boolean. The various renderers then can map the boolean value to the correct output as needed; eni uses 'on/off', sysconfig uses 'yes/no' and netplan will use the boolean directly. Update unittest values for sysconfig and netplan. Both contained the network_state string value which resulted in not correctly enable/disable STP in the target system. Update network_state comment (fd -> forward-delay, add stp as boolean) on bridge commands to match the expected format of a netplan bridge command. LP: #1721157
2017-09-07Use /run/cloud-init for tempfile operations.Scott Moser
During boot, the usage of /tmp is not safe. In systemd systems, systemd-tmpfiles-clean may run at any point and clear out a temp file while cloud-init is using it. The solution here is to use /run/cloud-init/tmp. LP: #1707222
2017-09-05relocate tests/unittests/helpers.py to cloudinit/testsLars Kellogg-Stedman
This moves the base test case classes into into cloudinit/tests and updates all the corresponding imports.
2017-08-15network: add v2 passthrough and fix parsing v2 config with bonds/bridge paramsRyan Harper
If the network-config sent to cloud-init is in version: 2 format then when rendering netplan, we can pass the content through and avoid consuming network_state elements. This removes the need for trying to map many v2 features onto network state where other renderers won't be able to use anyhow (for example match parameters for multi-interface configuration and wifi configuration support). Additionally ensure we retain bond/bridge v2 configuration in network state so when rendering to eni or sysconfig we don't lose the configuration - Drop the NotImplemented wifi exception, log a warning that it works for netplan only - Adjust unittests to new code path and output - Fix issue with v2 macaddress values getting dropped - Add unittests for consuming/validating v2 configurations LP: #1709180
2017-08-01sysconfig: Dont repeat header when rendering resolv.confRyan Harper
The sysconfig renderer duplicates the cloud-init header string when rendering resolv.conf file. This leads to resolv.conf file growing with every reboot of a system. Fix this by checking for the header when loading content from existing file. Update one of the sysconfig unittests with multiple render calls to simulate the reboot to check that we don't repeat the header. LP: #1701420
2017-07-22sysconfig: support subnet type of 'manual'.Scott Moser
The subnet type 'manual' was used as a way to declare a device and set an MTU for it but not assign network addresses. This updates the manual example config to handle that case and provides expected rendered output for sysconfig, eni, and netplan.
2017-07-20sysconfig: use MACADDR on bonds/bridges to configure mac_addressRyan Harper
Previously, sysconfig rendered HWADDR for all interface types, but that value is only used to identify physical devices. Instead use MACADDR to configure the MAC on virtual devices, like bonds and bridges. - Sort bond slave list to ensure consistent ordering in sysconfig rendered files. - Add unittests for sysconfig rendering of bonds/bridges with mac_address LP: #1701417
2017-07-20net: eni route rendering missed ipv6 default route configRyan Harper
In some network configurations a network value of '::' and a netmask value of '::' were used to indicate a default IPV6 gateway. Commit d00da2d5 removed ipv6 'netmask' attributes and calculate a prefix length value instead. The eni route rendering failed to update the check to use prefix value of 0 to indicate the presence of an IPV6 default route. A broken ipv6 default route rendered like: post-up route add -net :: netmask :: gw 2001:4800:78ff:1b::1 || true And with this patch, it now renders like: post-up route add -A inet6 default gw 2001:4800:78ff:1b::1 || true LP: #1701097
2017-07-20sysconfig: enable mtu set per subnet, including ipv6 mtuRyan Harper
Render MTU values if present in subnet and route configurations for v4 and v6. LP: #1702513
2017-07-20sysconfig: handle manual type subnetsRyan Harper
Implement manual control for sysconfig by using ONBOOT=N. This allows an interface to be configured but not brought up. Note that ONBOOT is per-interface not per address. LP: #1687725
2017-07-20sysconfig: fix ipv6 gateway routesRyan Harper
Currently only the subnet is checked for 'ipv6' setting, however, the routes array may include a mix of v4 or v6 configurations, in particular, the gateway in a route may be ipv6, and if so, should export the value via IPV6_DEFAULTGW in the ifcfg-XXXX file. Additionally, if the route is v6, it should rendering a routes6-XXXX file; this is present but missing the 'dev <interface>' scoping. LP: #1694801
2017-07-20sysconfig: fix rendering of bond, bridge and vlan types.Ryan Harper
Previously, virtual types (bond, bridge, vlan) were almost completely broken. They would not get any network configuration (ip addresses or dhcp config) and or routes rendered. This fixes those issues. For bonds we now correctly render BONDING_SLAVE entries. Also add tests for simple bond, bridge and vlan. LP: #1695092
2017-07-19sysconfig: ipv6 and default gateway fixes.Ryan Harper
With this change, entries in IPV6ADDR and IPV6ADDR_SECONDARIES will now always be in format addr/prefix. When a subnet has a gateway will be written. If the gateway is ipv6, use the key IPV6_DEFAULTGW rather than GATEWAY. LP: #1704872
2017-07-19net: fix renaming of nics to support mac addresses written in upper case.Scott Moser
The network device renaming code previously required the case of the mac address input to match that of the data read from the system. For example, if user provided network config with mac address in upper case, then cloud-init would not rename the device correctly as /sys/class/net/address stores lower case values. The fix here is to always compare lower case mac addresses. LP: #1705147
2017-07-18sysconfig: include GATEWAY value if set in subnetRyan Harper
Render the GATEWAY= value in interface files which have a gateway in the subnet configuration. LP: #1686856
2017-06-27Azure: Add network-config, Refactor net layer to handle duplicate macs.Ryan Harper
On systems with network devices with duplicate mac addresses, cloud-init will fail to rename the devices according to the specified network configuration. Refactor net layer to search by device driver and device id if available. Azure systems may have duplicate mac addresses by design. Update Azure datasource to run at init-local time and let Azure datasource generate a fallback networking config to handle advanced networking configurations. Lastly, add a 'setup' method to the datasources that is called before userdata/vendordata is processed but after networking is up. That is used here on Azure to interact with the 'fabric'.
2017-06-12net: Allow for NetworkManager configurationRyan McCabe
In cases where the config json specifies nameserver entries, if there are interfaces configured to use dhcp, NetworkManager, if enabled, will clobber the /etc/resolv.conf that cloud-init has produced, which can break dns. If there are no interfaces configured to use dhcp, NetworkManager could clobber /etc/resolv.conf with an empty file. This patch adds a mechanism for dropping additional configuration into /etc/NetworkManager/conf.d/ and disables management of /etc/resolv.conf by NetworkManager when nameserver information is provided in the config. LP: #1693251 Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
2017-06-08net: normalize data in network_state objectScott Moser
The network_state object's network and route keys would have different information depending upon how the network_state object was populated. This change cleans that up. Now: * address will always contain an IP address. * prefix will always include an integer value that is the network_prefix for the address. * netmask will be present only if the address is ipv4, and its value will always correlate to the 'prefix'.
2017-06-07RHEL/CentOS: Fix default routes for IPv4/IPv6 configuration.Andreas Karis
Since f38fa413176, default routes get added to both ifcfg-* and route-* and route6-* files. Default routes should only go to ifcfg-* files, otherwise the information is redundant. LP: #1696176
2017-06-06net: when selecting a network device, use natural sort orderMarc-Aurèle Brothier
The code deciding which interface to choose as the default to request the IP address through DHCP does not sort the interfaces correctly. On Ubuntu Xenial images for example, the interfaces are named ens1, ens2, ens3..., ens11, ... depending on the pci bus address. The python sorting will list 'ens11' before 'ens3' for example despite the fact that 'ens3' should be before 'ens11'. This patch address this issue and sort the interface names according to a human sorting. Signed-off-by: Marc-Aurèle Brothier <m@brothier.org>
2017-05-31Fix eni rendering for bridge params that require repeated key for values.Ryan Harper
There are a few bridge parameters which require repeating the key with each value in the list when rendering eni. Extend the network unittests to cover all of the known bridge parameters and check we render eni and netplan correctly.
2017-05-31net: remove systemd link file writing from eni rendererRyan Harper
During the network v2 merge, we inadvertently re-enabled rendering systemd .link files. This files are not required as cloud-init already has to do interface renaming due to issues with udevd which may refuse to rename certain interfaces (such as veth devices in a LXD container). As such, removing the code altogether.
2017-05-26net: fix reading and rendering addresses in cidr format.Dimitri John Ledkov
Input (specifically OpenStack) that had: "ip_address" : "104.130.20.155", "netmask" : "255.255.255.0" Was being rendered to netplan as '104.130.20.155/255.255.255.0'. That is now fixed to '104.130.20.155/24' Also fixed is reading of a route that had a network prefix integer in the 'netmask' rather than a netmask. LP: #1689346 LP: #1684349
2017-05-25nplan: For bonds, allow dashed or underscore names of keys.Dimitri John Ledkov
As some of the bond paramemters are passed in as dashed, or underscored, depending on the input source. Also correct transmit-hash-policy netplan target key. LP: #1690480
2017-05-23flake8: move the pinned version of flake8 up to 3.3.0Scott Moser
This just moves flake8 and related tools up to newer versions and fixes the complaints associated with that. We added to the list of flake8 ignores: H102: do not put vim info in source files H304: no relative imports Also updates and pins the following in the flake8 environment: pep8: 1.7.0 => drop (although hacking still pulls it in). pyflakes 1.1.0 => 1.5.0 hacking 0.10.2 => 0.13.0 flake8 2.5.4 => 3.3.0 pycodestyle none => 2.3.1
2017-05-23RHEL/CentOS: Fix dual stack IPv4/IPv6 configuration.Andreas Karis
Dual stack IPv4/IPv6 configuration via config drive is broken for RHEL7. This patch fixes several scenarios for IPv4/IPv6/dual-stack with multiple IP assignment. Removes usage of unpopular IPv4 alias files and invalid IPv6 alias files. Also fix associated unit tests. LP: #1679817 LP: #1685534 LP: #1685532
2017-05-22Fix get_interfaces_by_mac for empty macsScott Moser
Some interfaces (greptap0 in the bug) have a mac address of '00:00:00:00:00:00'. That was causing a duplicate mac detection as the 'lo' device also has that mac. The change here is to just ignore macs other than 'lo' that have that. LP: #1692028
2017-05-19netplan: pass macaddress, when specified, for vlansDimitri John Ledkov
When vlan mac address is specified in config, render it for netplan and for ENI. LP: #1690388