summaryrefslogtreecommitdiffstats
path: root/deploy
diff options
context:
space:
mode:
Diffstat (limited to 'deploy')
-rw-r--r--deploy/deploy.py48
1 files changed, 43 insertions, 5 deletions
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)