diff --git a/kolla_cli/commands/deploy.py b/kolla_cli/commands/deploy.py index e107436..c6419f0 100644 --- a/kolla_cli/commands/deploy.py +++ b/kolla_cli/commands/deploy.py @@ -38,6 +38,9 @@ class Deploy(Command): parser.add_argument('--timeout', nargs=1, metavar='', help=u._('timeout (in minutes)')) + parser.add_argument('--services', nargs='?', + metavar='', + help=u._('Deploy service list')) return parser def take_action(self, parsed_args): @@ -45,6 +48,7 @@ class Deploy(Command): serial_flag = False verbose_level = self.app.options.verbose_level timeout_target = 0 + services = None try: if parsed_args.hosts: host_list = parsed_args.hosts.strip() @@ -57,6 +61,9 @@ class Deploy(Command): except Exception: raise CommandError(u._('Timeout value is not a number.')) timeout_target = time.time() + (60 * timeout) + if parsed_args.services: + service_list = parsed_args.services.strip() + services = service_list.split(',') # if we are doing a targeted host deploy make sure we are doing it # to only compute nodes @@ -74,8 +81,7 @@ class Deploy(Command): 'Invalid hosts: {hosts}') .format(hosts=invalid_host_list)) - job = CLIENT.deploy(hosts, serial_flag, - verbose_level) + job = CLIENT.deploy(hosts, serial_flag, verbose_level, services) # wait for job to complete status = None diff --git a/kolla_cli/tests/unit/test_deploy_cmd.py b/kolla_cli/tests/unit/test_deploy_cmd.py new file mode 100644 index 0000000..62eceb9 --- /dev/null +++ b/kolla_cli/tests/unit/test_deploy_cmd.py @@ -0,0 +1,42 @@ +# Copyright (c) 2018 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import mock + +from kolla_cli.tests.unit.common import KollaCliUnitTest + + +class TestUnit(KollaCliUnitTest): + @mock.patch('kolla_cli.api.control_plane.ControlPlaneApi.deploy') + @mock.patch('kolla_cli.common.ansible.job.AnsibleJob.get_status') + @mock.patch('kolla_cli.shell.KollaCli._is_inventory_present', + return_value=True) + def test_deploy(self, _, mock_get_status, mock_deploy): + mock_get_status.return_value = 0 + mock_deploy.return_value = self.get_fake_job() + ret = self.run_cli_command('deploy') + self.assertEqual(ret, 0) + mock_deploy.assert_called_once_with(None, False, 1, None) + + @mock.patch('kolla_cli.api.control_plane.ControlPlaneApi.deploy') + @mock.patch('kolla_cli.common.ansible.job.AnsibleJob.get_status') + @mock.patch('kolla_cli.shell.KollaCli._is_inventory_present', + return_value=True) + def test_deploy_with_services(self, _, mock_get_status, mock_deploy): + mock_get_status.return_value = 0 + mock_deploy.return_value = self.get_fake_job() + services = ['foo', 'bar'] + ret = self.run_cli_command( + 'deploy --services {}'.format(','.join(services))) + self.assertEqual(ret, 0) + mock_deploy.assert_called_once_with(None, False, 1, services)