diff options
author | Zhijiang Hu <hu.zhijiang@zte.com.cn> | 2017-08-04 02:34:59 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-04 02:34:59 +0000 |
commit | 99e92d157cd01e5e6e545cb6eb779c7fe9875b23 (patch) | |
tree | 60851c692eb5d464cf498091f81e18f040aa8281 | |
parent | e17dc35e2e445a7b7d52398a55d196cca8a680b3 (diff) | |
parent | 60fac3073876a9a5591c42cd3fa0cb5237ed2177 (diff) |
Merge "Add the unit test by pytest for get_conf.py"
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | test-requirements.txt | 1 | ||||
-rw-r--r-- | tests/conftest.py | 17 | ||||
-rw-r--r-- | tests/data/lab_conf/deploy_virtual1.yml | 31 | ||||
-rw-r--r-- | tests/data/lab_conf/network_virtual1.yml | 69 | ||||
-rw-r--r-- | tests/unit/test_get_conf.py | 64 |
6 files changed, 183 insertions, 0 deletions
diff --git a/requirements.txt b/requirements.txt index 7a329b1e..3d4d50be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ jsonschema paramiko pyyaml scp +oslo_config diff --git a/test-requirements.txt b/test-requirements.txt index 1def47c3..9ab1fa4a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,3 +7,4 @@ pytest-faker pytest-mock pyyaml scp +oslo_config diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..6a8dd68f --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +############################################################################## +# Copyright (c) 2016 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 +############################################################################## + +from os import path + +import pytest + + +@pytest.fixture(scope='session') +def data_root(): + return path.join(path.dirname(__file__), 'data') diff --git a/tests/data/lab_conf/deploy_virtual1.yml b/tests/data/lab_conf/deploy_virtual1.yml new file mode 100644 index 00000000..7fdfc3ba --- /dev/null +++ b/tests/data/lab_conf/deploy_virtual1.yml @@ -0,0 +1,31 @@ +adapter: libvirt +hosts: +- name: 'controller01' + roles: + - 'CONTROLLER_LB' + template: 'templates/virtual_environment/vms/controller.xml' +- name: 'controller02' + roles: + - 'CONTROLLER_LB' + template: 'templates/virtual_environment/vms/controller.xml' +- name: 'controller03' + roles: + - 'CONTROLLER_LB' + template: 'templates/virtual_environment/vms/controller.xml' +- name: 'computer01' + roles: + - 'COMPUTER' + template: 'templates/virtual_environment/vms/computer.xml' +- name: 'computer02' + roles: + - 'COMPUTER' + template: 'templates/virtual_environment/vms/computer.xml' +disks: + daisy: 50 + controller: 110 + compute: 110 + ceph: 110 +daisy_passwd: 'r00tme' +daisy_ip: '10.20.11.2' +daisy_gateway: '10.20.11.1' +ceph_disk_name: '/dev/sdb'
\ No newline at end of file diff --git a/tests/data/lab_conf/network_virtual1.yml b/tests/data/lab_conf/network_virtual1.yml new file mode 100644 index 00000000..d0fc26bf --- /dev/null +++ b/tests/data/lab_conf/network_virtual1.yml @@ -0,0 +1,69 @@ +############################################################################## +# Copyright (c) 2016 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 +############################################################################## + +network-config-metadata: + title: 'zte-virtual1 network config' + version: '0.1' + created: 'Tue Apr 11 2017' + comment: 'five vm node deploy' +networks: + - cidr: '10.20.11.0/24' + gateway: '10.20.11.1' + ip_ranges: + - start: '10.20.11.3' + end: '10.20.11.10' + name: 'MANAGEMENT' + - cidr: '10.20.11.0/24' + gateway: '10.20.11.1' + ip_ranges: + - start: '10.20.11.3' + end: '10.20.11.10' + name: 'STORAGE' + - cidr: '172.10.101.0/24' + gateway: '172.10.101.1' + ip_ranges: + - start: '172.10.101.2' + end: '172.10.101.20' + name: 'EXTERNAL' + network_name: 'admin_external' + mapping: 'physnet1' + - cidr: '10.20.11.0/24' + gateway: '10.20.11.1' + ip_ranges: + - start: '10.20.11.3' + end: '10.20.11.10' + name: 'PUBLICAPI' + - cidr: '10.20.11.0/24' + gateway: '10.20.11.1' + ip_ranges: + - start: '10.20.11.3' + end: '10.20.11.10' + name: 'TENANT' + - cidr: '100.20.11.0/24' + gateway: '100.20.11.1' + ip_ranges: + - start: '100.20.11.3' + end: '100.20.11.10' + name: 'HEARTBEAT' +interfaces: + - name: 'EXTERNAL' + interface: 'ens8' + - name: 'MANAGEMENT' + interface: 'ens3' + - name: 'PUBLICAPI' + interface: 'ens3' + - name: 'STORAGE' + interface: 'ens3' + - name: 'TENANT' + interface: 'ens3' + - name: 'HEARTBEAT' + interface: 'ens9' +internal_vip: '10.20.11.11' +public_vip: '10.20.11.11'
\ No newline at end of file diff --git a/tests/unit/test_get_conf.py b/tests/unit/test_get_conf.py new file mode 100644 index 00000000..66fb2261 --- /dev/null +++ b/tests/unit/test_get_conf.py @@ -0,0 +1,64 @@ +############################################################################## +# 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 os +import pytest + +from deploy.get_conf import ( + get_yml_para, + config +) + + +@pytest.fixture(scope="session") +def deploy_file(data_root): + return os.path.join(data_root, 'lab_conf', 'deploy_virtual1.yml') + + +@pytest.fixture(scope="session") +def network_file(data_root): + return os.path.join(data_root, 'lab_conf', 'network_virtual1.yml') + + +def test_get_yml_para(deploy_file): + assert get_yml_para(deploy_file) == (50, 110, 110, 'r00tme', '10.20.11.2', '10.20.11.1', 5) + + +def test_config(deploy_file, network_file): + assert config(deploy_file, network_file) == ({'ens8': [{'ip': '', 'name': 'EXTERNAL'}], + 'ens3': [{'ip': '', 'name': 'MANAGEMENT'}, + {'ip': '', 'name': 'PUBLICAPI'}, + {'ip': '', 'name': 'STORAGE'}, + {'ip': '', 'name': 'physnet1'}], + 'ens9': [{'ip': '', 'name': 'HEARTBEAT'}]}, + ['computer01', 'computer02', 'controller01', 'controller02', + 'controller03'], + {'MANAGEMENT': {'cidr': '10.20.11.0/24', 'gateway': '10.20.11.1', + 'ip_ranges': [{'start': '10.20.11.3', + 'end': '10.20.11.10'}]}, + 'STORAGE': {'cidr': '10.20.11.0/24', 'gateway': '10.20.11.1', + 'ip_ranges': [{'start': '10.20.11.3', + 'end': '10.20.11.10'}]}, + 'EXTERNAL': {'cidr': '172.10.101.0/24', 'gateway': '172.10.101.1', + 'ip_ranges': [{'start': '172.10.101.2', + 'end': '172.10.101.20'}], + 'network_name': 'admin_external', + 'mapping': 'physnet1'}, + 'PUBLICAPI': {'cidr': '10.20.11.0/24', 'gateway': '10.20.11.1', + 'ip_ranges': [{'start': '10.20.11.3', + 'end': '10.20.11.10'}]}, + 'physnet1': {'cidr': '10.20.11.0/24', 'gateway': '10.20.11.1', + 'ip_ranges': [{'start': '10.20.11.3', + 'end': '10.20.11.10'}]}, + 'HEARTBEAT': {'cidr': '100.20.11.0/24', 'gateway': '100.20.11.1', + 'ip_ranges': [{'start': '100.20.11.3', + 'end': '100.20.11.10'}]}}, + '10.20.11.11', '/dev/sdb', + {'controller01': [], 'controller02': [], 'controller03': [], + 'computer01': [], 'computer02': []}) |