Fix the assert comparison error in test_get_conf.py 53/38753/3
authorzhongjun <zhong.jun@zte.com.cn>
Fri, 4 Aug 2017 07:24:00 +0000 (15:24 +0800)
committerzhongjun <zhong.jun@zte.com.cn>
Fri, 4 Aug 2017 07:52:14 +0000 (15:52 +0800)
Because the list/dict parse can not ensure the element sequence in
python, using == method to compare the dict content may cause the
fault. we replace it with DeepDiff function.

Change-Id: I1db52347e24a0b3968bcf645fd47c4fc5b768dc7
Signed-off-by: zhongjun <zhong.jun@zte.com.cn>
requirements.txt
test-requirements.txt
tests/unit/test_get_conf.py

index 3d4d50b..5d78734 100644 (file)
@@ -4,3 +4,4 @@ paramiko
 pyyaml
 scp
 oslo_config
+deepdiff
index 9ab1fa4..26409b1 100644 (file)
@@ -8,3 +8,4 @@ pytest-mock
 pyyaml
 scp
 oslo_config
+deepdiff
index 66fb226..10b040a 100644 (file)
@@ -10,6 +10,8 @@
 import os
 import pytest
 
+from deepdiff import DeepDiff
+
 from deploy.get_conf import (
     get_yml_para,
     config
@@ -31,34 +33,35 @@ def test_get_yml_para(deploy_file):
 
 
 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': []})
+    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) == {}