python-tripleoclient/tripleoclient/tests/test_overcloud_credentials.py
Ryan Brady c692982bee Changes Creation Of overcloudrc File to Call Workflow
This patch updates the code and associated tests to change from
directly calling the tripleo.deployment.overcloudrc action to
calling the tripleo.deployment.v1.create_overcloudrc workflow.

Change-Id: Ib100163a5c9a5d2e6cca6cbc5a186e8e5cbc19ce
Depends-On: I6074b4085b5b77f010f5f2972e7b120aa344f6c5
Partial-Bug: 1640436
2018-06-29 09:46:25 -04:00

96 lines
3.4 KiB
Python

# Copyright 2016 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
import shutil
import tempfile
from tripleoclient.tests.v1 import test_plugin
from tripleoclient.v1 import overcloud_credentials
class TestOvercloudCredentials(test_plugin.TestPluginV1):
def setUp(self):
super(TestOvercloudCredentials, self).setUp()
self.cmd = overcloud_credentials.OvercloudCredentials(self.app, None)
self.app.client_manager.workflow_engine = self.workflow = mock.Mock()
self.tripleoclient = mock.Mock()
self.websocket = mock.Mock()
self.websocket.__enter__ = lambda s: self.websocket
self.websocket.__exit__ = lambda s, *exc: None
self.tripleoclient.messaging_websocket.return_value = self.websocket
self.app.client_manager.tripleoclient = self.tripleoclient
self.websocket.wait_for_messages.return_value = iter([{
"execution": {"id": "IDID"},
"status": "SUCCESS",
"message": {
"overcloudrc": "OVERCLOUDRC CONTENTS",
"overcloudrc.v3": "OVERCLOUDRC.v3 CONTENTS",
}
}])
@mock.patch('os.chmod')
def test_ok(self, mock_chmod):
arglist = ['overcloud', ]
verifylist = [
('plan', 'overcloud'),
('directory', '.')
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
with mock.patch("tripleoclient.utils.open", create=True) as m:
self.cmd.take_action(parsed_args)
self.assertIn(mock.call('./overcloudrc', 'w'), m.call_args_list)
self.assertIn(mock.call('./overcloudrc.v3', 'w'), m.call_args_list)
mock_chmod.assert_has_calls([
mock.call('./overcloudrc', 384),
mock.call('./overcloudrc.v3', 384)])
self.workflow.executions.create.assert_called_once_with(
'tripleo.deployment.v1.create_overcloudrc',
workflow_input={'container': 'overcloud'})
@mock.patch('os.chmod')
def test_okay_custom_dir(self, mock_chmod):
temp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, temp)
arglist = ['overcloud', '--directory', temp]
verifylist = [
('plan', 'overcloud'),
('directory', temp)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
with mock.patch("tripleoclient.utils.open", create=True) as m:
self.cmd.take_action(parsed_args)
path = "{}/overcloudrc".format(temp)
pathv3 = "{}/overcloudrc.v3".format(temp)
self.assertIn(mock.call(path, 'w'), m.call_args_list)
self.assertIn(mock.call(pathv3, 'w'), m.call_args_list)
mock_chmod.assert_has_calls([
mock.call(path, 384),
mock.call(pathv3, 384)])
self.workflow.executions.create.assert_called_once_with(
'tripleo.deployment.v1.create_overcloudrc',
workflow_input={'container': 'overcloud'})