Browse Source

Fixed switch to deploying state for nodes which will not be deployed

Nodes can be exluded from deployment, if there is no tasks to run on this nodes.
Such nodes should not be switched to deployment state.

Change-Id: I4cd23769b7643aae7b149ba30e5b0e91a3021563
changes/92/424192/7
Bulat Gaifullin 2 years ago
parent
commit
dc8fd092d3

+ 30
- 0
nailgun/nailgun/test/unit/test_transactions_manager.py View File

@@ -464,3 +464,33 @@ class TestGetCurrentState(BaseUnitTest):
464 464
         }
465 465
 
466 466
         self.assertEqual(expected_state, current_state)
467
+
468
+
469
+class TestPrepareNodes(BaseUnitTest):
470
+    def test_apply_only_for_involved_nodes(self):
471
+        nodes = [
472
+            mock.MagicMock(
473
+                uid=1, progress=0, error_type='deployment', error_msg='test'
474
+            ),
475
+            mock.MagicMock(
476
+                uid=2, progress=0, error_type='provision', error_msg='test2'
477
+            ),
478
+        ]
479
+        manager._prepare_nodes(nodes, False, {2})
480
+        self.assertEqual(0, nodes[0].progress)
481
+        self.assertEqual('deployment', nodes[0].error_type)
482
+        self.assertEqual('test', nodes[0].error_msg)
483
+        self.assertEqual(1, nodes[1].progress)
484
+        self.assertIsNone(nodes[1].error_type)
485
+        self.assertIsNone(nodes[1].error_msg)
486
+
487
+    def test_not_reset_error_if_dry_run(self):
488
+        nodes = [
489
+            mock.MagicMock(
490
+                uid=1, progress=0, error_type='deployment', error_msg='test'
491
+            )
492
+        ]
493
+        manager._prepare_nodes(nodes, True, {1})
494
+        self.assertEqual(1, nodes[0].progress)
495
+        self.assertEqual('deployment', nodes[0].error_type)
496
+        self.assertEqual('test', nodes[0].error_msg)

+ 11
- 7
nailgun/nailgun/transactions/manager.py View File

@@ -350,13 +350,6 @@ class TransactionsManager(object):
350 350
             "execute graph %s on nodes %s",
351 351
             sub_transaction.graph_type, [n.id for n in nodes]
352 352
         )
353
-        for node in nodes:
354
-            # set progress to show that node is in progress state
355
-            node.progress = 1
356
-            if not sub_transaction.dry_run:
357
-                node.error_type = None
358
-                node.error_msg = None
359
-
360 353
         # we should initialize primary roles for cluster before
361 354
         # role resolve has been created
362 355
         objects.Cluster.set_primary_tags(cluster, nodes)
@@ -374,6 +367,8 @@ class TransactionsManager(object):
374 367
                 sub_transaction.cache.get('force')
375 368
             ))
376 369
 
370
+        _prepare_nodes(nodes, sub_transaction.dry_run, context.new['nodes'])
371
+
377 372
         # Attach desired state to the sub transaction, so when we continue
378 373
         # our top-level transaction, the new state will be calculated on
379 374
         # top of this.
@@ -567,6 +562,15 @@ def _dump_expected_state(transaction, state, tasks):
567 562
     db().flush()
568 563
 
569 564
 
565
+def _prepare_nodes(nodes, dry_run, involved_node_ids):
566
+    for node in (node for node in nodes if node.uid in involved_node_ids):
567
+        # set progress to show that node is in progress state
568
+        node.progress = 1
569
+        if not dry_run:
570
+            node.error_type = None
571
+            node.error_msg = None
572
+
573
+
570 574
 def _update_nodes(transaction, nodes_instances, nodes_params):
571 575
     allow_update = {
572 576
         'name',

Loading…
Cancel
Save