// CreateSnapshot will create a volume snapshot based off of a given volume and // with a random name. An error will be returned if the snapshot failed to be // created. func CreateSnapshot(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) (*snapshots.Snapshot, error) { if testing.Short() { t.Skip("Skipping test that requires snapshot creation in short mode.") } snapshotName := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create snapshot %s based on volume %s", snapshotName, volume.ID) createOpts := snapshots.CreateOpts{ Name: snapshotName, VolumeID: volume.ID, } snapshot, err := snapshots.Create(client, createOpts).Extract() if err != nil { return snapshot, err } err = snapshots.WaitForStatus(client, snapshot.ID, "available", 60) if err != nil { return snapshot, err } return snapshot, nil }
// CreateRouter creates a router on a specified Network ID. An error will be // returned if the creation failed. func CreateRouter(t *testing.T, client *gophercloud.ServiceClient, networkID string) (*routers.Router, error) { routerName := tools.RandomString("TESTACC-", 8) t.Logf("Attempting to create router: %s", routerName) adminStateUp := true gatewayInfo := routers.GatewayInfo{ NetworkID: networkID, } 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 }
// CreateMonitor will create a monitor with a random name for a specific pool. // An error will be returned if the monitor could not be created. func CreateMonitor(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer, pool *pools.Pool) (*monitors.Monitor, error) { monitorName := tools.RandomString("TESTACCT-", 8) t.Logf("Attempting to create monitor %s", monitorName) createOpts := monitors.CreateOpts{ PoolID: pool.ID, Name: monitorName, Delay: 10, Timeout: 5, MaxRetries: 5, Type: "PING", } monitor, err := monitors.Create(client, createOpts).Extract() if err != nil { return monitor, err } t.Logf("Successfully created monitor: %s", monitorName) if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { return monitor, fmt.Errorf("Timed out waiting for loadbalancer to become active") } return monitor, nil }
// CreatePortsbinding will create a port on the specified subnet. An error will be // returned if the port could not be created. func CreatePortsbinding(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID, hostID string) (*portsbinding.Port, error) { portName := tools.RandomString("TESTACC-", 8) iFalse := false t.Logf("Attempting to create port: %s", portName) createOpts := portsbinding.CreateOpts{ CreateOptsBuilder: ports.CreateOpts{ NetworkID: networkID, Name: portName, AdminStateUp: &iFalse, FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}}, }, HostID: hostID, } port, err := portsbinding.Create(client, createOpts).Extract() if err != nil { return port, err } t.Logf("Successfully created port: %s", portName) return port, nil }
// CreateListener will create a listener for a given load balancer on a random // port with a random name. An error will be returned if the listener could not // be created. func CreateListener(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer) (*listeners.Listener, error) { listenerName := tools.RandomString("TESTACCT-", 8) listenerPort := tools.RandomInt(1, 100) t.Logf("Attempting to create listener %s on port %d", listenerName, listenerPort) createOpts := listeners.CreateOpts{ Name: listenerName, LoadbalancerID: lb.ID, Protocol: "TCP", ProtocolPort: listenerPort, } listener, err := listeners.Create(client, createOpts).Extract() if err != nil { return listener, err } t.Logf("Successfully created listener %s", listenerName) if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { return listener, fmt.Errorf("Timed out waiting for loadbalancer to become active") } return listener, nil }
func TestNetworksCRUD(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } // Create a network network, err := CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer DeleteNetwork(t, client, network.ID) PrintNetwork(t, network) newName := tools.RandomString("TESTACC-", 8) updateOpts := &networks.UpdateOpts{ Name: newName, } _, err = networks.Update(client, network.ID, updateOpts).Extract() if err != nil { t.Fatalf("Unable to update network: %v", err) } newNetwork, err := networks.Get(client, network.ID).Extract() if err != nil { t.Fatalf("Unable to retrieve network: %v", err) } PrintNetwork(t, newNetwork) }
// 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 }
// CreatePool will create a pool with a random name with a specified listener // and loadbalancer. An error will be returned if the pool could not be // created. func CreatePool(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer) (*pools.Pool, error) { poolName := tools.RandomString("TESTACCT-", 8) t.Logf("Attempting to create pool %s", poolName) createOpts := pools.CreateOpts{ Name: poolName, Protocol: pools.ProtocolTCP, LoadbalancerID: lb.ID, LBMethod: pools.LBMethodLeastConnections, } pool, err := pools.Create(client, createOpts).Extract() if err != nil { return pool, err } t.Logf("Successfully created pool %s", poolName) if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { return pool, fmt.Errorf("Timed out waiting for loadbalancer to become active") } return pool, nil }
// CreateVolumeFromImage will create a volume from with a random name and size of // 1GB. An error will be returned if the volume was unable to be created. func CreateVolumeFromImage(t *testing.T, client *gophercloud.ServiceClient, choices *clients.AcceptanceTestChoices) (*volumes.Volume, error) { if testing.Short() { t.Skip("Skipping test that requires volume creation in short mode.") } volumeName := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create volume: %s", volumeName) createOpts := volumes.CreateOpts{ Size: 1, Name: volumeName, ImageID: choices.ImageID, } volume, err := volumes.Create(client, createOpts).Extract() if err != nil { return volume, err } err = volumes.WaitForStatus(client, volume.ID, "available", 60) if err != nil { return volume, err } return volume, nil }
// CreatePort will create a port on the specified subnet. An error will be // returned if the port could not be created. func CreatePort(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID string) (*ports.Port, error) { portName := tools.RandomString("TESTACC-", 8) t.Logf("Attempting to create port: %s", portName) createOpts := ports.CreateOpts{ NetworkID: networkID, Name: portName, AdminStateUp: gophercloud.Enabled, FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}}, } port, err := ports.Create(client, createOpts).Extract() if err != nil { return port, err } if err := WaitForPortToCreate(client, port.ID, 60); err != nil { return port, err } newPort, err := ports.Get(client, port.ID).Extract() if err != nil { return newPort, err } t.Logf("Successfully created port: %s", portName) return newPort, nil }
// CreateRule will create a Firewall Rule with a random source address and //source port, destination address and port. An error will be returned if // the rule could not be created. func CreateRule(t *testing.T, client *gophercloud.ServiceClient) (*rules.Rule, error) { ruleName := tools.RandomString("TESTACC-", 8) sourceAddress := fmt.Sprintf("192.168.1.%d", tools.RandomInt(1, 100)) sourcePort := strconv.Itoa(tools.RandomInt(1, 100)) destinationAddress := fmt.Sprintf("192.168.2.%d", tools.RandomInt(1, 100)) destinationPort := strconv.Itoa(tools.RandomInt(1, 100)) t.Logf("Attempting to create rule %s with source %s:%s and destination %s:%s", ruleName, sourceAddress, sourcePort, destinationAddress, destinationPort) createOpts := rules.CreateOpts{ Name: ruleName, Protocol: rules.ProtocolTCP, Action: "allow", SourceIPAddress: sourceAddress, SourcePort: sourcePort, DestinationIPAddress: destinationAddress, DestinationPort: destinationPort, } rule, err := rules.Create(client, createOpts).Extract() if err != nil { return rule, err } t.Logf("Rule %s successfully created", ruleName) return rule, nil }
// CreateSubnetWithNoGateway will create a subnet with no gateway on the // specified Network ID. An error will be returned if the subnet could not be // created. func CreateSubnetWithNoGateway(t *testing.T, client *gophercloud.ServiceClient, networkID string) (*subnets.Subnet, error) { var noGateway = "" subnetName := tools.RandomString("TESTACC-", 8) subnetOctet := tools.RandomInt(1, 250) subnetCIDR := fmt.Sprintf("192.168.%d.0/24", subnetOctet) dhcpStart := fmt.Sprintf("192.168.%d.10", subnetOctet) dhcpEnd := fmt.Sprintf("192.168.%d.200", subnetOctet) createOpts := subnets.CreateOpts{ NetworkID: networkID, CIDR: subnetCIDR, IPVersion: 4, Name: subnetName, EnableDHCP: gophercloud.Disabled, GatewayIP: &noGateway, AllocationPools: []subnets.AllocationPool{ { Start: dhcpStart, End: dhcpEnd, }, }, } t.Logf("Attempting to create subnet: %s", subnetName) subnet, err := subnets.Create(client, createOpts).Extract() if err != nil { return subnet, err } t.Logf("Successfully created subnet.") return subnet, nil }
// CreateShareType will create a share type with a random name. An // error will be returned if the share type was unable to be created. func CreateShareType(t *testing.T, client *gophercloud.ServiceClient) (*sharetypes.ShareType, error) { if testing.Short() { t.Skip("Skipping test that requires share type creation in short mode.") } shareTypeName := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create share type: %s", shareTypeName) extraSpecsOps := sharetypes.ExtraSpecsOpts{ DriverHandlesShareServers: true, } createOpts := sharetypes.CreateOpts{ Name: shareTypeName, IsPublic: true, ExtraSpecs: extraSpecsOps, } shareType, err := sharetypes.Create(client, createOpts).Extract() if err != nil { return shareType, err } return shareType, nil }
func TestLayer3RouterCreateDelete(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } router, err := CreateExternalRouter(t, client) if err != nil { t.Fatalf("Unable to create router: %v", err) } defer DeleteRouter(t, client, router.ID) PrintRouter(t, router) newName := tools.RandomString("TESTACC-", 8) updateOpts := routers.UpdateOpts{ Name: newName, } _, err = routers.Update(client, router.ID, updateOpts).Extract() if err != nil { t.Fatalf("Unable to update router: %v", err) } newRouter, err := routers.Get(client, router.ID).Extract() if err != nil { t.Fatalf("Unable to get router: %v", err) } PrintRouter(t, newRouter) }
// CreateMember will create a member with a random name, port, address, and // weight. An error will be returned if the member could not be created. func CreateMember(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer, pool *pools.Pool, subnetID, subnetCIDR string) (*pools.Member, error) { memberName := tools.RandomString("TESTACCT-", 8) memberPort := tools.RandomInt(100, 1000) memberWeight := tools.RandomInt(1, 10) cidrParts := strings.Split(subnetCIDR, "/") subnetParts := strings.Split(cidrParts[0], ".") memberAddress := fmt.Sprintf("%s.%s.%s.%d", subnetParts[0], subnetParts[1], subnetParts[2], tools.RandomInt(10, 100)) t.Logf("Attempting to create member %s", memberName) createOpts := pools.CreateMemberOpts{ Name: memberName, ProtocolPort: memberPort, Weight: memberWeight, Address: memberAddress, SubnetID: subnetID, } t.Logf("Member create opts: %#v", createOpts) member, err := pools.CreateMember(client, pool.ID, createOpts).Extract() if err != nil { return member, err } t.Logf("Successfully created member %s", memberName) if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { return member, fmt.Errorf("Timed out waiting for loadbalancer to become active") } return member, nil }
// CreateLoadBalancer will create a load balancer with a random name on a given // subnet. An error will be returned if the loadbalancer could not be created. func CreateLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, subnetID string) (*loadbalancers.LoadBalancer, error) { lbName := tools.RandomString("TESTACCT-", 8) t.Logf("Attempting to create loadbalancer %s on subnet %s", lbName, subnetID) createOpts := loadbalancers.CreateOpts{ Name: lbName, VipSubnetID: subnetID, AdminStateUp: gophercloud.Enabled, } lb, err := loadbalancers.Create(client, createOpts).Extract() if err != nil { return lb, err } t.Logf("Successfully created loadbalancer %s on subnet %s", lbName, subnetID) t.Logf("Waiting for loadbalancer %s to become active", lbName) if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { return lb, err } t.Logf("LoadBalancer %s is active", lbName) return lb, nil }
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 (c context) createUsers() { users := []string{ tools.RandomString("user_", 5), tools.RandomString("user_", 5), tools.RandomString("user_", 5), } db1 := db.CreateOpts{Name: "db1"} db2 := db.CreateOpts{Name: "db2"} db3 := db.CreateOpts{Name: "db3"} opts := u.BatchCreateOpts{ u.CreateOpts{ Name: users[0], Password: tools.RandomString("", 5), Databases: db.BatchCreateOpts{db1, db2, db3}, }, u.CreateOpts{ Name: users[1], Password: tools.RandomString("", 5), Databases: db.BatchCreateOpts{db1, db2}, }, u.CreateOpts{ Name: users[2], Password: tools.RandomString("", 5), Databases: db.BatchCreateOpts{db3}, }, } err := u.Create(c.client, c.instanceID, opts).ExtractErr() c.AssertNoErr(err) c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, users[0], users[1], users[2]) c.users = users }
func TestSecGroupsUpdate(t *testing.T) { client, err := clients.NewComputeV2Client() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } securityGroup, err := CreateSecurityGroup(t, client) if err != nil { t.Fatalf("Unable to create security group: %v", err) } defer DeleteSecurityGroup(t, client, securityGroup) updateOpts := secgroups.UpdateOpts{ Name: tools.RandomString("secgroup_", 4), Description: tools.RandomString("dec_", 10), } updatedSecurityGroup, err := secgroups.Update(client, securityGroup.ID, updateOpts).Extract() if err != nil { t.Fatalf("Unable to update security group: %v", err) } t.Logf("Updated %s's name to %s", updatedSecurityGroup.ID, updatedSecurityGroup.Name) }
// CreateSecurityGroup will create a security group with a random name. // An error will be returned if one was failed to be created. func CreateSecurityGroup(t *testing.T, client *gophercloud.ServiceClient) (secgroups.SecurityGroup, error) { createOpts := secgroups.CreateOpts{ Name: tools.RandomString("secgroup_", 5), Description: "something", } securityGroup, err := secgroups.Create(client, createOpts).Extract() if err != nil { return *securityGroup, err } t.Logf("Created security group: %s", securityGroup.ID) return *securityGroup, nil }
func createVolume(t *testing.T, blockClient *gophercloud.ServiceClient) (*volumes.Volume, error) { volumeName := tools.RandomString("ACPTTEST", 16) createOpts := volumes.CreateOpts{ Size: 1, Name: volumeName, } volume, err := volumes.Create(blockClient, createOpts).Extract() if err != nil { return volume, err } t.Logf("Created volume: %s", volume.ID) return volume, nil }
// CreateKeyPair will create a KeyPair with a random name. An error will occur // if the keypair failed to be created. An error will be returned if the // keypair was unable to be created. func CreateKeyPair(t *testing.T, client *gophercloud.ServiceClient) (*keypairs.KeyPair, error) { keyPairName := tools.RandomString("keypair_", 5) t.Logf("Attempting to create keypair: %s", keyPairName) createOpts := keypairs.CreateOpts{ Name: keyPairName, } keyPair, err := keypairs.Create(client, createOpts).Extract() if err != nil { return keyPair, err } t.Logf("Created keypair: %s", keyPairName) return keyPair, nil }
func TestListAllContainers(t *testing.T) { // Create a new client to execute the HTTP requests. See common.go for newClient body. client := newClient(t) numContainers := 20 // Create a slice of random container names. cNames := make([]string, numContainers) for i := 0; i < numContainers; i++ { cNames[i] = tools.RandomString("gophercloud-test-container-", 8) } // Create numContainers containers. for i := 0; i < len(cNames); i++ { res := containers.Create(client, cNames[i], nil) th.AssertNoErr(t, res.Err) } // Delete the numContainers containers after function completion. defer func() { for i := 0; i < len(cNames); i++ { res := containers.Delete(client, cNames[i]) th.AssertNoErr(t, res.Err) } }() // List all the numContainer names that were just created. To just list those, // the 'prefix' parameter is used. allPages, err := containers.List(client, &containers.ListOpts{Full: true, Limit: 5, Prefix: "gophercloud-test-container-"}).AllPages() th.AssertNoErr(t, err) containerInfoList, err := containers.ExtractInfo(allPages) th.AssertNoErr(t, err) for _, n := range containerInfoList { t.Logf("Container: Name [%s] Count [%d] Bytes [%d]", n.Name, n.Count, n.Bytes) } th.AssertEquals(t, numContainers, len(containerInfoList)) // List the info for all the numContainer containers that were created. allPages, err = containers.List(client, &containers.ListOpts{Full: false, Limit: 2, Prefix: "gophercloud-test-container-"}).AllPages() th.AssertNoErr(t, err) containerNamesList, err := containers.ExtractNames(allPages) th.AssertNoErr(t, err) for _, n := range containerNamesList { t.Logf("Container: Name [%s]", n) } th.AssertEquals(t, numContainers, len(containerNamesList)) }
// CreateNetwork will create basic network. An error will be returned if the // network could not be created. func CreateNetwork(t *testing.T, client *gophercloud.ServiceClient) (*networks.Network, error) { networkName := tools.RandomString("TESTACC-", 8) createOpts := networks.CreateOpts{ Name: networkName, AdminStateUp: gophercloud.Enabled, } t.Logf("Attempting to create network: %s", networkName) network, err := networks.Create(client, createOpts).Extract() if err != nil { return network, err } t.Logf("Successfully created network.") return network, nil }
// CreateServer creates a basic instance with a randomly generated name. // The flavor of the instance will be the value of the OS_FLAVOR_ID environment variable. // The image will be the value of the OS_IMAGE_ID environment variable. // The instance will be launched on the network specified in OS_NETWORK_NAME. // An error will be returned if the instance was unable to be created. func CreateServer(t *testing.T, client *gophercloud.ServiceClient, choices *clients.AcceptanceTestChoices) (*servers.Server, error) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } var server *servers.Server networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) if err != nil { return server, err } name := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create server: %s", name) pwd := tools.MakeNewPassword("") server, err = servers.Create(client, servers.CreateOpts{ Name: name, FlavorRef: choices.FlavorID, ImageRef: choices.ImageID, AdminPass: pwd, Networks: []servers.Network{ servers.Network{UUID: networkID}, }, Metadata: map[string]string{ "abc": "def", }, Personality: servers.Personality{ &servers.File{ Path: "/etc/test", Contents: []byte("hello world"), }, }, }).Extract() if err != nil { return server, err } if err := WaitForComputeStatus(client, server, "ACTIVE"); err != nil { return server, err } return server, nil }
// UpdateUser will update an existing user with a new randomly generated name. // An error will be returned if the update was unsuccessful. func UpdateUser(t *testing.T, client *gophercloud.ServiceClient, user *users.User) (*users.User, error) { userName := tools.RandomString("user_", 5) userEmail := userName + "@foo.com" t.Logf("Attempting to update user name from %s to %s", user.Name, userName) updateOpts := users.UpdateOpts{ Name: userName, Email: userEmail, } newUser, err := users.Update(client, user.ID, updateOpts).Extract() if err != nil { return newUser, err } return newUser, nil }
// CreateSecurityGroup will create a security group with a random name. // An error will be returned if one was failed to be created. func CreateSecurityGroup(t *testing.T, client *gophercloud.ServiceClient) (*groups.SecGroup, error) { secGroupName := tools.RandomString("TESTACC-", 8) t.Logf("Attempting to create security group: %s", secGroupName) createOpts := groups.CreateOpts{ Name: secGroupName, } secGroup, err := groups.Create(client, createOpts).Extract() if err != nil { return secGroup, err } t.Logf("Created security group: %s", secGroup.ID) return secGroup, nil }
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) } }
// CreateBootableVolumeServer works like CreateServer but is configured with // one or more block devices defined by passing in []bootfromvolume.BlockDevice. // An error will be returned if a server was unable to be created. func CreateBootableVolumeServer(t *testing.T, client *gophercloud.ServiceClient, blockDevices []bootfromvolume.BlockDevice, choices *clients.AcceptanceTestChoices) (*servers.Server, error) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } var server *servers.Server networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName) if err != nil { return server, err } name := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create bootable volume server: %s", name) serverCreateOpts := servers.CreateOpts{ Name: name, FlavorRef: choices.FlavorID, Networks: []servers.Network{ servers.Network{UUID: networkID}, }, } if blockDevices[0].SourceType == bootfromvolume.SourceImage && blockDevices[0].DestinationType == bootfromvolume.DestinationLocal { serverCreateOpts.ImageRef = blockDevices[0].UUID } server, err = bootfromvolume.Create(client, bootfromvolume.CreateOptsExt{ serverCreateOpts, blockDevices, }).Extract() if err != nil { return server, err } if err := WaitForComputeStatus(client, server, "ACTIVE"); err != nil { return server, err } newServer, err := servers.Get(client, server.ID).Extract() return newServer, nil }
func TestPortsbindingCRUD(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } // Create Network network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) // Create Subnet subnet, err := networking.CreateSubnet(t, client, network.ID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) // Define a host hostID := "localhost" // Create port port, err := CreatePortsbinding(t, client, network.ID, subnet.ID, hostID) if err != nil { t.Fatalf("Unable to create port: %v", err) } defer networking.DeletePort(t, client, port.ID) PrintPortsbinding(t, port) // Update port newPortName := tools.RandomString("TESTACC-", 8) updateOpts := ports.UpdateOpts{ Name: newPortName, } newPort, err := portsbinding.Update(client, port.ID, updateOpts).Extract() if err != nil { t.Fatalf("Could not update port: %v", err) } PrintPortsbinding(t, newPort) }