Replace ansible shell with python runner

This change replaces all of the ansible shell commands with the
python library, ansible-runner. This library is supported by
upstream ansible, is approved by the openstack foundation, is
supported in global requirements, and provides a better, more
programatic interface into running ansible playbooks.

All tests that interacted with the old shell commands have been
updated to now test using the library.

Change-Id: I8db50da826e2fbc074f4e7986d6fd00f6d488648
Signed-off-by: Kevin Carter <kecarter@redhat.com>
changes/78/671878/44
Kevin Carter 2019-07-19 21:45:52 -05:00
parent 29b00170b3
commit bcc9c66747
No known key found for this signature in database
GPG Key ID: CE94BD890A47B20A
25 changed files with 789 additions and 926 deletions

View File

@ -1,5 +1,6 @@
alembic==0.8.10
amqp==2.1.1
ansible-runner===1.4.4
aodhclient==0.9.0
appdirs==1.3.0
asn1crypto==0.23.0

View File

@ -19,3 +19,4 @@ websocket-client>=0.44.0 # LGPLv2+
tripleo-common>=11.3.1 # Apache-2.0
cryptography>=2.1 # BSD/Apache-2.0
futures>=3.0.0;python_version=='2.7' or python_version=='2.6' # BSD
ansible-runner>=1.4.4 # Apache 2.0

View File

@ -102,16 +102,33 @@ CTLPLANE_INSPECTION_IPRANGE_DEFAULT = '192.168.24.100,192.168.24.120'
CTLPLANE_GATEWAY_DEFAULT = '192.168.24.1'
CTLPLANE_DNS_NAMESERVERS_DEFAULT = []
# Ansible parameters used for the actions being
# executed during tripleo deploy/upgrade.
# Ansible parameters used for the actions being executed during tripleo
# deploy/upgrade. Used as kwargs in the `utils.run_ansible_playbook`
# function. A playbook entry is either a string representing the name of
# one the playbook or a list of playbooks to execute. The lookup
# will search for the playbook in the work directory path.
DEPLOY_ANSIBLE_ACTIONS = {
'deploy': 'deploy_steps_playbook.yaml',
'upgrade': 'upgrade_steps_playbook.yaml --skip-tags '
'validation',
'post-upgrade': 'post_upgrade_steps_playbook.yaml '
'--skip-tags validation',
'online-upgrade': 'external_upgrade_steps_playbook.yaml '
'--tags online_upgrade',
'deploy': {
'playbook': 'deploy_steps_playbook.yaml'
},
'upgrade': {
'playbook': 'upgrade_steps_playbook.yaml',
'skip_tags': 'validation'
},
'post-upgrade': {
'playbook': 'post_upgrade_steps_playbook.yaml',
'skip_tags': 'validation'
},
'online-upgrade': {
'playbook': 'external_upgrade_steps_playbook.yaml',
'tags': 'online_upgrade'
},
'preflight-deploy': {
'playbook': 'undercloud-disk-space.yaml'
},
'preflight-upgrade': {
'playbook': 'undercloud-disk-space-pre-upgrade.yaml'
},
}
# Key-value pair of deprecated service and its warning message

View File

@ -80,3 +80,8 @@ class FakeClientWrapper(object):
def messaging_websocket(self):
return self.ws
def fake_ansible_runner_run_return(rc=0):
return 'Test Status', rc

View File

@ -38,9 +38,13 @@ import yaml
from tripleoclient import exceptions
from tripleoclient import utils
from tripleoclient.tests import fakes
from six.moves.configparser import ConfigParser
from six.moves.urllib import error as url_error
from ansible_runner import Runner
class TestRunAnsiblePlaybook(TestCase):
def setUp(self):
@ -48,329 +52,130 @@ class TestRunAnsiblePlaybook(TestCase):
self.addCleanup(self.unlink_patch.stop)
self.unlink_patch.start()
self.mock_log = mock.Mock('logging.getLogger')
python_version = sys.version_info[0]
self.ansible_playbook_cmd = "ansible-playbook-%s" % (python_version)
self.ansible_playbook_cmd = "ansible-playbook"
@mock.patch('os.path.exists', return_value=False)
@mock.patch('tripleoclient.utils.run_command_and_log')
def test_no_playbook(self, mock_run, mock_exists):
self.assertRaises(RuntimeError,
utils.run_ansible_playbook,
self.mock_log,
'/tmp',
'non-existing.yaml',
'localhost,'
)
mock_exists.assert_called_once_with('/tmp/non-existing.yaml')
self.assertRaises(
RuntimeError,
utils.run_ansible_playbook,
'non-existing.yaml',
'localhost,',
'/tmp'
)
mock_exists.assert_called_with('/tmp/non-existing.yaml')
mock_run.assert_not_called()
@mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg'))
@mock.patch('os.path.exists', return_value=True)
@mock.patch('tripleoclient.utils.run_command_and_log')
def test_subprocess_error(self, mock_run, mock_exists, mock_mkstemp):
mock_process = mock.Mock()
mock_process.returncode = 1
mock_process.stdout.read.side_effect = ["Error\n"]
mock_run.return_value = mock_process
env = os.environ.copy()
env['ANSIBLE_LIBRARY'] = \
('/root/.ansible/plugins/modules:'
'/usr/share/ansible/plugins/modules:'
'/usr/share/openstack-tripleo-validations/library')
env['ANSIBLE_LOOKUP_PLUGINS'] = \
('root/.ansible/plugins/lookup:'
'/usr/share/ansible/plugins/lookup:'
'/usr/share/openstack-tripleo-validations/lookup_plugins')
env['ANSIBLE_CALLBACK_PLUGINS'] = \
('~/.ansible/plugins/callback:'
'/usr/share/ansible/plugins/callback:'
'/usr/share/openstack-tripleo-validations/callback_plugins')
env['ANSIBLE_ROLES_PATH'] = \
('/root/.ansible/roles:'
'/usr/share/ansible/roles:'
'/etc/ansible/roles:'
'/usr/share/openstack-tripleo-validations/roles')
env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg'
env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
env['ANSIBLE_LOG_PATH'] = '/tmp/ansible.log'
env['TRIPLEO_PLAN_NAME'] = 'overcloud'
self.assertRaises(RuntimeError,
utils.run_ansible_playbook,
self.mock_log,
'/tmp',
'existing.yaml',
'localhost,'
)
mock_run.assert_called_once_with(self.mock_log,
[self.ansible_playbook_cmd,
'-u', 'root',
'-i', 'localhost,', '-v',
'-c', 'smart',
'/tmp/existing.yaml'],
env=env, retcode_only=False)
@mock.patch('os.path.isabs')
@mock.patch('os.path.exists', return_value=False)
@mock.patch('tripleoclient.utils.run_command_and_log')
def test_non_existing_config(self, mock_run, mock_exists, mock_isabs):
self.assertRaises(RuntimeError,
utils.run_ansible_playbook, self.mock_log,
'/tmp', 'existing.yaml', 'localhost,',
'/home/foo', '/tmp/foo.cfg'
)
mock_exists.assert_called_with('/tmp/foo.cfg')
mock_isabs.assert_called_with('/tmp/foo.cfg')
mock_run.assert_not_called()
@mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg'))
@mock.patch('os.path.exists', return_value=True)
@mock.patch('tripleoclient.utils.run_command_and_log')
def test_run_success_default(self, mock_run, mock_exists, mock_mkstemp):
mock_process = mock.Mock()
mock_process.returncode = 0
mock_run.return_value = mock_process
retcode, output = utils.run_ansible_playbook(
self.mock_log, '/tmp', 'existing.yaml', 'localhost,')
self.assertEqual(retcode, 0)
mock_exists.assert_called_once_with('/tmp/existing.yaml')
env = os.environ.copy()
env['ANSIBLE_LIBRARY'] = \
('/root/.ansible/plugins/modules:'
'/usr/share/ansible/plugins/modules:'
'/usr/share/openstack-tripleo-validations/library')
env['ANSIBLE_LOOKUP_PLUGINS'] = \
('root/.ansible/plugins/lookup:'
'/usr/share/ansible/plugins/lookup:'
'/usr/share/openstack-tripleo-validations/lookup_plugins')
env['ANSIBLE_CALLBACK_PLUGINS'] = \
('~/.ansible/plugins/callback:'
'/usr/share/ansible/plugins/callback:'
'/usr/share/openstack-tripleo-validations/callback_plugins')
env['ANSIBLE_ROLES_PATH'] = \
('/root/.ansible/roles:'
'/usr/share/ansible/roles:'
'/etc/ansible/roles:'
'/usr/share/openstack-tripleo-validations/roles')
env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg'
env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
env['ANSIBLE_LOG_PATH'] = '/tmp/ansible.log'
env['TRIPLEO_PLAN_NAME'] = 'overcloud'
mock_run.assert_called_once_with(self.mock_log,
[self.ansible_playbook_cmd,
'-u', 'root',
'-i', 'localhost,', '-v',
'-c', 'smart',
'/tmp/existing.yaml'],
env=env, retcode_only=False)
@mock.patch('os.path.isabs')
@mock.patch('os.path.exists', return_value=True)
@mock.patch('tripleoclient.utils.run_command_and_log')
def test_run_success_ansible_cfg(self, mock_run, mock_exists, mock_isabs):
mock_process = mock.Mock()
mock_process.returncode = 0
mock_run.return_value = mock_process
retcode, output = utils.run_ansible_playbook(
self.mock_log,
'/tmp',
@mock.patch('os.makedirs')
@mock.patch.object(
Runner,
'run',
return_value=fakes.fake_ansible_runner_run_return(rc=1)
)
def test_subprocess_error(self, mock_run, mock_mkdirs, mock_exists,
mock_mkstemp):
self.assertRaises(
RuntimeError,
utils.run_ansible_playbook,
'existing.yaml',
'localhost,',
ansible_config='/tmp/foo.cfg')
self.assertEqual(retcode, 0)
mock_isabs.assert_called_once_with('/tmp/foo.cfg')
exist_calls = [mock.call('/tmp/foo.cfg'),
mock.call('/tmp/existing.yaml')]
mock_exists.assert_has_calls(exist_calls, any_order=False)
env = os.environ.copy()
env['ANSIBLE_LIBRARY'] = \
('/root/.ansible/plugins/modules:'
'/usr/share/ansible/plugins/modules:'
'/usr/share/openstack-tripleo-validations/library')
env['ANSIBLE_LOOKUP_PLUGINS'] = \
('root/.ansible/plugins/lookup:'
'/usr/share/ansible/plugins/lookup:'
'/usr/share/openstack-tripleo-validations/lookup_plugins')
env['ANSIBLE_CALLBACK_PLUGINS'] = \
('~/.ansible/plugins/callback:'
'/usr/share/ansible/plugins/callback:'
'/usr/share/openstack-tripleo-validations/callback_plugins')
env['ANSIBLE_ROLES_PATH'] = \
('/root/.ansible/roles:'
'/usr/share/ansible/roles:'
'/etc/ansible/roles:'
'/usr/share/openstack-tripleo-validations/roles')
env['ANSIBLE_CONFIG'] = '/tmp/foo.cfg'
env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
env['ANSIBLE_LOG_PATH'] = '/tmp/ansible.log'
env['TRIPLEO_PLAN_NAME'] = 'overcloud'
mock_run.assert_called_once_with(self.mock_log,
[self.ansible_playbook_cmd,
'-u', 'root',
'-i', 'localhost,', '-v',
'-c', 'smart',
'/tmp/existing.yaml'],
env=env, retcode_only=False)
'/tmp'
)
@mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg'))
@mock.patch('os.path.exists', return_value=True)
@mock.patch('tripleoclient.utils.run_command_and_log')
def test_run_success_connection_local(self, mock_run, mock_exists,
mok_mkstemp):
mock_process = mock.Mock()
mock_process.returncode = 0
mock_run.return_value = mock_process
@mock.patch('os.makedirs')
@mock.patch.object(
Runner,
'run',
return_value=fakes.fake_ansible_runner_run_return()
)
def test_run_success_default(self, mock_run, mock_mkdirs, mock_exists,
mock_mkstemp):
retcode, output = utils.run_ansible_playbook(
self.mock_log,
'/tmp',
'existing.yaml',
'localhost,',
connection='local')
playbook='existing.yaml',
inventory='localhost,',
workdir='/tmp'
)
self.assertEqual(retcode, 0)
mock_exists.assert_called_once_with('/tmp/existing.yaml')
env = os.environ.copy()
env['ANSIBLE_LIBRARY'] = \
('/root/.ansible/plugins/modules:'
'/usr/share/ansible/plugins/modules:'
'/usr/share/openstack-tripleo-validations/library')
env['ANSIBLE_LOOKUP_PLUGINS'] = \
('root/.ansible/plugins/lookup:'
'/usr/share/ansible/plugins/lookup:'
'/usr/share/openstack-tripleo-validations/lookup_plugins')
env['ANSIBLE_CALLBACK_PLUGINS'] = \
('~/.ansible/plugins/callback:'
'/usr/share/ansible/plugins/callback:'
'/usr/share/openstack-tripleo-validations/callback_plugins')
env['ANSIBLE_ROLES_PATH'] = \
('/root/.ansible/roles:'
'/usr/share/ansible/roles:'
'/etc/ansible/roles:'
'/usr/share/openstack-tripleo-validations/roles')
env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg'
env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
env['ANSIBLE_LOG_PATH'] = '/tmp/ansible.log'
env['TRIPLEO_PLAN_NAME'] = 'overcloud'
mock_run.assert_called_once_with(self.mock_log,
[self.ansible_playbook_cmd,
'-u', 'root',
'-i', 'localhost,', '-v',
'-c', 'local',
'/tmp/existing.yaml'],
env=env, retcode_only=False)
@mock.patch('os.path.exists', return_value=True)
@mock.patch('os.makedirs')
@mock.patch.object(
Runner,
'run',
return_value=fakes.fake_ansible_runner_run_return()
)
def test_run_success_ansible_cfg(self, mock_run, mock_mkdirs, mock_exists):
retcode, output = utils.run_ansible_playbook(
playbook='existing.yaml',
inventory='localhost,',
workdir='/tmp'
)
self.assertEqual(retcode, 0)
@mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg'))
@mock.patch('os.path.exists', return_value=True)
@mock.patch('tripleoclient.utils.run_command_and_log')
@mock.patch('os.makedirs')
@mock.patch.object(
Runner,
'run',
return_value=fakes.fake_ansible_runner_run_return()
)
def test_run_success_connection_local(self, mock_run, mock_mkdirs,
mock_exists, mock_mkstemp):
retcode, output = utils.run_ansible_playbook(
playbook='existing.yaml',
inventory='localhost,',
workdir='/tmp',
connection='local'
)
self.assertEqual(retcode, 0)
@mock.patch('os.makedirs', return_value=None)
@mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg'))
@mock.patch('os.path.exists', return_value=True)
@mock.patch.object(
Runner,
'run',
return_value=fakes.fake_ansible_runner_run_return()
)
def test_run_success_gathering_policy(self, mock_run, mock_exists,
mok_mkstemp):
mock_process = mock.Mock()
mock_process.returncode = 0
mock_run.return_value = mock_process
mock_mkstemp, mock_makedirs):
retcode, output = utils.run_ansible_playbook(
self.mock_log,
'/tmp',
'existing.yaml',
'localhost,',
gathering_policy='explicit')
playbook='existing.yaml',
inventory='localhost,',
workdir='/tmp',
connection='local',
gathering_policy='smart'
)
self.assertEqual(retcode, 0)
mock_exists.assert_called_once_with('/tmp/existing.yaml')
env = os.environ.copy()
env['ANSIBLE_LIBRARY'] = \
('/root/.ansible/plugins/modules:'
'/usr/share/ansible/plugins/modules:'
'/usr/share/openstack-tripleo-validations/library')
env['ANSIBLE_LOOKUP_PLUGINS'] = \
('root/.ansible/plugins/lookup:'
'/usr/share/ansible/plugins/lookup:'
'/usr/share/openstack-tripleo-validations/lookup_plugins')
env['ANSIBLE_CALLBACK_PLUGINS'] = \
('~/.ansible/plugins/callback:'
'/usr/share/ansible/plugins/callback:'
'/usr/share/openstack-tripleo-validations/callback_plugins')
env['ANSIBLE_ROLES_PATH'] = \
('/root/.ansible/roles:'
'/usr/share/ansible/roles:'
'/etc/ansible/roles:'
'/usr/share/openstack-tripleo-validations/roles')
env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg'
env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
env['ANSIBLE_LOG_PATH'] = '/tmp/ansible.log'
env['TRIPLEO_PLAN_NAME'] = 'overcloud'
env['ANSIBLE_GATHERING'] = 'explicit'
mock_run.assert_called_once_with(self.mock_log,
[self.ansible_playbook_cmd,
'-u', 'root',
'-i', 'localhost,', '-v',
'-c', 'smart',
'/tmp/existing.yaml'],
env=env, retcode_only=False)
@mock.patch('os.makedirs', return_value=None)
@mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg'))
@mock.patch('os.path.exists', return_value=True)
@mock.patch('tripleoclient.utils.run_command_and_log')
def test_run_success_extra_vars(self, mock_run, mock_exists, mock_mkstemp):
mock_process = mock.Mock()
mock_process.returncode = 0
mock_run.return_value = mock_process
@mock.patch.object(
Runner,
'run',
return_value=fakes.fake_ansible_runner_run_return()
)
def test_run_success_extra_vars(self, mock_run, mock_exists, mock_mkstemp,
mock_makedirs):
arglist = {
'var_one': 'val_one',
}
retcode, output = utils.run_ansible_playbook(
self.mock_log,
'/tmp',
'existing.yaml',
'localhost,',
extra_vars=arglist)
playbook='existing.yaml',
inventory='localhost,',
workdir='/tmp',
connection='local',
gathering_policy='smart',
extra_vars=arglist
)
self.assertEqual(retcode, 0)
mock_exists.assert_called_once_with('/tmp/existing.yaml')
env = os.environ.copy()
env['ANSIBLE_LIBRARY'] = \
('/root/.ansible/plugins/modules:'
'/usr/share/ansible/plugins/modules:'
'/usr/share/openstack-tripleo-validations/library')
env['ANSIBLE_LOOKUP_PLUGINS'] = \
('root/.ansible/plugins/lookup:'
'/usr/share/ansible/plugins/lookup:'
'/usr/share/openstack-tripleo-validations/lookup_plugins')
env['ANSIBLE_CALLBACK_PLUGINS'] = \
('~/.ansible/plugins/callback:'
'/usr/share/ansible/plugins/callback:'
'/usr/share/openstack-tripleo-validations/callback_plugins')
env['ANSIBLE_ROLES_PATH'] = \
('/root/.ansible/roles:'
'/usr/share/ansible/roles:'
'/etc/ansible/roles:'
'/usr/share/openstack-tripleo-validations/roles')
env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg'
env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
env['ANSIBLE_LOG_PATH'] = '/tmp/ansible.log'
env['TRIPLEO_PLAN_NAME'] = 'overcloud'
mock_run.assert_called_once_with(
self.mock_log, [
self.ansible_playbook_cmd, '-u', 'root',
'-i', 'localhost,', '-v',
'--extra-vars', '%s' % arglist,
'-c', 'smart', '/tmp/existing.yaml'
],
env=env,
retcode_only=False)
class TestRunCommandAndLog(TestCase):
@ -1170,14 +975,6 @@ class TestStoreCliParam(TestCase):
def setUp(self):
self.args = argparse.ArgumentParser()
@mock.patch('os.mkdir')
@mock.patch('os.path.exists')
def test_fail_to_create_file(self, mock_exists, mock_mkdir):
mock_exists.return_value = False
mock_mkdir.side_effect = OSError()
command = "undercloud install"
self.assertRaises(OSError, utils.store_cli_param, command, self.args)
@mock.patch('os.path.isdir')
@mock.patch('os.path.exists')
def test_exists_but_not_dir(self, mock_exists, mock_isdir):
@ -1741,36 +1538,6 @@ class TestGetLocalTimezone(TestCase):
self.assertEqual('UTC', utils.get_local_timezone())
class TestAnsibleSymlink(TestCase):
@mock.patch('tripleoclient.utils.run_command')
@mock.patch('os.path.exists', side_effect=[False, True])
def test_ansible_symlink_needed(self, mock_path, mock_cmd):
utils.ansible_symlink()
python_version = sys.version_info[0]
ansible_playbook_cmd = "ansible-playbook-{}".format(python_version)
mock_cmd.assert_called_once_with(['sudo', 'ln', '-s',
'/usr/bin/' + ansible_playbook_cmd,
'/usr/bin/ansible-playbook'],
name='ansible-playbook-symlink')
@mock.patch('tripleoclient.utils.run_command')
@mock.patch('os.path.exists', side_effect=[True, False])
def test_ansible3_symlink_needed(self, mock_path, mock_cmd):
utils.ansible_symlink()
python_version = sys.version_info[0]
ansible_playbook_cmd = "ansible-playbook-{}".format(python_version)
mock_cmd.assert_called_once_with(['sudo', 'ln', '-s',
'/usr/bin/ansible-playbook',
'/usr/bin/' + ansible_playbook_cmd],
name='ansible-playbook-3-symlink')
@mock.patch('tripleoclient.utils.run_command')
@mock.patch('os.path.exists', side_effect=[False, False])
def test_ansible_symlink_not_needed(self, mock_path, mock_cmd):
utils.ansible_symlink()
mock_cmd.assert_not_called()
class TestGetParamFieldName(TestCase):
def test_with_empty_val_data(self):
input_parameter = {}

View File

@ -262,9 +262,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
'UndercloudHostsEntries':
['192.168.0.1 uc.ctlplane.localhost uc.ctlplane']}}
mock_rm = shutil.rmtree = mock.MagicMock()
self.cmd.take_action(parsed_args)
mock_rm.assert_not_called()
self.assertFalse(orchestration_client.stacks.create.called)
@ -309,6 +307,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
self.assertEqual(env_map.get('parameter_defaults'),
parameters_env.get('parameter_defaults'))
@mock.patch('os.chdir')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_get_undercloud_host_entry', autospec=True,
return_value='192.168.0.1 uc.ctlplane.localhost uc.ctlplane')
@ -339,7 +338,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_postconfig, mock_shutil_rmtree,
mock_invoke_plan_env_wf,
mock_stack_network_check,
mock_get_undercloud_host_entry):
mock_get_undercloud_host_entry,
mock_chdir):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
plane_management_fixture = deployment.PlanManagementFixture()
@ -446,6 +446,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
clients.tripleoclient.object_store.put_object.assert_called()
self.assertTrue(mock_invoke_plan_env_wf.called)
@mock.patch('os.chdir')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_get_undercloud_host_entry', autospec=True,
return_value='192.168.0.1 uc.ctlplane.localhost uc.ctlplane')
@ -470,7 +471,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_create_parameters_env, mock_validate_args,
mock_breakpoints_cleanup,
mock_postconfig, mock_deprecated_params, mock_stack_network_check,
mock_get_undercloud_host_entry):
mock_get_undercloud_host_entry,
mock_chdir):
fixture = deployment.DeploymentWorkflowFixture()
self.useFixture(fixture)
plane_management_fixture = deployment.PlanManagementFixture()
@ -526,9 +528,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_create_parameters_env.side_effect = _custom_create_params_env
mock_rm = shutil.rmtree = mock.MagicMock()
self.cmd.take_action(parsed_args)
mock_rm.assert_called_once()
execution_calls = workflow_client.executions.create.call_args_list
deploy_plan_call = execution_calls[1]
deploy_plan_call_input = deploy_plan_call[1]['workflow_input']

View File

@ -968,17 +968,21 @@ class TestContainerImageBuild(TestPluginV1):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
f, path = tempfile.mkstemp(dir=self.temp_dir)
with mock.patch('tempfile.mkstemp') as mock_mkstemp:
mock_mkstemp.return_value = f, path
self.cmd.take_action(parsed_args)
with mock.patch('tempfile.mkdtemp') as mock_mkd:
mock_mkd.return_value = '/tmp/testing'
with mock.patch('tempfile.mkstemp') as mock_mkstemp:
with mock.patch('os.chdir'):
mock_mkstemp.return_value = f, path
self.cmd.take_action(parsed_args)
mock_builder.assert_called_once_with([
'/tmp/foo.yaml', '/tmp/bar.yaml'])
mock_builder.return_value.build_images.assert_called_once_with([
self.default_kolla_conf, '/tmp/kolla.conf',
path
], [], False, None)
], [], False, '/tmp/testing')
@mock.patch('os.chdir')
@mock.patch('os.fdopen', autospec=True)
@mock.patch('tempfile.mkdtemp')
@mock.patch('tempfile.mkstemp')
@ -997,7 +1001,8 @@ class TestContainerImageBuild(TestPluginV1):
mock_builder, mock_buildah,
mock_kolla_boolean_cfg,
mock_kolla_cfg, mock_mkstemp,
mock_mkdtemp, mock_fdopen):
mock_mkdtemp, mock_fdopen,
mock_chdir):
arglist = [
'--config-file',
'/tmp/bar.yaml',
@ -1056,16 +1061,19 @@ class TestContainerImageBuild(TestPluginV1):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
f, path = tempfile.mkstemp(dir=self.temp_dir)
with mock.patch('tempfile.mkstemp') as mock_mkstemp:
mock_mkstemp.return_value = f, path
self.cmd.take_action(parsed_args)
with mock.patch('tempfile.mkdtemp') as mock_mkd:
mock_mkd.return_value = '/tmp/testing'
with mock.patch('tempfile.mkstemp') as mock_mkstemp:
with mock.patch('os.chdir'):
mock_mkstemp.return_value = f, path
self.cmd.take_action(parsed_args)
mock_builder.assert_called_once_with([
'/tmp/foo.yaml', '/tmp/bar.yaml'])
mock_builder.return_value.build_images.assert_called_once_with([
self.default_kolla_conf, '/tmp/kolla.conf',
path
], ['foo', 'bar'], False, None)
], ['foo', 'bar'], False, '/tmp/testing')
@mock.patch('tripleo_common.image.kolla_builder.KollaImageBuilder',
autospec=True)

View File

@ -24,11 +24,15 @@ from heatclient import exc as hc_exc
from tripleo_common.image import kolla_builder
from tripleoclient import exceptions
from tripleoclient.tests import fakes
from tripleoclient.tests.v1.test_plugin import TestPluginV1
# Load the plugin init module for the plugin list and show commands
from tripleoclient.v1 import tripleo_deploy
import ansible_runner
# TODO(sbaker) Remove after a tripleo-common release contains this new function
if not hasattr(kolla_builder, 'container_images_prepare_multi'):
setattr(kolla_builder, 'container_images_prepare_multi', mock.Mock())
@ -47,6 +51,7 @@ class TestDeployUndercloud(TestPluginV1):
# Get the command object to test
self.cmd = tripleo_deploy.Deploy(self.app, None)
self.cmd.ansible_dir = '/tmp'
tripleo_deploy.Deploy.heat_pid = mock.MagicMock(
return_value=False)
@ -59,8 +64,7 @@ class TestDeployUndercloud(TestPluginV1):
self.orc.stacks.create = mock.MagicMock(
return_value={'stack': {'id': 'foo'}})
python_version = sys.version_info[0]
self.ansible_playbook_cmd = "ansible-playbook-%s" % (python_version)
self.ansible_playbook_cmd = "ansible-playbook"
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy._is_undercloud_deploy')
@mock.patch('tripleoclient.utils.check_hostname')
@ -833,37 +837,6 @@ class TestDeployUndercloud(TestPluginV1):
mock_inventory.write_static_inventory.assert_called_once_with(
fake_output_dir + '/inventory.yaml', extra_vars)
@mock.patch('tripleoclient.utils.'
'run_command_and_log', autospec=True)
@mock.patch('os.chdir')
@mock.patch('os.execvp')
def test_launch_ansible_deploy(self, mock_execvp, mock_chdir, mock_run):
self.cmd._launch_ansible('/tmp')
mock_chdir.assert_called_once()
mock_run.assert_called_once_with(self.cmd.log, [
self.ansible_playbook_cmd, '-i', '/tmp/inventory.yaml',
'deploy_steps_playbook.yaml'])
@mock.patch('tripleoclient.utils.'
'run_command_and_log', autospec=True)
@mock.patch('os.chdir')
@mock.patch('os.execvp')
def test_launch_ansible_with_args(self, mock_execvp, mock_chdir, mock_run):
args = ['--skip-tags', 'validation']
self.cmd._launch_ansible('/tmp', args, operation='deploy')
mock_chdir.assert_called_once()
mock_run.assert_called_once_with(self.cmd.log, [
self.ansible_playbook_cmd, '-i', '/tmp/inventory.yaml',
'deploy_steps_playbook.yaml', '--skip-tags', 'validation'])
@mock.patch('os.execvp')
def test_launch_ansible_invalid_op(self, mock_execvp):
self.assertRaises(exceptions.DeploymentError, self.cmd._launch_ansible,
'/tmp', operation='unploy')
@mock.patch('tripleo_common.image.kolla_builder.'
'container_images_prepare_multi')
def test_prepare_container_images(self, mock_cipm):
@ -886,6 +859,18 @@ class TestDeployUndercloud(TestPluginV1):
env
)
@mock.patch.object(
ansible_runner.runner_config.RunnerConfig,
'prepare',
return_value=fakes.fake_ansible_runner_run_return()
)
@mock.patch.object(
ansible_runner.Runner,
'run',
return_value=fakes.fake_ansible_runner_run_return()
)
@mock.patch('os.path.exists')
@mock.patch('os.chdir')
@mock.patch('tripleoclient.utils.reset_cmdline')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_download_stack_outputs')
@ -903,8 +888,6 @@ class TestDeployUndercloud(TestPluginV1):
'_populate_templates_dir')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_create_install_artifact', return_value='/tmp/foo.tar.bzip2')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_launch_ansible', return_value=0)
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_cleanup_working_dirs')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
@ -928,18 +911,17 @@ class TestDeployUndercloud(TestPluginV1):
@mock.patch('tripleoclient.utils.wait_for_stack_ready', return_value=True)
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_set_default_plan')
@mock.patch('tripleoclient.utils.ansible_symlink')
def test_take_action_standalone(self, mock_slink, mock_def_plan, mock_poll,
def test_take_action_standalone(self, mock_def_plan, mock_poll,
mock_environ, mock_geteuid, mock_puppet,
mock_killheat, mock_launchheat,
mock_download, mock_tht,
mock_wait_for_port, mock_createdirs,
mock_cleanupdirs, mock_launchansible,
mock_tarball, mock_templates_dir,
mock_open, mock_os, mock_user, mock_cc,
mock_chmod, mock_ac, mock_outputs,
mock_cmdline):
mock_slink.side_effect = 'fake-cmd'
mock_cleanupdirs, mock_tarball,
mock_templates_dir, mock_open, mock_os,
mock_user, mock_cc, mock_chmod, mock_ac,
mock_outputs, mock_cmdline, mock_chdir,
mock_file_exists, mock_run,
mock_run_prepare):
parsed_args = self.check_parser(self.cmd,
['--local-ip', '127.0.0.1',
'--templates', '/tmp/thtroot',
@ -957,6 +939,7 @@ class TestDeployUndercloud(TestPluginV1):
'-e', '../../../outside.yaml',
'--standalone'], [])
mock_file_exists.return_value = True
fake_orchestration = mock_launchheat(parsed_args)
self.cmd.take_action(parsed_args)
mock_createdirs.assert_called_once()
@ -967,16 +950,12 @@ class TestDeployUndercloud(TestPluginV1):
mock_download.assert_called_with(self.cmd, fake_orchestration,
'undercloud', 'Undercloud',
sys.executable)
mock_launchansible.assert_called_once()
mock_tarball.assert_called_once()
mock_cleanupdirs.assert_called_once()
self.assertEqual(mock_killheat.call_count, 2)
mock_cmdline.assert_called_once()
@mock.patch('tripleoclient.utils.reset_cmdline')
@mock.patch('tripleoclient.utils.ansible_symlink')
def test_take_action(self, mock_slink, mock_cmdline):
mock_slink.side_effect = 'fake-cmd'
def test_take_action(self, mock_cmdline):
parsed_args = self.check_parser(self.cmd,
['--local-ip', '127.0.0.1',
'--templates', '/tmp/thtroot',
@ -984,14 +963,11 @@ class TestDeployUndercloud(TestPluginV1):
'--output-dir', '/my'], [])
self.assertRaises(exceptions.DeploymentError,
self.cmd.take_action, parsed_args)
mock_cmdline.assert_called_once()
@mock.patch('tripleoclient.utils.reset_cmdline')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy._standalone_deploy',
return_value=1)
@mock.patch('tripleoclient.utils.ansible_symlink')
def test_take_action_failure(self, mock_slink, mock_deploy, mock_cmdline):
mock_slink.side_effect = 'fake-cmd'
def test_take_action_failure(self, mock_deploy, mock_cmdline):
parsed_args = self.check_parser(self.cmd,
['--local-ip', '127.0.0.1',
'--templates', '/tmp/thtroot',
@ -1000,7 +976,6 @@ class TestDeployUndercloud(TestPluginV1):
'--standalone'], [])
self.assertRaises(exceptions.DeploymentError,
self.cmd.take_action, parsed_args)
mock_cmdline.assert_called_once()
@mock.patch('os.path.isfile', return_value=False)
def test_set_stack_action_default_create(self, mock_isfile):

View File

@ -14,7 +14,6 @@
#
import mock
import sys
from osc_lib.tests import utils
import six
@ -31,48 +30,8 @@ class TestUpgrade(utils.TestCommand):
# Get the command object to test
self.cmd = tripleo_upgrade.Upgrade(self.app, None)
python_version = sys.version_info[0]
self.ansible_playbook_cmd = "ansible-playbook-%s" % (python_version)
@mock.patch('tripleoclient.utils.'
'run_command_and_log', autospec=True)
@mock.patch('os.chdir')
@mock.patch('os.execvp')
def test_launch_ansible_upgrade(self, mock_execvp, mock_chdir, mock_run):
self.cmd._launch_ansible('/tmp', operation='upgrade')
mock_chdir.assert_called_once()
mock_run.assert_called_once_with(self.cmd.log, [
self.ansible_playbook_cmd, '-i', '/tmp/inventory.yaml',
'upgrade_steps_playbook.yaml',
'--skip-tags', 'validation'])
@mock.patch('tripleoclient.utils.'
'run_command_and_log', autospec=True)
@mock.patch('os.chdir')
@mock.patch('os.execvp')
def test_launch_ansible_post_upgrade(self, mock_execvp, mock_chdir,
mock_run):
self.cmd._launch_ansible('/tmp', operation='post-upgrade')
mock_chdir.assert_called_once()
mock_run.assert_called_once_with(self.cmd.log, [
self.ansible_playbook_cmd, '-i', '/tmp/inventory.yaml',
'post_upgrade_steps_playbook.yaml',
'--skip-tags', 'validation'])
@mock.patch('tripleoclient.utils.'
'run_command_and_log', autospec=True)
@mock.patch('os.chdir')
@mock.patch('os.execvp')
def test_launch_ansible_online_upgrade(self, mock_execvp, mock_chdir,
mock_run):
self.cmd._launch_ansible('/tmp', operation='online-upgrade')
mock_chdir.assert_called_once()
mock_run.assert_called_once_with(self.cmd.log, [
self.ansible_playbook_cmd, '-i', '/tmp/inventory.yaml',
'external_upgrade_steps_playbook.yaml',
'--tags', 'online_upgrade'])
self.cmd.ansible_dir = '/tmp'
self.ansible_playbook_cmd = "ansible-playbook"
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.take_action',
autospec=True)
@ -127,9 +86,7 @@ class TestUpgrade(utils.TestCommand):
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy',
autospec=True)
@mock.patch('sys.stdin', spec=six.StringIO)
@mock.patch('tripleoclient.utils.ansible_symlink')
def test_take_action_prompt_no(self, mock_slink, mock_stdin, mock_deploy):
mock_slink.side_effect = 'fake-cmd'
def test_take_action_prompt_no(self, mock_stdin, mock_deploy):
mock_stdin.isatty.return_value = True
mock_stdin.readline.return_value = 'n'
parsed_args = self.check_parser(self.cmd,
@ -153,10 +110,7 @@ class TestUpgrade(utils.TestCommand):
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy',
autospec=True)
@mock.patch('sys.stdin', spec=six.StringIO)
@mock.patch('tripleoclient.utils.ansible_symlink')
def test_take_action_prompt_invalid_option(self, mock_slink, mock_stdin,
mock_deploy):
mock_slink.side_effect = 'fake-cmd'
def test_take_action_prompt_invalid_option(self, mock_stdin, mock_deploy):
mock_stdin.isatty.return_value = True
mock_stdin.readline.return_value = 'Dontwant'
parsed_args = self.check_parser(self.cmd,

View File

@ -14,7 +14,6 @@
#
import mock
import sys
from osc_lib.tests import utils
from tripleoclient.v1 import tripleo_validator
@ -115,56 +114,3 @@ class TestValidatorShowParameter(utils.TestCommand):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
class TestValidatorRun(utils.TestCommand):
def setUp(self):
super(TestValidatorRun, self).setUp()
# Get the command object to test
self.cmd = tripleo_validator.TripleOValidatorRun(self.app, None)
@mock.patch('sys.exit')
@mock.patch('logging.getLogger')
@mock.patch('pwd.getpwuid')
@mock.patch('os.getuid')
@mock.patch('tripleoclient.utils.get_tripleo_ansible_inventory',
return_value='/home/stack/inventory.yaml')
@mock.patch('tripleoclient.utils.run_ansible_playbook',
autospec=True)
def test_validation_run_with_ansible(self, plan_mock, mock_inventory,
mock_getuid, mock_getpwuid,
mock_logger, mock_sysexit):
mock_pwuid = mock.Mock()
mock_pwuid.pw_dir = '/home/stack'
mock_getpwuid.return_value = mock_pwuid
mock_log = mock.Mock()
mock_logger.return_value = mock_log
playbooks_dir = '/usr/share/openstack-tripleo-validations/playbooks'
arglist = [
'--validation',
'check-ftype'
]
verifylist = [('validation_name', ['check-ftype'])]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
plan_mock.assert_called_once_with(
logger=mock_log,
plan='overcloud',
inventory='/home/stack/inventory.yaml',
workdir=playbooks_dir,
log_path_dir='/home/stack',
playbook='check-ftype.yaml',
retries=False,
output_callback='validation_output',
extra_vars={},
python_interpreter='/usr/bin/python{}'.format(sys.version_info[0]),
gathering_policy='explicit'
)
assert mock_sysexit.called

View File

@ -36,8 +36,7 @@ class TestMinionDeploy(base.TestCase):
@mock.patch('tripleoclient.v1.minion_config._process_undercloud_passwords')
@mock.patch('tripleoclient.v1.undercloud_preflight.minion_check')
@mock.patch('tripleoclient.utils.ansible_symlink')
@mock.patch('os.path.isdir', return_value=True)
@mock.patch('os.makedirs', return_value=None)
@mock.patch('tripleoclient.v1.minion_config._process_undercloud_output',
return_value='output.yaml')
@mock.patch('tripleoclient.v1.minion_config._container_images_config')
@ -46,7 +45,7 @@ class TestMinionDeploy(base.TestCase):
@mock.patch('tripleoclient.utils.load_config')
def test_basic_deploy(self, mock_load_config, mock_get_user,
mock_write_env, mock_undercloud_output,
mock_images_config, mock_isdir, mock_ans_symlink,
mock_images_config, mock_isdir,
mock_check, mock_pass):
mock_get_user.return_value = 'foo'
cmd = minion_config.prepare_minion_deploy()
@ -102,9 +101,8 @@ class TestMinionDeploy(base.TestCase):
@mock.patch('tripleoclient.v1.minion_config._process_undercloud_passwords')
@mock.patch('tripleoclient.v1.undercloud_preflight.minion_check')
@mock.patch('tripleoclient.utils.ansible_symlink')
@mock.patch('os.path.exists', return_value=True)
@mock.patch('os.path.isdir', return_value=True)
@mock.patch('os.makedirs', return_value=None)
@mock.patch('tripleoclient.v1.minion_config._process_undercloud_output',
return_value='output.yaml')
@mock.patch('tripleoclient.v1.minion_config._container_images_config')
@ -113,7 +111,7 @@ class TestMinionDeploy(base.TestCase):
def test_configured_deploy(self, mock_load_config,
mock_write_env, mock_undercloud_output,
mock_images_config, mock_isdir, mock_exists,
mock_ans_symlink, mock_check, mock_pass):
mock_check, mock_pass):
self.conf.set_default('deployment_user', 'bar')
self.conf.set_default('enable_heat_engine', False)
self.conf.set_default('enable_ironic_conductor', True)

View File

@ -54,6 +54,7 @@ class TestUndercloudInstall(TestPluginV1):
self.cmd = undercloud.InstallUndercloud(self.app, app_args)
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('six.moves.builtins.open')
@mock.patch('shutil.copy')
@ -63,7 +64,7 @@ class TestUndercloudInstall(TestPluginV1):
def test_undercloud_install_default(self, mock_subprocess,
mock_wr,
mock_os, mock_copy,
mock_open, mock_user):
mock_open, mock_user, mock_getuid):
arglist = ['--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -118,14 +119,16 @@ class TestUndercloudInstall(TestPluginV1):
'undercloud-stack-vstate-dropin.yaml'])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@mock.patch('os.makedirs', return_value=None)
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_install_with_heat_customized(self, mock_subprocess,
mock_wr, mock_os,
mock_copy, mock_user):
mock_copy, mock_user,
mock_getuid):
self.conf.config(output_dir='/foo')
self.conf.config(templates='/usertht')
self.conf.config(heat_native='false')
@ -178,6 +181,7 @@ class TestUndercloudInstall(TestPluginV1):
'--force-stack-update'])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@ -200,7 +204,8 @@ class TestUndercloudInstall(TestPluginV1):
mock_sroutes,
mock_masq,
mock_wr, mock_os,
mock_copy, mock_user):
mock_copy, mock_user,
mock_getuid):
self.conf.config(net_config_override='/foo/net-config.json')
self.conf.config(local_interface='ethX')
self.conf.config(undercloud_public_host='4.3.2.1')
@ -348,6 +353,7 @@ class TestUndercloudInstall(TestPluginV1):
'undercloud-stack-vstate-dropin.yaml'])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('six.moves.builtins.open')
@mock.patch('shutil.copy')
@ -357,7 +363,8 @@ class TestUndercloudInstall(TestPluginV1):
def test_undercloud_install_with_heat_and_debug(self, mock_subprocess,
mock_wr,
mock_os, mock_copy,
mock_open, mock_user):
mock_open, mock_user,
mock_getuid):
self.conf.config(undercloud_log_file='/foo/bar')
arglist = ['--no-validations']
verifylist = []
@ -416,6 +423,7 @@ class TestUndercloudInstall(TestPluginV1):
'undercloud-stack-vstate-dropin.yaml'])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('six.moves.builtins.open')
@mock.patch('shutil.copy')
@ -425,7 +433,8 @@ class TestUndercloudInstall(TestPluginV1):
def test_undercloud_install_with_heat_true(self, mock_subprocess,
mock_wr,
mock_os, mock_copy,
mock_open, mock_user):
mock_open, mock_user,
mock_getuid):
self.conf.config(undercloud_log_file='/foo/bar')
arglist = ['--no-validations']
verifylist = []
@ -480,6 +489,7 @@ class TestUndercloudInstall(TestPluginV1):
'undercloud-stack-vstate-dropin.yaml'])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@ -487,7 +497,8 @@ class TestUndercloudInstall(TestPluginV1):
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_install_with_swift_encryption(self, mock_subprocess,
mock_wr, mock_os,
mock_copy, mock_user):
mock_copy, mock_user,
mock_getuid):
arglist = ['--no-validations']
verifylist = []
self.conf.set_default('enable_swift_encryption', True)
@ -564,6 +575,7 @@ class TestUndercloudUpgrade(TestPluginV1):
self.cmd = undercloud.UpgradeUndercloud(self.app, app_args)
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@ -571,7 +583,8 @@ class TestUndercloudUpgrade(TestPluginV1):
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_upgrade_default(self, mock_subprocess,
mock_wr,
mock_os, mock_copy, mock_user):
mock_os, mock_copy, mock_user,
mock_getuid):
arglist = ['--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -629,6 +642,7 @@ class TestUndercloudUpgrade(TestPluginV1):
'undercloud-stack-vstate-dropin.yaml'])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@ -636,7 +650,8 @@ class TestUndercloudUpgrade(TestPluginV1):
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_upgrade_with_heat_enabled(self, mock_subprocess,
mock_wr, mock_os,
mock_copy, mock_user):
mock_copy, mock_user,
mock_getuid):
arglist = ['--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -693,6 +708,7 @@ class TestUndercloudUpgrade(TestPluginV1):
'undercloud-stack-vstate-dropin.yaml'])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@ -700,7 +716,8 @@ class TestUndercloudUpgrade(TestPluginV1):
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_upgrade_with_heat_true(self, mock_subprocess,
mock_wr, mock_os,
mock_copy, mock_user):
mock_copy, mock_user,
mock_getuid):
arglist = ['--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -757,6 +774,7 @@ class TestUndercloudUpgrade(TestPluginV1):
'/usr/share/openstack-tripleo-heat-templates/'
'undercloud-stack-vstate-dropin.yaml'])
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@ -764,7 +782,8 @@ class TestUndercloudUpgrade(TestPluginV1):
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_upgrade_with_heat_and_yes(self, mock_subprocess,
mock_wr, mock_os,
mock_user, mock_copy):
mock_copy, mock_user,
mock_getuid):
arglist = ['--no-validations', '-y']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -822,6 +841,7 @@ class TestUndercloudUpgrade(TestPluginV1):
'undercloud-stack-vstate-dropin.yaml'])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('os.geteuid', return_value=1001)
@mock.patch('getpass.getuser', return_value='stack')
@mock.patch('shutil.copy')
@mock.patch('os.mkdir')
@ -829,7 +849,8 @@ class TestUndercloudUpgrade(TestPluginV1):
@mock.patch('subprocess.check_call', autospec=True)
def test_undercloud_upgrade_with_heat_and_debug(self, mock_subprocess,
mock_wr, mock_os,
mock_copy, mock_user):
mock_copy, mock_user,
mock_getuid):
arglist = ['--no-validations']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

View File

@ -46,14 +46,16 @@ class TestDeploymentWorkflows(utils.TestCommand):
"message": "Fail.",
}])
@mock.patch('os.chdir')