More technical debt payoff.
Applied refactoring across the entire acceptance test code base.
diff --git a/acceptance/07-change-admin-password.go b/acceptance/07-change-admin-password.go
index 2ce7bbe..e44bda0 100644
--- a/acceptance/07-change-admin-password.go
+++ b/acceptance/07-change-admin-password.go
@@ -4,7 +4,6 @@
"flag"
"fmt"
"github.com/rackspace/gophercloud"
- "time"
)
var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
@@ -12,62 +11,37 @@
var newPass = flag.String("p", "", "New password for the server.")
func main() {
- provider, username, password := getCredentials()
flag.Parse()
- acc, err := gophercloud.Authenticate(
- provider,
- gophercloud.AuthOptions{
- Username: username,
- Password: password,
- },
- )
- if err != nil {
- panic(err)
- }
+ withIdentity(func(acc gophercloud.AccessProvider) {
+ withServerApi(acc, func(api gophercloud.CloudServersProvider) {
+ // If user doesn't explicitly provide a server ID, create one dynamically.
+ if *serverId == "" {
+ var err error
+ *serverId, err = createServer(api, "", "", "", "")
+ if err != nil {
+ panic(err)
+ }
+ waitForServerState(api, *serverId, "ACTIVE")
+ }
- api, err := gophercloud.ServersApi(acc, gophercloud.ApiCriteria{
- Name: "cloudServersOpenStack",
- Region: "DFW",
- VersionId: "2",
- UrlChoice: gophercloud.PublicURL,
- })
- if err != nil {
- panic(err)
- }
+ // If no password is provided, create one dynamically.
+ if *newPass == "" {
+ *newPass = randomString("", 16)
+ }
- // If user doesn't explicitly provide a server ID, create one dynamically.
- if *serverId == "" {
- var err error
- *serverId, err = createServer(api, "", "", "", "")
- if err != nil {
- panic(err)
- }
-
- // Wait for server to finish provisioning.
- for {
- s, err := api.ServerById(*serverId)
+ // Submit the request for changing the admin password.
+ // Note that we don't verify this actually completes;
+ // doing so is beyond the scope of the SDK, and should be
+ // the responsibility of your specific OpenStack provider.
+ err := api.SetAdminPassword(*serverId, *newPass)
if err != nil {
panic(err)
}
- if s.Status == "ACTIVE" {
- break
+
+ if !*quiet {
+ fmt.Println("Password change request submitted.")
}
- time.Sleep(10 * time.Second)
- }
- }
-
- // If no password is provided, create one dynamically.
- if *newPass == "" {
- *newPass = randomString("", 16)
- }
-
- err = api.SetAdminPassword(*serverId, *newPass)
- if err != nil {
- panic(err)
- }
-
- if !*quiet {
- fmt.Println("Password change request submitted.")
- }
+ })
+ })
}