Commit 1b3e0bc8 authored by Cédric de Saint Martin's avatar Cédric de Saint Martin Committed by Cédric Le Ninivin

Add support for not-ready-yet main kvm instances.

parent 15c0e377
...@@ -51,18 +51,39 @@ def setRandomKey(ip): ...@@ -51,18 +51,39 @@ def setRandomKey(ip):
Set a random key that will be stored inside of the virtual hard drive. Set a random key that will be stored inside of the virtual hard drive.
""" """
random_key = ''.join(random.SystemRandom().sample(string.ascii_lowercase, 20)) random_key = ''.join(random.SystemRandom().sample(string.ascii_lowercase, 20))
connection = urllib.urlopen('http://%s:10080/set?key=%s' % (ip, random_key)) for i in range(0, 60):
if connection.getcode() is not 200: connection = urllib.urlopen('http://%s:10080/set?key=%s' % (ip, random_key))
raise Exception('Bad return code when setting key in main instance.') if connection.getcode() is 200:
break
else:
logger.info('Impossible to connect to virtual machine to set key. sleeping...')
time.sleep(60)
if i is 59:
raise Exception('Bad return code when setting key in main instance, after trying for 60 minutes.')
return random_key return random_key
def fetchKey(ip): def fetchKey(ip):
""" """
Fetch the key that had been set on original virtual hard drive. Fetch the key that had been set on original virtual hard drive.
If doesn't exist (503), fail. If other error: retry after a few minutes, If doesn't exist (503), fail. If other error: retry after a few minutes,
fail after XX (2?) hours. fail after XX (2?) hours.
""" """
return urllib.urlopen('http://%s:10080/get' % ip).read().strip() new_key = None
for i in range(0, 10):
try:
new_key = urllib.urlopen('http://%s:10080/get' % ip).read().strip()
break
except IOError:
logger.error('Server in new KVM does not answer.')
time.sleep(60)
if not new_key:
raise Exception('Server in new KVM does not answer for too long.')
return new_key
def runTestCase(server_url, key_file, cert_file, def runTestCase(server_url, key_file, cert_file,
computer_id, partition_id, software, computer_id, partition_id, software,
...@@ -108,23 +129,12 @@ def runTestCase(server_url, key_file, cert_file, ...@@ -108,23 +129,12 @@ def runTestCase(server_url, key_file, cert_file,
logger.info('Waiting for new main instance to be ready...') logger.info('Waiting for new main instance to be ready...')
new_ip = None new_ip = None
while not new_ip or new_ip == 'None' or new_ip == ip: while not new_ip or new_ip == 'None' or new_ip == ip:
logger.info('Not ready yet. New IP is %s' % new_ip) logger.info('Not ready yet. SlapOS says main IP is %s' % new_ip)
time.sleep(60) time.sleep(60)
new_ip = fetchMainInstanceIP(partition, software, kvm_rootinstance_name) new_ip = fetchMainInstanceIP(partition, software, kvm_rootinstance_name)
logger.info('New IP of instance is %s' % new_ip) logger.info('New IP of instance is %s' % new_ip)
new_key = None new_key = fetchKey(new_ip)
for i in range(0, 10):
try:
new_key = fetchKey(new_ip)
break
except IOError:
logger.error('Server in new KVM does not answer.')
time.sleep(60)
if not new_key:
raise Exception('Server in new KVM does not answer for too long.')
logger.info('Key on this new instance is %s' % new_key) logger.info('Key on this new instance is %s' % new_key)
# Compare with original key. If same: success. # Compare with original key. If same: success.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment