summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_deploy.py
diff options
context:
space:
mode:
authorzhongjun <zhong.jun@zte.com.cn>2017-09-08 17:27:26 +0800
committerzhongjun <zhong.jun@zte.com.cn>2017-09-11 17:15:03 +0800
commit81f5a26699ced0d7f254d05705e8c028471e44d1 (patch)
tree0a3162ab21c6c58e9543de5eefaab7cbfaa3ff41 /tests/unit/test_deploy.py
parent923bd1535dd590754c33a6a8e2a664fd07eb4227 (diff)
Add the pytest file test_deploy.py
1.add the pytest file test_deploy.py 2.fix the tmpfile clearup issue. Change-Id: I3a7e0f9199f1bf518b332fd3e9884c8f084575ae Signed-off-by: zhongjun <zhong.jun@zte.com.cn>
Diffstat (limited to 'tests/unit/test_deploy.py')
-rw-r--r--tests/unit/test_deploy.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/unit/test_deploy.py b/tests/unit/test_deploy.py
new file mode 100644
index 00000000..fe796800
--- /dev/null
+++ b/tests/unit/test_deploy.py
@@ -0,0 +1,112 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Corp and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import pytest
+import argparse
+import os
+import sys
+import yaml
+import mock
+sys.modules['libvirt'] = mock.Mock()
+
+from deploy.deploy import (
+ config_arg_parser,
+ DaisyDeployment
+) # noqa: ignore=E402
+
+
+def test_config_arg_parser():
+ parser = config_arg_parser()
+ assert isinstance(parser, argparse.ArgumentParser)
+
+
+@pytest.fixture(scope="session")
+def conf_file_dir(data_root):
+ return os.path.join(data_root, 'lab_conf')
+
+
+@pytest.mark.parametrize('kwargs, expect_dasiy_info', [
+ ({'lab_name': 'zte',
+ 'pod_name': 'virtual1',
+ 'deploy_file': 'deploy_virtual1.yml',
+ 'net_file': 'network_virtual1.yml',
+ 'bin_file': 'opnfv.bin',
+ 'daisy_only': False,
+ 'cleanup_only': False,
+ 'remote_dir': '/home/daisy',
+ 'work_dir': 'workdir',
+ 'storage_dir': 'vms',
+ 'pxe_bridge': 'pxebr',
+ 'deploy_log': 'deploy.log',
+ 'scenario': 'os-nosdn-nofeature-ha'},
+ {'name': 'daisy',
+ 'image': 'daisy.qcow2',
+ 'address': '10.20.11.2',
+ 'gateway': '10.20.11.1',
+ 'password': 'r00tme',
+ 'disk_size': 50}),
+ ({'lab_name': 'zte',
+ 'pod_name': 'pod1',
+ 'deploy_file': 'deploy_baremetal.yml',
+ 'net_file': 'network_baremetal.yml',
+ 'bin_file': 'opnfv.bin',
+ 'daisy_only': False,
+ 'cleanup_only': False,
+ 'remote_dir': '/home/daisy',
+ 'work_dir': 'workdir',
+ 'storage_dir': 'vms',
+ 'pxe_bridge': 'pxebr',
+ 'deploy_log': 'deploy.log',
+ 'scenario': 'os-odl-nofeature-ha'},
+ {'name': 'daisy',
+ 'image': 'daisy.qcow2',
+ 'address': '10.20.0.2',
+ 'gateway': '10.20.0.1',
+ 'password': 'r00tme',
+ 'disk_size': 50})])
+def test_create_DaisyDeployment_instance(kwargs, expect_dasiy_info, conf_file_dir, tmpdir):
+ kwargs['deploy_file'] = os.path.join(conf_file_dir, kwargs['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'])
+ kwargs['deploy_log'] = os.path.join(tmpdir.dirname, tmpdir.basename, kwargs['deploy_log'])
+ tmpsubdir = tmpdir.mkdir(kwargs['work_dir'])
+ kwargs['work_dir'] = os.path.join(tmpsubdir.dirname, tmpsubdir.basename)
+ tmpsubdir = tmpdir.mkdir(kwargs['storage_dir'])
+ kwargs['storage_dir'] = os.path.join(tmpsubdir.dirname, tmpsubdir.basename)
+
+ deploy = DaisyDeployment(**kwargs)
+ 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['bin_file'], kwargs['daisy_only'], kwargs['cleanup_only'], kwargs['remote_dir'],
+ kwargs['work_dir'], kwargs['storage_dir'], kwargs['deploy_log'], kwargs['scenario'])
+
+ assert deploy.deploy_file_name == 'final_deploy.yml'
+ assert deploy.deploy_file == os.path.join(deploy.work_dir, 'final_deploy.yml')
+ assert os.path.isfile(os.path.join(deploy.work_dir, 'final_deploy.yml'))
+
+ if not deploy.cleanup_only:
+ assert deploy.net_file_name == os.path.basename(kwargs['net_file'])
+ with open(deploy.net_file) as yaml_file:
+ expected_net_struct = yaml.safe_load(yaml_file)
+ assert expected_net_struct == deploy.net_struct
+ else:
+ assert deploy.net_struct is None
+
+ if 'virtual' in kwargs['deploy_file']:
+ assert (deploy.adapter == 'libvirt' and deploy.pxe_bridge == 'daisy1')
+
+ else:
+ assert (deploy.adapter == 'ipmi' and deploy.pxe_bridge == 'br7')
+
+ expect_dasiy_info['image'] = os.path.join(kwargs['storage_dir'], expect_dasiy_info['image'])
+ assert deploy.daisy_server_info == expect_dasiy_info
+
+ tmpdir.remove()