diff --git a/nailgun/nailgun/test/unit/test_transactions_manager.py b/nailgun/nailgun/test/unit/test_transactions_manager.py index 5006b0c9cb..f49b066347 100644 --- a/nailgun/nailgun/test/unit/test_transactions_manager.py +++ b/nailgun/nailgun/test/unit/test_transactions_manager.py @@ -464,3 +464,33 @@ class TestGetCurrentState(BaseUnitTest): } self.assertEqual(expected_state, current_state) + + +class TestPrepareNodes(BaseUnitTest): + def test_apply_only_for_involved_nodes(self): + nodes = [ + mock.MagicMock( + uid=1, progress=0, error_type='deployment', error_msg='test' + ), + mock.MagicMock( + uid=2, progress=0, error_type='provision', error_msg='test2' + ), + ] + manager._prepare_nodes(nodes, False, {2}) + self.assertEqual(0, nodes[0].progress) + self.assertEqual('deployment', nodes[0].error_type) + self.assertEqual('test', nodes[0].error_msg) + self.assertEqual(1, nodes[1].progress) + self.assertIsNone(nodes[1].error_type) + self.assertIsNone(nodes[1].error_msg) + + def test_not_reset_error_if_dry_run(self): + nodes = [ + mock.MagicMock( + uid=1, progress=0, error_type='deployment', error_msg='test' + ) + ] + manager._prepare_nodes(nodes, True, {1}) + self.assertEqual(1, nodes[0].progress) + self.assertEqual('deployment', nodes[0].error_type) + self.assertEqual('test', nodes[0].error_msg) diff --git a/nailgun/nailgun/transactions/manager.py b/nailgun/nailgun/transactions/manager.py index 7be79fda87..0b2608ab96 100644 --- a/nailgun/nailgun/transactions/manager.py +++ b/nailgun/nailgun/transactions/manager.py @@ -350,13 +350,6 @@ class TransactionsManager(object): "execute graph %s on nodes %s", sub_transaction.graph_type, [n.id for n in nodes] ) - for node in nodes: - # set progress to show that node is in progress state - node.progress = 1 - if not sub_transaction.dry_run: - node.error_type = None - node.error_msg = None - # we should initialize primary roles for cluster before # role resolve has been created objects.Cluster.set_primary_tags(cluster, nodes) @@ -374,6 +367,8 @@ class TransactionsManager(object): sub_transaction.cache.get('force') )) + _prepare_nodes(nodes, sub_transaction.dry_run, context.new['nodes']) + # Attach desired state to the sub transaction, so when we continue # our top-level transaction, the new state will be calculated on # top of this. @@ -567,6 +562,15 @@ def _dump_expected_state(transaction, state, tasks): db().flush() +def _prepare_nodes(nodes, dry_run, involved_node_ids): + for node in (node for node in nodes if node.uid in involved_node_ids): + # set progress to show that node is in progress state + node.progress = 1 + if not dry_run: + node.error_type = None + node.error_msg = None + + def _update_nodes(transaction, nodes_instances, nodes_params): allow_update = { 'name',