Skip to content

Commit 17efa60

Browse files
author
Max Rantil
committed
Make it able to bring your own OpenStack volume
Signed-off-by: Max Rantil <[email protected]>
1 parent 3ceeeae commit 17efa60

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

hack/ci/cloud-init/controller.yaml.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@
150150
openstack aggregate add host "$aggregateid" "$host"
151151
done
152152

153+
# Create the volume type and directly fetch the ID
154+
VOLUME_TYPE_NAME="test-volume-type"
155+
VOLUME_TYPE_ID=$(openstack volume type create --description "Test volume type" --public "${VOLUME_TYPE_NAME}" -f value -c id)
156+
if [[ ! -z "${VOLUME_TYPE_ID}" ]]; then
157+
echo "Volume type '${VOLUME_TYPE_NAME}' created successfully with ID: ${VOLUME_TYPE_ID}"
158+
else
159+
echo "Error: Failed to create volume type '${VOLUME_TYPE_NAME}'."
160+
fi
161+
153162
# the flavors are created in a way that we can execute at least 2 e2e tests in parallel (overall we have 32 vCPUs)
154163
openstack flavor delete m1.tiny
155164
openstack flavor create --ram 512 --disk 1 --ephemeral 1 --vcpus 1 --public --id 1 m1.tiny --property hw_rng:allowed='True'

test/e2e/suites/e2e/e2e_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestE2E(t *testing.T) {
5252

5353
var _ = SynchronizedBeforeSuite(func() []byte {
5454
data := shared.Node1BeforeSuite(e2eCtx)
55-
createTestVolumeType(e2eCtx)
55+
getVolumeType(e2eCtx)
5656
return data
5757
}, func(data []byte) {
5858
shared.AllNodesBeforeSuite(e2eCtx, data)

test/e2e/suites/e2e/e2e_test.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import (
5757
crclient "sigs.k8s.io/controller-runtime/pkg/client"
5858

5959
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8"
60-
capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors"
6160
"sigs.k8s.io/cluster-api-provider-openstack/test/e2e/shared"
6261
)
6362

@@ -891,23 +890,43 @@ func isCloudProviderInitialized(taints []corev1.Taint) bool {
891890
return true
892891
}
893892

894-
func createTestVolumeType(e2eCtx *shared.E2EContext) {
893+
func findVolumeTypeID(volumeClient *gophercloud.ServiceClient, volumeTypeName string) (string, error) {
894+
allPages, err := volumetypes.List(volumeClient, volumetypes.ListOpts{}).AllPages()
895+
if err != nil {
896+
return "", err
897+
}
898+
899+
allVolumeTypes, err := volumetypes.ExtractVolumeTypes(allPages)
900+
if err != nil {
901+
return "", err
902+
}
903+
904+
for _, volumeType := range allVolumeTypes {
905+
if volumeType.Name == volumeTypeName {
906+
return volumeType.ID, nil
907+
}
908+
}
909+
910+
return "", fmt.Errorf("volume type '%s' not found", volumeTypeName)
911+
}
912+
913+
func getVolumeType(e2eCtx *shared.E2EContext) {
895914
providerClient, clientOpts, _, err := shared.GetAdminProviderClient(e2eCtx)
896-
Expect(err).NotTo(HaveOccurred())
915+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to get admin provider client: %v", err))
897916

898917
volumeClient, err := openstack.NewBlockStorageV3(providerClient, gophercloud.EndpointOpts{Region: clientOpts.RegionName})
899-
Expect(err).NotTo(HaveOccurred())
900-
901-
shared.Logf("Creating test volume type")
902-
_, err = volumetypes.Create(volumeClient, &volumetypes.CreateOpts{
903-
Name: e2eCtx.E2EConfig.GetVariable(shared.OpenStackVolumeTypeAlt),
904-
Description: "Test volume type",
905-
IsPublic: pointer.Bool(true),
906-
ExtraSpecs: map[string]string{},
907-
}).Extract()
908-
if capoerrors.IsConflict(err) {
909-
shared.Logf("Volume type already exists. This may happen in development environments, but it is not expected in CI.")
910-
return
911-
}
912-
Expect(err).NotTo(HaveOccurred())
918+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to create volume client: %v", err))
919+
920+
volumeTypeName := e2eCtx.E2EConfig.GetVariable("OPENSTACK_VOLUME_TYPE_ALT")
921+
Expect(volumeTypeName).NotTo(BeEmpty(), "Volume type name must not be empty")
922+
923+
volumeTypeID, err := findVolumeTypeID(volumeClient, volumeTypeName)
924+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Error finding volume type '%s': %v", volumeTypeName, err))
925+
926+
shared.Logf("Found volume type ID '%s' for volume type '%s'", volumeTypeID, volumeTypeName)
927+
928+
_, err = volumetypes.Get(volumeClient, volumeTypeID).Extract()
929+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Error retrieving volume type with ID '%s': %v", volumeTypeID, err))
930+
931+
shared.Logf("Proceeding with volume type ID '%s'.", volumeTypeID)
913932
}

0 commit comments

Comments
 (0)