Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat.] random az support for instance creation #745

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acceptance/openstack/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func GetCloudServerCreateOpts(t *testing.T) cloudservers.CreateOpts {
},
},
},
AvailabilityZone: az,
AvailabilityZone: &az,
}

return createOpts
Expand Down
74 changes: 74 additions & 0 deletions acceptance/openstack/ecs/v1/cloudservers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/ecs/v1/cloudservers"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/ims/v2/images"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

Expand Down Expand Up @@ -40,3 +42,75 @@ func TestCloudServerLifecycle(t *testing.T) {

tools.PrintResource(t, ecs)
}

func TestCloudServersRandomAzLifecycle(t *testing.T) {
client, err := clients.NewComputeV1Client()
th.AssertNoErr(t, err)

prefix := "ecs-"
ecsName := tools.RandomString(prefix, 3)
imageName := "Standard_Debian_11_latest"
flavorID := "s3.large.2"

vpcID := clients.EnvOS.GetEnv("VPC_ID")
subnetID := clients.EnvOS.GetEnv("NETWORK_ID")

imageV2Client, err := clients.NewIMSV2Client()
th.AssertNoErr(t, err)

image, err := images.ListImages(imageV2Client, images.ListImagesOpts{
Name: imageName,
})
th.AssertNoErr(t, err)
if len(image) == 0 {
t.Skip("Change image query filter, no results returned")
}
if vpcID == "" || subnetID == "" {
t.Skip("One of OS_VPC_ID, OS_NETWORK_ID env vars is missing but ECSv1 test requires")
}

// Get ECSv1 createOpts
createOpts := cloudservers.CreateOpts{
ImageRef: image[0].Id,
FlavorRef: flavorID,
Name: ecsName,
VpcId: vpcID,
Nics: []cloudservers.Nic{
{
SubnetId: subnetID,
},
},
RootVolume: cloudservers.RootVolume{
VolumeType: "SSD",
},
DataVolumes: []cloudservers.DataVolume{
{
VolumeType: "SSD",
Size: 20,
},
},
}

// Check ECSv1 createOpts
openstack.DryRunCloudServerConfig(t, client, createOpts)
t.Logf("CreateOpts are ok for creating a cloudServer")

// Create ECSv1 instance
ecs := openstack.CreateCloudServer(t, client, createOpts)
defer openstack.DeleteCloudServer(t, client, ecs.ID)

tagsList := []tags.ResourceTag{
{
Key: "TestKey",
Value: "TestValue",
},
{
Key: "empty",
Value: "",
},
}
err = tags.Create(client, "cloudservers", ecs.ID, tagsList).ExtractErr()
th.AssertNoErr(t, err)

tools.PrintResource(t, ecs)
}
2 changes: 1 addition & 1 deletion acceptance/openstack/networking/v1/routetables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestRouteTablesLifecycle(t *testing.T) {
Size: 40,
},
},
AvailabilityZone: az,
AvailabilityZone: &az,
}
t.Logf("Attempting to create cloud server: %s", sererName)
ecs := openstack.CreateCloudServer(t, clientCompute, createEcsOpts)
Expand Down
5 changes: 4 additions & 1 deletion openstack/ecs/v1/cloudservers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type CreateOpts struct {
SecurityGroups []SecurityGroup `json:"security_groups,omitempty"`

// AvailabilityZone specifies name of the AZ where the ECS is located.
AvailabilityZone string `json:"availability_zone" required:"true"`
AvailabilityZone *string `json:"availability_zone,omitempty"`

// ExtendParam provides the supplementary information about the ECS to be created.
ExtendParam *ServerExtendParam `json:"extendparam,omitempty"`
Expand All @@ -64,6 +64,9 @@ type CreateOpts struct {
Tags []string `json:"tags,omitempty"`

ServerTags []ServerTags `json:"server_tags,omitempty"`

// Specifies whether ECSs can be deployed in multiple random AZs. The default value is false.
CreateInMultiAz *bool `json:"batch_create_in_multi_az,omitempty"`
}

// CreateOptsBuilder allows extensions to add additional parameters to the
Expand Down