Add more unit test case in test_get_conf.py 53/39053/1
authorzhongjun <zhong.jun@zte.com.cn>
Thu, 10 Aug 2017 11:34:10 +0000 (19:34 +0800)
committerzhongjun <zhong.jun@zte.com.cn>
Thu, 10 Aug 2017 11:55:25 +0000 (19:55 +0800)
Add more unit test cases by pytest parametrize fixture.

Change-Id: I208bcff9af79b73556638e20df96235c4ac60ee2
Signed-off-by: zhongjun <zhong.jun@zte.com.cn>
tests/data/lab_conf/deploy_virtual2.yml [new file with mode: 0644]
tests/data/lab_conf/network_virtual2.yml [new file with mode: 0644]
tests/unit/test_get_conf.py

diff --git a/tests/data/lab_conf/deploy_virtual2.yml b/tests/data/lab_conf/deploy_virtual2.yml
new file mode 100644 (file)
index 0000000..d4c99e9
--- /dev/null
@@ -0,0 +1,15 @@
+adapter: libvirt
+hosts:
+- name: 'all_in_one'
+  roles:
+    - 'CONTROLLER_LB'
+    - 'COMPUTER'
+  template: 'templates/virtual_environment/vms/all_in_one.xml'
+disks:
+  daisy: 50
+  controller: 110
+  compute: 110
+daisy_passwd: 'r00tme'
+daisy_ip: '10.20.11.2'
+daisy_gateway: '10.20.11.1'
+ceph_disk_name: ''
\ No newline at end of file
diff --git a/tests/data/lab_conf/network_virtual2.yml b/tests/data/lab_conf/network_virtual2.yml
new file mode 100644 (file)
index 0000000..7b4a501
--- /dev/null
@@ -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-virtual2 network config'
+  version: '0.1'
+  created: 'Tue Apr 11 2017'
+  comment: 'all-in-one 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'
index f882d9d..dd8480f 100644 (file)
@@ -18,49 +18,82 @@ from deploy.get_conf import (
 
 
 @pytest.fixture(scope="session")
-def deploy_file(data_root):
-    return os.path.join(data_root, 'lab_conf', 'deploy_virtual1.yml')
+def conf_file_dir(data_root):
+    return os.path.join(data_root, 'lab_conf')
 
 
-@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)
+@pytest.mark.parametrize('deploy_file_name, expected', [
+    ('deploy_virtual1.yml', (50, 110, 110, 'r00tme', '10.20.11.2', '10.20.11.1', 5)),
+    ('deploy_virtual2.yml', (50, 110, 110, 'r00tme', '10.20.11.2', '10.20.11.1', 1))])
+def test_get_yml_para(conf_file_dir, deploy_file_name, expected):
+    deploy_file = os.path.join(conf_file_dir, deploy_file_name)
+    assert get_yml_para(deploy_file) == expected
 
 
-def test_config(deploy_file, network_file):
+@pytest.mark.parametrize('deploy_file_name, network_file_name, expected', [
+    ('deploy_virtual1.yml', 'network_virtual1.yml',
+     ({'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': []})),
+    ('deploy_virtual2.yml', 'network_virtual2.yml',
+     ({'ens8': [{'ip': '', 'name': 'EXTERNAL'}],
+       'ens3': [{'ip': '', 'name': 'MANAGEMENT'},
+                {'ip': '', 'name': 'PUBLICAPI'},
+                {'ip': '', 'name': 'STORAGE'},
+                {'ip': '', 'name': 'physnet1'}],
+       'ens9': [{'ip': '', 'name': 'HEARTBEAT'}]},
+      ['all_in_one'],
+      {'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', '',
+      {'all_in_one': []}))])
+def test_config(conf_file_dir, deploy_file_name, network_file_name, expected):
+    deploy_file = os.path.join(conf_file_dir, deploy_file_name)
+    network_file = os.path.join(conf_file_dir, network_file_name)
     result = config(deploy_file, network_file)
-    expect = ({'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': []})
-    assert DeepDiff(result, expect, ignore_order=True) == {}
+    assert DeepDiff(result, expected, ignore_order=True) == {}