Allow kvm resiliency test case to be easily run from outer module.

parent 508200ee
...@@ -31,24 +31,14 @@ from slapos.recipe.addresiliency.takeover import takeover ...@@ -31,24 +31,14 @@ from slapos.recipe.addresiliency.takeover import takeover
import slapos.slap import slapos.slap
import logging
import argparse import argparse
import random import random
import string import string
import time import time
import urllib import urllib
def parseArguments(): logger = logging.getLogger('KVMResiliencyTest')
parser = argparse.ArgumentParser()
parser.add_argument('--server-url', type=str)
parser.add_argument('--key-file', type=str)
parser.add_argument('--cert-file', type=str)
parser.add_argument('--computer-id', type=str)
parser.add_argument('--partition-id', type=str)
parser.add_argument('--software', type=str)
parser.add_argument('--namebase', type=str)
parser.add_argument('--kvm-rootinstance-name', type=str)
args = parser.parse_args()
return args
def fetchMainInstanceIP(current_partition, software_release, instance_name): def fetchMainInstanceIP(current_partition, software_release, instance_name):
return current_partition.request( return current_partition.request(
...@@ -74,57 +64,54 @@ def fetchKey(ip): ...@@ -74,57 +64,54 @@ def fetchKey(ip):
""" """
return urllib.urlopen('http://%s:10080/get' % ip).read().strip() return urllib.urlopen('http://%s:10080/get' % ip).read().strip()
def main(): def runTestCase(server_url, key_file, cert_file,
computer_id, partition_id, software,
namebase, kvm_rootinstance_name):
""" """
Run KVM Resiliency Test. Run KVM Resiliency Test.
Requires a specific KVM environment (virtual hard drive), see KVM SR for more Requires a specific KVM environment (virtual hard drive), see KVM SR for more
informations. informations.
""" """
# XXX-Cedric: add erp5 scalabilitytest so that we can receive/send informations
arguments = parseArguments()
slap = slapos.slap.slap() slap = slapos.slap.slap()
slap.initializeConnection(arguments.server_url, arguments.key_file, arguments.cert_file) slap.initializeConnection(server_url, key_file, cert_file)
partition = slap.registerComputerPartition( partition = slap.registerComputerPartition(
computer_guid=arguments.computer_id, computer_guid=computer_id,
partition_id=arguments.partition_id partition_id=partition_id
) )
ip = fetchMainInstanceIP(partition, arguments.software, arguments.kvm_rootinstance_name) ip = fetchMainInstanceIP(partition, software, kvm_rootinstance_name)
print('KVM IP is %s.' % ip) logger.info('KVM IP is %s.' % ip)
key = setRandomKey(ip) key = setRandomKey(ip)
print('Key set for test in current KVM: %s.' % key) logger.info('Key set for test in current KVM: %s.' % key)
# Wait for XX minutes so that replication is done # Wait for XX minutes so that replication is done
sleep_time = 60 * 15#2 * 60 * 60 sleep_time = 60 * 15#2 * 60 * 60
print('Sleeping for %s seconds.' % sleep_time) logger.info('Sleeping for %s seconds.' % sleep_time)
time.sleep(sleep_time) time.sleep(sleep_time)
# Make the clone instance takeover the main instance # Make the clone instance takeover the main instance
print('Replacing main instance by clone instance...') logger.info('Replacing main instance by clone instance...')
takeover( takeover(
server_url=arguments.server_url, server_url=server_url,
key_file=arguments.key_file, key_file=key_file,
cert_file=arguments.cert_file, cert_file=cert_file,
computer_guid=arguments.computer_id, computer_guid=computer_id,
partition_id=arguments.partition_id, partition_id=partition_id,
software_release=arguments.software, software_release=software,
namebase=arguments.namebase, namebase=namebase,
winner_instance_suffix='1', # XXX: hardcoded value. winner_instance_suffix='1', # XXX: hardcoded value.
) )
print('Done.') logger.info('Done.')
# Wait for the new IP (of old-clone new-main instance) to appear. # Wait for the new IP (of old-clone new-main instance) to appear.
print('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:
print ip logger.info('Not ready yet. New IP is %s' % new_ip)
print('Not ready yet. New IP is %s' % new_ip)
time.sleep(60) time.sleep(60)
new_ip = fetchMainInstanceIP(partition, arguments.software, arguments.kvm_rootinstance_name) new_ip = fetchMainInstanceIP(partition, software, kvm_rootinstance_name)
print('New IP of instance is %s' % new_ip) logger.info('New IP of instance is %s' % new_ip)
new_key = None new_key = None
for i in range(0, 10): for i in range(0, 10):
...@@ -132,17 +119,43 @@ def main(): ...@@ -132,17 +119,43 @@ def main():
new_key = fetchKey(new_ip) new_key = fetchKey(new_ip)
break break
except IOError: except IOError:
print('Server in new KVM does not answer.') logger.error('Server in new KVM does not answer.')
time.sleep(60) time.sleep(60)
if not new_key: if not new_key:
raise Exception('Server in new KVM does not answer for too long.') raise Exception('Server in new KVM does not answer for too long.')
print('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.
# XXX TODO
if new_key == key: if new_key == key:
print('Success') logger.info('Success')
return True
else: else:
print('Failure') logger.error('Failure')
return False
# Used if launched as standalone script
def parseArguments():
parser = argparse.ArgumentParser()
parser.add_argument('--server-url', type=str)
parser.add_argument('--key-file', type=str)
parser.add_argument('--cert-file', type=str)
parser.add_argument('--computer-id', type=str)
parser.add_argument('--partition-id', type=str)
parser.add_argument('--software', type=str)
parser.add_argument('--namebase', type=str)
parser.add_argument('--kvm-rootinstance-name', type=str)
args = parser.parse_args()
return args
def main():
arguments = parseArguments()
runTestCase(arguments.server_url, arguments.key_file, arguments.cert_file,
arguments.computer_id, arguments.partition_id, arguments.software,
arguments.namebase, arguments.kvm_rootinstance_name)
if __name__ == '__main__':
main()
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