summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xci/deploy/deploy.sh34
-rw-r--r--deploy/deploy.py48
-rw-r--r--requirements.txt1
-rw-r--r--test-requirements.txt1
4 files changed, 79 insertions, 5 deletions
diff --git a/ci/deploy/deploy.sh b/ci/deploy/deploy.sh
index 31382623..9360da85 100755
--- a/ci/deploy/deploy.sh
+++ b/ci/deploy/deploy.sh
@@ -173,6 +173,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 5d787343..99af97bb 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 26409b1c..e80bdb21 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,4 +1,5 @@
configobj
+jinja2
jsonschema
paramiko
pytest