[TRAIN-Only] Reduce open mock scope
There appears to be a race condition related to language parsing that is being uncovered when we mock open around the arg parse code. This highlights that we're relying to open mock instead of mocking a function that uses open. Rather than rewrite all the tests, let's reduce the scope of the open mock to the action execution instead. This only really applies to train and older because we rewrote many of these actions to ansible executions instead. Change-Id: I7f7b25aa76bef692991200ba621a536f8868200a Closes-Bug: #1909118
This commit is contained in:
parent
3af6f58e7d
commit
e5b8ebde85
|
@ -40,8 +40,7 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_update_with_user_and_tags(self, mock_open, mock_execute,
|
||||
def test_update_with_user_and_tags(self, mock_execute,
|
||||
mock_expanduser, update_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
|
@ -53,7 +52,8 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
|
@ -75,8 +75,7 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_update_with_user_and_extra_vars(self, mock_open, mock_execute,
|
||||
def test_update_with_user_and_extra_vars(self, mock_execute,
|
||||
mock_expanduser, update_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
|
@ -89,7 +88,8 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
|
|
|
@ -40,8 +40,7 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_with_user_and_tags(self, mock_open, mock_execute,
|
||||
def test_upgrade_with_user_and_tags(self, mock_execute,
|
||||
mock_expanduser, update_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
|
@ -53,7 +52,8 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
|
@ -75,8 +75,7 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_with_user_and_extra_vars(self, mock_open, mock_execute,
|
||||
def test_upgrade_with_user_and_extra_vars(self, mock_execute,
|
||||
mock_expanduser, update_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
|
@ -89,7 +88,8 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
|
|
|
@ -52,10 +52,9 @@ class TestOvercloudUpdatePrepare(fakes.TestOvercloudUpdatePrepare):
|
|||
@mock.patch('os.path.abspath')
|
||||
@mock.patch('yaml.safe_load')
|
||||
@mock.patch('shutil.copytree', autospec=True)
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
'_deploy_tripleo_heat_templates_tmpdir', autospec=True)
|
||||
def test_update_out(self, mock_deploy, mock_open, mock_copy, mock_yaml,
|
||||
def test_update_out(self, mock_deploy, mock_copy, mock_yaml,
|
||||
mock_abspath, mock_update, mock_logger,
|
||||
mock_get_stack, mock_get_undercloud_host_entry,
|
||||
mock_confirm, mock_get_stack_output_item):
|
||||
|
@ -73,7 +72,8 @@ class TestOvercloudUpdatePrepare(fakes.TestOvercloudUpdatePrepare):
|
|||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('os.path.isfile') as mock_isfile:
|
||||
mock.patch('os.path.isfile') as mock_isfile, \
|
||||
mock.patch('six.moves.builtins.open'):
|
||||
mock_exists.return_value = True
|
||||
mock_isfile.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
@ -90,14 +90,13 @@ class TestOvercloudUpdatePrepare(fakes.TestOvercloudUpdatePrepare):
|
|||
autospec=True)
|
||||
@mock.patch('tripleoclient.workflows.package_update.update',
|
||||
autospec=True)
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('os.path.abspath')
|
||||
@mock.patch('yaml.safe_load')
|
||||
@mock.patch('shutil.copytree', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
'_deploy_tripleo_heat_templates', autospec=True)
|
||||
def test_update_failed(self, mock_deploy, mock_copy, mock_yaml,
|
||||
mock_abspath, mock_open, mock_update,
|
||||
mock_abspath, mock_update,
|
||||
mock_get_stack, mock_confirm,
|
||||
mock_get_stack_output_item):
|
||||
mock_stack = mock.Mock(parameters={'DeployIdentifier': ''})
|
||||
|
@ -113,7 +112,8 @@ class TestOvercloudUpdatePrepare(fakes.TestOvercloudUpdatePrepare):
|
|||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('os.path.isfile') as mock_isfile:
|
||||
mock.patch('os.path.isfile') as mock_isfile, \
|
||||
mock.patch('six.moves.builtins.open'):
|
||||
mock_exists.return_value = True
|
||||
mock_isfile.return_value = True
|
||||
self.assertRaises(exceptions.DeploymentError,
|
||||
|
@ -140,8 +140,7 @@ class TestOvercloudUpdateRun(fakes.TestOvercloudUpdateRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_update_with_playbook_and_user(self, mock_open, mock_execute,
|
||||
def test_update_with_playbook_and_user(self, mock_execute,
|
||||
mock_expanduser, update_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
|
@ -156,7 +155,8 @@ class TestOvercloudUpdateRun(fakes.TestOvercloudUpdateRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
|
@ -178,8 +178,7 @@ class TestOvercloudUpdateRun(fakes.TestOvercloudUpdateRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_update_limit_with_all_playbooks(self, mock_open, mock_execute,
|
||||
def test_update_limit_with_all_playbooks(self, mock_execute,
|
||||
mock_expanduser, update_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
|
@ -191,7 +190,8 @@ class TestOvercloudUpdateRun(fakes.TestOvercloudUpdateRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MINOR_UPDATE_PLAYBOOKS:
|
||||
|
@ -214,9 +214,8 @@ class TestOvercloudUpdateRun(fakes.TestOvercloudUpdateRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_update_with_no_limit(
|
||||
self, mock_open, mock_execute, mock_expanduser, update_ansible,
|
||||
self, mock_execute, mock_expanduser, update_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = []
|
||||
|
|
|
@ -51,9 +51,7 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
|
|||
@mock.patch('tripleoclient.v1.overcloud_upgrade.UpgradePrepare.log',
|
||||
autospec=True)
|
||||
@mock.patch('yaml.safe_load')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_out(self,
|
||||
mock_open,
|
||||
mock_yaml,
|
||||
mock_logger,
|
||||
mock_get_stack,
|
||||
|
@ -80,7 +78,8 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
with mock.patch('six.moves.builtins.open'):
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
mock_overcloud_deploy.assert_called_once_with(parsed_args)
|
||||
args, kwargs = mock_overcloud_deploy.call_args
|
||||
|
@ -102,9 +101,8 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
|
|||
@mock.patch('tripleoclient.utils.get_stack',
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.utils.prepend_environment', autospec=True)
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('yaml.safe_load')
|
||||
def test_upgrade_failed(self, mock_yaml, mock_open,
|
||||
def test_upgrade_failed(self, mock_yaml,
|
||||
add_env, mock_get_stack, mock_overcloud_deploy,
|
||||
mock_confirm):
|
||||
mock_overcloud_deploy.side_effect = exceptions.DeploymentError()
|
||||
|
@ -121,8 +119,9 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
|
|||
]
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
|
||||
self.assertRaises(exceptions.DeploymentError,
|
||||
self.cmd.take_action, parsed_args)
|
||||
with mock.patch('six.moves.builtins.open'):
|
||||
self.assertRaises(exceptions.DeploymentError,
|
||||
self.cmd.take_action, parsed_args)
|
||||
mock_overcloud_deploy.assert_called_once_with(parsed_args)
|
||||
|
||||
@mock.patch('tripleo_common.update.check_neutron_mechanism_drivers')
|
||||
|
@ -156,9 +155,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_limit_with_playbook_and_user(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'Compute, Controller',
|
||||
|
@ -171,7 +169,9 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
upgrade_ansible.assert_called_once_with(
|
||||
|
@ -193,9 +193,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_limit_all_playbooks_skip_validation(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'Compute', '--playbook', 'all',
|
||||
|
@ -208,7 +207,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MAJOR_UPGRADE_PLAYBOOKS:
|
||||
|
@ -231,9 +231,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_limit_all_playbooks_only_validation(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'Compute', '--playbook', 'all',
|
||||
|
@ -246,7 +245,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MAJOR_UPGRADE_PLAYBOOKS:
|
||||
|
@ -269,9 +269,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_nodes_with_playbook_no_skip_tags(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'compute-0,compute-1',
|
||||
|
@ -283,7 +282,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
upgrade_ansible.assert_called_once_with(
|
||||
|
@ -305,9 +305,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_node_all_playbooks_skip_tags_default(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'swift-1', '--playbook', 'all']
|
||||
|
@ -318,7 +317,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MAJOR_UPGRADE_PLAYBOOKS:
|
||||
|
@ -341,9 +341,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_node_all_playbooks_skip_tags_all_supported(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'swift-1', '--playbook', 'all',
|
||||
|
@ -356,7 +355,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open') as mock_open:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MAJOR_UPGRADE_PLAYBOOKS:
|
||||
|
@ -377,9 +377,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_upgrade_with_no_limit(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible):
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = []
|
||||
verifylist = []
|
||||
|
@ -392,9 +391,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
# it is 'validation' not 'validations'
|
||||
def test_upgrade_skip_tags_validations(self, mock_open, mock_execute,
|
||||
def test_upgrade_skip_tags_validations(self, mock_execute,
|
||||
mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
|
@ -407,7 +405,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
('skip_tags', 'validations'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open'):
|
||||
mock_exists.return_value = True
|
||||
self.assertRaises(exceptions.InvalidConfiguration,
|
||||
lambda: self.cmd.take_action(parsed_args))
|
||||
|
@ -418,10 +417,9 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
# should only support the constants.MAJOR_UPGRADE_SKIP_TAGS
|
||||
def test_upgrade_skip_tags_unsupported_validation_anything_else(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'overcloud-compute-1',
|
||||
|
@ -433,7 +431,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
('skip_tags', 'validation,anything-else'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open'):
|
||||
mock_exists.return_value = True
|
||||
self.assertRaises(exceptions.InvalidConfiguration,
|
||||
lambda: self.cmd.take_action(parsed_args))
|
||||
|
@ -444,10 +443,9 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
# should only support the constants.MAJOR_UPGRADE_SKIP_TAGS
|
||||
def test_upgrade_skip_tags_unsupported_pre_upgrade_anything_else(
|
||||
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
self, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_confirm):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'overcloud-compute-1',
|
||||
|
@ -459,7 +457,8 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
('skip_tags', 'pre-upgrade,anything-else'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
with mock.patch('os.path.exists') as mock_exists, \
|
||||
mock.patch('six.moves.builtins.open'):
|
||||
mock_exists.return_value = True
|
||||
self.assertRaises(exceptions.InvalidConfiguration,
|
||||
lambda: self.cmd.take_action(parsed_args))
|
||||
|
|
|
@ -405,13 +405,12 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
'_setup_heat_environments', autospec=True)
|
||||
@mock.patch('yaml.safe_dump', autospec=True)
|
||||
@mock.patch('yaml.safe_load', autospec=True)
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('tempfile.NamedTemporaryFile', autospec=True)
|
||||
@mock.patch('tripleo_common.image.kolla_builder.'
|
||||
'container_images_prepare_multi')
|
||||
def test_deploy_tripleo_heat_templates_rewrite(self,
|
||||
mock_cipm,
|
||||
mock_temp, mock_open,
|
||||
mock_temp,
|
||||
mock_yaml_load,
|
||||
mock_yaml_dump,
|
||||
mock_setup_heat_envs,
|
||||
|
@ -458,7 +457,8 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
'/tmp/thtroot/environments/myenv.yaml',
|
||||
'../outside.yaml']
|
||||
|
||||
self.cmd._deploy_tripleo_heat_templates(self.orc, parsed_args)
|
||||
with mock.patch('six.moves.builtins.open'):
|
||||
self.cmd._deploy_tripleo_heat_templates(self.orc, parsed_args)
|
||||
|
||||
mock_yaml_dump.assert_has_calls([mock.call(rewritten_env,
|
||||
default_flow_style=False)])
|
||||
|
@ -481,13 +481,12 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
'_setup_heat_environments', autospec=True)
|
||||
@mock.patch('yaml.safe_dump', autospec=True)
|
||||
@mock.patch('yaml.safe_load', autospec=True)
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('tempfile.NamedTemporaryFile', autospec=True)
|
||||
@mock.patch('tripleo_common.image.kolla_builder.'
|
||||
'container_images_prepare_multi')
|
||||
def test_deploy_tripleo_heat_templates_remove(self,
|
||||
mock_cipm,
|
||||
mock_temp, mock_open,
|
||||
mock_temp,
|
||||
mock_yaml_load,
|
||||
mock_yaml_dump,
|
||||
mock_setup_heat_envs,
|
||||
|
@ -545,7 +544,8 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
'/tmp/thtroot/environments/myenv.yaml',
|
||||
'../outside.yaml']
|
||||
|
||||
self.cmd._deploy_tripleo_heat_templates(self.orc, parsed_args)
|
||||
with mock.patch('six.moves.builtins.open'):
|
||||
self.cmd._deploy_tripleo_heat_templates(self.orc, parsed_args)
|
||||
|
||||
mock_yaml_dump.assert_has_calls([mock.call(rewritten_role)])
|
||||
|
||||
|
@ -607,7 +607,6 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
@mock.patch('yaml.safe_load', return_value={}, autospec=True)
|
||||
@mock.patch('yaml.safe_dump', autospec=True)
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_process_hieradata_overrides', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
|
@ -620,7 +619,7 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
autospec=True)
|
||||
def test_setup_heat_environments_dropin(
|
||||
self, mock_run, mock_paths, mock_norm, mock_update_pass_env,
|
||||
mock_process_hiera, mock_open, mock_os, mock_yaml_dump,
|
||||
mock_process_hiera, mock_os, mock_yaml_dump,
|
||||
mock_yaml_load, mock_time):
|
||||
|
||||
parsed_args = self.check_parser(self.cmd,
|
||||
|
@ -631,11 +630,12 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
self.cmd.output_dir = 'tht_to'
|
||||
self.cmd.tht_render = 'tht_from'
|
||||
self.cmd.stack_action = 'UPDATE'
|
||||
environment = self.cmd._setup_heat_environments(
|
||||
parsed_args.roles_file, parsed_args.networks_file, parsed_args)
|
||||
with mock.patch('six.moves.builtins.open') as mock_open:
|
||||
environment = self.cmd._setup_heat_environments(
|
||||
parsed_args.roles_file, parsed_args.networks_file, parsed_args)
|
||||
mock_open.assert_has_calls([mock.call(dropin, 'w')])
|
||||
|
||||
self.assertIn(dropin, environment)
|
||||
mock_open.assert_has_calls([mock.call(dropin, 'w')])
|
||||
|
||||
# unpack the dump yaml calls to verify if the produced stack update
|
||||
# dropin matches our expectations
|
||||
|
@ -899,7 +899,6 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
# TODO(cjeanner) drop once we have proper oslo.privsep
|
||||
@mock.patch('getpass.getuser', return_value='stack')
|
||||
@mock.patch('os.mkdir')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_populate_templates_dir')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
|
@ -937,7 +936,7 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
mock_wait_for_port, mock_createdirs,
|
||||
mock_cleanupdirs, mock_launchansible,
|
||||
mock_tarball, mock_templates_dir,
|
||||
mock_open, mock_os, mock_user, mock_cc,
|
||||
mock_os, mock_user, mock_cc,
|
||||
mock_chmod, mock_ac, mock_outputs,
|
||||
mock_copy, mock_cmdline):
|
||||
mock_slink.side_effect = 'fake-cmd'
|
||||
|
@ -959,7 +958,9 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
'--standalone'], [])
|
||||
|
||||
fake_orchestration = mock_launchheat(parsed_args)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
with mock.patch('six.moves.builtins.open'):
|
||||
self.cmd.take_action(parsed_args)
|
||||
mock_createdirs.assert_called_once()
|
||||
mock_puppet.assert_called_once()
|
||||
mock_launchheat.assert_called_with(parsed_args)
|
||||
|
|
|
@ -56,7 +56,6 @@ class TestUndercloudInstall(TestPluginV1):
|
|||
|
||||
# TODO(cjeanner) drop once we have proper oslo.privsep
|
||||
@mock.patch('getpass.getuser', return_value='stack')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('shutil.copy')
|
||||
@mock.patch('os.mkdir')
|
||||
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
|
||||
|
@ -64,13 +63,15 @@ class TestUndercloudInstall(TestPluginV1):
|
|||
def test_undercloud_install_default(self, mock_subprocess,
|
||||
mock_wr,
|
||||
mock_os, mock_copy,
|
||||
mock_open, mock_user):
|
||||
mock_user):
|
||||
arglist = ['--no-validations']
|
||||
verifylist = []
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
with mock.patch('six.moves.builtins.open'):
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
mock_subprocess.assert_called_with(
|
||||
['sudo', '--preserve-env', 'openstack', 'tripleo', 'deploy',
|
||||
|
@ -350,7 +351,6 @@ class TestUndercloudInstall(TestPluginV1):
|
|||
|
||||
# TODO(cjeanner) drop once we have proper oslo.privsep
|
||||
@mock.patch('getpass.getuser', return_value='stack')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('shutil.copy')
|
||||
@mock.patch('os.mkdir')
|
||||
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
|
||||
|
@ -358,7 +358,7 @@ 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_user):
|
||||
self.conf.config(undercloud_log_file='/foo/bar')
|
||||
arglist = ['--no-validations']
|
||||
verifylist = []
|
||||
|
@ -367,7 +367,8 @@ class TestUndercloudInstall(TestPluginV1):
|
|||
# DisplayCommandBase.take_action() returns two tuples
|
||||
old_verbose = self.cmd.app_args.verbose_level
|
||||
self.cmd.app_args.verbose_level = 2
|
||||
self.cmd.take_action(parsed_args)
|
||||
with mock.patch('six.moves.builtins.open'):
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.cmd.app_args.verbose_level = old_verbose
|
||||
|
||||
mock_subprocess.assert_called_with(
|
||||
|
@ -418,7 +419,6 @@ class TestUndercloudInstall(TestPluginV1):
|
|||
|
||||
# TODO(cjeanner) drop once we have proper oslo.privsep
|
||||
@mock.patch('getpass.getuser', return_value='stack')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('shutil.copy')
|
||||
@mock.patch('os.mkdir')
|
||||
@mock.patch('tripleoclient.utils.write_env_file', autospec=True)
|
||||
|
@ -426,14 +426,15 @@ class TestUndercloudInstall(TestPluginV1):
|
|||
def test_undercloud_install_with_heat_true(self, mock_subprocess,
|
||||
mock_wr,
|
||||
mock_os, mock_copy,
|
||||
mock_open, mock_user):
|
||||
mock_user):
|
||||
self.conf.config(undercloud_log_file='/foo/bar')
|
||||
arglist = ['--no-validations']
|
||||
verifylist = []
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
self.cmd.take_action(parsed_args)
|
||||
with mock.patch('six.moves.builtins.open'):
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
mock_subprocess.assert_called_with(
|
||||
['sudo', '--preserve-env', 'openstack', 'tripleo', 'deploy',
|
||||
|
|
Loading…
Reference in New Issue