Make change-admin-password acceptence test autonomous
Up to this commit, 09-change-admin-password.go required human
intervention to run.
diff --git a/acceptance/09-change-admin-password.go b/acceptance/09-change-admin-password.go
index 4804726..2ce7bbe 100644
--- a/acceptance/09-change-admin-password.go
+++ b/acceptance/09-change-admin-password.go
@@ -4,6 +4,7 @@
"flag"
"fmt"
"github.com/rackspace/gophercloud"
+ "time"
)
var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
@@ -14,14 +15,6 @@
provider, username, password := getCredentials()
flag.Parse()
- if *serverId == "" {
- panic("Server ID expected [use -i option]")
- }
-
- if *newPass == "" {
- panic("Password expected [use -p option]")
- }
-
acc, err := gophercloud.Authenticate(
provider,
gophercloud.AuthOptions{
@@ -43,6 +36,32 @@
panic(err)
}
+ // 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)
+ if err != nil {
+ panic(err)
+ }
+ if s.Status == "ACTIVE" {
+ break
+ }
+ 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)