Browse Source

Merge "prepare_net_info only if info contains quantum_settings"

changes/97/371597/1
Jenkins 2 years ago
parent
commit
adf928ece2

+ 4
- 4
octane/commands/install_node.py View File

@@ -30,12 +30,12 @@ LOG = logging.getLogger(__name__)
30 30
 def isolate(nodes, env):
31 31
     nodes.sort(key=lambda node: node.id, reverse=True)
32 32
     hub = nodes[0]
33
-    deployment_info = env.get_default_facts(
34
-        'deployment', nodes=[hub.data['id']])
33
+    deployment_info = env_util.get_node_default_facts(
34
+        env, nodes=[hub.data['id']])
35 35
     network.create_bridges(hub, env, deployment_info)
36 36
     for node in nodes[1:]:
37
-        deployment_info = env.get_default_facts(
38
-            'deployment', nodes=[node.data['id']])
37
+        deployment_info = env_util.get_node_default_facts(
38
+            env, nodes=[node.data['id']])
39 39
         network.setup_isolation(hub, node, env, deployment_info)
40 40
     for node in nodes:
41 41
         network.flush_arp(node)

+ 1
- 1
octane/handlers/upgrade/controller.py View File

@@ -31,7 +31,7 @@ class ControllerUpgrade(upgrade.UpgradeHandler):
31 31
         self.gateway = None
32 32
 
33 33
     def predeploy(self):
34
-        default_info = self.env.get_default_facts('deployment')
34
+        default_info = env_util.get_node_default_facts(self.env)
35 35
         deployment_info = []
36 36
         network_data = self.env.get_network_data()
37 37
         gw_admin = transformations.get_network_gw(network_data,

+ 32
- 0
octane/tests/test_env.py View File

@@ -316,3 +316,35 @@ def test_wait_for_node_stopped(mocker):
316 316
             ) in excinfo.args)
317 317
     sleep.assert_called_once_with(60)
318 318
     time.assert_has_calls((mock.call(), mock.call()))
319
+
320
+
321
+@pytest.mark.parametrize("api,modified", [
322
+    ([], []),
323
+    (
324
+        [
325
+            {'uid': 'common', 'common_key': 'common_value'},
326
+            {'uid': 'master'},
327
+            {'uid': 'node-1', 'common_key': 'uncommon_value'},
328
+        ],
329
+        [
330
+            {'uid': 'master', 'common_key': 'common_value'},
331
+            {'uid': 'node-1', 'common_key': 'uncommon_value'},
332
+        ]
333
+    ),
334
+    (
335
+        [
336
+            {'uid': 'master', 'common_key': 'common_value'},
337
+            {'uid': 'node-1', 'common_key': 'uncommon_value'},
338
+        ],
339
+        [
340
+            {'uid': 'master', 'common_key': 'common_value'},
341
+            {'uid': 'node-1', 'common_key': 'uncommon_value'},
342
+        ]
343
+    ),
344
+])
345
+@pytest.mark.parametrize("nodes", [None, [1, 2, 3]])
346
+def test_util_env(mocker, api, modified, nodes):
347
+    env = mock.Mock()
348
+    env.get_default_facts.return_value = api
349
+    assert modified == env_util.get_node_default_facts(env, nodes)
350
+    env.get_default_facts.assert_called_once_with('deployment', nodes=nodes)

+ 18
- 1
octane/util/env.py View File

@@ -10,6 +10,7 @@
10 10
 # License for the specific language governing permissions and limitations
11 11
 # under the License.
12 12
 
13
+import copy
13 14
 import json
14 15
 import logging
15 16
 import os.path
@@ -237,6 +238,8 @@ def deploy_changes(env, nodes):
237 238
 
238 239
 
239 240
 def prepare_net_info(info):
241
+    if "quantum_settings" not in info:
242
+        return
240 243
     quantum_settings = info["quantum_settings"]
241 244
     pred_nets = quantum_settings["predefined_networks"]
242 245
     phys_nets = quantum_settings["L2"]["phys_nets"]
@@ -259,8 +262,22 @@ def get_admin_password(env, node=None):
259 262
     return get_astute_yaml(env, node)['access']['password']
260 263
 
261 264
 
265
+def get_node_default_facts(env, nodes=None):
266
+    facts = env.get_default_facts('deployment', nodes=nodes)
267
+    common = None
268
+    node_facts = []
269
+    for fact in facts:
270
+        if fact.get("uid") == "common":
271
+            common = fact
272
+        else:
273
+            node_facts.append(fact)
274
+    if not common:
275
+        return node_facts
276
+    return [helpers.merge_dicts(copy.deepcopy(common), n) for n in node_facts]
277
+
278
+
262 279
 def update_deployment_info(env, isolated):
263
-    default_info = env.get_default_facts('deployment')
280
+    default_info = get_node_default_facts(env)
264 281
     network_data = env.get_network_data()
265 282
     gw_admin = transformations.get_network_gw(network_data,
266 283
                                               "fuelweb_admin")

Loading…
Cancel
Save