Handle when lists not only string in config download
There was a comment about this in the code, we didn't handle when lists properly, only strings. Also fixed the test to avoid leaking temporary files every tox run. Change-Id: I24f80199ba430870af2b4aab9453387304403215 Closes-Bug: #1715871
This commit is contained in:
parent
66f875a7d3
commit
fa4b8fb00c
|
@ -50,11 +50,13 @@ FAKE_STACK = {
|
||||||
'upgrade_batch_tasks': [],
|
'upgrade_batch_tasks': [],
|
||||||
'upgrade_tasks': [{'name': 'Stop fake service',
|
'upgrade_tasks': [{'name': 'Stop fake service',
|
||||||
'service': 'name=fake state=stopped',
|
'service': 'name=fake state=stopped',
|
||||||
'tags': 'step1'},
|
'tags': 'step1',
|
||||||
|
'when': 'existingcondition'},
|
||||||
{'name': 'Stop nova-compute service',
|
{'name': 'Stop nova-compute service',
|
||||||
'service': 'name=openstack-nova-compute '
|
'service': 'name=openstack-nova-compute '
|
||||||
'state=stopped',
|
'state=stopped',
|
||||||
'tags': 'step1'}]
|
'tags': 'step1',
|
||||||
|
'when': ['existing', 'list']}]
|
||||||
},
|
},
|
||||||
'FakeController': {
|
'FakeController': {
|
||||||
'config_settings': {'tripleo::haproxy::user': 'admin'},
|
'config_settings': {'tripleo::haproxy::user': 'admin'},
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import fixtures
|
||||||
import mock
|
import mock
|
||||||
|
import os
|
||||||
|
|
||||||
from mock import call
|
from mock import call
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
@ -127,45 +129,41 @@ class TestOvercloudConfig(utils.TestCommand):
|
||||||
self.cmd.take_action, parsed_args)
|
self.cmd.take_action, parsed_args)
|
||||||
|
|
||||||
@mock.patch('tripleoclient.utils.get_role_data', autospec=True)
|
@mock.patch('tripleoclient.utils.get_role_data', autospec=True)
|
||||||
@mock.patch('os.mkdir')
|
def test_overcloud_config_upgrade_tasks(self, mock_get_role_data):
|
||||||
@mock.patch('six.moves.builtins.open')
|
|
||||||
@mock.patch('tempfile.mkdtemp', autospec=True)
|
|
||||||
def test_overcloud_config_upgrade_tasks(self, mock_tmpdir,
|
|
||||||
mock_open,
|
|
||||||
mock_mkdir,
|
|
||||||
mock_get_role_data):
|
|
||||||
|
|
||||||
clients = self.app.client_manager
|
clients = self.app.client_manager
|
||||||
orchestration_client = clients.orchestration
|
orchestration_client = clients.orchestration
|
||||||
orchestration_client.stacks.get.return_value = fakes.create_tht_stack()
|
orchestration_client.stacks.get.return_value = fakes.create_tht_stack()
|
||||||
mock_tmpdir.return_value = "/tmp/tht"
|
self.tmp_dir = self.useFixture(fixtures.TempDir()).path
|
||||||
fake_role = [role for role in
|
fake_role = [role for role in
|
||||||
fakes.FAKE_STACK['outputs'][1]['output_value']]
|
fakes.FAKE_STACK['outputs'][1]['output_value']]
|
||||||
fake_tasks = {'FakeController': [{'name': 'Stop fake service',
|
expected_tasks = {'FakeController': [{'name': 'Stop fake service',
|
||||||
'service': 'name=fake '
|
'service': 'name=fake '
|
||||||
'state=stopped',
|
'state=stopped',
|
||||||
'tags': 'step1',
|
'tags': 'step1',
|
||||||
'when': 'step|int == 1'}],
|
'when': 'step|int == 1'}],
|
||||||
'FakeCompute': [{'name': 'Stop fake service',
|
'FakeCompute': [{'name': 'Stop fake service',
|
||||||
'service': 'name=fake state=stopped',
|
'service':
|
||||||
'tags': 'step1',
|
'name=fake state=stopped',
|
||||||
'when': 'step|int == 1'},
|
'tags': 'step1',
|
||||||
{'name': 'Stop nova-'
|
'when': ['existingcondition',
|
||||||
'compute service',
|
'step|int == 1']},
|
||||||
'service':
|
{'name': 'Stop nova-'
|
||||||
'name=openstack-nova-'
|
'compute service',
|
||||||
'compute state=stopped',
|
'service':
|
||||||
'tags': 'step1',
|
'name=openstack-nova-'
|
||||||
'when': 'step|int == 1'}]
|
'compute state=stopped',
|
||||||
}
|
'tags': 'step1',
|
||||||
|
'when': ['existing',
|
||||||
|
'list', 'step|int == 1']}]}
|
||||||
mock_get_role_data.return_value = fake_role
|
mock_get_role_data.return_value = fake_role
|
||||||
|
|
||||||
for role in fake_role:
|
for role in fake_role:
|
||||||
filepath = "/tmp/tht/%s/upgrade_tasks_playbook" % role
|
filedir = os.path.join(self.tmp_dir, role)
|
||||||
with mock.patch('os.fdopen'), \
|
os.makedirs(filedir)
|
||||||
mock.patch('os.mkdir'), mock.patch('os.open') as open:
|
filepath = os.path.join(filedir, "upgrade_tasks_playbook.yaml")
|
||||||
playbook_tasks = self.cmd._write_playbook_get_tasks(
|
playbook_tasks = self.cmd._write_playbook_get_tasks(
|
||||||
fakes.FAKE_STACK['outputs'][1]['output_value'][role]
|
fakes.FAKE_STACK['outputs'][1]['output_value'][role]
|
||||||
['upgrade_tasks'], role, filepath)
|
['upgrade_tasks'], role, filepath)
|
||||||
self.assertEqual(fake_tasks[role], playbook_tasks)
|
self.assertTrue(os.path.isfile(filepath))
|
||||||
open.assert_called()
|
self.assertEqual(expected_tasks[role], playbook_tasks)
|
||||||
|
|
|
@ -66,13 +66,21 @@ class DownloadConfig(command.Command):
|
||||||
match = re.search('step([0-9]+)', tag)
|
match = re.search('step([0-9]+)', tag)
|
||||||
if match:
|
if match:
|
||||||
step = match.group(1)
|
step = match.group(1)
|
||||||
whenline = task.get('when', None)
|
whenexpr = task.get('when', None)
|
||||||
if whenline: # how about list of when conditionals
|
if whenexpr:
|
||||||
when_exists = re.search('step.* == [0-9]', whenline)
|
# Handle when: foo and a list of when conditionals
|
||||||
if when_exists: # skip if there is an existing 'step == N'
|
if not isinstance(whenexpr, list):
|
||||||
|
whenexpr = [whenexpr]
|
||||||
|
for w in whenexpr:
|
||||||
|
when_exists = re.search('step|int == [0-9]', w)
|
||||||
|
if when_exists:
|
||||||
|
break
|
||||||
|
if when_exists:
|
||||||
|
# Skip to the next task,
|
||||||
|
# there is an existing 'step|int == N'
|
||||||
continue
|
continue
|
||||||
task['when'] = "(%s) and (step|int == %s)" % (whenline,
|
whenexpr.append("step|int == %s" % step)
|
||||||
step)
|
task['when'] = whenexpr
|
||||||
else:
|
else:
|
||||||
task.update({"when": "step|int == %s" % step})
|
task.update({"when": "step|int == %s" % step})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue