client/test: add test for VLANs on OCI

This commit is contained in:
Lubomir Rintel
2024-12-03 10:48:13 +01:00
parent 6ff4b9e57c
commit 9b258faab4

View File

@@ -2801,6 +2801,115 @@ 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.expelliarmus"
},
{
"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, just no changes this time
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")
nmc.pexp.expect("no changes were applied for provider oci")
nmc.pexp.expect(pexpect.EOF)
Util.valgrind_check_log(nmc.valgrind_log, "test_oci_vlans")
###############################################################################