Remove mistral from the config_download deploy workflow
This change removes all of mistral from the config_download_deploy function by calling the required functions directly. - All of the inputs within this function have been cleaned up and documented. - New log entires will be created when using this method giving the deployer a better overall user experience. - To ensure we're able to support the ability to reproduce commands, the ssh args extravar has been moved to an environment variable. - The methods get_config and get_key have been moved to the utils module. This was done to help avoid circular imports. Update methods have been changed to execute without running within a mistral workflow. This was changed because there's no need to support the multiple code paths anymore given config_download is now running directly. Test classes have been updated to reduce duplication. With the new streamlined execution process we should see improved deployment times and better visability into the deployment process. Task: 38422 Story: 2007212 Depends-On: I006291a2465aa4c950abce76f9e5f9459b76e330 Change-Id: Ide1a4503dd2bdd2d5e494cd1eac483b842a21acf Co-authored-by: Luke Short <ekultails@gmail.com> Co-authored-by: Dougal Matthews <dougal@dougalmatthews.com> Signed-off-by: Kevin Carter <kecarter@redhat.com>changes/93/705793/21
parent
712d8d7a61
commit
dc9ae1ac5b
|
@ -18,6 +18,8 @@ import logging
|
|||
from osc_lib.command import command
|
||||
from osc_lib import exceptions as oscexc
|
||||
|
||||
from tripleo_common.utils import config
|
||||
|
||||
from tripleoclient import exceptions
|
||||
from tripleoclient import utils
|
||||
|
||||
|
@ -36,6 +38,38 @@ class Command(command.Command):
|
|||
self.log.exception("Exception occured while running the command")
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
def get_ansible_key_and_dir(no_workflow, stack, orchestration):
|
||||
"""Return the ansible directory and key path.
|
||||
|
||||
:param no_workflow: Enable or disable the mistral workflow code path.
|
||||
:type no_workflow: Boolean
|
||||
|
||||
:oaram stack: Name of a given stack to run against.
|
||||
:type stack: String
|
||||
|
||||
:param orchestration: Orchestration client object.
|
||||
:type orchestration: Object
|
||||
|
||||
:returns: Tuple
|
||||
"""
|
||||
|
||||
if no_workflow:
|
||||
key = utils.get_key(stack=stack)
|
||||
stack_config = config.Config(orchestration)
|
||||
with utils.TempDirs(cleanup=False, chdir=False) as tmp:
|
||||
stack_config.write_config(
|
||||
stack_config.fetch_config(stack),
|
||||
stack,
|
||||
tmp
|
||||
)
|
||||
return key, tmp
|
||||
else:
|
||||
# Assumes execution will take place from within a mistral
|
||||
# container.
|
||||
key = '.ssh/tripleo-admin-rsa'
|
||||
return key, None
|
||||
|
||||
|
||||
class Lister(Command, command.Lister):
|
||||
pass
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
import mock
|
||||
import sys
|
||||
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from tripleoclient import plugin
|
||||
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://0.0.0.0"
|
||||
|
@ -36,6 +40,11 @@ class FakeApp(object):
|
|||
|
||||
class FakeStackObject(object):
|
||||
stack_name = 'undercloud'
|
||||
outputs = []
|
||||
|
||||
@staticmethod
|
||||
def get(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class FakeClientManager(object):
|
||||
|
@ -81,6 +90,8 @@ class FakeClientWrapper(object):
|
|||
|
||||
def __init__(self):
|
||||
self.ws = FakeWebSocket()
|
||||
self.object_store = FakeObjectClient()
|
||||
self._instance = mock.Mock()
|
||||
|
||||
def messaging_websocket(self):
|
||||
return self.ws
|
||||
|
@ -125,6 +136,60 @@ class FakeInstanceData(object):
|
|||
_data = {'token': {}}
|
||||
|
||||
|
||||
class FakeObjectClient(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.put_object = mock.Mock()
|
||||
|
||||
def get_object(self, *args):
|
||||
return [None, "fake"]
|
||||
|
||||
def get_container(self, *args):
|
||||
return [None, [{"name": "fake"}]]
|
||||
|
||||
|
||||
class FakePlaybookExecution(utils.TestCommand):
|
||||
|
||||
def setUp(self, ansible_mock=True):
|
||||
super(FakePlaybookExecution, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.baremetal = mock.Mock()
|
||||
self.app.client_manager.compute = mock.Mock()
|
||||
self.app.client_manager.identity = mock.Mock()
|
||||
self.app.client_manager.image = mock.Mock()
|
||||
self.app.client_manager.network = mock.Mock()
|
||||
tc = self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
stack = self.app.client_manager.orchestration = mock.Mock()
|
||||
stack.stacks.get.return_value = FakeStackObject
|
||||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=FakeInstanceData
|
||||
).create_mistral_context
|
||||
|
||||
# NOTE(cloudnull): When mistral is gone this should be removed.
|
||||
workflow = execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
workflow.executions.create.return_value = execution
|
||||
self.app.client_manager.workflow_engine = workflow
|
||||
|
||||
if ansible_mock:
|
||||
self.gcn = mock.patch(
|
||||
'tripleo_common.utils.config.Config',
|
||||
autospec=True
|
||||
)
|
||||
self.gcn.start()
|
||||
self.addCleanup(self.gcn.stop)
|
||||
|
||||
self.mkdirs = mock.patch(
|
||||
'os.makedirs',
|
||||
autospec=True
|
||||
)
|
||||
self.mkdirs.start()
|
||||
self.addCleanup(self.mkdirs.stop)
|
||||
|
||||
|
||||
def fake_ansible_runner_run_return(rc=0):
|
||||
|
||||
return 'Test Status', rc
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#
|
||||
|
||||
import mock
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from tripleoclient.tests import fakes
|
||||
|
||||
|
@ -105,43 +104,7 @@ def create_env(**kwargs):
|
|||
return env
|
||||
|
||||
|
||||
class FakeClientWrapper(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.object_store = FakeObjectClient()
|
||||
|
||||
def messaging_websocket(self):
|
||||
return fakes.FakeWebSocket()
|
||||
|
||||
|
||||
class FakeObjectClient(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.put_object = mock.Mock()
|
||||
|
||||
def get_object(self, *args):
|
||||
return [None, "fake"]
|
||||
|
||||
def get_container(self, *args):
|
||||
return [None, [{"name": "fake"}]]
|
||||
|
||||
|
||||
class TestDeployOvercloud(utils.TestCommand):
|
||||
class TestDeployOvercloud(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDeployOvercloud, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.baremetal = mock.Mock()
|
||||
self.app.client_manager.compute = mock.Mock()
|
||||
self.app.client_manager.identity = mock.Mock()
|
||||
self.app.client_manager.image = mock.Mock()
|
||||
self.app.client_manager.network = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
workflow = execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
workflow.executions.create.return_value = execution
|
||||
self.app.client_manager.workflow_engine = workflow
|
||||
self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
super(TestDeployOvercloud, self).setUp(ansible_mock=False)
|
||||
|
|
|
@ -877,9 +877,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
parsed_args)
|
||||
self.assertIn('/tmp/notthere', str(error))
|
||||
|
||||
@mock.patch('tripleoclient.tests.v1.overcloud_deploy.fakes.'
|
||||
'FakeObjectClient.get_object', autospec=True)
|
||||
def test_validate_args_missing_environment_files(self, mock_obj):
|
||||
def test_validate_args_missing_environment_files(self):
|
||||
arglist = ['--templates',
|
||||
'-e', 'nonexistent.yaml']
|
||||
verifylist = [
|
||||
|
@ -887,8 +885,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
('environment_files', ['nonexistent.yaml']),
|
||||
]
|
||||
|
||||
mock_obj.side_effect = ObjectClientException(mock.Mock(
|
||||
'/fake/path not found'))
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.assertRaises(oscexc.CommandError,
|
||||
|
@ -1482,8 +1478,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
self.cmd.take_action(parsed_args)
|
||||
self.assertTrue(fixture.mock_get_hosts_and_enable_ssh_admin.called)
|
||||
self.assertTrue(fixture.mock_config_download.called)
|
||||
self.assertEqual('ansible.cfg',
|
||||
fixture.mock_config_download.call_args[0][8])
|
||||
mock_copy.assert_called_once()
|
||||
|
||||
@mock.patch('tripleoclient.utils.copy_clouds_yaml')
|
||||
|
@ -1514,7 +1508,6 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
|
||||
self.cmd.take_action(parsed_args)
|
||||
fixture.mock_config_download.assert_called()
|
||||
self.assertEqual(240*60, fixture.mock_config_download.call_args[0][9])
|
||||
mock_copy.assert_called_once()
|
||||
|
||||
def test_download_missing_files_from_plan(self):
|
||||
|
|
|
@ -13,38 +13,10 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from tripleoclient.tests import fakes
|
||||
|
||||
|
||||
class FakeClientWrapper(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.object_store = FakeObjectClient()
|
||||
|
||||
def messaging_websocket(self):
|
||||
return fakes.FakeWebSocket()
|
||||
|
||||
|
||||
class FakeObjectClient(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.put_object = mock.Mock()
|
||||
|
||||
def get_object(self, *args):
|
||||
return
|
||||
|
||||
|
||||
class TestOvercloudExternalUpdateRun(utils.TestCommand):
|
||||
class TestOvercloudExternalUpdateRun(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOvercloudExternalUpdateRun, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import mock
|
||||
|
||||
from tripleoclient.tests import fakes as ooofakes
|
||||
from tripleoclient.tests.v1.overcloud_external_update import fakes
|
||||
from tripleoclient.v1 import overcloud_external_update
|
||||
|
||||
|
@ -34,13 +35,23 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
|
|||
self.mock_uuid4 = uuid4_patcher.start()
|
||||
self.addCleanup(self.mock_uuid4.stop)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch(
|
||||
'ansible_runner.runner_config.RunnerConfig',
|
||||
autospec=True,
|
||||
return_value=ooofakes.FakeRunnerConfig()
|
||||
)
|
||||
@mock.patch(
|
||||
'ansible_runner.Runner.run',
|
||||
return_value=ooofakes.fake_ansible_runner_run_return()
|
||||
)
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
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,
|
||||
mock_expanduser, update_ansible):
|
||||
mock_expanduser, update_ansible,
|
||||
mock_run, mock_run_prepare):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--ssh-user', 'tripleo-admin',
|
||||
'--tags', 'ceph']
|
||||
|
@ -54,25 +65,35 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
|
|||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='all',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook='external_update_steps_playbook.yaml',
|
||||
node_user='tripleo-admin',
|
||||
inventory=mock.ANY,
|
||||
workdir=mock.ANY,
|
||||
ssh_user='tripleo-admin',
|
||||
key='/var/lib/mistral/overcloud/ssh_private_key',
|
||||
module_path='/usr/share/ansible-modules',
|
||||
limit_hosts='all',
|
||||
tags='ceph',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars={}
|
||||
extra_vars={'ansible_become': True}
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch(
|
||||
'ansible_runner.runner_config.RunnerConfig',
|
||||
autospec=True,
|
||||
return_value=ooofakes.FakeRunnerConfig()
|
||||
)
|
||||
@mock.patch(
|
||||
'ansible_runner.Runner.run',
|
||||
return_value=ooofakes.fake_ansible_runner_run_return()
|
||||
)
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
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,
|
||||
mock_expanduser, update_ansible):
|
||||
mock_expanduser, update_ansible,
|
||||
mock_run, mock_run_prepare):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--ssh-user', 'tripleo-admin',
|
||||
'--extra-vars', 'key1=val1',
|
||||
|
@ -87,14 +108,18 @@ class TestOvercloudExternalUpdateRun(fakes.TestOvercloudExternalUpdateRun):
|
|||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='all',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook='external_update_steps_playbook.yaml',
|
||||
node_user='tripleo-admin',
|
||||
inventory=mock.ANY,
|
||||
workdir=mock.ANY,
|
||||
ssh_user='tripleo-admin',
|
||||
key='/var/lib/mistral/overcloud/ssh_private_key',
|
||||
module_path='/usr/share/ansible-modules',
|
||||
limit_hosts='all',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars={'key1': 'val1', 'key2': 'val2'}
|
||||
extra_vars={
|
||||
'key1': 'val1',
|
||||
'key2': 'val2',
|
||||
'ansible_become': True
|
||||
}
|
||||
)
|
||||
|
|
|
@ -13,38 +13,10 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from tripleoclient.tests import fakes
|
||||
|
||||
|
||||
class FakeClientWrapper(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.object_store = FakeObjectClient()
|
||||
|
||||
def messaging_websocket(self):
|
||||
return fakes.FakeWebSocket()
|
||||
|
||||
|
||||
class FakeObjectClient(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.put_object = mock.Mock()
|
||||
|
||||
def get_object(self, *args):
|
||||
return
|
||||
|
||||
|
||||
class TestOvercloudExternalUpgradeRun(utils.TestCommand):
|
||||
class TestOvercloudExternalUpgradeRun(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOvercloudExternalUpgradeRun, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import mock
|
||||
|
||||
from tripleoclient.tests import fakes as ooofakes
|
||||
from tripleoclient.tests.v1.overcloud_external_upgrade import fakes
|
||||
from tripleoclient.v1 import overcloud_external_upgrade
|
||||
|
||||
|
@ -34,13 +35,23 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
|
|||
self.mock_uuid4 = uuid4_patcher.start()
|
||||
self.addCleanup(self.mock_uuid4.stop)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch(
|
||||
'ansible_runner.runner_config.RunnerConfig',
|
||||
autospec=True,
|
||||
return_value=ooofakes.FakeRunnerConfig()
|
||||
)
|
||||
@mock.patch(
|
||||
'ansible_runner.Runner.run',
|
||||
return_value=ooofakes.fake_ansible_runner_run_return()
|
||||
)
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
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,
|
||||
mock_expanduser, update_ansible):
|
||||
mock_expanduser, update_ansible,
|
||||
mock_run, mock_run_prepare):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--ssh-user', 'tripleo-admin',
|
||||
'--tags', 'ceph']
|
||||
|
@ -54,25 +65,35 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
|
|||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='all',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook='external_upgrade_steps_playbook.yaml',
|
||||
node_user='tripleo-admin',
|
||||
inventory=mock.ANY,
|
||||
workdir=mock.ANY,
|
||||
ssh_user='tripleo-admin',
|
||||
key='/var/lib/mistral/overcloud/ssh_private_key',
|
||||
module_path='/usr/share/ansible-modules',
|
||||
limit_hosts='all',
|
||||
tags='ceph',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars={}
|
||||
extra_vars={'ansible_become': True}
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch(
|
||||
'ansible_runner.runner_config.RunnerConfig',
|
||||
autospec=True,
|
||||
return_value=ooofakes.FakeRunnerConfig()
|
||||
)
|
||||
@mock.patch(
|
||||
'ansible_runner.Runner.run',
|
||||
return_value=ooofakes.fake_ansible_runner_run_return()
|
||||
)
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
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,
|
||||
mock_expanduser, update_ansible):
|
||||
mock_expanduser, update_ansible,
|
||||
mock_run, mock_run_prepare):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--ssh-user', 'tripleo-admin',
|
||||
'--extra-vars', 'key1=val1',
|
||||
|
@ -87,14 +108,18 @@ class TestOvercloudExternalUpgradeRun(fakes.TestOvercloudExternalUpgradeRun):
|
|||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='all',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook='external_upgrade_steps_playbook.yaml',
|
||||
node_user='tripleo-admin',
|
||||
inventory=mock.ANY,
|
||||
workdir=mock.ANY,
|
||||
ssh_user='tripleo-admin',
|
||||
key='/var/lib/mistral/overcloud/ssh_private_key',
|
||||
module_path='/usr/share/ansible-modules',
|
||||
limit_hosts='all',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars={'key1': 'val1', 'key2': 'val2'}
|
||||
extra_vars={
|
||||
'key1': 'val1',
|
||||
'key2': 'val2',
|
||||
'ansible_become': True
|
||||
}
|
||||
)
|
||||
|
|
|
@ -13,78 +13,22 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from tripleoclient import plugin
|
||||
from tripleoclient.tests import fakes
|
||||
|
||||
|
||||
class FakeClientWrapper(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.object_store = FakeObjectClient()
|
||||
|
||||
def messaging_websocket(self, queue="tripleo"):
|
||||
return fakes.FakeWebSocket()
|
||||
|
||||
|
||||
class FakeObjectClient(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.put_object = mock.Mock()
|
||||
|
||||
def get_object(self, *args):
|
||||
return
|
||||
|
||||
|
||||
class TestFFWDUpgradePrepare(utils.TestCommand):
|
||||
class TestFFWDUpgradePrepare(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFFWDUpgradePrepare, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.baremetal = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
workflow = execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
workflow.executions.create.return_value = execution
|
||||
self.app.client_manager.workflow_engine = workflow
|
||||
tc = self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=fakes.FakeInstanceData
|
||||
).create_mistral_context
|
||||
|
||||
|
||||
class TestFFWDUpgradeRun(utils.TestCommand):
|
||||
class TestFFWDUpgradeRun(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFFWDUpgradeRun, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
tc = self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=fakes.FakeInstanceData
|
||||
).create_mistral_context
|
||||
|
||||
|
||||
class TestFFWDUpgradeConverge(utils.TestCommand):
|
||||
class TestFFWDUpgradeConverge(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFFWDUpgradeConverge, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.baremetal = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
workflow = execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
workflow.executions.create.return_value = execution
|
||||
self.app.client_manager.workflow_engine = workflow
|
||||
tc = self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=fakes.FakeInstanceData
|
||||
).create_mistral_context
|
||||
|
|
|
@ -155,7 +155,7 @@ class TestFFWDUpgradeRun(fakes.TestFFWDUpgradeRun):
|
|||
self.mock_uuid4 = uuid4_patcher.start()
|
||||
self.addCleanup(self.mock_uuid4.stop)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
|
@ -171,19 +171,19 @@ class TestFFWDUpgradeRun(fakes.TestFFWDUpgradeRun):
|
|||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
upgrade_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
nodes='',
|
||||
playbook=constants.FFWD_UPGRADE_PLAYBOOK,
|
||||
node_user='heat-admin',
|
||||
playbook='fast_forward_upgrade_playbook.yaml',
|
||||
inventory=mock.ANY,
|
||||
workdir=mock.ANY,
|
||||
ssh_user='heat-admin',
|
||||
key='/var/lib/mistral/overcloud/ssh_private_key',
|
||||
module_path='/usr/share/ansible-modules',
|
||||
limit_hosts='',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
extra_vars={'ansible_become': True}
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
|
@ -199,19 +199,19 @@ class TestFFWDUpgradeRun(fakes.TestFFWDUpgradeRun):
|
|||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
upgrade_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
nodes='',
|
||||
playbook=constants.FFWD_UPGRADE_PLAYBOOK,
|
||||
node_user='my-user',
|
||||
playbook='fast_forward_upgrade_playbook.yaml',
|
||||
inventory=mock.ANY,
|
||||
workdir=mock.ANY,
|
||||
ssh_user='my-user',
|
||||
key='/var/lib/mistral/overcloud/ssh_private_key',
|
||||
module_path='/usr/share/ansible-modules',
|
||||
limit_hosts='',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
extra_vars={'ansible_become': True}
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
|
|
|
@ -51,10 +51,31 @@ class TestDeleteNode(fakes.TestDeleteNode):
|
|||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=ooofakes.FakeInstanceData
|
||||
).create_mistral_context
|
||||
self.gcn = mock.patch(
|
||||
'tripleo_common.actions.config.DownloadConfigAction',
|
||||
autospec=True
|
||||
)
|
||||
self.gcn.start()
|
||||
self.addCleanup(self.gcn.stop)
|
||||
self.ansible = mock.patch(
|
||||
'tripleo_common.actions.ansible.AnsibleGenerateInventoryAction',
|
||||
autospec=True
|
||||
)
|
||||
self.ansible.start()
|
||||
self.addCleanup(self.ansible.stop)
|
||||
config_mock = mock.patch(
|
||||
'tripleo_common.actions.config.GetOvercloudConfig',
|
||||
autospec=True
|
||||
)
|
||||
config_mock.start()
|
||||
self.addCleanup(config_mock.stop)
|
||||
|
||||
self.workflow = self.app.client_manager.workflow_engine
|
||||
self.stack_name = self.app.client_manager.orchestration.stacks.get
|
||||
self.stack_name.return_value = mock.Mock(stack_name="overcloud")
|
||||
stack = self.stack_name.return_value = mock.Mock(
|
||||
stack_name="overcloud"
|
||||
)
|
||||
stack.output_show.return_value = {'output': {'output_value': []}}
|
||||
execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
self.workflow.executions.create.return_value = execution
|
||||
|
@ -67,11 +88,19 @@ class TestDeleteNode(fakes.TestDeleteNode):
|
|||
delete_node.return_value = None
|
||||
self.addCleanup(delete_node.stop)
|
||||
|
||||
wait_stack = mock.patch(
|
||||
'tripleoclient.utils.wait_for_stack_ready',
|
||||
autospec=True
|
||||
)
|
||||
wait_stack.start()
|
||||
wait_stack.return_value = None
|
||||
self.addCleanup(wait_stack.stop)
|
||||
|
||||
# TODO(someone): This test does not pass with autospec=True, it should
|
||||
# probably be fixed so that it can pass with that.
|
||||
@mock.patch("heatclient.common.event_utils.poll_for_events")
|
||||
def test_node_delete(self, mock_poll):
|
||||
mock_poll.return_value = ("CREATE_IN_PROGRESS", "MESSAGE")
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
def test_node_delete(self, mock_playbook):
|
||||
argslist = ['instance1', 'instance2', '--templates',
|
||||
'--stack', 'overcast', '--timeout', '90', '--yes']
|
||||
verifylist = [
|
||||
|
@ -79,14 +108,6 @@ class TestDeleteNode(fakes.TestDeleteNode):
|
|||
('nodes', ['instance1', 'instance2'])
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"message": "Success.",
|
||||
}])
|
||||
|
||||
self.stack_name.return_value = mock.Mock(stack_name="overcast")
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
@mock.patch('tripleoclient.utils.prompt_user_for_confirmation',
|
||||
|
@ -122,9 +143,9 @@ class TestDeleteNode(fakes.TestDeleteNode):
|
|||
# Verify
|
||||
self.workflow.executions.create.assert_not_called()
|
||||
|
||||
@mock.patch("heatclient.common.event_utils.poll_for_events")
|
||||
def test_node_delete_without_stack(self, mock_poll):
|
||||
mock_poll.return_value = ("CREATE_IN_PROGRESS", "MESSAGE")
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
def test_node_delete_without_stack(self, mock_playbook):
|
||||
arglist = ['instance1', '--yes']
|
||||
|
||||
verifylist = [
|
||||
|
@ -132,49 +153,17 @@ class TestDeleteNode(fakes.TestDeleteNode):
|
|||
('nodes', ['instance1']),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"message": "Success.",
|
||||
}])
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
def test_node_delete_wrong_instance(self):
|
||||
|
||||
argslist = ['wrong_instance', '--templates',
|
||||
'--stack', 'overcloud', '--yes']
|
||||
verifylist = [
|
||||
('stack', 'overcloud'),
|
||||
('nodes', ['wrong_instance']),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"status": "FAILED",
|
||||
"execution_id": "IDID",
|
||||
"message": """Failed to run action ERROR: Couldn't find \
|
||||
following instances in stack overcloud: wrong_instance"""
|
||||
}])
|
||||
|
||||
# Verify
|
||||
self.assertRaises(exceptions.DeploymentError,
|
||||
self.cmd.take_action, parsed_args)
|
||||
|
||||
@mock.patch("heatclient.common.event_utils.poll_for_events")
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.workflows.baremetal.expand_roles',
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.workflows.baremetal.undeploy_roles',
|
||||
autospec=True)
|
||||
def test_node_delete_baremetal_deployment(self, mock_undeploy_roles,
|
||||
mock_expand_roles, mock_poll):
|
||||
mock_poll.return_value = ("CREATE_IN_PROGRESS", "MESSAGE")
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"message": "Success.",
|
||||
}])
|
||||
mock_expand_roles,
|
||||
mock_playbook):
|
||||
bm_yaml = [{
|
||||
'name': 'Compute',
|
||||
'count': 5,
|
||||
|
@ -219,7 +208,6 @@ class TestDeleteNode(fakes.TestDeleteNode):
|
|||
expand_to_translate
|
||||
]
|
||||
|
||||
self.stack_name.return_value = mock.Mock(stack_name="overcast")
|
||||
res_list = self.app.client_manager.orchestration.resources.list
|
||||
res_list.return_value = [
|
||||
mock.Mock(
|
||||
|
|
|
@ -13,75 +13,22 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from tripleoclient import plugin
|
||||
from tripleoclient.tests import fakes
|
||||
|
||||
|
||||
class FakeClientWrapper(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.object_store = FakeObjectClient()
|
||||
|
||||
def messaging_websocket(self):
|
||||
return fakes.FakeWebSocket()
|
||||
|
||||
|
||||
class FakeObjectClient(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.put_object = mock.Mock()
|
||||
|
||||
def get_object(self, *args):
|
||||
return
|
||||
|
||||
|
||||
class TestOvercloudUpdatePrepare(utils.TestCommand):
|
||||
class TestOvercloudUpdatePrepare(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOvercloudUpdatePrepare, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.baremetal = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
workflow = execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
workflow.executions.create.return_value = execution
|
||||
self.app.client_manager.workflow_engine = workflow
|
||||
tc = self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=fakes.FakeInstanceData
|
||||
).create_mistral_context
|
||||
|
||||
|
||||
class TestOvercloudUpdateRun(utils.TestCommand):
|
||||
class TestOvercloudUpdateRun(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOvercloudUpdateRun, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
tc = self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=fakes.FakeInstanceData
|
||||
).create_mistral_context
|
||||
|
||||
|
||||
class TestOvercloudUpdateConverge(utils.TestCommand):
|
||||
class TestOvercloudUpdateConverge(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOvercloudUpdateConverge, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.baremetal = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
tc = self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=fakes.FakeInstanceData
|
||||
).create_mistral_context
|
||||
|
|
|
@ -130,75 +130,7 @@ class TestOvercloudUpdateRun(fakes.TestOvercloudUpdateRun):
|
|||
self.mock_uuid4 = uuid4_patcher.start()
|
||||
self.addCleanup(self.mock_uuid4.stop)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
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,
|
||||
mock_expanduser, update_ansible):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'Compute',
|
||||
'--playbook', 'fake-playbook.yaml',
|
||||
'--ssh-user', 'tripleo-admin']
|
||||
verifylist = [
|
||||
('limit', 'Compute'),
|
||||
('static_inventory', None),
|
||||
('playbook', 'fake-playbook.yaml'),
|
||||
('ssh_user', 'tripleo-admin')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
update_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='Compute',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook='fake-playbook.yaml',
|
||||
node_user='tripleo-admin',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
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,
|
||||
mock_expanduser, update_ansible):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'Compute', '--playbook', 'all']
|
||||
verifylist = [
|
||||
('limit', 'Compute'),
|
||||
('static_inventory', None),
|
||||
('playbook', 'all')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MINOR_UPDATE_PLAYBOOKS:
|
||||
update_ansible.assert_any_call(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='Compute',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook=book,
|
||||
node_user='tripleo-admin',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
|
|
|
@ -13,57 +13,16 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from tripleoclient import plugin
|
||||
from tripleoclient.tests import fakes
|
||||
|
||||
|
||||
class FakeClientWrapper(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.object_store = FakeObjectClient()
|
||||
|
||||
def messaging_websocket(self):
|
||||
return fakes.FakeWebSocket()
|
||||
|
||||
|
||||
class FakeObjectClient(object):
|
||||
|
||||
def __init__(self):
|
||||
self._instance = mock.Mock()
|
||||
self.put_object = mock.Mock()
|
||||
|
||||
def get_object(self, *args):
|
||||
return
|
||||
|
||||
|
||||
class TestOvercloudUpgradePrepare(utils.TestCommand):
|
||||
class TestOvercloudUpgradePrepare(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOvercloudUpgradePrepare, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.baremetal = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
tc = self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
tc.create_mistral_context = plugin.ClientWrapper(
|
||||
instance=fakes.FakeInstanceData
|
||||
).create_mistral_context
|
||||
workflow = execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
workflow.executions.create.return_value = execution
|
||||
self.app.client_manager.workflow_engine = workflow
|
||||
|
||||
|
||||
class TestOvercloudUpgradeRun(utils.TestCommand):
|
||||
class TestOvercloudUpgradeRun(fakes.FakePlaybookExecution):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOvercloudUpgradeRun, self).setUp()
|
||||
|
||||
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
|
||||
self.app.client_manager.tripleoclient = FakeClientWrapper()
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
self.app.client_manager.orchestration = mock.Mock()
|
||||
|
|
|
@ -19,6 +19,7 @@ from osc_lib import exceptions as oscexc
|
|||
from osc_lib.tests.utils import ParserException
|
||||
from tripleoclient import constants
|
||||
from tripleoclient import exceptions
|
||||
from tripleoclient.tests import fakes as ooofakes
|
||||
from tripleoclient.tests.v1.overcloud_upgrade import fakes
|
||||
from tripleoclient.v1 import overcloud_upgrade
|
||||
|
||||
|
@ -173,13 +174,23 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
self.mock_uuid4 = uuid4_patcher.start()
|
||||
self.addCleanup(self.mock_uuid4.stop)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch(
|
||||
'ansible_runner.runner_config.RunnerConfig',
|
||||
autospec=True,
|
||||
return_value=ooofakes.FakeRunnerConfig()
|
||||
)
|
||||
@mock.patch(
|
||||
'ansible_runner.Runner.run',
|
||||
return_value=ooofakes.fake_ansible_runner_run_return()
|
||||
)
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
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_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_run, mock_run_prepare):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'Compute, Controller',
|
||||
'--playbook', 'fake-playbook.yaml',
|
||||
|
@ -195,95 +206,35 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
upgrade_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='Compute, Controller',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook='fake-playbook.yaml',
|
||||
node_user='tripleo-admin',
|
||||
inventory=mock.ANY,
|
||||
workdir=mock.ANY,
|
||||
ssh_user='tripleo-admin',
|
||||
key='/var/lib/mistral/overcloud/ssh_private_key',
|
||||
module_path='/usr/share/ansible-modules',
|
||||
limit_hosts='Compute, Controller',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
extra_vars={'ansible_become': True}
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
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):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'Compute', '--playbook', 'all',
|
||||
'--skip-tags', 'validation']
|
||||
verifylist = [
|
||||
('limit', 'Compute'),
|
||||
('static_inventory', None),
|
||||
('playbook', 'all'),
|
||||
('skip_tags', 'validation')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MAJOR_UPGRADE_PLAYBOOKS:
|
||||
upgrade_ansible.assert_any_call(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='Compute',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook=book,
|
||||
node_user='tripleo-admin',
|
||||
tags='',
|
||||
skip_tags='validation',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
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):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'Compute', '--playbook', 'all',
|
||||
'--tags', 'validation']
|
||||
verifylist = [
|
||||
('limit', 'Compute'),
|
||||
('static_inventory', None),
|
||||
('playbook', 'all'),
|
||||
('tags', 'validation')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MAJOR_UPGRADE_PLAYBOOKS:
|
||||
upgrade_ansible.assert_any_call(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='Compute',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook=book,
|
||||
node_user='tripleo-admin',
|
||||
tags='validation',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch(
|
||||
'ansible_runner.runner_config.RunnerConfig',
|
||||
autospec=True,
|
||||
return_value=ooofakes.FakeRunnerConfig()
|
||||
)
|
||||
@mock.patch(
|
||||
'ansible_runner.Runner.run',
|
||||
return_value=ooofakes.fake_ansible_runner_run_return()
|
||||
)
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
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_open, mock_execute, mock_expanduser, upgrade_ansible,
|
||||
mock_run, mock_run_prepare):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'compute-0, compute-1',
|
||||
'--playbook', 'fake-playbook.yaml', ]
|
||||
|
@ -298,87 +249,19 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
upgrade_ansible.assert_called_once_with(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='compute-0, compute-1',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook='fake-playbook.yaml',
|
||||
node_user='tripleo-admin',
|
||||
inventory=mock.ANY,
|
||||
workdir=mock.ANY,
|
||||
ssh_user='tripleo-admin',
|
||||
key='/var/lib/mistral/overcloud/ssh_private_key',
|
||||
module_path='/usr/share/ansible-modules',
|
||||
limit_hosts='compute-0, compute-1',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
extra_vars={'ansible_become': True}
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
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):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'swift-1', '--playbook', 'all']
|
||||
verifylist = [
|
||||
('limit', 'swift-1'),
|
||||
('static_inventory', None),
|
||||
('playbook', 'all'),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MAJOR_UPGRADE_PLAYBOOKS:
|
||||
upgrade_ansible.assert_any_call(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='swift-1',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook=book,
|
||||
node_user='tripleo-admin',
|
||||
tags='',
|
||||
skip_tags='',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
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):
|
||||
mock_expanduser.return_value = '/home/fake/'
|
||||
argslist = ['--limit', 'swift-1', '--playbook', 'all',
|
||||
'--skip-tags', 'pre-upgrade,validation']
|
||||
verifylist = [
|
||||
('limit', 'swift-1'),
|
||||
('static_inventory', None),
|
||||
('playbook', 'all'),
|
||||
('skip_tags', 'pre-upgrade,validation')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
|
||||
with mock.patch('os.path.exists') as mock_exists:
|
||||
mock_exists.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
for book in constants.MAJOR_UPGRADE_PLAYBOOKS:
|
||||
upgrade_ansible.assert_any_call(
|
||||
self.app.client_manager,
|
||||
container='overcloud',
|
||||
nodes='swift-1',
|
||||
inventory_file=mock_open().__enter__().read(),
|
||||
playbook=book,
|
||||
node_user='tripleo-admin',
|
||||
tags='',
|
||||
skip_tags='pre-upgrade,validation',
|
||||
verbosity=0,
|
||||
extra_vars=None
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
|
@ -391,7 +274,7 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
self.assertRaises(ParserException, lambda: self.check_parser(
|
||||
self.cmd, argslist, verifylist))
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
|
@ -414,7 +297,7 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
self.assertRaises(exceptions.InvalidConfiguration,
|
||||
lambda: self.cmd.take_action(parsed_args))
|
||||
|
||||
@mock.patch('tripleoclient.workflows.package_update.update_ansible',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
@mock.patch('os.path.expanduser')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
|
@ -437,7 +320,7 @@ class TestOvercloudUpgradeRun(fakes.TestOvercloudUpgradeRun):
|
|||
self.assertRaises(exceptions.InvalidConfiguration,
|
||||