Load Mistral workbooks via Python instead of Bash
Calling openstack clients in a loop from bash is terribly slow. As an example, during a recent undercloud upgrade I saw the process take a full 3 minutes. Doing this via Python instead results in a runtime of 20-25 seconds. Unit test coverage is also added since there was none. Change-Id: I2d3576d30fcae74ea692bd712a40264004d9b9d1
This commit is contained in:
parent
712ee7c8a3
commit
0eb1b59926
|
@ -90,17 +90,6 @@ openstack quota set --cores -1 --instances -1 --ram -1 $(openstack project show
|
|||
# instack-prepare-for-overcloud
|
||||
rm -rf $HOME/.novaclient
|
||||
|
||||
# load workflows
|
||||
for workbook in $(openstack workbook list -f value -c Name | grep tripleo); do
|
||||
openstack workbook delete $workbook
|
||||
done
|
||||
for workflow in $(openstack workflow list -f value -c Name | grep tripleo); do
|
||||
openstack workflow delete $workflow
|
||||
done
|
||||
for workbook in $(ls /usr/share/openstack-tripleo-common/workbooks/*); do
|
||||
openstack workbook create $workbook
|
||||
done
|
||||
|
||||
# IP forwarding is needed to allow the overcloud nodes access to the outside
|
||||
# internet in cases where they are on an isolated network.
|
||||
sysctl -w net.ipv4.ip_forward=1
|
||||
|
|
|
@ -914,6 +914,43 @@ class TestPostConfig(base.BaseTestCase):
|
|||
undercloud._delete_default_flavors(mock_instance)
|
||||
mock_instance.flavors.delete.assert_called_once_with('8ar')
|
||||
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
@mock.patch('os.listdir')
|
||||
@mock.patch('instack_undercloud.undercloud._create_mistral_config_'
|
||||
'environment')
|
||||
@mock.patch('instack_undercloud.undercloud._migrate_plans')
|
||||
@mock.patch('instack_undercloud.undercloud._create_default_plan')
|
||||
def test_post_config_mistral(self, mock_create, mock_migrate, mock_cmce,
|
||||
mock_listdir, mock_isfile):
|
||||
instack_env = {}
|
||||
mock_mistral = mock.Mock()
|
||||
mock_swift = mock.Mock()
|
||||
mock_swift.get_account.return_value = [None, [{'name': 'hut8'}]]
|
||||
|
||||
mock_workbooks = [mock.Mock() for m in range(2)]
|
||||
mock_workbooks[0].name = 'foo'
|
||||
mock_workbooks[1].name = 'tripleo.bar'
|
||||
mock_mistral.workbooks.list.return_value = mock_workbooks
|
||||
mock_workflows = [mock.Mock() for m in range(2)]
|
||||
mock_workflows[0].name = 'foo'
|
||||
mock_workflows[1].name = 'tripleo.bar'
|
||||
mock_mistral.workflows.list.return_value = mock_workflows
|
||||
mock_listdir.return_value = ['foo.yaml', 'bar.yaml']
|
||||
undercloud._post_config_mistral(instack_env, mock_mistral, mock_swift)
|
||||
self.assertEqual([mock.call('tripleo.bar')],
|
||||
mock_mistral.workbooks.delete.mock_calls)
|
||||
self.assertEqual([mock.call('tripleo.bar')],
|
||||
mock_mistral.workflows.delete.mock_calls)
|
||||
self.assertEqual([mock.call(undercloud.PATHS.WORKBOOK_PATH +
|
||||
'/foo.yaml'),
|
||||
mock.call(undercloud.PATHS.WORKBOOK_PATH +
|
||||
'/bar.yaml')],
|
||||
mock_mistral.workbooks.create.mock_calls)
|
||||
mock_cmce.assert_called_once_with(instack_env, mock_mistral)
|
||||
mock_migrate.assert_called_once_with(mock_mistral, mock_swift,
|
||||
['hut8'])
|
||||
mock_create.assert_called_once_with(mock_mistral, ['hut8'])
|
||||
|
||||
|
||||
class TestUpgradeFact(base.BaseTestCase):
|
||||
@mock.patch('instack_undercloud.undercloud._run_command')
|
||||
|
|
|
@ -70,6 +70,10 @@ class Paths(object):
|
|||
def LOG_FILE(self):
|
||||
return os.path.expanduser('~/.instack/install-undercloud.log')
|
||||
|
||||
@property
|
||||
def WORKBOOK_PATH(self):
|
||||
return '/usr/share/openstack-tripleo-common/workbooks'
|
||||
|
||||
|
||||
PATHS = Paths()
|
||||
DEFAULT_LOG_LEVEL = logging.DEBUG
|
||||
|
@ -1459,6 +1463,18 @@ def _prepare_ssh_environment(mistral):
|
|||
|
||||
|
||||
def _post_config_mistral(instack_env, mistral, swift):
|
||||
LOG.info('Configuring Mistral workbooks')
|
||||
for workbook in [w for w in mistral.workbooks.list()
|
||||
if 'tripleo' in w.name]:
|
||||
mistral.workbooks.delete(workbook.name)
|
||||
for workflow in [w for w in mistral.workflows.list()
|
||||
if 'tripleo' in w.name]:
|
||||
mistral.workflows.delete(workflow.name)
|
||||
for workbook in [f for f in os.listdir(PATHS.WORKBOOK_PATH)
|
||||
if os.path.isfile(os.path.join(PATHS.WORKBOOK_PATH, f))]:
|
||||
mistral.workbooks.create(os.path.join(PATHS.WORKBOOK_PATH, workbook))
|
||||
LOG.info('Mistral workbooks configured successfully')
|
||||
|
||||
plans = [container["name"] for container in swift.get_account()[1]]
|
||||
|
||||
_create_mistral_config_environment(instack_env, mistral)
|
||||
|
|
Loading…
Reference in New Issue