Ash Wilson | 88074d5 | 2014-10-21 10:04:17 -0400 | [diff] [blame^] | 1 | // +build acceptance |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | "github.com/rackspace/gophercloud/acceptance/tools" |
| 10 | os "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
| 11 | "github.com/rackspace/gophercloud/rackspace/compute/v2/servers" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
| 15 | func createServer(t *testing.T, client *gophercloud.ServiceClient) *os.Server { |
| 16 | options, err := optionsFromEnv() |
| 17 | th.AssertNoErr(t, err) |
| 18 | |
| 19 | r := servers.Create(client, &os.CreateOpts{ |
| 20 | Name: tools.RandomString("Gophercloud-", 8), |
| 21 | ImageRef: options.imageID, |
| 22 | FlavorRef: options.flavorID, |
| 23 | }) |
| 24 | t.Logf("\n%s", r.PrettyPrintJSON()) |
| 25 | s, err := r.Extract() |
| 26 | th.AssertNoErr(t, err) |
| 27 | return s |
| 28 | } |
| 29 | |
| 30 | func deleteServer(t *testing.T, client *gophercloud.ServiceClient, server *os.Server) { |
| 31 | err := servers.Delete(client, server.ID) |
| 32 | th.AssertNoErr(t, err) |
| 33 | } |
| 34 | |
| 35 | func logServer(t *testing.T, server *os.Server, index int) { |
| 36 | if index == -1 { |
| 37 | t.Logf(" id=[%s]", server.ID) |
| 38 | } else { |
| 39 | t.Logf("[%02d] id=[%s]", index, server.ID) |
| 40 | } |
| 41 | t.Logf(" name=[%s]", server.Name) |
| 42 | t.Logf(" tenant ID=[%s]", server.TenantID) |
| 43 | t.Logf(" user ID=[%s]", server.UserID) |
| 44 | t.Logf(" updated=[%s]", server.Updated) |
| 45 | t.Logf(" created=[%s]", server.Created) |
| 46 | t.Logf(" host ID=[%s]", server.HostID) |
| 47 | t.Logf(" access IPv4=[%s]", server.AccessIPv4) |
| 48 | t.Logf(" access IPv6=[%s]", server.AccessIPv6) |
| 49 | t.Logf(" image=[%v]", server.Image) |
| 50 | t.Logf(" flavor=[%v]", server.Flavor) |
| 51 | t.Logf(" addresses=[%v]", server.Addresses) |
| 52 | t.Logf(" metadata=[%v]", server.Metadata) |
| 53 | t.Logf(" links=[%v]", server.Links) |
| 54 | t.Logf(" keyname=[%s]", server.KeyName) |
| 55 | t.Logf(" admin password=[%s]", server.AdminPass) |
| 56 | t.Logf(" status=[%s]", server.Status) |
| 57 | t.Logf(" progress=[%d]", server.Progress) |
| 58 | } |
| 59 | |
| 60 | func TestCreateServer(t *testing.T) { |
| 61 | client, err := newClient() |
| 62 | th.AssertNoErr(t, err) |
| 63 | |
| 64 | t.Logf("Creating a new server:") |
| 65 | s := createServer(t, client) |
| 66 | defer func() { |
| 67 | t.Logf("Deleting server") |
| 68 | deleteServer(t, client, s) |
| 69 | }() |
| 70 | |
| 71 | t.Logf("Waiting for server to become active ...") |
| 72 | err = servers.WaitForStatus(client, s.ID, "ACTIVE", 300) |
| 73 | th.AssertNoErr(t, err) |
| 74 | |
| 75 | t.Logf("Server launched:") |
| 76 | logServer(t, s, -1) |
| 77 | } |