Browse Source

Make chef agent tests more reliable

They fail sometimes on py35 because we rely on dict order in asserts.
Let's remove that and load json instead.

Change-Id: I7bff32028cc130128ce05c151534c85ef99607d5
Thomas Herve 1 year ago
parent
commit
62c4511eeb
1 changed files with 4 additions and 6 deletions
  1. 4
    6
      tests/test_hook_chef.py

+ 4
- 6
tests/test_hook_chef.py View File

@@ -96,8 +96,6 @@ class HookChefTest(common.RunScriptTest):
96 96
                     'fooval': {u'bar': u'baz'},
97 97
                     'run_list': [u'recipe[apache]']
98 98
                 }
99
-                exp_node = json.dumps(exp_node, indent=4,
100
-                                      separators=(',', ': '))
101 99
                 exp_cfg = ("log_level :debug\n"
102 100
                            "log_location STDOUT\n"
103 101
                            "local_mode true\n"
@@ -111,7 +109,8 @@ class HookChefTest(common.RunScriptTest):
111 109
                            "node_path '/var/lib/heat-config/"
112 110
                            "heat-config-chef/node'")
113 111
                 mfdopen.return_value.write.assert_any_call(exp_cfg)
114
-                mfdopen.return_value.write.assert_any_call(exp_node)
112
+                args = mfdopen.return_value.write.mock_calls[0][1][0]
113
+                self.assertEqual(exp_node, json.loads(args))
115 114
         calls = [
116 115
             mock.call(['hostname', '-f'], env=mock.ANY, stderr=mock.ANY,
117 116
                       stdout=mock.ANY),
@@ -194,8 +193,6 @@ class HookChefTest(common.RunScriptTest):
194 193
                     'fooval': {u'bar': u'baz'},
195 194
                     'run_list': [u'recipe[apache]']
196 195
                 }
197
-                exp_node = json.dumps(exp_node, indent=4,
198
-                                      separators=(',', ': '))
199 196
                 exp_cfg = ("log_level :debug\n"
200 197
                            "log_location STDOUT\n"
201 198
                            "local_mode true\n"
@@ -210,4 +207,5 @@ class HookChefTest(common.RunScriptTest):
210 207
                            "node_path '/var/lib/heat-config/"
211 208
                            "heat-config-chef/node'")
212 209
                 mfdopen.return_value.write.assert_any_call(exp_cfg)
213
-                mfdopen.return_value.write.assert_any_call(exp_node)
210
+                args = mfdopen.return_value.write.mock_calls[0][1][0]
211
+                self.assertEqual(exp_node, json.loads(args))

Loading…
Cancel
Save