diff options
author | Alex Yang <yangyang1@zte.com.cn> | 2017-08-03 11:48:13 +0800 |
---|---|---|
committer | Alex Yang <yangyang1@zte.com.cn> | 2017-08-03 19:28:52 +0800 |
commit | bd241b3bdc1f7494cd8bb7fc120155c8b1cb305f (patch) | |
tree | f35c2ac5f9f88242ab67cc7d96905582a168e936 | |
parent | e17dc35e2e445a7b7d52398a55d196cca8a680b3 (diff) |
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 <yangyang1@zte.com.cn>
-rwxr-xr-x | ci/deploy/deploy.sh | 34 | ||||
-rw-r--r-- | deploy/deploy.py | 48 | ||||
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | test-requirements.txt | 1 |
4 files changed, 79 insertions, 5 deletions
diff --git a/ci/deploy/deploy.sh b/ci/deploy/deploy.sh index bfe0f6fa..a4f1e7a3 100755 --- a/ci/deploy/deploy.sh +++ b/ci/deploy/deploy.sh @@ -172,6 +172,40 @@ done BMDEPLOY_DAISY_SERVER_NET=$WORKSPACE/templates/physical_environment/networks/daisy.xml BMDEPLOY_DAISY_SERVER_VM=$WORKSPACE/templates/physical_environment/vms/daisy.xml +function update_dha_by_pdf() +{ + local pdf_yaml=securedlab/labs/$LAB_NAME/${POD_NAME}.yaml + local jinja2_template=securedlab/installers/daisy/pod_config.yaml.j2 + local generate_config=securedlab/utils/generate_config.py + if [ ! -f ${generate_config} ] || [ ! -f ${pdf_yaml} ] || [ ! -f ${jinja2_template} ]; then + return + fi + + local tmpfile=$(mktemp XXXXXXXX.yml) + python ${generate_config} -j ${jinja2_template} -y ${pdf_yaml} > ${tmpfile} + if [ $? -ne 0 ]; then + echo "Cannot generate config from POD Descriptor File, use original deploy.yml !" + return + fi + if [ -z $(awk "BEGIN{}(/daisy_ip/){print NR}" $tmpfile) ]; then + line=$(awk "BEGIN{}(/daisy_gateway/){print NR}" $tmpfile) + sed -i "${line}b\daisy_ip: $INSTALLER_IP" $tmpfile + fi + if [ $? -ne 0 ]; then + echo "Cannot write INSTALLER_IP to config file, use original deploy.yml !" + return + fi + cp ${tmpfile} ${DHA_CONF} + echo "====== Update deploy.yml from POD Descriptor File ======" + rm -f $tmpfile +} + +if [[ ! -z $INSTALLER_IP ]]; then + pushd ${WORKSPACE} + update_dha_by_pdf + popd +fi + PARAS_FROM_DEPLOY=`python $WORKSPACE/deploy/get_conf.py --dha $DHA_CONF` TARGET_HOSTS_NUM=`echo $PARAS_FROM_DEPLOY | cut -d " " -f 1` DAISY_IP=`echo $PARAS_FROM_DEPLOY | cut -d " " -f 2` 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) diff --git a/requirements.txt b/requirements.txt index 7a329b1e..2bdce8b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ configobj +jinja2 jsonschema paramiko pyyaml diff --git a/test-requirements.txt b/test-requirements.txt index 1def47c3..71796168 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,5 @@ configobj +jinja2 jsonschema paramiko pytest |