|
|
|
@ -11,9 +11,9 @@
|
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
|
|
import mock
|
|
|
|
|
import stat
|
|
|
|
|
|
|
|
|
|
from mock import call
|
|
|
|
|
from mock import patch
|
|
|
|
|
from osc_lib.tests import utils
|
|
|
|
|
|
|
|
|
|
from tripleoclient.tests.v1.overcloud_config import fakes
|
|
|
|
@ -30,8 +30,13 @@ class TestOvercloudConfig(utils.TestCommand):
|
|
|
|
|
self.app.client_manager.orchestration = mock.Mock()
|
|
|
|
|
self.workflow = self.app.client_manager.workflow_engine
|
|
|
|
|
|
|
|
|
|
@patch.object(overcloud_config.DownloadConfig, '_mkdir')
|
|
|
|
|
@patch.object(overcloud_config.DownloadConfig, '_open_file')
|
|
|
|
|
@mock.patch('tempfile.mkdtemp', autospec=True)
|
|
|
|
|
def test_overcloud_config_generate_config(self, mock_tmpdir):
|
|
|
|
|
def test_overcloud_config_generate_config(self,
|
|
|
|
|
mock_tmpdir,
|
|
|
|
|
mock_open,
|
|
|
|
|
mock_mkdir):
|
|
|
|
|
arglist = ['--name', 'overcloud', '--config-dir', '/tmp']
|
|
|
|
|
verifylist = [
|
|
|
|
|
('name', 'overcloud'),
|
|
|
|
@ -44,34 +49,34 @@ class TestOvercloudConfig(utils.TestCommand):
|
|
|
|
|
'service_names',
|
|
|
|
|
'upgrade_batch_tasks', 'upgrade_tasks']
|
|
|
|
|
fake_role = [role for role in
|
|
|
|
|
fakes.FAKE_STACK['outputs'][0]['output_value']]
|
|
|
|
|
fakes.FAKE_STACK['outputs'][1]['output_value']]
|
|
|
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
clients = self.app.client_manager
|
|
|
|
|
orchestration_client = clients.orchestration
|
|
|
|
|
orchestration_client.stacks.get.return_value = fakes.create_tht_stack()
|
|
|
|
|
mock_tmpdir.return_value = "/tmp/tht"
|
|
|
|
|
with mock.patch('os.open') as open, \
|
|
|
|
|
mock.patch('os.fdopen'), mock.patch('os.mkdir') as mkdir:
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
expected_mkdir_calls = [call('/tmp/tht/%s' % r,
|
|
|
|
|
stat.S_IRWXU) for r in fake_role]
|
|
|
|
|
mkdir.assert_has_calls(expected_mkdir_calls, any_order=True)
|
|
|
|
|
expected_calls = []
|
|
|
|
|
for config in config_type_list:
|
|
|
|
|
for role in fake_role:
|
|
|
|
|
if config == 'step_config':
|
|
|
|
|
expected_calls += [call('/tmp/tht/%s/%s.pp' %
|
|
|
|
|
(role, config), 65,
|
|
|
|
|
stat.S_IRUSR | stat.S_IWUSR)]
|
|
|
|
|
else:
|
|
|
|
|
expected_calls += [call('/tmp/tht/%s/%s.yaml' %
|
|
|
|
|
(role, config), 65,
|
|
|
|
|
stat.S_IRUSR | stat.S_IWUSR)]
|
|
|
|
|
open.assert_has_calls(expected_calls, any_order=True)
|
|
|
|
|
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
expected_mkdir_calls = [call('/tmp/tht/%s' % r) for r in fake_role]
|
|
|
|
|
mock_mkdir.assert_has_calls(expected_mkdir_calls, any_order=True)
|
|
|
|
|
expected_calls = []
|
|
|
|
|
for config in config_type_list:
|
|
|
|
|
for role in fake_role:
|
|
|
|
|
if config == 'step_config':
|
|
|
|
|
expected_calls += [call('/tmp/tht/%s/%s.pp' %
|
|
|
|
|
(role, config))]
|
|
|
|
|
else:
|
|
|
|
|
expected_calls += [call('/tmp/tht/%s/%s.yaml' %
|
|
|
|
|
(role, config))]
|
|
|
|
|
mock_open.assert_has_calls(expected_calls, any_order=True)
|
|
|
|
|
|
|
|
|
|
@patch.object(overcloud_config.DownloadConfig, '_mkdir')
|
|
|
|
|
@patch.object(overcloud_config.DownloadConfig, '_open_file')
|
|
|
|
|
@mock.patch('tempfile.mkdtemp', autospec=True)
|
|
|
|
|
def test_overcloud_config_one_config_type(self, mock_tmpdir):
|
|
|
|
|
def test_overcloud_config_one_config_type(self,
|
|
|
|
|
mock_tmpdir,
|
|
|
|
|
mock_open,
|
|
|
|
|
mock_mkdir):
|
|
|
|
|
|
|
|
|
|
arglist = ['--name', 'overcloud', '--config-dir', '/tmp',
|
|
|
|
|
'--config-type', ['config_settings']]
|
|
|
|
@ -82,25 +87,20 @@ class TestOvercloudConfig(utils.TestCommand):
|
|
|
|
|
]
|
|
|
|
|
expected_config_type = 'config_settings'
|
|
|
|
|
fake_role = [role for role in
|
|
|
|
|
fakes.FAKE_STACK['outputs'][0]['output_value']]
|
|
|
|
|
|
|
|
|
|
fakes.FAKE_STACK['outputs'][1]['output_value']]
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
|
|
clients = self.app.client_manager
|
|
|
|
|
orchestration_client = clients.orchestration
|
|
|
|
|
orchestration_client.stacks.get.return_value = fakes.create_tht_stack()
|
|
|
|
|
mock_tmpdir.return_value = "/tmp/tht"
|
|
|
|
|
with mock.patch('os.open') as open, \
|
|
|
|
|
mock.patch('os.fdopen'), mock.patch('os.mkdir') as mkdir:
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
expected_mkdir_calls = [call('/tmp/tht/%s' % r,
|
|
|
|
|
stat.S_IRWXU) for r in fake_role]
|
|
|
|
|
mkdir.assert_has_calls(expected_mkdir_calls, any_order=True)
|
|
|
|
|
expected_calls = [call('/tmp/tht/%s/%s.yaml' %
|
|
|
|
|
(r, expected_config_type), 65,
|
|
|
|
|
stat.S_IRUSR | stat.S_IWUSR)
|
|
|
|
|
for r in fake_role]
|
|
|
|
|
open.assert_has_calls(expected_calls, any_order=True)
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
expected_mkdir_calls = [call('/tmp/tht/%s' % r) for r in fake_role]
|
|
|
|
|
expected_calls = [call('/tmp/tht/%s/%s.yaml'
|
|
|
|
|
% (r, expected_config_type))
|
|
|
|
|
for r in fake_role]
|
|
|
|
|
mock_mkdir.assert_has_calls(expected_mkdir_calls, any_order=True)
|
|
|
|
|
mock_open.assert_has_calls(expected_calls, any_order=True)
|
|
|
|
|
|
|
|
|
|
@mock.patch('os.mkdir')
|
|
|
|
|
@mock.patch('six.moves.builtins.open')
|
|
|
|
@ -140,7 +140,7 @@ class TestOvercloudConfig(utils.TestCommand):
|
|
|
|
|
orchestration_client.stacks.get.return_value = fakes.create_tht_stack()
|
|
|
|
|
mock_tmpdir.return_value = "/tmp/tht"
|
|
|
|
|
fake_role = [role for role in
|
|
|
|
|
fakes.FAKE_STACK['outputs'][0]['output_value']]
|
|
|
|
|
fakes.FAKE_STACK['outputs'][1]['output_value']]
|
|
|
|
|
fake_tasks = {'FakeController': [{'name': 'Stop fake service',
|
|
|
|
|
'service': 'name=fake '
|
|
|
|
|
'state=stopped',
|
|
|
|
@ -165,7 +165,7 @@ class TestOvercloudConfig(utils.TestCommand):
|
|
|
|
|
with mock.patch('os.fdopen'), \
|
|
|
|
|
mock.patch('os.mkdir'), mock.patch('os.open') as open:
|
|
|
|
|
playbook_tasks = self.cmd._write_playbook_get_tasks(
|
|
|
|
|
fakes.FAKE_STACK['outputs'][0]['output_value'][role]
|
|
|
|
|
fakes.FAKE_STACK['outputs'][1]['output_value'][role]
|
|
|
|
|
['upgrade_tasks'], role, filepath)
|
|
|
|
|
self.assertEqual(fake_tasks[role], playbook_tasks)
|
|
|
|
|
open.assert_called()
|
|
|
|
|