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

[EVS] V3 API Update #466

Draft
wants to merge 51 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
57353b0
Copy
Aloento Nov 2, 2022
1f1b77b
Replace
Aloento Nov 2, 2022
c1e8296
Replace
Aloento Nov 2, 2022
4d7b0c3
Create
Aloento Nov 2, 2022
bc69d51
Create
Aloento Nov 2, 2022
c77043b
Delete
Aloento Nov 2, 2022
3361565
Update
Aloento Nov 2, 2022
ac36160
Update
Aloento Nov 2, 2022
e8b0dbb
List
Aloento Nov 2, 2022
048589a
Get
Aloento Nov 2, 2022
676cc54
Test
Aloento Nov 2, 2022
7bb8570
extract
Aloento Nov 2, 2022
09a6f66
List
Aloento Nov 3, 2022
d20e07f
volumetypes
Aloento Nov 3, 2022
a67046a
move
Aloento Nov 3, 2022
c4c676a
reverse
Aloento Nov 3, 2022
70cfe31
move
Aloento Nov 3, 2022
bff1475
List
Aloento Nov 3, 2022
5dea94c
os-quota-sets
Aloento Nov 3, 2022
f04f739
List
Aloento Nov 3, 2022
eaafa7b
QuotaSet
Aloento Nov 3, 2022
a397d31
metadata
Aloento Nov 3, 2022
83c8394
Create
Aloento Nov 3, 2022
8621116
Get
Aloento Nov 3, 2022
57fa244
Update
Aloento Nov 3, 2022
da6e8de
One
Aloento Nov 3, 2022
90f815c
ListAvailabilityZone
Aloento Nov 3, 2022
a8f7485
ExtendSize
Aloento Nov 3, 2022
f8c9ccd
SetBootable
Aloento Nov 4, 2022
32721e0
SetReadonly
Aloento Nov 4, 2022
4738699
UploadImage
Aloento Nov 4, 2022
0ffd28f
clr
Aloento Nov 4, 2022
9256085
Create
Aloento Nov 4, 2022
26f1541
Delete
Aloento Nov 4, 2022
828854a
Update
Aloento Nov 4, 2022
00b9bd1
List
Aloento Nov 4, 2022
3fe9730
metadata unf
Aloento Nov 4, 2022
4b4036e
Get
Aloento Nov 7, 2022
4fbc771
snapshot_id
Aloento Nov 8, 2022
2a0f3e9
Create
Aloento Nov 8, 2022
ec20199
Delete
Aloento Nov 8, 2022
503fe5e
Get
Aloento Nov 8, 2022
85893ae
List
Aloento Nov 8, 2022
0e30094
test
Aloento Nov 8, 2022
ced95f3
test
Aloento Nov 8, 2022
29ba3d5
fix
Aloento Nov 8, 2022
0e0b02e
fix
Aloento Nov 9, 2022
d0cf3be
rm
Aloento Jan 4, 2023
3d6c6b0
mv
Aloento Jan 4, 2023
fe4fade
AvailabilityZone
Aloento Jan 4, 2023
5a313a0
VolumeTenantExt
Aloento Jan 5, 2023
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
11 changes: 7 additions & 4 deletions acceptance/openstack/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/blockstorage/v2/volumes"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/extensions"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/extensions/secgroups"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/ecs/v1/cloudservers"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/evs/v3/volumes"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/imageservice/v2/images"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v1/subnets"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
Expand Down Expand Up @@ -82,11 +82,11 @@ func CreateVolume(t *testing.T) *volumes.Volume {
Name: tools.RandomString("test-vol-", 6),
Size: 10,
VolumeType: "SSD",
}).Extract()
})
th.AssertNoErr(t, err)

err = golangsdk.WaitFor(300, func() (bool, error) {
volume, err := volumes.Get(client, vol.ID).Extract()
volume, err := volumes.Get(client, vol.ID)
if err != nil {
return false, err
}
Expand All @@ -106,7 +106,10 @@ func CreateVolume(t *testing.T) *volumes.Volume {
func DeleteVolume(t *testing.T, id string) {
client, err := clients.NewBlockStorageV3Client()
th.AssertNoErr(t, err)
th.AssertNoErr(t, volumes.Delete(client, id, volumes.DeleteOpts{Cascade: true}).ExtractErr())
th.AssertNoErr(t, volumes.Delete(client, volumes.DeleteOpts{
VolumeId: id,
Cascade: true,
}))
}

const (
Expand Down
79 changes: 79 additions & 0 deletions acceptance/openstack/compute/v2/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package v2

import (
"testing"
"time"

golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/flavors"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/images"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/servers"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func CreateServer(t *testing.T, client *golangsdk.ServiceClient) (*servers.Server, error) {
t.Logf("Attempting to create ECSv2")
ecsName := tools.RandomString("create-ecs-", 3)

az := clients.EnvOS.GetEnv("AVAILABILITY_ZONE")
if az == "" {
az = "eu-de-01"
}

networkID := clients.EnvOS.GetEnv("NETWORK_ID")
if networkID == "" {
t.Skip("OS_NETWORK_ID env var is missing but ECS test requires using existing network")
}

imageID, err := images.IDFromName(client, "Standard_Debian_10_latest")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this request fails by timeout

Copy link
Member Author

@Aloento Aloento Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot make request images.ListDetail: server no response.
hard to fix, still trying.

Copy link
Member Author

@Aloento Aloento Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot fix now, do it in another PR.
because API discarded and not working.

th.AssertNoErr(t, err)

flavorID, err := flavors.IDFromName(client, "s2.large.2")
th.AssertNoErr(t, err)

ecs, err := servers.Create(client, servers.CreateOpts{
Name: ecsName,
ImageRef: imageID,
FlavorRef: flavorID,
SecurityGroups: []string{
openstack.DefaultSecurityGroup(t),
},
AvailabilityZone: az,
Networks: []servers.Network{
{
UUID: networkID,
},
},
}).Extract()
th.AssertNoErr(t, err)

err = servers.WaitForStatus(client, ecs.ID, "ACTIVE", 1200)
th.AssertNoErr(t, err)
t.Logf("Created ECSv2: %s", ecs.ID)
return ecs, err
}

func DeleteServer(t *testing.T, client *golangsdk.ServiceClient, ecs *servers.Server) {
t.Logf("Attempting to delete ECSv2: %s", ecs.ID)

_, err := servers.Delete(client, ecs.ID).ExtractJobResponse()
th.AssertNoErr(t, err)

err = golangsdk.WaitFor(1200, func() (bool, error) {
_, err := servers.Get(client, ecs.ID).Extract()
if err != nil {
if _, ok := err.(golangsdk.ErrDefault400); ok {
time.Sleep(10 * time.Second)
return false, nil
}
return false, err
}
return true, nil
})
th.AssertNoErr(t, err)

t.Logf("ECSv2 instance deleted: %s", ecs.ID)
}
82 changes: 7 additions & 75 deletions acceptance/openstack/compute/v2/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ package v2

import (
"testing"
"time"

"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/flavors"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/images"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/servers"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)
Expand All @@ -34,85 +29,22 @@ func TestServerLifecycle(t *testing.T) {
client, err := clients.NewComputeV2Client()
th.AssertNoErr(t, err)

t.Logf("Attempting to create ECSv2")
ecsName := tools.RandomString("create-ecs-", 3)

az := clients.EnvOS.GetEnv("AVAILABILITY_ZONE")
if az == "" {
az = "eu-de-01"
}

networkID := clients.EnvOS.GetEnv("NETWORK_ID")
if networkID == "" {
t.Skip("OS_NETWORK_ID env var is missing but ECS test requires using existing network")
}

imageID, err := images.IDFromName(client, "Standard_Debian_10_latest")
th.AssertNoErr(t, err)

flavorID, err := flavors.IDFromName(client, "s2.large.2")
th.AssertNoErr(t, err)

createOpts := servers.CreateOpts{
Name: ecsName,
ImageRef: imageID,
FlavorRef: flavorID,
SecurityGroups: []string{
openstack.DefaultSecurityGroup(t),
},
AvailabilityZone: az,
Networks: []servers.Network{
{
UUID: networkID,
},
},
}

ecs, err := servers.Create(client, createOpts).Extract()
ecs, err := CreateServer(t, client)
th.AssertNoErr(t, err)

err = servers.WaitForStatus(client, ecs.ID, "ACTIVE", 1200)
th.AssertNoErr(t, err)
t.Logf("Created ECSv2: %s", ecs.ID)

ecs, err = servers.Get(client, ecs.ID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, ecsName, ecs.Name)
t.Cleanup(func() {
DeleteServer(t, client, ecs)
})

nicInfo, err := servers.GetNICs(client, ecs.ID).Extract()
th.AssertNoErr(t, err)
tools.PrintResource(t, nicInfo)

defer func() {
t.Logf("Attempting to delete ECSv2: %s", ecs.ID)

_, err := servers.Delete(client, ecs.ID).ExtractJobResponse()
th.AssertNoErr(t, err)

err = golangsdk.WaitFor(1200, func() (bool, error) {
_, err := servers.Get(client, ecs.ID).Extract()
if err != nil {
if _, ok := err.(golangsdk.ErrDefault400); ok {
time.Sleep(10 * time.Second)
return false, nil
}
return false, err
}
return true, nil
})
th.AssertNoErr(t, err)

t.Logf("ECSv2 instance deleted: %s", ecs.ID)
}()

t.Logf("Attempting to update ECSv2: %s", ecs.ID)

ecsName = tools.RandomString("update-ecs-", 3)
updateOpts := servers.UpdateOpts{
ecsName := tools.RandomString("update-ecs-", 3)
_, err = servers.Update(client, ecs.ID, servers.UpdateOpts{
Name: ecsName,
}

_, err = servers.Update(client, ecs.ID, updateOpts).Extract()
}).Extract()
th.AssertNoErr(t, err)

t.Logf("ECSv2 successfully updated: %s", ecs.ID)
Expand Down
167 changes: 167 additions & 0 deletions acceptance/openstack/evs/v3/blockstorage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package v3

import (
"testing"

golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/evs/v3/snapshots"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/evs/v3/volumes"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/evs/v3/volumetypes"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

// CreateSnapshot will create a snapshot of the specified volume.
// Snapshot will be assigned a random name and description.
func CreateSnapshot(t *testing.T, client *golangsdk.ServiceClient, volume *volumes.Volume) (*snapshots.Snapshot, error) {
snapshotName := tools.RandomString("ACPTTEST", 16)
snapshotDescription := tools.RandomString("ACPTTEST", 16)
t.Logf("Attempting to create snapshot: %s", snapshotName)

createOpts := snapshots.CreateOpts{
VolumeID: volume.ID,
Name: snapshotName,
Description: snapshotDescription,
}

snapshot, err := snapshots.Create(client, createOpts)
if err != nil {
return snapshot, err
}

err = snapshots.WaitForStatus(client, snapshot.ID, "available", 60)
if err != nil {
return snapshot, err
}

tools.PrintResource(t, snapshot)
th.AssertEquals(t, snapshot.Name, snapshotName)
th.AssertEquals(t, snapshot.VolumeID, volume.ID)

t.Logf("Successfully created snapshot: %s", snapshot.ID)

return snapshot, nil
}

// CreateVolume will create a volume with a random name and size of 1GB. An
// error will be returned if the volume was unable to be created.
func CreateVolume(t *testing.T, client *golangsdk.ServiceClient) (*volumes.Volume, error) {
volumeName := tools.RandomString("ACPTTEST", 16)
volumeDescription := tools.RandomString("ACPTTEST-DESC", 16)
t.Logf("Attempting to create volume: %s", volumeName)

createOpts := volumes.CreateOpts{
Size: 1,
Name: volumeName,
Description: volumeDescription,
}

volume, err := volumes.Create(client, createOpts)
if err != nil {
return volume, err
}

err = volumes.WaitForStatus(client, volume.ID, "available", 60)
if err != nil {
return volume, err
}

tools.PrintResource(t, volume)
th.AssertEquals(t, volume.Name, volumeName)
th.AssertEquals(t, volume.Description, volumeDescription)
th.AssertEquals(t, volume.Size, 1)

t.Logf("Successfully created volume: %s", volume.ID)

return volume, nil
}

// CreateVolumeWithType will create a volume of the given volume type
// with a random name and size of 1GB. An error will be returned if
// the volume was unable to be created.
func CreateVolumeWithType(t *testing.T, client *golangsdk.ServiceClient, vt *volumetypes.VolumeType) (*volumes.Volume, error) {
volumeName := tools.RandomString("ACPTTEST", 16)
volumeDescription := tools.RandomString("ACPTTEST-DESC", 16)
t.Logf("Attempting to create volume: %s", volumeName)

createOpts := volumes.CreateOpts{
Size: 1,
Name: volumeName,
Description: volumeDescription,
VolumeType: vt.Name,
}

volume, err := volumes.Create(client, createOpts)
if err != nil {
return volume, err
}

err = volumes.WaitForStatus(client, volume.ID, "available", 60)
if err != nil {
return volume, err
}

tools.PrintResource(t, volume)
th.AssertEquals(t, volume.Name, volumeName)
th.AssertEquals(t, volume.Description, volumeDescription)
th.AssertEquals(t, volume.Size, 1)
th.AssertEquals(t, volume.VolumeType, vt.Name)

t.Logf("Successfully created volume: %s", volume.ID)

return volume, nil
}

// DeleteSnapshot will delete a snapshot. A fatal error will occur if the
// snapshot failed to be deleted.
func DeleteSnapshot(t *testing.T, client *golangsdk.ServiceClient, snapshot *snapshots.Snapshot) {
err := snapshots.Delete(client, snapshot.ID)
if err != nil {
t.Fatalf("Unable to delete snapshot %s: %+v", snapshot.ID, err)
}

// Volumes can't be deleted until their snapshots have been,
// so block until the snapshot as been deleted.
err = tools.WaitFor(func() (bool, error) {
_, err := snapshots.Get(client, snapshot.ID)
if err != nil {
return true, nil
}

return false, nil
})
if err != nil {
t.Fatalf("Error waiting for snapshot to delete: %v", err)
}

t.Logf("Deleted snapshot: %s", snapshot.ID)
}

// DeleteVolume will delete a volume. A fatal error will occur if the volume
// failed to be deleted. This works best when used as a deferred function.
func DeleteVolume(t *testing.T, client *golangsdk.ServiceClient, volume *volumes.Volume) {
t.Logf("Attempting to delete volume: %s", volume.ID)

err := volumes.Delete(client, volumes.DeleteOpts{
VolumeId: volume.ID,
})
if err != nil {
t.Fatalf("Unable to delete volume %s: %v", volume.ID, err)
}

// VolumeTypes can't be deleted until their volumes have been,
// so block until the volume is deleted.
err = tools.WaitFor(func() (bool, error) {
_, err := volumes.Get(client, volume.ID)
if err != nil {
return true, nil
}

return false, nil
})
if err != nil {
t.Fatalf("Error waiting for volume to delete: %v", err)
}

t.Logf("Successfully deleted volume: %s", volume.ID)
}
Loading