Merge "Get the stack name if possible before running the validations group" into stable/queens

This commit is contained in:
Zuul 2019-05-07 18:35:26 +00:00 committed by Gerrit Code Review
commit d381995a8c
2 changed files with 149 additions and 13 deletions

View File

@ -1006,7 +1006,12 @@ class TestPostConfig(BaseTestCase):
@mock.patch('instack_undercloud.undercloud._get_auth_values')
@mock.patch('instack_undercloud.undercloud._get_session')
@mock.patch('mistralclient.api.client.client', autospec=True)
def test_run_validation_groups_success(self, mock_mistral_client,
@mock.patch('swiftclient.client.Connection', autospec=True)
@mock.patch('os_client_config.make_client')
def test_run_validation_groups_success(self,
mock_make_client,
mock_swift_client,
mock_mistral_client,
mock_get_session,
mock_auth_values):
mock_mistral = mock.Mock()
@ -1014,19 +1019,76 @@ class TestPostConfig(BaseTestCase):
mock_mistral.environments.list.return_value = []
mock_mistral.executions.get.return_value = mock.Mock(state="SUCCESS")
mock_get_session.return_value = mock.MagicMock()
mock_auth_values.return_value = ('aturing', '3nigma', 'hut8',
'http://bletchley:5000/')
mock_instance_swift = mock.Mock()
mock_instance_swift.get_account.return_value = [None,
[{'name': 'hut8'},
{'name': 'mystack'}]]
mock_swift_client.return_value = mock_instance_swift
mock_heat = mock.Mock()
aux_stack = {}
aux_stack['stack_name'] = "mystack"
mock_heat.stacks.list.return_value = [aux_stack]
mock_make_client.return_value = mock_heat
undercloud._run_validation_groups(["post-upgrade"])
mock_mistral.executions.create.assert_called_once_with(
'tripleo.validations.v1.run_groups',
workflow_input={
'group_names': ['post-upgrade'],
'plan': 'mystack',
}
)
@mock.patch('instack_undercloud.undercloud._get_auth_values')
@mock.patch('instack_undercloud.undercloud._get_session')
@mock.patch('mistralclient.api.client.client', autospec=True)
@mock.patch('swiftclient.client.Connection', autospec=True)
@mock.patch('os_client_config.make_client')
def test_run_validation_groups_no_overcloud(self,
mock_make_client,
mock_swift_client,
mock_mistral_client,
mock_get_session,
mock_auth_values):
mock_mistral = mock.Mock()
mock_mistral_client.return_value = mock_mistral
mock_mistral.environments.list.return_value = []
mock_mistral.executions.get.return_value = mock.Mock(state="SUCCESS")
mock_get_session.return_value = mock.MagicMock()
mock_auth_values.return_value = ('aturing', '3nigma', 'hut8',
'http://bletchley:5000/')
mock_instance_swift = mock.Mock()
mock_instance_swift.get_account.return_value = [None,
[{'name': 'hut8'},
{'name': 'mystack'}]]
mock_swift_client.return_value = mock_instance_swift
mock_heat = mock.Mock()
aux_stack = {}
aux_stack['stack_name'] = "mystackooo"
mock_heat.stacks.list.return_value = [aux_stack]
mock_make_client.return_value = mock_heat
undercloud._run_validation_groups(["post-upgrade"])
mock_mistral.executions.create.assert_not_called()
@mock.patch('instack_undercloud.undercloud._get_auth_values')
@mock.patch('instack_undercloud.undercloud._get_session')
@mock.patch('mistralclient.api.client.client', autospec=True)
@mock.patch('time.strptime')
def test_run_validation_groups_fail(self, mock_strptime,
@mock.patch('swiftclient.client.Connection', autospec=True)
@mock.patch('os_client_config.make_client')
def test_run_validation_groups_fail(self,
mock_make_client,
mock_swift_client,
mock_strptime,
mock_mistral_client, mock_get_session,
mock_auth_values):
mock_mistral = mock.Mock()
@ -1036,6 +1098,22 @@ class TestPostConfig(BaseTestCase):
mock_mistral.executions.get_output.return_value = "ERROR!"
mock_mistral.executions.get.id = "1234"
mock_mistral.action_executions.list.return_value = []
mock_auth_values.return_value = ('aturing', '3nigma', 'hut8',
'http://bletchley:5000/')
mock_instance_swift = mock.Mock()
mock_instance_swift.get_account.return_value = [None,
[{'name': 'hut8'},
{'name': 'mystack'}]]
mock_swift_client.return_value = mock_instance_swift
mock_heat = mock.Mock()
aux_stack = {}
aux_stack['stack_name'] = "mystack"
mock_heat.stacks.list.return_value = [aux_stack]
mock_make_client.return_value = mock_heat
mock_strptime.return_value = time.mktime(time.localtime())
mock_get_session.return_value = mock.MagicMock()
self.assertRaises(
@ -1046,7 +1124,12 @@ class TestPostConfig(BaseTestCase):
@mock.patch('instack_undercloud.undercloud._get_session')
@mock.patch('mistralclient.api.client.client', autospec=True)
@mock.patch('time.strptime')
def test_run_validation_groups_timeout(self, mock_strptime,
@mock.patch('swiftclient.client.Connection', autospec=True)
@mock.patch('os_client_config.make_client')
def test_run_validation_groups_timeout(self,
mock_make_client,
mock_swift_client,
mock_strptime,
mock_mistral_client,
mock_get_session, mock_auth_values):
mock_mistral = mock.Mock()
@ -1054,7 +1137,23 @@ class TestPostConfig(BaseTestCase):
mock_mistral.environments.list.return_value = []
mock_mistral.executions.get.id = "1234"
mock_mistral.action_executions.list.return_value = []
mock_get_session.return_value = mock.MagicMock()
mock_instance_swift = mock.Mock()
mock_auth_values.return_value = ('aturing', '3nigma', 'hut8',
'http://bletchley:5000/')
mock_instance_swift = mock.Mock()
mock_instance_swift.get_account.return_value = [None,
[{'name': 'hut8'},
{'name': 'mystack'}]]
mock_swift_client.return_value = mock_instance_swift
mock_heat = mock.Mock()
aux_stack = {}
aux_stack['stack_name'] = "mystack"
mock_heat.stacks.list.return_value = [aux_stack]
mock_make_client.return_value = mock_heat
mock_time = mock.MagicMock()
mock_time.return_value = time.mktime(time.localtime())
mock_strptime.return_value = time.mktime(time.localtime())

View File

@ -1931,15 +1931,52 @@ def _run_validation_groups(groups=[], mistral_url='', timeout=540,
fail_on_error=False):
sess = _get_session()
mistral = mistralclient.client(mistral_url=mistral_url, session=sess)
LOG.info('Starting and waiting for validation groups %s ', groups)
execution = mistral.executions.create(
'tripleo.validations.v1.run_groups',
workflow_input={'group_names': groups}
)
fail_message = ("error running the validation groups %s " % groups)
timeout_at = time.time() + timeout
_wait_for_mistral_execution(timeout_at, mistral, execution, fail_message,
fail_on_error)
# Here we fetch all the containers names from swift, we should have
# a container called with the same name as the deployment plan.
swift_client = swiftclient.Connection(session=sess)
swift = swift_client.get_account()[1]
plans = [container["name"] for container in swift]
user, password, project, auth_url = _get_auth_values()
heat = os_client_config.make_client('orchestration',
auth_url=auth_url,
username=user,
password=password,
project_name=project,
project_domain_name='Default',
user_domain_name='Default')
# Here we get all the stack names, we should have only one.
stack_names_list = [stack['stack_name'] for stack in heat.stacks.list()]
# We calculate the interception of the two previous list, the
# result should be only one value in case the Overcloud exists.
existing_stack = list(set(plans) & set(stack_names_list))
# We can not run the validations if we do not have the Overcloud deployed
# We are running a group validation and if the validation runs in both
# the Undercloud and Overcloud nodes is mandatory to define the Overcloud
# stack name. For example there are validations in the post-upgrade group
# that will run in both the Undercloud and Overcloud making this mistral
# execution fail.
if existing_stack:
LOG.info('Starting and waiting for validation groups %s ', groups)
execution = mistral.executions.create(
'tripleo.validations.v1.run_groups',
workflow_input={'group_names': groups, 'plan': existing_stack[0]}
)
fail_message = ("error running the validation groups %s " % groups)
timeout_at = time.time() + timeout
_wait_for_mistral_execution(timeout_at,
mistral,
execution,
fail_message,
fail_on_error)
else:
LOG.info('We can not run validations if the Overcloud is not deployed')
def _create_default_plan(mistral, plans, timeout=360):