13 exec_cmd = common.exec_cmd
14 run_proc = common.run_proc
20 class Deployment(object):
22 def __init__(self, dea, yaml_config_dir, env_id, node_id_roles_dict):
24 self.env_name = dea.get_environment_name()
25 self.yaml_config_dir = yaml_config_dir
27 self.node_id_roles_dict = node_id_roles_dict
28 self.node_id_list = []
29 for node_id in self.node_id_roles_dict.iterkeys():
30 self.node_id_list.append(node_id)
31 self.node_id_list.sort()
33 def download_deployment_info(self):
34 LOG.debug('Download deployment info for environment %s\n' % self.env_id)
35 deployment_dir = self.yaml_config_dir + '/deployment_%s' % self.env_id
36 if os.path.exists(deployment_dir):
37 shutil.rmtree(deployment_dir)
38 r, c = exec_cmd('fuel --env %s deployment --default --dir %s'
39 % (self.env_id, self.yaml_config_dir))
41 err('Error: Could not download deployment info for env %s,'
42 ' reason: %s\n' % (self.env_id, r))
44 def upload_deployment_info(self):
45 LOG.debug('Upload deployment info for environment %s\n' % self.env_id)
46 r, c = exec_cmd('fuel --env %s deployment --upload --dir %s'
47 % (self.env_id, self.yaml_config_dir))
49 err('Error: Could not upload deployment info for env %s,'
50 ' reason: %s\n' % (self.env_id, r))
53 LOG.debug('Running pre-deploy on environment %s\n' % self.env_name)
54 self.download_deployment_info()
57 for node_file in glob.glob('%s/deployment_%s/*.yaml'
58 % (self.yaml_config_dir, self.env_id)):
59 with io.open(node_file) as stream:
60 node = yaml.load(stream)
62 if 'opnfv' not in node:
65 with io.open(node_file, 'w') as stream:
66 yaml.dump(node, stream, default_flow_style=False)
67 self.upload_deployment_info()
76 log_file = 'cloud.log'
78 LOG.debug('Starting deployment of environment %s\n' % self.env_name)
79 run_proc('fuel --env %s deploy-changes | strings | tee %s'
80 % (self.env_id, log_file))
83 for i in range(WAIT_LOOP):
84 env = parse(exec_cmd('fuel env --env %s' % self.env_id))
85 LOG.debug('Environment status: %s\n' % env[0][E['status']])
86 r, _ = exec_cmd('tail -2 %s | head -1' % log_file)
89 if env[0][E['status']] == 'operational':
93 time.sleep(SLEEP_TIME)
94 exec_cmd('rm %s' % log_file)
97 LOG.debug('Environment %s successfully deployed\n' % self.env_name)
99 err('Deployment failed, environment %s is not operational\n'