Browse Source

Stop polling the instance when status is ERROR

Fix #1269

Signed-off-by: Guillaume Giamarchi <guillaume.giamarchi@gmail.com>
Guillaume Giamarchi 3 years ago
parent
commit
641d5bde24
2 changed files with 21 additions and 7 deletions
  1. 20
    6
      drivers/openstack/client.go
  2. 1
    1
      drivers/openstack/openstack.go

+ 20
- 6
drivers/openstack/client.go View File

@@ -4,8 +4,10 @@ import (
4 4
 	"crypto/tls"
5 5
 	"fmt"
6 6
 	"net/http"
7
+	"time"
7 8
 
8 9
 	"github.com/docker/machine/log"
10
+	"github.com/docker/machine/utils"
9 11
 	"github.com/docker/machine/version"
10 12
 	"github.com/rackspace/gophercloud"
11 13
 	"github.com/rackspace/gophercloud/openstack"
@@ -31,7 +33,7 @@ type Client interface {
31 33
 	StopInstance(d *Driver) error
32 34
 	RestartInstance(d *Driver) error
33 35
 	DeleteInstance(d *Driver) error
34
-	WaitForInstanceStatus(d *Driver, status string, timeout int) error
36
+	WaitForInstanceStatus(d *Driver, status string) error
35 37
 	GetInstanceIpAddresses(d *Driver) ([]IpAddress, error)
36 38
 	CreateKeyPair(d *Driver, name string, publicKey string) error
37 39
 	DeleteKeyPair(d *Driver, name string) error
@@ -132,11 +134,23 @@ func (c *GenericClient) DeleteInstance(d *Driver) error {
132 134
 	return nil
133 135
 }
134 136
 
135
-func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string, timeout int) error {
136
-	if err := servers.WaitForStatus(c.Compute, d.MachineId, status, timeout); err != nil {
137
-		return err
138
-	}
139
-	return nil
137
+func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string) error {
138
+	return utils.WaitForSpecificOrError(func() (bool, error) {
139
+		current, err := servers.Get(c.Compute, d.MachineId).Extract()
140
+		if err != nil {
141
+			return true, err
142
+		}
143
+
144
+		if current.Status == "ERROR" {
145
+			return true, fmt.Errorf("Instance creation failed. Instance is in ERROR state")
146
+		}
147
+
148
+		if current.Status == status {
149
+			return true, nil
150
+		}
151
+
152
+		return false, nil
153
+	}, 50, 4*time.Second)
140 154
 }
141 155
 
142 156
 func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {

+ 1
- 1
drivers/openstack/openstack.go View File

@@ -664,7 +664,7 @@ func (d *Driver) assignFloatingIp() error {
664 664
 
665 665
 func (d *Driver) waitForInstanceActive() error {
666 666
 	log.WithField("MachineId", d.MachineId).Debug("Waiting for the OpenStack instance to be ACTIVE...")
667
-	if err := d.client.WaitForInstanceStatus(d, "ACTIVE", 200); err != nil {
667
+	if err := d.client.WaitForInstanceStatus(d, "ACTIVE"); err != nil {
668 668
 		return err
669 669
 	}
670 670
 	return nil

Loading…
Cancel
Save