From 2541ec003037380c147a54799ad40804e2601c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulko?= Date: Thu, 16 Feb 2023 19:11:37 +0100 Subject: [PATCH] Fix test checking if Machine addresses match VMs The aforementioned test blindly tries to check all the Machines in the cluster, assuming each have a VM in OpenStack. That might not be true as in other tests we create Machines that are supposed to fail provisioning and never produce a VM. This commit fixes this by adding several precautions: * We only consider machines having addresses set in .status. * We skip machines without openstack-resourceId annotation. * We skip checking machines that do not have VM in OpenStack (could have been deleted between we fetched the Machines and did OpenStack query). --- test/extended/openstack/servers.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/extended/openstack/servers.go b/test/extended/openstack/servers.go index 2d392cd69..8f1a8effa 100644 --- a/test/extended/openstack/servers.go +++ b/test/extended/openstack/servers.go @@ -119,10 +119,15 @@ var _ = g.Describe("[sig-installer][Suite:openshift/openstack] The OpenStack pla // Fetch IP addresses of OpenStack instances corresponding to the machines for _, machine := range machines { machineName := machine.Get("metadata.name").String() - machineIPs[machineName] = getAddressesFromMachine(machine) + machineAddresses := getAddressesFromMachine(machine) + machineResourceID := machine.Get("metadata.annotations.openstack-resourceId").String() + if len(machineAddresses) == 0 || len(machineResourceID) == 0 { + // Only consider machines that have addresses and a VM in OpenStack. + continue + } g.By(fmt.Sprintf("Gather Openstack attributes for machine %q", machineName)) - instance, err := servers.Get(computeClient, machine.Get("metadata.annotations.openstack-resourceId").String()).Extract() + instance, err := servers.Get(computeClient, machineResourceID).Extract() var gerr gophercloud.ErrDefault404 if !errors.As(err, &gerr) { @@ -130,7 +135,12 @@ var _ = g.Describe("[sig-installer][Suite:openshift/openstack] The OpenStack pla instanceAddresses, err := parseInstanceAddresses(instance.Addresses) o.Expect(err).NotTo(o.HaveOccurred(), "Error parsing addresses for instance %q", instance.Name) openstackIPs[machineName] = instanceAddresses + } else { + // A VM for a Machine is missing from OpenStack. It's possible that the test which created the + // machine deleted it after we've fetched the list. + continue } + machineIPs[machineName] = machineAddresses } // Assert that the maps are equal, ignoring ordering within the map or of addresses