summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Yang <yangyang1@zte.com.cn>2017-10-12 17:12:53 +0800
committerAlex Yang <yangyang1@zte.com.cn>2017-10-12 17:12:53 +0800
commit32cfe455476673af240681c83790a3c017ae2246 (patch)
tree118e96fc198ca691a7fdbc49a2706c079c27ba1b
parent164ffc1780a6ffd2634533849f67ed640fb0745b (diff)
Support securelab dir param in python script
Change-Id: I39d6643aac190820ae30b945f71d21a0ea2e73c9 Signed-off-by: Alex Yang <yangyang1@zte.com.cn>
-rw-r--r--deploy/deploy.py31
-rw-r--r--tests/unit/test_deploy.py40
2 files changed, 34 insertions, 37 deletions
diff --git a/deploy/deploy.py b/deploy/deploy.py
index 42a9d2f7..245776fb 100644
--- a/deploy/deploy.py
+++ b/deploy/deploy.py
@@ -53,19 +53,8 @@ from environment import (
class DaisyDeployment(object):
def __init__(self, **kwargs):
- self.lab_name = kwargs['lab_name']
- self.pod_name = kwargs['pod_name']
- self.src_deploy_file = kwargs['deploy_file']
- self.net_file = kwargs['net_file']
- self.bin_file = kwargs['bin_file']
- self.daisy_only = kwargs['daisy_only']
- self.cleanup_only = kwargs['cleanup_only']
- self.remote_dir = kwargs['remote_dir']
- self.work_dir = kwargs['work_dir']
- self.storage_dir = kwargs['storage_dir']
- self.pxe_bridge = kwargs['pxe_bridge']
- self.deploy_log = kwargs['deploy_log']
- self.scenario = kwargs['scenario']
+ for key in kwargs:
+ self.__setattr__(key, kwargs[key])
self.deploy_struct = self._construct_final_deploy_conf(self.scenario)
self.deploy_file, self.deploy_file_name = self._construct_final_deploy_file(self.deploy_struct, self.work_dir)
@@ -130,8 +119,8 @@ class DaisyDeployment(object):
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')
+ pdf_yaml = path_join(self.labs_dir, 'labs', self.lab_name, self.pod_name + '.yaml')
+ template_file = path_join(self.labs_dir, '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 !')
@@ -207,8 +196,13 @@ class DaisyDeployment(object):
def config_arg_parser():
parser = argparse.ArgumentParser(prog='python %s' % __file__,
+ formatter_class=argparse.RawTextHelpFormatter,
description='NOTE: You need ROOT privilege to run this script.')
+ parser.add_argument('-L', dest='labs_dir', action='store',
+ default=None, required=True,
+ help='Base directory to store the labs configuration')
+
parser.add_argument('-lab', dest='lab_name', action='store',
default=None, required=True,
help='Lab Name')
@@ -239,7 +233,7 @@ def config_arg_parser():
help='Storage directory for VM images')
parser.add_argument('-B', dest='pxe_bridge', action='store',
default='pxebr',
- help='Linux Bridge for booting up the Daisy Server VM '
+ help='Linux Bridge for booting up the Daisy Server VM\n'
'[default: pxebr]')
parser.add_argument('-log', dest='deploy_log', action='store',
default=path_join(WORKSPACE, 'deploy.log'),
@@ -261,7 +255,7 @@ def parse_arguments():
check_scenario_valid(args.scenario)
- conf_base_dir = path_join(WORKSPACE, 'labs', args.lab_name, args.pod_name)
+ conf_base_dir = path_join(args.labs_dir, 'labs', args.lab_name, args.pod_name)
deploy_file = path_join(conf_base_dir, 'daisy/config/deploy.yml')
net_file = path_join(conf_base_dir, 'daisy/config/network.yml')
@@ -273,9 +267,10 @@ def parse_arguments():
confirm_dir_exists(args.storage_dir)
kwargs = {
+ 'labs_dir': args.labs_dir,
'lab_name': args.lab_name,
'pod_name': args.pod_name,
- 'deploy_file': deploy_file,
+ 'src_deploy_file': deploy_file,
'net_file': net_file,
'bin_file': args.bin_file,
'daisy_only': args.daisy_only,
diff --git a/tests/unit/test_deploy.py b/tests/unit/test_deploy.py
index 142a7f45..db887a01 100644
--- a/tests/unit/test_deploy.py
+++ b/tests/unit/test_deploy.py
@@ -12,7 +12,6 @@ import os
import sys
import shutil
import yaml
-from deploy.utils import WORKSPACE
import mock
sys.modules['libvirt'] = mock.Mock()
@@ -38,7 +37,7 @@ def conf_file_dir(data_root):
@pytest.mark.parametrize('kwargs, check_err, expect_dasiy_info', [
({'lab_name': 'zte',
'pod_name': 'virtual1',
- 'deploy_file': 'deploy_virtual1.yml',
+ 'src_deploy_file': 'deploy_virtual1.yml',
'net_file': 'network_virtual1.yml',
'bin_file': 'opnfv.bin',
'daisy_only': False,
@@ -58,7 +57,7 @@ def conf_file_dir(data_root):
'disk_size': 50}),
({'lab_name': 'zte',
'pod_name': 'pod1',
- 'deploy_file': 'deploy_baremetal.yml',
+ 'src_deploy_file': 'deploy_baremetal.yml',
'net_file': 'network_baremetal.yml',
'bin_file': 'opnfv.bin',
'daisy_only': False,
@@ -82,7 +81,7 @@ def test_create_DaisyDeployment_instance(mock_err_exit, mock_deploy_schema_valid
kwargs, expect_dasiy_info,
conf_file_dir, tmpdir,
check_err):
- kwargs['deploy_file'] = os.path.join(conf_file_dir, kwargs['deploy_file'])
+ kwargs['src_deploy_file'] = os.path.join(conf_file_dir, kwargs['src_deploy_file'])
kwargs['net_file'] = os.path.join(conf_file_dir, kwargs['net_file'])
tmpdir.join(kwargs['bin_file']).write('testdata')
kwargs['bin_file'] = os.path.join(tmpdir.dirname, tmpdir.basename, kwargs['bin_file'])
@@ -97,7 +96,7 @@ def test_create_DaisyDeployment_instance(mock_err_exit, mock_deploy_schema_valid
assert (deploy.lab_name, deploy.pod_name, deploy.src_deploy_file, deploy.net_file, deploy.bin_file,
deploy.daisy_only, deploy.cleanup_only, deploy.remote_dir, deploy.work_dir, deploy.storage_dir,
deploy.deploy_log, deploy.scenario) == \
- (kwargs['lab_name'], kwargs['pod_name'], kwargs['deploy_file'], kwargs['net_file'],
+ (kwargs['lab_name'], kwargs['pod_name'], kwargs['src_deploy_file'], kwargs['net_file'],
kwargs['bin_file'], kwargs['daisy_only'], kwargs['cleanup_only'], kwargs['remote_dir'],
kwargs['work_dir'], kwargs['storage_dir'], kwargs['deploy_log'], kwargs['scenario'])
if check_err:
@@ -117,7 +116,7 @@ def test_create_DaisyDeployment_instance(mock_err_exit, mock_deploy_schema_valid
else:
assert deploy.net_struct is None
- if 'virtual' in kwargs['deploy_file']:
+ if 'virtual' in kwargs['src_deploy_file']:
assert (deploy.adapter == 'libvirt' and deploy.pxe_bridge == 'daisy1')
else:
@@ -133,7 +132,7 @@ def test_create_DaisyDeployment_instance(mock_err_exit, mock_deploy_schema_valid
{
'lab_name': 'zte',
'pod_name': 'virtual1',
- 'deploy_file': 'deploy_virtual1.yml',
+ 'src_deploy_file': 'deploy_virtual1.yml',
'net_file': 'network_virtual1.yml',
'bin_file': 'opnfv.bin',
'daisy_only': False,
@@ -150,7 +149,7 @@ def test_create_DaisyDeployment_instance(mock_err_exit, mock_deploy_schema_valid
{
'lab_name': 'zte',
'pod_name': 'pod1',
- 'deploy_file': 'deploy_baremetal.yml',
+ 'src_deploy_file': 'deploy_baremetal.yml',
'net_file': 'network_baremetal.yml',
'bin_file': 'opnfv.bin',
'daisy_only': False,
@@ -167,7 +166,7 @@ def test_create_DaisyDeployment_instance(mock_err_exit, mock_deploy_schema_valid
def test__construct_final_deploy_conf_in_DaisyDeployment(mock__use_pod_descriptor_file,
conf_file_dir, tmpdir,
kwargs, is_use_pdf, exp_deploy_file):
- kwargs['deploy_file'] = os.path.join(conf_file_dir, kwargs['deploy_file'])
+ kwargs['src_deploy_file'] = os.path.join(conf_file_dir, kwargs['src_deploy_file'])
kwargs['net_file'] = os.path.join(conf_file_dir, kwargs['net_file'])
tmpdir.join(kwargs['bin_file']).write('testdata')
kwargs['bin_file'] = os.path.join(tmpdir.dirname, tmpdir.basename, kwargs['bin_file'])
@@ -177,7 +176,7 @@ def test__construct_final_deploy_conf_in_DaisyDeployment(mock__use_pod_descripto
tmpsubdir = tmpdir.mkdir(kwargs['storage_dir'])
kwargs['storage_dir'] = os.path.join(tmpsubdir.dirname, tmpsubdir.basename)
exp_deploy_file_path = os.path.join(conf_file_dir, exp_deploy_file)
- pdf_deploy_file = None if not is_use_pdf else kwargs['deploy_file']
+ pdf_deploy_file = None if not is_use_pdf else kwargs['src_deploy_file']
mock__use_pod_descriptor_file.return_value = pdf_deploy_file
daisy_deploy = DaisyDeployment(**kwargs)
@@ -193,7 +192,7 @@ def test__construct_final_deploy_conf_in_DaisyDeployment(mock__use_pod_descripto
{
'lab_name': 'zte',
'pod_name': 'virtual1',
- 'deploy_file': 'deploy_baremetal.yml',
+ 'src_deploy_file': 'deploy_baremetal.yml',
'net_file': 'network_baremetal.yml',
'bin_file': 'opnfv.bin',
'daisy_only': False,
@@ -210,7 +209,7 @@ def test__construct_final_deploy_conf_in_DaisyDeployment(mock__use_pod_descripto
{
'lab_name': 'zte',
'pod_name': 'pod1',
- 'deploy_file': 'deploy_baremetal.yml',
+ 'src_deploy_file': 'deploy_baremetal.yml',
'net_file': 'network_baremetal.yml',
'bin_file': 'opnfv.bin',
'daisy_only': False,
@@ -227,7 +226,7 @@ def test__construct_final_deploy_conf_in_DaisyDeployment(mock__use_pod_descripto
{
'lab_name': 'zte',
'pod_name': 'pod1',
- 'deploy_file': 'deploy_baremetal.yml',
+ 'src_deploy_file': 'deploy_baremetal.yml',
'net_file': 'network_baremetal.yml',
'bin_file': 'opnfv.bin',
'daisy_only': True,
@@ -247,7 +246,7 @@ def test__construct_final_deploy_conf_in_DaisyDeployment(mock__use_pod_descripto
def test_run_in_DaisyDeployment(mock_deploy, mock_install_daisy,
mock_create_daisy_server, mock_delete_old_environment,
conf_file_dir, tmpdir, kwargs):
- kwargs['deploy_file'] = os.path.join(conf_file_dir, kwargs['deploy_file'])
+ kwargs['src_deploy_file'] = os.path.join(conf_file_dir, kwargs['src_deploy_file'])
kwargs['net_file'] = os.path.join(conf_file_dir, kwargs['net_file'])
tmpdir.join(kwargs['bin_file']).write('testdata')
kwargs['bin_file'] = os.path.join(tmpdir.dirname, tmpdir.basename, kwargs['bin_file'])
@@ -287,9 +286,10 @@ def test_parse_arguments(mock_confirm_dir_exists, mock_make_file_executable,
mock_save_log_to_file, mock_check_sudo_privilege,
mock_parse_args, cleanup_only, tmpdir):
class MockArg():
- def __init__(self, lab_name, pod_name, bin_file, daisy_only,
+ def __init__(self, labs_dir, lab_name, pod_name, bin_file, daisy_only,
cleanup_only, remote_dir, work_dir, storage_dir, pxe_bridge,
deploy_log, scenario):
+ self.labs_dir = labs_dir
self.lab_name = lab_name
self.pod_name = pod_name
self.bin_file = bin_file
@@ -304,13 +304,15 @@ def test_parse_arguments(mock_confirm_dir_exists, mock_make_file_executable,
bin_file_path = os.path.join(tmpdir.dirname, tmpdir.basename, 'opnfv.bin')
deploy_log_path = os.path.join(tmpdir.dirname, tmpdir.basename, 'deploy.log')
- conf_base_dir = os.path.join(WORKSPACE, 'labs', 'zte', 'pod2')
+ labs_dir = '/var/tmp/securedlab'
+ conf_base_dir = os.path.join(labs_dir, 'labs', 'zte', 'pod2')
deploy_file = os.path.join(conf_base_dir, 'daisy/config/deploy.yml')
net_file = os.path.join(conf_base_dir, 'daisy/config/network.yml')
expected = {
+ 'labs_dir': labs_dir,
'lab_name': 'zte',
'pod_name': 'pod2',
- 'deploy_file': deploy_file,
+ 'src_deploy_file': deploy_file,
'net_file': net_file,
'bin_file': bin_file_path,
'daisy_only': False,
@@ -322,7 +324,7 @@ def test_parse_arguments(mock_confirm_dir_exists, mock_make_file_executable,
'deploy_log': deploy_log_path,
'scenario': 'os-nosdn-nofeature-noha'
}
- mockarg = MockArg('zte', 'pod2', bin_file_path, False, cleanup_only, '/home/daisy', '/tmp/workdir',
+ mockarg = MockArg('/var/tmp/securedlab', 'zte', 'pod2', bin_file_path, False, cleanup_only, '/home/daisy', '/tmp/workdir',
'/home/qemu/vms', 'pxebr', deploy_log_path, 'os-nosdn-nofeature-noha')
mock_parse_args.return_value = mockarg
ret = parse_arguments()
@@ -356,7 +358,7 @@ def test_main(mock_parse_arguments, mock_run, cleanup_only, tmpdir, conf_file_di
kwargs = {
'lab_name': 'zte',
'pod_name': 'pod2',
- 'deploy_file': deploy_file,
+ 'src_deploy_file': deploy_file,
'net_file': net_file,
'bin_file': bin_file_path,
'daisy_only': False,