Fix tests

This commit is contained in:
vic 2012-09-21 14:23:08 +04:00
parent 9b92696b57
commit dfd15499af
2 changed files with 27 additions and 58 deletions

View File

@ -347,10 +347,10 @@ class Libvirt:
continue continue
self._virsh( self._virsh(
['send-key', node.id, ['send-key', node.id].append(
' '.join(map(lambda x: str(x), key_codes))]) map(lambda x: str(x), key_codes)))
def _create_disk(self, name, capacity=1, pool='default', format='qcow2'): def _create_disk(self, name, capacity='1', pool='default', format='qcow2'):
self._virsh( self._virsh(
['vol-create-as', '--pool', pool, '--name', name, ['vol-create-as', '--pool', pool, '--name', name,
'--capacity', capacity,'--format', format]) '--capacity', capacity,'--format', format])
@ -369,7 +369,7 @@ class Libvirt:
'--pool', 'default', '--format', disk.format, '--pool', 'default', '--format', disk.format,
'--backing-vol', base_name, '--backing-vol-format', 'qcow2']) '--backing-vol', base_name, '--backing-vol-format', 'qcow2'])
else: else:
capacity = disk.size capacity = str(disk.size)
self._create_disk(name=name, capacity=capacity, format=disk.format) self._create_disk(name=name, capacity=capacity, format=disk.format)
return self.get_disk_path(name) return self.get_disk_path(name)

View File

@ -18,17 +18,12 @@ class Ci(object):
self.environment_cache_file = cache_file self.environment_cache_file = cache_file
self.iso = iso self.iso = iso
self.environment = None self.environment = None
if self.environment_cache_file and os.path.exists(self.environment_cache_file): try:
logger.info("Loading existing integration environment...") self.environment = devops.load('integration')
with file(self.environment_cache_file) as f: logger.info("Successfully loaded existing environment")
environment_id = f.read() except Exception, e:
try: logger.info("Failed to load existing integration environment: " + str(e) + "\n" + traceback.format_exc())
#self.environment = devops.load(environment_id) pass
self.environment = devops.load('integration')
logger.info("Successfully loaded existing environment")
except Exception, e:
logger.error("Failed to load existing integration environment: " + str(e) + "\n" + traceback.format_exc())
pass
def setup_environment(self): def setup_environment(self):
if self.environment: if self.environment:
@ -64,24 +59,26 @@ class Ci(object):
environment.nodes.append(node2) environment.nodes.append(node2)
devops.build(environment) devops.build(environment)
self.environment = environment
except Exception, e: except Exception, e:
logger.error("Failed to build environment: %s\n%s" % (str(e), traceback.format_exc())) logger.error("Failed to build environment: %s\n%s" % (str(e), traceback.format_exc()))
return False return False
self.environment = environment devops.save(self.environment)
logger.info("Environment has been saved")
try:
node.interfaces[0].ip_addresses = network.ip_addresses[2]
logger.info("Starting admin node") node.interfaces[0].ip_addresses = network.ip_addresses[2]
node.start()
logger.info("Waiting admin node installation software to boot") logger.info("Starting admin node")
# todo await node.start()
time.sleep(10)
logger.info("Executing admin node software installation") logger.info("Waiting admin node installation software to boot")
node.send_keys("""<Esc><Enter> # todo await
time.sleep(10)
logger.info("Executing admin node software installation")
node.send_keys("""<Esc><Enter>
<Wait> <Wait>
/install/vmlinuz initrd=/install/initrd.gz /install/vmlinuz initrd=/install/initrd.gz
priority=critical priority=critical
@ -102,47 +99,19 @@ class Ci(object):
'hostname': self.hostname, 'hostname': self.hostname,
'domain': self.domain}) 'domain': self.domain})
logger.info("Waiting for completion of admin node software installation") logger.info("Waiting for completion of admin node software installation")
wait(lambda: tcp_ping(node.ip_address, 22), timeout=self.installation_timeout) wait(lambda: tcp_ping(node.ip_address, 22), timeout=self.installation_timeout)
logger.info("Got SSH access to admin node, waiting for ports 80 and 8000 to open") logger.info("Got SSH access to admin node, waiting for ports 80 and 8000 to open")
wait(lambda: tcp_ping(node.ip_address, 80) and tcp_ping(node.ip_address, 8000), timeout=self.chef_timeout) wait(lambda: tcp_ping(node.ip_address, 80) and tcp_ping(node.ip_address, 8000), timeout=self.chef_timeout)
logger.info("Admin node software is installed and ready for use") logger.info("Admin node software is installed and ready for use")
devops.save(self.environment)
try:
os.makedirs(os.path.dirname(self.environment_cache_file))
except OSError as e:
logger.warning("Error occured while creating directory: %s", os.path.dirname(self.environment_cache_file))
with file(self.environment_cache_file, 'w') as f:
f.write(self.environment.id)
logger.info("Environment has been saved")
except Exception, e:
devops.save(self.environment)
cache_file = self.environment_cache_file + '.candidate'
try:
os.makedirs(os.path.dirname(cache_file))
except OSError:
logger.warning("Exception occured while making directory: %s" % os.path.dirname(cache_file))
with file(cache_file, 'w') as f:
f.write(self.environment.id)
logger.error("Failed to build environment. Candidate environment cache file is %s" % cache_file)
return False
return True return True
def destroy_environment(self): def destroy_environment(self):
if self.environment: if self.environment:
devops.destroy(self.environment) devops.destroy(self.environment)
if self.environment_cache_file and os.path.exists(self.environment_cache_file):
os.remove(self.environment_cache_file)
return True return True
ci = None ci = None