From 692cdf1ed673ad111ad4d28086f8b6c44ca8b6d8 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 3 Dec 2024 10:48:13 +0100 Subject: [PATCH] FIXME test/client: add test for VLANs on OCI XXX Two FIXMEs need addressing!!! --- src/nm-cloud-setup/main.c | 4 ++ src/tests/client/test-client.py | 110 ++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c index 5fc5dc04df..f4cc53085f 100644 --- a/src/nm-cloud-setup/main.c +++ b/src/nm-cloud-setup/main.c @@ -442,6 +442,10 @@ _nmc_mangle_connection(NMDevice *device, guint len; guint j; + // FIXME: + // We don't check if the connection already contains the addrs/routes/rules we're + // about to add are already present. We should! + len = nm_setting_ip_config_get_num_addresses(remote_s_ip); for (j = 0; j < len; j++) { g_ptr_array_add(addrs_new, diff --git a/src/tests/client/test-client.py b/src/tests/client/test-client.py index 785df5054f..346206146b 100755 --- a/src/tests/client/test-client.py +++ b/src/tests/client/test-client.py @@ -2795,6 +2795,116 @@ class TestNmCloudSetup(unittest.TestCase): Util.valgrind_check_log(nmc.valgrind_log, "test_oci") + @cloud_setup_test + def test_oci_vlans(self): + self._mock_devices() + + oci_meta = "/opc/v2/" + self._mock_path(oci_meta + "instance", "{}") + self._mock_path( + oci_meta + "vnics", + """ + [ + { + "macAddr": "%s", + "privateIp": "%s", + "subnetCidrBlock": "172.31.16.0/20", + "virtualRouterIp": "172.31.16.1", + "vlanTag": 0, + "nicIndex": 0, + "vnicId": "ocid1.vnic.oc1.cz-adamov1.foobarbaz" + }, + { + "macAddr": "%s", + "privateIp": "%s", + "subnetCidrBlock": "172.31.166.0/20", + "virtualRouterIp": "172.31.166.1", + "vlanTag": 0, + "nicIndex": 1, + "vnicId": "ocid1.vnic.oc1.uk-hogwarts.abracadabra" + }, + { + "macAddr": "C0:00:00:00:00:10", + "privateIp": "172.31.10.10", + "subnetCidrBlock": "172.31.10.0/20", + "virtualRouterIp": "172.31.10.1", + "vlanTag": 700, + "nicIndex": 0, + "vnicId": "ocid1.vnic.oc1.uk-hogwarts.keka" + } + ] + """ + % ( + TestNmCloudSetup._mac1, + TestNmCloudSetup._ip1, + TestNmCloudSetup._mac2, + TestNmCloudSetup._ip2, + ), + ) + + # Run nm-cloud-setup for the first time + nmc = Util.cmd_call_pexpect( + ENV_NM_TEST_CLIENT_CLOUD_SETUP_PATH, + [], + { + "NM_CLOUD_SETUP_OCI_HOST": self.md_url, + "NM_CLOUD_SETUP_LOG": "trace", + "NM_CLOUD_SETUP_OCI": "yes", + }, + ) + + nmc.pexp.expect("provider oci detected") + nmc.pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02") + nmc.pexp.expect("get-config: starting") + nmc.pexp.expect("get-config: success") + nmc.pexp.expect("meta data received") + + # No configuration for the ethernets + nmc.pexp.expect('configuring "eth0"') + nmc.pexp.expect("device has no suitable applied connection. Skip") + + # Setting up the VLAN + nmc.pexp.expect( + "creating macvlan2 connection for VLAN 700 on CC:00:00:00:00:01..." + ) + nmc.pexp.expect("creating vlan connection for VLAN 700 on C0:00:00:00:00:10...") + + nmc.pexp.expect("some changes were applied for provider oci") + nmc.pexp.expect(pexpect.EOF) + + # TODO: Actually check the contents of the connection + # Probably needs changes to the mock service API + conn_macvlan = self.ctx.srv.findConnections(con_id="connection-3") + assert conn_macvlan is not None + conn_vlan = self.ctx.srv.findConnections(con_id="connection-4") + assert conn_vlan is not None + + # Run nm-cloud-setup for the second time + nmc = Util.cmd_call_pexpect( + ENV_NM_TEST_CLIENT_CLOUD_SETUP_PATH, + [], + { + "NM_CLOUD_SETUP_OCI_HOST": self.md_url, + "NM_CLOUD_SETUP_LOG": "trace", + "NM_CLOUD_SETUP_OCI": "yes", + }, + ) + + # Just the same ol' thing + nmc.pexp.expect("provider oci detected") + nmc.pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02") + nmc.pexp.expect("get-config: starting") + nmc.pexp.expect("get-config: success") + nmc.pexp.expect("meta data received") + nmc.pexp.expect('configuring "eth0"') + nmc.pexp.expect("device has no suitable applied connection. Skip") + + # FIXME: we should be having applying nothing here! + nmc.pexp.expect("some changes were applied for provider oci") + nmc.pexp.expect(pexpect.EOF) + + Util.valgrind_check_log(nmc.valgrind_log, "test_oci_vlans") + ###############################################################################