Add --services flag for deploy

Allow users to pass tags to the underlying ansible command.

Added some bare bones unit tests for deploy to ensure the arg is being
parsed and passed down correctly.

Change-Id: I9d321a7a088d09894ae00f41a2ccb6978690b128
This commit is contained in:
Paul Bourke 2018-10-31 14:20:25 +00:00
parent 07dbcbd4fd
commit 6aaa28f83a
2 changed files with 50 additions and 2 deletions

View File

@ -38,6 +38,9 @@ class Deploy(Command):
parser.add_argument('--timeout', nargs=1,
metavar='<timeout>',
help=u._('timeout (in minutes)'))
parser.add_argument('--services', nargs='?',
metavar='<service_list>',
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

View File

@ -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)