summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test-requirements.txt2
-rw-r--r--tests/data/daisy_conf/daisy.conf38
-rw-r--r--tests/data/lab_conf/network_baremetal.yml84
-rw-r--r--tests/unit/post/test_post_execute.py6
-rw-r--r--tests/unit/test_deploy.py112
-rw-r--r--tests/unit/test_utils.py9
6 files changed, 243 insertions, 8 deletions
diff --git a/test-requirements.txt b/test-requirements.txt
index a22ef3d5..3dfb92b4 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -14,4 +14,4 @@ keystoneauth1
python-glanceclient
python-neutronclient
python-novaclient
-
+argparse
diff --git a/tests/data/daisy_conf/daisy.conf b/tests/data/daisy_conf/daisy.conf
new file mode 100644
index 00000000..22e71d59
--- /dev/null
+++ b/tests/data/daisy_conf/daisy.conf
@@ -0,0 +1,38 @@
+[DEFAULT]
+#The mangement ip of daisy
+#When Daisy will be installed in the virtual machine, this option is required.
+daisy_management_ip=10.20.11.2
+
+[BACKEND]
+#Default backend types of daisy, including tecs, zenic, proton, kolla.
+#If you want to create a cluster with more than one backend,
+#all backend names should be provided for this configuration item,
+#such as, default_backend_types=tecs,zenic,proton,kolla.
+default_backend_types=kolla
+
+[OS]
+#Default os install types of daisy
+os_install_type=pxe
+
+[PXE]
+#Set to 'yes' if you want to build a PXE server, otherwise to 'no'.
+build_pxe=no
+
+#the nic name, to build a PXE server on this nic.
+eth_name=ens3
+
+#The ip value of PXE server
+ip_address=99.99.1.5
+
+#the net mask of PXE server
+net_mask=255.255.255.0
+
+#The start value of PXE client ip range
+client_ip_begin=99.99.1.50
+
+#The end value of PXE client ip range
+client_ip_end=99.99.1.150
+
+[multicast]
+#enabled multicast or not.
+daisy_conf_mcast_enabled=False
diff --git a/tests/data/lab_conf/network_baremetal.yml b/tests/data/lab_conf/network_baremetal.yml
new file mode 100644
index 00000000..36640c1a
--- /dev/null
+++ b/tests/data/lab_conf/network_baremetal.yml
@@ -0,0 +1,84 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@zte.com.cn
+# 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
+##############################################################################
+
+##############################################################################
+# Description
+# MANAGEMENT: used for PXE, vlan used
+# SOTRAGE: used for storage access
+# EXTERNAL: tenant public/floating IP associated network,
+# requires a dedicated interface
+# PUBLICAPI: used for horizon access, openstack API access
+# TENANT: used for tenant access, vlan and VxLan supported, default VxLan
+##############################################################################
+network-config-metadata:
+ title: 'Deployment Adapter for baremetal POD'
+ version: '0.1'
+ created: 'Feb 2 2017'
+ comment: 'For Daisy initial'
+networks:
+ - cidr: '192.168.71.0/24'
+ gateway: '192.168.71.1'
+ ip_ranges:
+ - 'start': '192.168.71.2'
+ 'end': '192.168.71.254'
+ vlan_id: 171
+ name: 'MANAGEMENT'
+ - cidr: '192.168.72.0/24'
+ gateway: '192.168.72.1'
+ ip_ranges:
+ - 'start': '192.168.72.2'
+ 'end': '192.168.72.254'
+ vlan_id: 172
+ name: 'STORAGE'
+ - cidr: '172.70.0.0/24'
+ gateway: '172.70.0.1'
+ ip_ranges:
+ - 'start': '172.70.0.2'
+ 'end': '172.70.0.100'
+ vlan_id: 173
+ 'name': 'EXTERNAL'
+ network_name: 'admin_external'
+ mapping: 'physnet1'
+ - cidr: '192.168.71.0/24'
+ gateway: '192.168.71.1'
+ ip_ranges:
+ - 'start': '192.168.71.2'
+ 'end': '192.168.71.254'
+ vlan_id: 171
+ name: 'PUBLICAPI'
+ - cidr: '192.168.73.0/24'
+ gateway: '192.168.73.1'
+ ip_ranges:
+ - 'start': '192.168.73.2'
+ 'end': '192.168.73.254'
+ vlan_id: 1130
+ name: 'TENANT'
+ - cidr: '10.20.7.0/24'
+ gateway: '10.20.7.1'
+ ip_ranges:
+ - 'start': '10.20.7.20'
+ 'end': '10.20.7.200'
+ vlan_id: null
+ name: 'HEARTBEAT'
+interfaces:
+ - name: 'EXTERNAL'
+ interface: 'ens44f1'
+ - name: 'MANAGEMENT'
+ interface: 'ens12f0'
+ - name: 'PUBLICAPI'
+ interface: 'ens12f0'
+ - name: 'STORAGE'
+ interface: 'ens12f1'
+ - name: 'TENANT'
+ interface: 'ens44f0'
+ - name: 'HEARTBEAT'
+ interface: 'ens4f0'
+internal_vip: '192.168.71.10'
+public_vip: '10.20.7.11'
diff --git a/tests/unit/post/test_post_execute.py b/tests/unit/post/test_post_execute.py
index d614360c..c06bc085 100644
--- a/tests/unit/post/test_post_execute.py
+++ b/tests/unit/post/test_post_execute.py
@@ -110,14 +110,14 @@ def openrc_conf_file_dir(data_root):
('globals.yml'), ('globals_odl.yml')])
def test__config_kolla_admin_openrc(globals_file_name, openrc_conf_file_dir, tmpdir):
src_globals_file_path = os.path.join(openrc_conf_file_dir, globals_file_name)
- dst_globals_file_path = os.path.join(tmpdir.dirname, 'globals.yml')
+ dst_globals_file_path = os.path.join(tmpdir.dirname, tmpdir.basename, 'globals.yml')
shutil.copyfile(src_globals_file_path, dst_globals_file_path)
src_openrc_file_path = os.path.join(openrc_conf_file_dir, 'admin-openrc.sh')
- dst_openrc_file_path = os.path.join(tmpdir.dirname, 'admin-openrc.sh')
+ dst_openrc_file_path = os.path.join(tmpdir.dirname, tmpdir.basename, 'admin-openrc.sh')
shutil.copyfile(src_openrc_file_path, dst_openrc_file_path)
- _config_kolla_admin_openrc(tmpdir.dirname)
+ _config_kolla_admin_openrc(os.path.join(tmpdir.dirname, tmpdir.basename))
src_openrc_lines = open(src_openrc_file_path, 'r').readlines()
dst_openrc_lines = open(dst_openrc_file_path, 'r').readlines()
if globals_file_name == 'globals.yml':
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()
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index a6d84de0..d6095c7f 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -23,7 +23,7 @@ from deploy.utils import (
('exist_file')])
def test_check_file_exists(tmpdir, test_file_name):
try:
- file_path = os.path.join(tmpdir.dirname, test_file_name)
+ file_path = os.path.join(tmpdir.dirname, tmpdir.basename, test_file_name)
if test_file_name == 'exist_file':
os.mknod(file_path)
check_file_exists(file_path)
@@ -43,7 +43,7 @@ def test_check_file_exists(tmpdir, test_file_name):
('exe_file')])
def test_make_file_executable(tmpdir, test_file_name):
try:
- file_path = os.path.join(tmpdir.dirname, test_file_name)
+ file_path = os.path.join(tmpdir.dirname, tmpdir.basename, test_file_name)
if test_file_name == 'no_exe_file':
os.mknod(file_path)
if test_file_name == 'exe_file':
@@ -66,9 +66,10 @@ def test_make_file_executable(tmpdir, test_file_name):
('exist_dir')])
def test_confirm_dir_exists(tmpdir, test_dir_name):
if test_dir_name == 'no_exist_dir':
- dir_path = os.path.join(tmpdir.dirname, 'no_exist_dir')
+ dir_path = os.path.join(tmpdir.dirname, tmpdir.basename, 'no_exist_dir')
if test_dir_name == 'exist_dir':
- dir_path = tmpdir.mkdir('exist_dir').dirname
+ tmpsubdir = tmpdir.mkdir('exist_dir')
+ dir_path = os.path.join(tmpsubdir.dirname, tmpsubdir.basename)
confirm_dir_exists(dir_path)
assert os.path.isdir(dir_path)
tmpdir.remove()