From bd241b3bdc1f7494cd8bb7fc120155c8b1cb305f Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Thu, 3 Aug 2017 11:48:13 +0800 Subject: Use PDF(POD descriptor file) and correct the mapping of nodes and roles JIRA: DAISY-42 JIRA: DAISY-56 In bare metal deployment, we can use PDF to get MAC addresses of nodes https://gerrit.opnfv.org/gerrit/#/c/38387/. Then we can use the MACs to help to distinguish the discovered nodes and assign roles to them, like virtual deployment in the link https://gerrit.opnfv.org/gerrit/#/c/38381/. Change-Id: Ib0f1a60b8935f528a828f716ccc916b767cfa6f9 Signed-off-by: Alex Yang --- deploy/deploy.py | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'deploy') diff --git a/deploy/deploy.py b/deploy/deploy.py index 47549b43..e8c9434b 100644 --- a/deploy/deploy.py +++ b/deploy/deploy.py @@ -19,9 +19,11 @@ ############################################################################## import argparse -import yaml -import time +from jinja2 import Template import os +import tempfile +import time +import yaml from config.schemas import ( @@ -32,6 +34,7 @@ from utils import ( WORKSPACE, save_log_to_file, LI, + LW, LE, err_exit, log_bar, @@ -57,7 +60,7 @@ class DaisyDeployment(object): self.src_deploy_file = deploy_file self.scenario = scenario - self.deploy_struct = self._construct_final_deploy_conf(deploy_file, scenario) + self.deploy_struct = self._construct_final_deploy_conf(scenario) self.deploy_file, self.deploy_file_name = self._construct_final_deploy_file(self.deploy_struct, work_dir) if not cleanup_only: @@ -123,7 +126,43 @@ class DaisyDeployment(object): 'password': password, 'disk_size': disk_size} - def _construct_final_deploy_conf(self, deploy_file, scenario): + def _use_pod_descriptor_file(self): + # INSTALLER_IP is provided by Jenkins on an OPNFV CI POD (bare metal) + installer_ip = os.environ.get('INSTALLER_IP', '') + if not installer_ip: + LW('INSTALLER_IP is not provided. Use deploy.yml in POD configuration directory !') + return None + + pdf_yaml = path_join(WORKSPACE, 'labs', self.lab_name, self.pod_name + '.yaml') + template_file = path_join(WORKSPACE, 'securedlab/installers/daisy/pod_config.yaml.j2') + if not os.access(pdf_yaml, os.R_OK) or not os.access(template_file, os.R_OK): + LI('There is not a POD Descriptor File or an installer template file for this deployment.') + LI('Use deploy.yml in POD configuration directory !') + return None + + try: + template = Template(open(template_file).read()) + output = template.render(conf=yaml.safe_load(open(pdf_yaml))) + deploy_struct = yaml.safe_load(output) + except Exception as e: + LE('Fail to use POD Descriptor File: %s' % e) + return None + + if not deploy_struct.get('daisy_ip', ''): + deploy_struct['daisy_ip'] = installer_ip + + dummy, deploy_file = tempfile.mkstemp(prefix='daisy_', suffix='.yml') + fh = open(deploy_file, 'w') + fh.write(yaml.safe_dump(deploy_struct)) + fh.close() + LI('Use %s generated by PDO Descriptor File as deployment configuration.' % deploy_file) + return deploy_file + + def _construct_final_deploy_conf(self, scenario): + deploy_file = self._use_pod_descriptor_file() + if not deploy_file: + deploy_file = self.src_deploy_file + check_file_exists(deploy_file) with open(deploy_file) as yaml_file: deploy_struct = yaml.safe_load(yaml_file) scenario_file = path_join(WORKSPACE, 'deploy/scenario/scenario.yaml') @@ -229,7 +268,6 @@ def parse_arguments(): deploy_file = path_join(conf_base_dir, 'daisy/config/deploy.yml') net_file = path_join(conf_base_dir, 'daisy/config/network.yml') - check_file_exists(deploy_file) if not args.cleanup_only: check_file_exists(net_file) make_file_executable(args.bin_file) -- cgit 1.2.3-korg