summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2015-09-08 16:26:18 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2015-09-11 08:50:45 +0000
commite0829a4106185624a8c57281d8a365d1828c1a68 (patch)
tree945edfbd3e3f87f38f2acd64bfccede0f5e93b96
parent644637928ab3f07a144a805728f64ab91c4bdd29 (diff)
downloaddefinitions-e0829a4106185624a8c57281d8a365d1828c1a68.tar.gz
Assign a floating IP address to the test instance.
-rwxr-xr-xscripts/release-test-os95
1 files changed, 31 insertions, 64 deletions
diff --git a/scripts/release-test-os b/scripts/release-test-os
index de2b656e..b0ea3c4a 100755
--- a/scripts/release-test-os
+++ b/scripts/release-test-os
@@ -32,67 +32,7 @@ import tempfile
import time
import uuid
-class NovaList:
- def __init__(self):
- self.output = []
- self.lines = []
- self.instance = []
-
- def update(self):
- self.output = cliapp.runcmd(['nova', 'list'])
- self.lines = self.output.split('\n')
- self.lines = self.lines[3:-2]
-
- def get_nova_details_for_instance(self, name):
- self.update()
-
- for line in self.lines:
- entries = line.split('|')
- stripped_line = [entry.strip() for entry in entries]
- if stripped_line.count(name) == 1:
- self.instance = stripped_line
-
- def get_nova_state_for_instance(self, name):
- self.get_nova_details_for_instance(name)
- if not self.instance:
- return
- return self.instance[3]
-
- def get_nova_ip_for_instance(self, name):
- self.get_nova_details_for_instance(name)
- if not self.instance:
- return
-
- if self.get_nova_state_for_instance(name) != 'ACTIVE':
- return
-
- return self.instance[6]
-
- def get_nova_ip_for_instance_timeout(self, name, timeout=120):
- start_time = time.time()
-
- while self.get_nova_state_for_instance(name) != 'ACTIVE':
-
- if time.time() > start_time + timeout:
- print "%s not ACTIVE after %i seconds" % (name, timeout)
- return
-
- time.sleep(1)
-
- ip_addr = self.get_nova_ip_for_instance(name)
- if not ip_addr:
- return
-
- if ip_addr.count('=') == 0:
- return
-
- ip_addr = ip_addr[ip_addr.find('=') + 1:]
-
- if ip_addr.count(',') == 0:
- return ip_addr
-
- return ip_addr[:ip_addr.find(',')]
-
+from novaclient import client
class TimeoutError(cliapp.AppException):
@@ -255,7 +195,15 @@ class Deployment(object):
'--file', self.image_file]
cliapp.runcmd(args, stdin=None, stdout=None, stderr=None)
+ # Get a novaclient object
+ nc = client.Client(2,
+ os.environ['OS_USERNAME'],
+ os.environ['OS_PASSWORD'],
+ os.environ['OS_TENANT_NAME'],
+ os.environ['OS_AUTH_URL'])
+
# Boot an instance from the image
+ # TODO: use python-novaclient
args = ['nova', 'boot',
'--flavor', 'm1.medium',
'--image', hostname,
@@ -273,9 +221,28 @@ class Deployment(object):
output = '\n'.join(output_lines)
print output
- # Get ip address from nova list
- nl = NovaList()
- ip_addr = nl.get_nova_ip_for_instance_timeout(hostname)
+ # Sleep for a bit, or nova explodes when trying to assign IP address
+ time.sleep(20)
+
+ # Assign a floating IP address
+ for retries in range(5, 0, -1):
+ ip_list = nc.floating_ips.list()
+ free_ip = None
+ for ip in ip_list:
+ if ip.instance_id == None:
+ free_ip = ip
+ break
+ if free_ip != None:
+ instance = nc.servers.find(name=hostname)
+ # TODO: switch back to cli tool, as python
+ # approach gave error.
+ instance.add_floating_ip(free_ip)
+ ip_addr = free_ip.ip
+ break
+ else:
+ raise cliapp.AppException('Could not get a floating IP')
+
+ # Print the IP address
print "IP address for instance %s: %s" % (hostname, ip_addr)
return DeployedSystemInstance(self, self.host_machine,