Merge "Move stop acton to kolla model from host"
This commit is contained in:
commit
c4eac7583e
|
@ -120,6 +120,31 @@ class ControlPlaneApi(object):
|
|||
ansible_job = action.pull(hostnames, servicenames)
|
||||
return Job(ansible_job)
|
||||
|
||||
@staticmethod
|
||||
def stop(verbose_level=1, hostnames=[]):
|
||||
# type: (int, List[str]) -> Job
|
||||
"""Stop Hosts.
|
||||
|
||||
Stops all kolla related docker containers on the specified hosts.
|
||||
|
||||
:param hostnames: host names
|
||||
:type hostnames: list
|
||||
:param verbose_level: the higher the number, the more verbose
|
||||
:type verbose_level: integer
|
||||
:return: Job object
|
||||
:rtype: Job
|
||||
"""
|
||||
check_arg(hostnames, u._('Host names'), list,
|
||||
empty_ok=True, none_ok=True)
|
||||
check_arg(verbose_level, u._('Verbose level'), int)
|
||||
|
||||
hostnames = safe_decode(hostnames)
|
||||
|
||||
action = KollaAction(verbose_level=verbose_level,
|
||||
playbook_name='site.yml')
|
||||
ansible_job = action.stop(hostnames)
|
||||
return Job(ansible_job)
|
||||
|
||||
@staticmethod
|
||||
def upgrade(verbose_level=1, servicenames=[]):
|
||||
# type: (int, List[str]) -> Job
|
||||
|
|
|
@ -190,32 +190,6 @@ class HostApi(object):
|
|||
include_data, remove_images)
|
||||
return Job(ansible_job)
|
||||
|
||||
@staticmethod
|
||||
def host_stop(hostnames, verbose_level=1):
|
||||
# type: (List[str], int) -> Job
|
||||
"""Stop Hosts.
|
||||
|
||||
Stops all kolla related docker containers on the specified hosts.
|
||||
|
||||
:param hostnames: host names
|
||||
:type hostnames: list
|
||||
:param verbose_level: the higher the number, the more verbose
|
||||
:type verbose_level: integer
|
||||
:return: Job object
|
||||
:rtype: Job
|
||||
"""
|
||||
check_arg(hostnames, u._('Host names'), list)
|
||||
check_arg(verbose_level, u._('Verbose level'), int)
|
||||
|
||||
hostnames = safe_decode(hostnames)
|
||||
inventory = Inventory.load()
|
||||
inventory.validate_hostnames(hostnames)
|
||||
|
||||
action = KollaAction(verbose_level=verbose_level,
|
||||
playbook_name='site.yml')
|
||||
ansible_job = action.stop_hosts(hostnames)
|
||||
return Job(ansible_job)
|
||||
|
||||
|
||||
class Host(object):
|
||||
"""Host"""
|
||||
|
|
|
@ -294,38 +294,6 @@ class HostSetup(Command):
|
|||
return hosts_info
|
||||
|
||||
|
||||
class HostStop(Command):
|
||||
"""Stop all kolla containers on host(s).
|
||||
|
||||
Stops all kolla related docker containers on either the
|
||||
specified host or all hosts if the hostname all is used.
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(HostStop, self).get_parser(prog_name)
|
||||
parser.add_argument('hostname', metavar='<hostname | all>',
|
||||
help=u._('Host name or ip address or "all"'))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
hostname = parsed_args.hostname.strip()
|
||||
|
||||
hostnames = [hostname]
|
||||
if hostname == 'all':
|
||||
hostnames = _get_all_hostnames()
|
||||
|
||||
verbose_level = self.app.options.verbose_level
|
||||
|
||||
job = CLIENT.host_stop(hostnames, verbose_level)
|
||||
status = job.wait()
|
||||
handers_action_result(job, status, verbose_level)
|
||||
except ClientException as e:
|
||||
raise CommandError(str(e))
|
||||
except Exception as e:
|
||||
raise Exception(traceback.format_exc())
|
||||
|
||||
|
||||
def _get_all_hostnames():
|
||||
hostnames = []
|
||||
hosts = CLIENT.host_get_all()
|
||||
|
|
|
@ -190,6 +190,33 @@ class Reconfigure(Command):
|
|||
raise Exception(traceback.format_exc())
|
||||
|
||||
|
||||
class Stop(Command):
|
||||
"""Stop all kolla containers on host(s).
|
||||
|
||||
Stops all kolla related docker containers on either the
|
||||
specified host or all hosts if the hostname all is used.
|
||||
"""
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(Stop, self).get_parser(prog_name)
|
||||
parser.add_argument('--hosts', nargs='?',
|
||||
metavar='<host_list>',
|
||||
help=u._('Stop host list'))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
hosts = []
|
||||
verbose_level = self.app.options.verbose_level
|
||||
if parsed_args.hosts:
|
||||
host_list = parsed_args.hosts.strip()
|
||||
hosts = host_list.split(',')
|
||||
job = CLIENT.stop(verbose_level, hosts)
|
||||
status = job.wait()
|
||||
handers_action_result(job, status, verbose_level)
|
||||
except Exception:
|
||||
raise Exception(traceback.format_exc())
|
||||
|
||||
|
||||
class Upgrade(Command):
|
||||
"""Upgrades existing OpenStack Environment."""
|
||||
def get_parser(self, prog_name):
|
||||
|
|
|
@ -103,7 +103,7 @@ class KollaAction(object):
|
|||
job = self.playbook.run()
|
||||
return job
|
||||
|
||||
def stop_hosts(self, hostnames=[]):
|
||||
def stop(self, hostnames=[]):
|
||||
'''stop containers on a set of hosts.
|
||||
|
||||
The containers on the specified hosts will be stopped
|
||||
|
|
|
@ -41,7 +41,7 @@ class TestFunctional(KollaCliTest):
|
|||
|
||||
# stop services, initialize server
|
||||
self.log.info('Start stop #1')
|
||||
job = CLIENT.host_stop(hostnames)
|
||||
job = CLIENT.stop(1, hostnames)
|
||||
self._process_job(job, 'stop #1')
|
||||
|
||||
self.log.info('updating various properties for the test')
|
||||
|
@ -59,7 +59,7 @@ class TestFunctional(KollaCliTest):
|
|||
self._process_job(job, 'deploy')
|
||||
|
||||
self.log.info('Start stop #2')
|
||||
job = CLIENT.host_stop(hostnames)
|
||||
job = CLIENT.stop(1, hostnames)
|
||||
self._process_job(job, 'stop #2')
|
||||
|
||||
def _process_job(self, job, descr, expect_kill=False):
|
||||
|
|
|
@ -176,26 +176,3 @@ class TestUnit(KollaCliUnitTest):
|
|||
mock_setup.assert_called_once_with({hostname: {'password': password}})
|
||||
mock_yml.assert_called_once_with(fake_path)
|
||||
mock_ssh_check.assert_not_called()
|
||||
|
||||
@mock.patch('kolla_cli.common.ansible.job.AnsibleJob.get_status')
|
||||
@mock.patch('kolla_cli.api.client.ClientApi.host_get_all')
|
||||
@mock.patch('kolla_cli.api.client.ClientApi.host_stop')
|
||||
@mock.patch('kolla_cli.shell.KollaCli._is_inventory_present',
|
||||
return_value=True)
|
||||
def test_host_stop(self, _, mock_stop, mock_get_all,
|
||||
mock_get_status):
|
||||
hostname = 'foo'
|
||||
mock_get_all.return_value = [self.get_fake_host(hostname)]
|
||||
mock_get_status.return_value = 0
|
||||
mock_stop.return_value = self.get_fake_job()
|
||||
|
||||
# host stop hostname
|
||||
ret = self.run_cli_command('host stop %s' % hostname)
|
||||
self.assertEqual(ret, 0)
|
||||
mock_stop.assert_called_once_with([hostname], 1)
|
||||
|
||||
# host stop all
|
||||
mock_stop.reset_mock()
|
||||
ret = self.run_cli_command('host stop all')
|
||||
self.assertEqual(ret, 0)
|
||||
mock_stop.assert_called_once_with([hostname], 1)
|
||||
|
|
|
@ -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.stop')
|
||||
@mock.patch('kolla_cli.common.ansible.job.AnsibleJob.get_status')
|
||||
@mock.patch('kolla_cli.shell.KollaCli._is_inventory_present',
|
||||
return_value=True)
|
||||
def test_stop(self, _, mock_get_status, mock_stop):
|
||||
mock_get_status.return_value = 0
|
||||
mock_stop.return_value = self.get_fake_job()
|
||||
ret = self.run_cli_command('action stop')
|
||||
self.assertEqual(ret, 0)
|
||||
mock_stop.assert_called_once_with(1, [])
|
||||
|
||||
@mock.patch('kolla_cli.api.control_plane.ControlPlaneApi.stop')
|
||||
@mock.patch('kolla_cli.common.ansible.job.AnsibleJob.get_status')
|
||||
@mock.patch('kolla_cli.shell.KollaCli._is_inventory_present',
|
||||
return_value=True)
|
||||
def test_stop_with_hosts(self, _, mock_get_status, mock_stop):
|
||||
mock_get_status.return_value = 0
|
||||
mock_stop.return_value = self.get_fake_job()
|
||||
hostnames = ['host1', 'host2']
|
||||
ret = self.run_cli_command('action stop --hosts {hosts}'.format(
|
||||
hosts=','.join(hostnames)))
|
||||
self.assertEqual(ret, 0)
|
||||
mock_stop.assert_called_once_with(1, hostnames)
|
|
@ -36,6 +36,7 @@ kolla.cli =
|
|||
action_postdeploy = kolla_cli.commands.kolla_action:PostDeploy
|
||||
action_pull = kolla_cli.commands.kolla_action:Pull
|
||||
action_reconfigure = kolla_cli.commands.kolla_action:Reconfigure
|
||||
action_stop = kolla_cli.commands.kolla_action:Stop
|
||||
action_upgrade = kolla_cli.commands.kolla_action:Upgrade
|
||||
certificate_init = kolla_cli.commands.kolla_action:CertificateInit
|
||||
config_reset = kolla_cli.commands.config:ConfigReset
|
||||
|
@ -54,7 +55,6 @@ kolla.cli =
|
|||
host_list = kolla_cli.commands.host:HostList
|
||||
host_remove = kolla_cli.commands.host:HostRemove
|
||||
host_setup = kolla_cli.commands.host:HostSetup
|
||||
host_stop = kolla_cli.commands.host:HostStop
|
||||
password_clear = kolla_cli.commands.password:PasswordClear
|
||||
password_init = kolla_cli.commands.password:PasswordInit
|
||||
password_list = kolla_cli.commands.password:PasswordList
|
||||
|
|
Loading…
Reference in New Issue