func TestBootFromNewVolume(t *testing.T) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } blockDevices := []bootfromvolume.BlockDevice{ bootfromvolume.BlockDevice{ DeleteOnTermination: true, DestinationType: bootfromvolume.DestinationVolume, SourceType: bootfromvolume.SourceImage, UUID: choices.ImageID, VolumeSize: 2, }, } server, err := CreateBootableVolumeServer(t, client, blockDevices, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, client, server) PrintServer(t, server) }
func TestServersActionChangeAdminPassword(t *testing.T) { t.Parallel() client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatal(err) } defer DeleteServer(t, client, server) randomPassword := tools.MakeNewPassword(server.AdminPass) res := servers.ChangeAdminPassword(client, server.ID, randomPassword) if res.Err != nil { t.Fatal(res.Err) } if err = WaitForComputeStatus(client, server, "PASSWORD"); err != nil { t.Fatal(err) } if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { t.Fatal(err) } }
// CreateExternalRouter creates a router on the external network. This requires // the OS_EXTGW_ID environment variable to be set. An error is returned if the // creation failed. func CreateExternalRouter(t *testing.T, client *gophercloud.ServiceClient) (*routers.Router, error) { var router *routers.Router choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { return router, err } routerName := tools.RandomString("TESTACC-", 8) t.Logf("Attempting to create external router: %s", routerName) adminStateUp := true gatewayInfo := routers.GatewayInfo{ NetworkID: choices.ExternalNetworkID, } createOpts := routers.CreateOpts{ Name: routerName, AdminStateUp: &adminStateUp, GatewayInfo: &gatewayInfo, } router, err = routers.Create(client, createOpts).Extract() if err != nil { return router, err } if err := WaitForRouterToCreate(client, router.ID, 60); err != nil { return router, err } t.Logf("Created router: %s", routerName) return router, nil }
func TestServersActionResizeRevert(t *testing.T) { t.Parallel() choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatal(err) } defer DeleteServer(t, client, server) t.Logf("Attempting to resize server %s", server.ID) ResizeServer(t, client, server, choices) t.Logf("Attempting to revert resize for server %s", server.ID) if res := servers.RevertResize(client, server.ID); res.Err != nil { t.Fatal(res.Err) } if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { t.Fatal(err) } }
func TestFloatingIPsFixedIPAssociate(t *testing.T) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, client, server) newServer, err := servers.Get(client, server.ID).Extract() if err != nil { t.Fatalf("Unable to get server %s: %v", server.ID, err) } floatingIP, err := CreateFloatingIP(t, client, choices) if err != nil { t.Fatalf("Unable to create floating IP: %v", err) } defer DeleteFloatingIP(t, client, floatingIP) PrintFloatingIP(t, floatingIP) var fixedIP string for _, networkAddresses := range newServer.Addresses[choices.NetworkName].([]interface{}) { address := networkAddresses.(map[string]interface{}) if address["OS-EXT-IPS:type"] == "fixed" { if address["version"].(float64) == 4 { fixedIP = address["addr"].(string) } } } err = AssociateFloatingIPWithFixedIP(t, client, floatingIP, newServer, fixedIP) if err != nil { t.Fatalf("Unable to associate floating IP %s with server %s: %v", floatingIP.IP, newServer.ID, err) } defer DisassociateFloatingIP(t, client, floatingIP, newServer) newFloatingIP, err := floatingips.Get(client, floatingIP.ID).Extract() if err != nil { t.Fatalf("Unable to get floating IP %s: %v", floatingIP.ID, err) } t.Logf("Floating IP %s is associated with Fixed IP %s", floatingIP.IP, newFloatingIP.FixedIP) PrintFloatingIP(t, newFloatingIP) }
func TestLayer3FloatingIPsCreateDelete(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatalf("Unable to get choices: %v", err) } subnet, err := networking.CreateSubnet(t, client, choices.ExternalNetworkID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) router, err := CreateExternalRouter(t, client) if err != nil { t.Fatalf("Unable to create router: %v", err) } defer DeleteRouter(t, client, router.ID) port, err := networking.CreatePort(t, client, choices.ExternalNetworkID, subnet.ID) if err != nil { t.Fatalf("Unable to create port: %v", err) } _, err = CreateRouterInterface(t, client, port.ID, router.ID) if err != nil { t.Fatalf("Unable to create router interface: %v", err) } defer DeleteRouterInterface(t, client, port.ID, router.ID) fip, err := CreateFloatingIP(t, client, choices.ExternalNetworkID, port.ID) if err != nil { t.Fatalf("Unable to create floating IP: %v", err) } defer DeleteFloatingIP(t, client, fip.ID) newFip, err := floatingips.Get(client, fip.ID).Extract() if err != nil { t.Fatalf("Unable to get floating ip: %v", err) } PrintFloatingIP(t, newFip) // Disassociate the floating IP updateOpts := floatingips.UpdateOpts{ PortID: nil, } newFip, err = floatingips.Update(client, fip.ID, updateOpts).Extract() if err != nil { t.Fatalf("Unable to disassociate floating IP: %v", err) } }
func TestServersCreateDestroy(t *testing.T) { client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, client, server) newServer, err := servers.Get(client, server.ID).Extract() if err != nil { t.Errorf("Unable to retrieve server: %v", err) } PrintServer(t, newServer) allAddressPages, err := servers.ListAddresses(client, server.ID).AllPages() if err != nil { t.Errorf("Unable to list server addresses: %v", err) } allAddresses, err := servers.ExtractAddresses(allAddressPages) if err != nil { t.Errorf("Unable to extract server addresses: %v", err) } for network, address := range allAddresses { t.Logf("Addresses on %s: %+v", network, address) } allNetworkAddressPages, err := servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName).AllPages() if err != nil { t.Errorf("Unable to list server addresses: %v", err) } allNetworkAddresses, err := servers.ExtractNetworkAddresses(allNetworkAddressPages) if err != nil { t.Errorf("Unable to extract server addresses: %v", err) } t.Logf("Addresses on %s:", choices.NetworkName) for _, address := range allNetworkAddresses { t.Logf("%+v", address) } }
func TestBootFromMultiEphemeralServer(t *testing.T) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } blockDevices := []bootfromvolume.BlockDevice{ bootfromvolume.BlockDevice{ BootIndex: 0, DestinationType: bootfromvolume.DestinationLocal, DeleteOnTermination: true, SourceType: bootfromvolume.SourceImage, UUID: choices.ImageID, VolumeSize: 5, }, bootfromvolume.BlockDevice{ BootIndex: -1, DestinationType: bootfromvolume.DestinationLocal, DeleteOnTermination: true, GuestFormat: "ext4", SourceType: bootfromvolume.SourceBlank, VolumeSize: 1, }, bootfromvolume.BlockDevice{ BootIndex: -1, DestinationType: bootfromvolume.DestinationLocal, DeleteOnTermination: true, GuestFormat: "ext4", SourceType: bootfromvolume.SourceBlank, VolumeSize: 1, }, } server, err := CreateMultiEphemeralServer(t, client, blockDevices, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, client, server) PrintServer(t, server) }
func TestAttachExistingVolume(t *testing.T) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } computeClient, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } blockStorageClient, err := clients.NewBlockStorageV2Client() if err != nil { t.Fatalf("Unable to create a block storage client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } volume, err := blockstorage.CreateVolume(t, blockStorageClient) if err != nil { t.Fatal(err) } blockDevices := []bootfromvolume.BlockDevice{ bootfromvolume.BlockDevice{ BootIndex: 0, DeleteOnTermination: true, DestinationType: bootfromvolume.DestinationLocal, SourceType: bootfromvolume.SourceImage, UUID: choices.ImageID, }, bootfromvolume.BlockDevice{ BootIndex: 1, DeleteOnTermination: true, DestinationType: bootfromvolume.DestinationVolume, SourceType: bootfromvolume.SourceVolume, UUID: volume.ID, }, } server, err := CreateBootableVolumeServer(t, computeClient, blockDevices, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, computeClient, server) PrintServer(t, server) }
func TestServersUpdate(t *testing.T) { client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatal(err) } defer DeleteServer(t, client, server) alternateName := tools.RandomString("ACPTTEST", 16) for alternateName == server.Name { alternateName = tools.RandomString("ACPTTEST", 16) } t.Logf("Attempting to rename the server to %s.", alternateName) updateOpts := servers.UpdateOpts{ Name: alternateName, } updated, err := servers.Update(client, server.ID, updateOpts).Extract() if err != nil { t.Fatalf("Unable to rename server: %v", err) } if updated.ID != server.ID { t.Errorf("Updated server ID [%s] didn't match original server ID [%s]!", updated.ID, server.ID) } err = tools.WaitFor(func() (bool, error) { latest, err := servers.Get(client, updated.ID).Extract() if err != nil { return false, err } return latest.Name == alternateName, nil }) }
func TestLayer3RouterInterface(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatalf("Unable to get choices: %v", err) } subnet, err := networking.CreateSubnet(t, client, choices.ExternalNetworkID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) networking.PrintSubnet(t, subnet) router, err := CreateExternalRouter(t, client) if err != nil { t.Fatalf("Unable to create router: %v", err) } defer DeleteRouter(t, client, router.ID) aiOpts := routers.AddInterfaceOpts{ SubnetID: subnet.ID, } iface, err := routers.AddInterface(client, router.ID, aiOpts).Extract() if err != nil { t.Fatalf("Failed to add interface to router: %v", err) } PrintRouter(t, router) PrintRouterInterface(t, iface) riOpts := routers.RemoveInterfaceOpts{ SubnetID: subnet.ID, } _, err = routers.RemoveInterface(client, router.ID, riOpts).Extract() if err != nil { t.Fatalf("Failed to remove interface from router: %v", err) } }
func TestSecGroupsAddGroupToServer(t *testing.T) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, client, server) securityGroup, err := CreateSecurityGroup(t, client) if err != nil { t.Fatalf("Unable to create security group: %v", err) } defer DeleteSecurityGroup(t, client, securityGroup) rule, err := CreateSecurityGroupRule(t, client, securityGroup.ID) if err != nil { t.Fatalf("Unable to create rule: %v", err) } defer DeleteSecurityGroupRule(t, client, rule) t.Logf("Adding group %s to server %s", securityGroup.ID, server.ID) err = secgroups.AddServer(client, server.ID, securityGroup.Name).ExtractErr() if err != nil && err.Error() != "EOF" { t.Fatalf("Unable to add group %s to server %s: %s", securityGroup.ID, server.ID, err) } t.Logf("Removing group %s from server %s", securityGroup.ID, server.ID) err = secgroups.RemoveServer(client, server.ID, securityGroup.Name).ExtractErr() if err != nil && err.Error() != "EOF" { t.Fatalf("Unable to remove group %s from server %s: %s", securityGroup.ID, server.ID, err) } }
func TestVolumeAttachAttachment(t *testing.T) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } blockClient, err := clients.NewBlockStorageV1Client() if err != nil { t.Fatalf("Unable to create a blockstorage client: %v", err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, client, server) volume, err := createVolume(t, blockClient) if err != nil { t.Fatalf("Unable to create volume: %v", err) } if err = volumes.WaitForStatus(blockClient, volume.ID, "available", 60); err != nil { t.Fatalf("Unable to wait for volume: %v", err) } defer deleteVolume(t, blockClient, volume) volumeAttachment, err := CreateVolumeAttachment(t, client, blockClient, server, volume) if err != nil { t.Fatalf("Unable to attach volume: %v", err) } defer DeleteVolumeAttachment(t, client, blockClient, server, volumeAttachment) PrintVolumeAttachment(t, volumeAttachment) }
func TestImagesGet(t *testing.T) { client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute: client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } image, err := images.Get(client, choices.ImageID).Extract() if err != nil { t.Fatalf("Unable to get image information: %v", err) } PrintImage(t, *image) }
func TestFlavorsGet(t *testing.T) { client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } flavor, err := flavors.Get(client, choices.FlavorID).Extract() if err != nil { t.Fatalf("Unable to get flavor information: %v", err) } PrintFlavor(t, flavor) }
func TestServersActionRebuild(t *testing.T) { t.Parallel() client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatal(err) } defer DeleteServer(t, client, server) t.Logf("Attempting to rebuild server %s", server.ID) rebuildOpts := servers.RebuildOpts{ Name: tools.RandomString("ACPTTEST", 16), AdminPass: tools.MakeNewPassword(server.AdminPass), ImageID: choices.ImageID, } rebuilt, err := servers.Rebuild(client, server.ID, rebuildOpts).Extract() if err != nil { t.Fatal(err) } if rebuilt.ID != server.ID { t.Errorf("Expected rebuilt server ID of [%s]; got [%s]", server.ID, rebuilt.ID) } if err = WaitForComputeStatus(client, rebuilt, "REBUILD"); err != nil { t.Fatal(err) } if err = WaitForComputeStatus(client, rebuilt, "ACTIVE"); err != nil { t.Fatal(err) } }
func TestFloatingIPsAssociate(t *testing.T) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, client, server) floatingIP, err := CreateFloatingIP(t, client, choices) if err != nil { t.Fatalf("Unable to create floating IP: %v", err) } defer DeleteFloatingIP(t, client, floatingIP) PrintFloatingIP(t, floatingIP) err = AssociateFloatingIP(t, client, floatingIP, server) if err != nil { t.Fatalf("Unable to associate floating IP %s with server %s: %v", floatingIP.IP, server.ID, err) } defer DisassociateFloatingIP(t, client, floatingIP, server) newFloatingIP, err := floatingips.Get(client, floatingIP.ID).Extract() if err != nil { t.Fatalf("Unable to get floating IP %s: %v", floatingIP.ID, err) } t.Logf("Floating IP %s is associated with Fixed IP %s", floatingIP.IP, newFloatingIP.FixedIP) PrintFloatingIP(t, newFloatingIP) }
func TestFloatingIPsCreate(t *testing.T) { client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } floatingIP, err := CreateFloatingIP(t, client, choices) if err != nil { t.Fatalf("Unable to create floating IP: %v", err) } defer DeleteFloatingIP(t, client, floatingIP) PrintFloatingIP(t, floatingIP) }
func TestServersWithoutImageRef(t *testing.T) { client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServerWithoutImageRef(t, client, choices) if err != nil { if err400, ok := err.(*gophercloud.ErrUnexpectedResponseCode); ok { if !strings.Contains("Missing imageRef attribute", string(err400.Body)) { defer DeleteServer(t, client, server) } } } }
func TestKeypairsServerCreateWithKey(t *testing.T) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } publicKey, err := createKey() if err != nil { t.Fatalf("Unable to create public key: %s", err) } keyPair, err := ImportPublicKey(t, client, publicKey) if err != nil { t.Fatalf("Unable to create keypair: %s", err) } defer DeleteKeyPair(t, client, keyPair) server, err := CreateServerWithPublicKey(t, client, choices, keyPair.Name) if err != nil { t.Fatalf("Unable to create server: %s", err) } defer DeleteServer(t, client, server) server, err = servers.Get(client, server.ID).Extract() if err != nil { t.Fatalf("Unable to retrieve server: %s", err) } if server.KeyName != keyPair.Name { t.Fatalf("key name of server %s is %s, not %s", server.ID, server.KeyName, keyPair.Name) } }
func TestServergroupsAffinityPolicy(t *testing.T) { client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } serverGroup, err := CreateServerGroup(t, client, "affinity") if err != nil { t.Fatalf("Unable to create server group: %v", err) } defer DeleteServerGroup(t, client, serverGroup) firstServer, err := CreateServerInServerGroup(t, client, choices, serverGroup) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer DeleteServer(t, client, firstServer) firstServer, err = servers.Get(client, firstServer.ID).Extract() secondServer, err := CreateServerInServerGroup(t, client, choices, serverGroup) if err != nil { t.Fatalf("Unable to create server: %v", err) } if err = WaitForComputeStatus(client, secondServer, "ACTIVE"); err != nil { t.Fatalf("Unable to wait for server: %v", err) } defer DeleteServer(t, client, secondServer) secondServer, err = servers.Get(client, secondServer.ID).Extract() if firstServer.HostID != secondServer.HostID { t.Fatalf("%s and %s were not scheduled on the same host.", firstServer.ID, secondServer.ID) } }
func TestVolumeActionsAttachCreateDestroy(t *testing.T) { blockClient, err := clients.NewBlockStorageV2Client() if err != nil { t.Fatalf("Unable to create a blockstorage client: %v", err) } computeClient, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := compute.CreateServer(t, computeClient, choices) if err != nil { t.Fatalf("Unable to create server: %v", err) } defer compute.DeleteServer(t, computeClient, server) volume, err := blockstorage.CreateVolume(t, blockClient) if err != nil { t.Fatalf("Unable to create volume: %v", err) } defer blockstorage.DeleteVolume(t, blockClient, volume) err = CreateVolumeAttach(t, blockClient, volume, server) if err != nil { t.Fatalf("Unable to attach volume: %v", err) } newVolume, err := volumes.Get(blockClient, volume.ID).Extract() if err != nil { t.Fatal("Unable to get updated volume information: %v", err) } DeleteVolumeAttach(t, blockClient, newVolume) }
func TestTenantNetworksGet(t *testing.T) { choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) if err != nil { t.Fatal(err) } network, err := tenantnetworks.Get(client, networkID).Extract() if err != nil { t.Fatalf("Unable to get network %s: %v", networkID, err) } PrintTenantNetwork(t, network) }
func TestServersActionReboot(t *testing.T) { t.Parallel() client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatal(err) } defer DeleteServer(t, client, server) rebootOpts := &servers.RebootOpts{ Type: servers.SoftReboot, } t.Logf("Attempting reboot of server %s", server.ID) res := servers.Reboot(client, server.ID, rebootOpts) if res.Err != nil { t.Fatalf("Unable to reboot server: %v", res.Err) } if err = WaitForComputeStatus(client, server, "REBOOT"); err != nil { t.Fatal(err) } if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { t.Fatal(err) } }
func TestServersMetadata(t *testing.T) { t.Parallel() choices, err := clients.AcceptanceTestChoicesFromEnv() if err != nil { t.Fatal(err) } client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } server, err := CreateServer(t, client, choices) if err != nil { t.Fatal(err) } defer DeleteServer(t, client, server) metadata, err := servers.UpdateMetadata(client, server.ID, servers.MetadataOpts{ "foo": "bar", "this": "that", }).Extract() if err != nil { t.Fatalf("Unable to update metadata: %v", err) } t.Logf("UpdateMetadata result: %+v\n", metadata) err = servers.DeleteMetadatum(client, server.ID, "foo").ExtractErr() if err != nil { t.Fatalf("Unable to delete metadatum: %v", err) } metadata, err = servers.CreateMetadatum(client, server.ID, servers.MetadatumOpts{ "foo": "baz", }).Extract() if err != nil { t.Fatalf("Unable to create metadatum: %v", err) } t.Logf("CreateMetadatum result: %+v\n", metadata) metadata, err = servers.Metadatum(client, server.ID, "foo").Extract() if err != nil { t.Fatalf("Unable to get metadatum: %v", err) } t.Logf("Metadatum result: %+v\n", metadata) th.AssertEquals(t, "baz", metadata["foo"]) metadata, err = servers.Metadata(client, server.ID).Extract() if err != nil { t.Fatalf("Unable to get metadata: %v", err) } t.Logf("Metadata result: %+v\n", metadata) metadata, err = servers.ResetMetadata(client, server.ID, servers.MetadataOpts{}).Extract() if err != nil { t.Fatalf("Unable to reset metadata: %v", err) } t.Logf("ResetMetadata result: %+v\n", metadata) th.AssertDeepEquals(t, map[string]string{}, metadata) }