1 ###############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # szilard.cserey@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ###############################################################################
23 exec_cmd = common.exec_cmd
24 run_proc = common.run_proc
30 class Deployment(object):
32 def __init__(self, dea, yaml_config_dir, env_id, node_id_roles_dict,
35 self.yaml_config_dir = yaml_config_dir
37 self.node_id_roles_dict = node_id_roles_dict
38 self.no_health_check = no_health_check
43 LOG_FILE = 'cloud.log'
45 log('Starting deployment of environment %s' % self.env_id)
46 run_proc('fuel --env %s deploy-changes | strings | tee %s'
47 % (self.env_id, LOG_FILE))
50 for i in range(WAIT_LOOP):
51 env = parse(exec_cmd('fuel env --env %s' % self.env_id))
52 log('Environment status: %s' % env[0][E['status']])
53 r, _ = exec_cmd('tail -2 %s | head -1' % LOG_FILE, False)
56 if env[0][E['status']] == 'operational':
59 elif (env[0][E['status']] == 'error'
60 or env[0][E['status']] == 'stopped'):
63 time.sleep(SLEEP_TIME)
64 exec_cmd('rm %s' % LOG_FILE)
67 log('Environment %s successfully deployed' % self.env_id)
69 err('Deployment failed, environment %s is not operational'
72 def verify_node_status(self):
73 node_list = parse(exec_cmd('fuel node list'))
75 for node in node_list:
76 if node[N['status']] != 'ready':
77 failed_nodes.append((node[N['id']], node[N['status']]))
81 for node, status in failed_nodes:
82 summary += '[node %s, status %s]\n' % (node, status)
83 err('Deployment failed: %s' % summary)
85 def health_check(self):
86 log('Now running sanity and smoke health checks')
87 r = exec_cmd('fuel health --env %s --check sanity,smoke --force'
91 err('Healthcheck failed!')
95 self.verify_node_status()
96 if not self.no_health_check: