Use keys and diskConfig in RS acceptance tests.
diff --git a/acceptance/rackspace/compute/v2/servers_test.go b/acceptance/rackspace/compute/v2/servers_test.go
index c3465cd..7973f75 100644
--- a/acceptance/rackspace/compute/v2/servers_test.go
+++ b/acceptance/rackspace/compute/v2/servers_test.go
@@ -7,14 +7,30 @@
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/acceptance/tools"
+ "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/diskconfig"
+ oskey "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
os "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
"github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/compute/v2/keypairs"
"github.com/rackspace/gophercloud/rackspace/compute/v2/servers"
th "github.com/rackspace/gophercloud/testhelper"
)
-func createServer(t *testing.T, client *gophercloud.ServiceClient) *os.Server {
- if testing.Short(){
+func createServerKeyPair(t *testing.T, client *gophercloud.ServiceClient) *oskey.KeyPair {
+ name := tools.RandomString("importedkey-", 8)
+ pubkey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDlIQ3r+zd97kb9Hzmujd3V6pbO53eb3Go4q2E8iqVGWQfZTrFdL9KACJnqJIm9HmncfRkUTxE37hqeGCCv8uD+ZPmPiZG2E60OX1mGDjbbzAyReRwYWXgXHopggZTLak5k4mwZYaxwaufbVBDRn847e01lZnaXaszEToLM37NLw+uz29sl3TwYy2R0RGHPwPc160aWmdLjSyd1Nd4c9pvvOP/EoEuBjIC6NJJwg2Rvg9sjjx9jYj0QUgc8CqKLN25oMZ69kNJzlFylKRUoeeVr89txlR59yehJWk6Uw6lYFTdJmcmQOFVAJ12RMmS1hLWCM8UzAgtw+EDa0eqBxBDl smash@winter"
+
+ k, err := keypairs.Create(client, oskey.CreateOpts{
+ Name: name,
+ PublicKey: pubkey,
+ }).Extract()
+ th.AssertNoErr(t, err)
+
+ return k
+}
+
+func createServer(t *testing.T, client *gophercloud.ServiceClient, keyName string) *os.Server {
+ if testing.Short() {
t.Skip("Skipping test that requires server creation in short mode.")
}
@@ -23,10 +39,12 @@
name := tools.RandomString("Gophercloud-", 8)
t.Logf("Creating server [%s].", name)
- s, err := servers.Create(client, &os.CreateOpts{
- Name: name,
- ImageRef: options.imageID,
- FlavorRef: options.flavorID,
+ s, err := servers.Create(client, &servers.CreateOpts{
+ Name: name,
+ ImageRef: options.imageID,
+ FlavorRef: options.flavorID,
+ KeyPair: keyName,
+ DiskConfig: diskconfig.Manual,
}).Extract()
th.AssertNoErr(t, err)
t.Logf("Creating server.")
@@ -147,11 +165,23 @@
t.Logf("Server deleted successfully.")
}
+func deleteServerKeyPair(t *testing.T, client *gophercloud.ServiceClient, k *oskey.KeyPair) {
+ t.Logf("> keypairs.Delete")
+
+ err := keypairs.Delete(client, k.Name).Extract()
+ th.AssertNoErr(t, err)
+
+ t.Logf("Keypair deleted successfully.")
+}
+
func TestServerOperations(t *testing.T) {
client, err := newClient()
th.AssertNoErr(t, err)
- server := createServer(t, client)
+ kp := createServerKeyPair(t, client)
+ defer deleteServerKeyPair(t, client, kp)
+
+ server := createServer(t, client, kp.Name)
defer deleteServer(t, client, server)
getServer(t, client, server)