本文整理匯總了Golang中github.com/gophercloud/gophercloud/acceptance/clients.AcceptanceTestChoicesFromEnv函數的典型用法代碼示例。如果您正苦於以下問題:Golang AcceptanceTestChoicesFromEnv函數的具體用法?Golang AcceptanceTestChoicesFromEnv怎麽用?Golang AcceptanceTestChoicesFromEnv使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AcceptanceTestChoicesFromEnv函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestBootFromNewVolume
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)
}
示例2: TestServersActionChangeAdminPassword
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)
}
}
示例3: CreateExternalRouter
// 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
}
示例4: TestServersActionResizeRevert
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)
}
}
示例5: TestFloatingIPsFixedIPAssociate
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)
}
示例6: TestLayer3FloatingIPsCreateDelete
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)
}
}
示例7: TestServersCreateDestroy
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)
}
}
示例8: TestBootFromMultiEphemeralServer
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)
}
示例9: TestAttachExistingVolume
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)
}
示例10: TestServersUpdate
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
})
}
示例11: TestLayer3RouterInterface
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)
}
}
示例12: TestSecGroupsAddGroupToServer
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)
}
}
示例13: TestVolumeAttachAttachment
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)
}
示例14: TestImagesGet
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)
}
示例15: TestFlavorsGet
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)
}