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

This commit is contained in:
Jenkins 2017-02-28 21:33:49 +00:00 committed by Gerrit Code Review
commit d72287f19e
2 changed files with 41 additions and 7 deletions

View File

@ -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)

View File

@ -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',