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.")
	}

	options, err := optionsFromEnv()
	th.AssertNoErr(t, err)

	name := tools.RandomString("Gophercloud-", 8)

	opts := &servers.CreateOpts{
		Name:       name,
		ImageRef:   options.imageID,
		FlavorRef:  options.flavorID,
		DiskConfig: diskconfig.Manual,
	}

	if keyName != "" {
		opts.KeyPair = keyName
	}

	t.Logf("Creating server [%s].", name)
	s, err := servers.Create(client, opts).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Creating server.")

	err = servers.WaitForStatus(client, s.ID, "ACTIVE", 300)
	th.AssertNoErr(t, err)
	t.Logf("Server created successfully.")

	return s
}
func rebootServer(t *testing.T, client *gophercloud.ServiceClient, server *os.Server) {
	t.Logf("> servers.Reboot")

	err := servers.Reboot(client, server.ID, os.HardReboot).Extract()
	th.AssertNoErr(t, err)

	err = servers.WaitForStatus(client, server.ID, "ACTIVE", 300)
	th.AssertNoErr(t, err)

	t.Logf("Server successfully rebooted.")
}
func changeAdminPassword(t *testing.T, client *gophercloud.ServiceClient, server *os.Server) {
	t.Logf("> servers.ChangeAdminPassword")

	original := server.AdminPass

	t.Logf("Changing server password.")
	err := servers.ChangeAdminPassword(client, server.ID, tools.MakeNewPassword(original)).Extract()
	th.AssertNoErr(t, err)

	err = servers.WaitForStatus(client, server.ID, "ACTIVE", 300)
	th.AssertNoErr(t, err)
	t.Logf("Password changed successfully.")
}
Exemple #4
0
func findServer(t *testing.T) string {
	var serverIP string

	client, err := newComputeClient()
	th.AssertNoErr(t, err)

	err = servers.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
		sList, err := servers.ExtractServers(page)
		th.AssertNoErr(t, err)

		for _, s := range sList {
			serverIP = s.AccessIPv4
			t.Logf("Found an existing server: ID [%s] Public IP [%s]", s.ID, serverIP)
			break
		}

		return true, nil
	})
	th.AssertNoErr(t, err)

	if serverIP == "" {
		t.Log("No server found, creating one")

		imageRef := os.Getenv("RS_IMAGE_ID")
		if imageRef == "" {
			t.Fatalf("OS var RS_IMAGE_ID undefined")
		}
		flavorRef := os.Getenv("RS_FLAVOR_ID")
		if flavorRef == "" {
			t.Fatalf("OS var RS_FLAVOR_ID undefined")
		}

		opts := &servers.CreateOpts{
			Name:       tools.RandomString("lb_test_", 5),
			ImageRef:   imageRef,
			FlavorRef:  flavorRef,
			DiskConfig: diskconfig.Manual,
		}

		s, err := servers.Create(client, opts).Extract()
		th.AssertNoErr(t, err)
		serverIP = s.AccessIPv4

		t.Logf("Created server %s, waiting for it to build", s.ID)
		err = servers.WaitForStatus(client, s.ID, "ACTIVE", 300)
		th.AssertNoErr(t, err)
		t.Logf("Server created successfully.")
	}

	return serverIP
}
func rebuildServer(t *testing.T, client *gophercloud.ServiceClient, server *os.Server) {
	t.Logf("> servers.Rebuild")

	options, err := optionsFromEnv()
	th.AssertNoErr(t, err)

	opts := servers.RebuildOpts{
		Name:       tools.RandomString("RenamedGopher", 16),
		AdminPass:  tools.MakeNewPassword(server.AdminPass),
		ImageID:    options.imageID,
		DiskConfig: diskconfig.Manual,
	}
	after, err := servers.Rebuild(client, server.ID, opts).Extract()
	th.AssertNoErr(t, err)
	th.CheckEquals(t, after.ID, server.ID)

	err = servers.WaitForStatus(client, after.ID, "ACTIVE", 300)
	th.AssertNoErr(t, err)

	t.Logf("Server successfully rebuilt.")
	logServer(t, after, -1)
}