Summary: add more group commands
Description: - new commands: - group add/remove host - group add/remove service - changed commands - host add (no more group on command line here) - change inventory extension to .json - remove zone unittest - new group unit test - better organized defaults -
This commit is contained in:
parent
01ff63f532
commit
398f4a61d5
|
@ -16,6 +16,7 @@ import jsonpickle
|
|||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import traceback
|
||||
|
||||
from tempfile import mkstemp
|
||||
|
||||
|
@ -30,40 +31,49 @@ from kollacli.sshutils import ssh_uninstall_host
|
|||
|
||||
from kollacli.exceptions import CommandError
|
||||
|
||||
INVENTORY_PATH = 'ansible/inventory/inventory.p'
|
||||
INVENTORY_PATH = 'ansible/inventory/inventory.json'
|
||||
|
||||
COMPUTE_GRP_NAME = 'compute'
|
||||
CONTROL_GRP_NAME = 'control'
|
||||
NETWORK_GRP_NAME = 'network'
|
||||
STORAGE_GRP_NAME = 'storage'
|
||||
|
||||
DEPLOY_GROUPS = [COMPUTE_GRP_NAME,
|
||||
CONTROL_GRP_NAME,
|
||||
NETWORK_GRP_NAME,
|
||||
STORAGE_GRP_NAME,
|
||||
]
|
||||
|
||||
SERVICE_GROUPS = ['mariadb', 'rabbitmq', 'keystone', 'glance',
|
||||
'nova', 'haproxy', 'neutron']
|
||||
|
||||
CONTAINER_GROUPS = ['glance-api', 'glance-registry',
|
||||
'nova-api', 'nova-conductor', 'nova-consoleauth',
|
||||
'nova-novncproxy', 'nova-scheduler',
|
||||
'neutron-server', 'neutron-agents']
|
||||
SERVICE_GROUPS = {'cinder': ['cinder-api', 'cinder-backup',
|
||||
'cinder-scheduler', 'cinder-volume'],
|
||||
'glance': ['glance-api', 'glance-registry'],
|
||||
'haproxy': [],
|
||||
'keystone': [],
|
||||
'mariadb': [],
|
||||
'ndb': ['ndb-data', 'ndb-mgmt', 'ndb-mysql'],
|
||||
'neutron': ['neutron-server', 'neutron-agents'],
|
||||
'nova': ['nova-api', 'nova-conductor',
|
||||
'nova-consoleauth',
|
||||
'nova-novncproxy', 'nova-scheduler'],
|
||||
'rabbitmq': [],
|
||||
}
|
||||
|
||||
DEFAULT_HIERARCHY = {
|
||||
CONTROL_GRP_NAME: {
|
||||
'glance': ['glance-api', 'glance-registry'],
|
||||
'keystone': [],
|
||||
'mariadb': [],
|
||||
'nova': ['nova-api', 'nova-conductor', 'nova-consoleauth',
|
||||
'nova-novncproxy', 'nova-scheduler'],
|
||||
'rabbitmq': [],
|
||||
},
|
||||
NETWORK_GRP_NAME: {
|
||||
'haproxy': [],
|
||||
'neutron': ['neutron-server', 'neutron-agents'],
|
||||
},
|
||||
COMPUTE_GRP_NAME: {
|
||||
},
|
||||
CONTROL_GRP_NAME: [
|
||||
'glance',
|
||||
'keystone',
|
||||
'ndb',
|
||||
'nova',
|
||||
'rabbitmq',
|
||||
],
|
||||
NETWORK_GRP_NAME: [
|
||||
'haproxy',
|
||||
'neutron',
|
||||
],
|
||||
COMPUTE_GRP_NAME: [],
|
||||
STORAGE_GRP_NAME: [
|
||||
'cinder',
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
@ -234,8 +244,9 @@ class Inventory(object):
|
|||
inventory.upgrade()
|
||||
else:
|
||||
inventory = Inventory()
|
||||
except Exception as e:
|
||||
raise Exception('ERROR: loading inventory : %s' % str(e))
|
||||
except Exception:
|
||||
raise Exception('ERROR: loading inventory : %s'
|
||||
% traceback.format_exc())
|
||||
return inventory
|
||||
|
||||
@staticmethod
|
||||
|
@ -271,13 +282,13 @@ class Inventory(object):
|
|||
pass
|
||||
|
||||
def _create_default_inventory(self):
|
||||
for (deploy_name, services) in DEFAULT_HIERARCHY.items():
|
||||
for (deploy_name, service_names) in DEFAULT_HIERARCHY.items():
|
||||
deploy_group = Group(deploy_name)
|
||||
# add service groups
|
||||
for (service_name, container_names) in services.items():
|
||||
for service_name in service_names:
|
||||
service_group = Group(service_name)
|
||||
deploy_group.children.append(service_group)
|
||||
for container_name in container_names:
|
||||
for container_name in SERVICE_GROUPS[service_name]:
|
||||
container_group = Group(container_name)
|
||||
service_group.children.append(container_group)
|
||||
self._groups[deploy_name] = deploy_group
|
||||
|
@ -305,33 +316,49 @@ class Inventory(object):
|
|||
host = self._hosts[hostname]
|
||||
return host
|
||||
|
||||
def add_host(self, hostname, groupname):
|
||||
if groupname not in self._groups:
|
||||
raise CommandError('Group name not valid')
|
||||
def add_host(self, hostname, groupname=None):
|
||||
"""add host
|
||||
|
||||
if groupname is none, create a new host
|
||||
if group name is not none, add host to group
|
||||
"""
|
||||
if groupname and groupname not in self._groups:
|
||||
raise CommandError('Group name (%s) does not exist'
|
||||
% groupname)
|
||||
|
||||
if groupname and hostname not in self._hosts:
|
||||
raise CommandError('Host name (%s) does not exist'
|
||||
% hostname)
|
||||
|
||||
# create new host if it doesn't exist
|
||||
if hostname not in self._hosts:
|
||||
host = Host(hostname)
|
||||
host = Host(hostname)
|
||||
if not groupname:
|
||||
self._hosts[hostname] = host
|
||||
else:
|
||||
host = self._hosts[hostname]
|
||||
|
||||
group = self._groups[groupname]
|
||||
group.add_host(host)
|
||||
group = self._groups[groupname]
|
||||
group.add_host(host)
|
||||
|
||||
def remove_host(self, hostname, groupname=None):
|
||||
if hostname in self._hosts:
|
||||
host = self._hosts[hostname]
|
||||
groups = self.get_groups(host)
|
||||
group_count = len(groups)
|
||||
for group in groups:
|
||||
if not groupname or groupname == group.name:
|
||||
group_count -= 1
|
||||
group.remove_host(host)
|
||||
"""remove host
|
||||
|
||||
# if host no longer exists in any group, remove it from inventory
|
||||
if group_count == 0:
|
||||
del self._hosts[hostname]
|
||||
if groupname is none, delete host
|
||||
if group name is not none, remove host from group
|
||||
"""
|
||||
if groupname and groupname not in self._groups:
|
||||
raise CommandError('Group name (%s) does not exist'
|
||||
% groupname)
|
||||
|
||||
if hostname not in self._hosts:
|
||||
return
|
||||
|
||||
host = self._hosts[hostname]
|
||||
groups = self.get_groups(host)
|
||||
for group in groups:
|
||||
if not groupname or groupname == group.name:
|
||||
group.remove_host(host)
|
||||
|
||||
if not groupname:
|
||||
del self._hosts[hostname]
|
||||
|
||||
def add_group(self, groupname):
|
||||
if groupname not in self._groups:
|
||||
|
@ -373,6 +400,36 @@ class Inventory(object):
|
|||
group_hosts[group.name].append(host.name)
|
||||
return group_hosts
|
||||
|
||||
def add_service(self, servicename, groupname):
|
||||
if groupname not in self._groups:
|
||||
raise CommandError('Group name (%s) does not exist'
|
||||
% groupname)
|
||||
|
||||
if servicename not in SERVICE_GROUPS.keys():
|
||||
raise CommandError('Service name (%s) does not exist'
|
||||
% servicename)
|
||||
|
||||
group_services = self.get_group_services()
|
||||
if servicename not in group_services[groupname]:
|
||||
group = self._groups[groupname]
|
||||
group.children.append(Group(servicename))
|
||||
|
||||
def remove_service(self, servicename, groupname):
|
||||
if groupname not in self._groups:
|
||||
raise CommandError('Group name (%s) does not exist'
|
||||
% groupname)
|
||||
|
||||
if servicename not in SERVICE_GROUPS.keys():
|
||||
raise CommandError('Service name (%s) does not exist'
|
||||
% servicename)
|
||||
|
||||
group_services = self.get_group_services()
|
||||
if servicename in group_services[groupname]:
|
||||
group = self._groups[groupname]
|
||||
for service in group.children:
|
||||
if service.name == servicename:
|
||||
group.children.remove(service)
|
||||
|
||||
def get_ansible_json(self):
|
||||
"""generate json inventory for ansible
|
||||
|
||||
|
|
|
@ -67,23 +67,53 @@ class GroupRemove(Command):
|
|||
raise Exception(traceback.format_exc())
|
||||
|
||||
|
||||
class GroupListservices(Lister):
|
||||
"""List all groups and their services"""
|
||||
|
||||
class GroupAddhost(Command):
|
||||
"""Add host to group"""
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(GroupAddhost, self).get_parser(prog_name)
|
||||
parser.add_argument('groupname', metavar='<groupname>',
|
||||
help='group')
|
||||
parser.add_argument('hostname', metavar='<hostname>',
|
||||
help='host')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
inventory = Inventory.load()
|
||||
groupname = parsed_args.groupname.strip()
|
||||
hostname = parsed_args.hostname.strip()
|
||||
|
||||
data = []
|
||||
group_services = inventory.get_group_services()
|
||||
if group_services:
|
||||
for (groupname, servicenames) in group_services.items():
|
||||
data.append((groupname, servicenames))
|
||||
else:
|
||||
data.append(('', ''))
|
||||
return (('Group Name', 'Services'), sorted(data))
|
||||
inventory = Inventory.load()
|
||||
inventory.add_host(hostname, groupname)
|
||||
Inventory.save(inventory)
|
||||
except CommandError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
raise Exception(traceback.format_exc())
|
||||
|
||||
|
||||
class GroupRemovehost(Command):
|
||||
"""Remove host group from group"""
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(GroupRemovehost, self).get_parser(prog_name)
|
||||
parser.add_argument('groupname', metavar='<groupname>',
|
||||
help='group')
|
||||
parser.add_argument('hostname', metavar='<hostname>',
|
||||
help='host')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
groupname = parsed_args.groupname.strip()
|
||||
hostname = parsed_args.hostname.strip()
|
||||
|
||||
inventory = Inventory.load()
|
||||
inventory.remove_host(hostname, groupname)
|
||||
Inventory.save(inventory)
|
||||
except CommandError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
|
@ -106,7 +136,83 @@ class GroupListhosts(Lister):
|
|||
data.append((groupname, hostnames))
|
||||
else:
|
||||
data.append(('', ''))
|
||||
return (('Group Name', 'Hosts'), sorted(data))
|
||||
return (('Group', 'Hosts'), sorted(data))
|
||||
except CommandError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
raise Exception(traceback.format_exc())
|
||||
|
||||
|
||||
class GroupAddservice(Command):
|
||||
"""Add service to group"""
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(GroupAddservice, self).get_parser(prog_name)
|
||||
parser.add_argument('groupname', metavar='<groupname>',
|
||||
help='group')
|
||||
parser.add_argument('servicename', metavar='<servicename>',
|
||||
help='service')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
groupname = parsed_args.groupname.strip()
|
||||
servicename = parsed_args.servicename.strip()
|
||||
|
||||
inventory = Inventory.load()
|
||||
inventory.add_service(servicename, groupname)
|
||||
Inventory.save(inventory)
|
||||
except CommandError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
raise Exception(traceback.format_exc())
|
||||
|
||||
|
||||
class GroupRemoveservice(Command):
|
||||
"""Remove service group from group"""
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(GroupRemoveservice, self).get_parser(prog_name)
|
||||
parser.add_argument('groupname', metavar='<groupname>',
|
||||
help='group')
|
||||
parser.add_argument('servicename', metavar='<servicename>',
|
||||
help='service')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
groupname = parsed_args.groupname.strip()
|
||||
servicename = parsed_args.servicename.strip()
|
||||
|
||||
inventory = Inventory.load()
|
||||
inventory.remove_service(servicename, groupname)
|
||||
Inventory.save(inventory)
|
||||
except CommandError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
raise Exception(traceback.format_exc())
|
||||
|
||||
|
||||
class GroupListservices(Lister):
|
||||
"""List all groups and their services"""
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
inventory = Inventory.load()
|
||||
|
||||
data = []
|
||||
group_services = inventory.get_group_services()
|
||||
if group_services:
|
||||
for (groupname, servicenames) in group_services.items():
|
||||
data.append((groupname, servicenames))
|
||||
else:
|
||||
data.append(('', ''))
|
||||
return (('Group', 'Services'), sorted(data))
|
||||
except CommandError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
|
|
|
@ -37,17 +37,14 @@ class HostAdd(Command):
|
|||
parser = super(HostAdd, self).get_parser(prog_name)
|
||||
parser.add_argument('hostname', metavar='<hostname>',
|
||||
help='host name or ip address')
|
||||
parser.add_argument('groupname', metavar='<groupname>',
|
||||
help='group name')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
hostname = parsed_args.hostname.strip()
|
||||
groupname = parsed_args.groupname.strip()
|
||||
|
||||
inventory = Inventory.load()
|
||||
inventory.add_host(hostname, groupname)
|
||||
inventory.add_host(hostname)
|
||||
Inventory.save(inventory)
|
||||
except CommandError as e:
|
||||
raise e
|
||||
|
@ -56,29 +53,20 @@ class HostAdd(Command):
|
|||
|
||||
|
||||
class HostRemove(Command):
|
||||
"""Remove host from openstack-kolla
|
||||
|
||||
If a group is specified, the host will be removed from that group.
|
||||
If no group is specified, the host will be removed from all groups.
|
||||
"""
|
||||
"""Remove host from openstack-kolla"""
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(HostRemove, self).get_parser(prog_name)
|
||||
parser.add_argument('hostname', metavar='<hostname>', help='host name')
|
||||
parser.add_argument('groupname', nargs='?',
|
||||
metavar='<group>', help='group name')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
try:
|
||||
hostname = parsed_args.hostname.strip()
|
||||
groupname = None
|
||||
if parsed_args.groupname:
|
||||
groupname = parsed_args.groupname.strip()
|
||||
inventory = Inventory.load()
|
||||
inventory.remove_host(hostname, groupname)
|
||||
inventory.remove_host(hostname)
|
||||
Inventory.save(inventory)
|
||||
except CommandError as e:
|
||||
raise e
|
||||
|
@ -102,7 +90,7 @@ class HostList(Lister):
|
|||
data.append((hostname, groupnames))
|
||||
else:
|
||||
data.append(('', ''))
|
||||
return (('Host Name', 'Groups'), sorted(data))
|
||||
return (('Host', 'Groups'), sorted(data))
|
||||
except CommandError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
|
|
11
setup.cfg
11
setup.cfg
|
@ -33,13 +33,15 @@ console_scripts =
|
|||
kolla.cli =
|
||||
group_add = kollacli.group:GroupAdd
|
||||
group_remove = kollacli.group:GroupRemove
|
||||
group_listservices = kollacli.group:GroupListservices
|
||||
group_addhost = kollacli.group:GroupAddhost
|
||||
group_removehost = kollacli.group:GroupRemovehost
|
||||
group_listhosts = kollacli.group:GroupListhosts
|
||||
group_addservice = kollacli.group:GroupAddservice
|
||||
group_removeservice = kollacli.group:GroupRemoveservice
|
||||
group_listservices = kollacli.group:GroupListservices
|
||||
host_add = kollacli.host:HostAdd
|
||||
host_remove = kollacli.host:HostRemove
|
||||
host_list = kollacli.host:HostList
|
||||
host_addservice = kollacli.host:HostAddservice
|
||||
host_removeservice = kollacli.host:HostRemoveservice
|
||||
host_check = kollacli.host:HostCheck
|
||||
host_install = kollacli.host:HostInstall
|
||||
host_uninstall = kollacli.host:HostUninstall
|
||||
|
@ -47,9 +49,6 @@ kolla.cli =
|
|||
service_deactivate = kollacli.service:ServiceDisable
|
||||
service_autodeploy = kollacli.service:ServiceAutodeploy
|
||||
service_list = kollacli.service:ServiceList
|
||||
zone_add = kollacli.zone:ZoneAdd
|
||||
zone_remove = kollacli.zone:ZoneRemove
|
||||
zone_list = kollacli.zone:ZoneList
|
||||
property_set = kollacli.property:PropertySet
|
||||
property_clear = kollacli.property:PropertyClear
|
||||
property_list = kollacli.property:PropertyList
|
||||
|
|
|
@ -57,7 +57,7 @@ class KollaCliTest(testtools.TestCase):
|
|||
self._init_dir(etc_ansible_path)
|
||||
etc_inventory_path = os.path.join(etc_ansible_path, 'inventory/')
|
||||
self._init_dir(etc_inventory_path)
|
||||
self._init_file(os.path.join(etc_inventory_path, 'inventory.p'))
|
||||
self._init_file(os.path.join(etc_inventory_path, 'inventory.json'))
|
||||
|
||||
def tearDown(self):
|
||||
self._restore_env_var()
|
||||
|
|
|
@ -0,0 +1,213 @@
|
|||
# Copyright(c) 2015, Oracle and/or its affiliates. All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
from common import KollaCliTest
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
|
||||
class TestFunctional(KollaCliTest):
|
||||
group1 = {
|
||||
'Group': 'control',
|
||||
'Services': [
|
||||
'glance',
|
||||
'keystone',
|
||||
'ndb',
|
||||
'nova',
|
||||
'rabbitmq'],
|
||||
'Hosts': [],
|
||||
}
|
||||
group2 = {
|
||||
'Group': 'network',
|
||||
'Services': [
|
||||
'haproxy',
|
||||
'neutron'],
|
||||
'Hosts': [],
|
||||
}
|
||||
group3 = {
|
||||
'Group': 'compute',
|
||||
'Services': [],
|
||||
'Hosts': [],
|
||||
}
|
||||
groups = [group1, group2, group3]
|
||||
|
||||
def test_group_add_remove(self):
|
||||
group4 = {
|
||||
'Group': 'test_group4',
|
||||
'Services': [],
|
||||
'Hosts': [],
|
||||
}
|
||||
group5 = {
|
||||
'Group': 'test_group5',
|
||||
'Services': [],
|
||||
'Hosts': [],
|
||||
}
|
||||
|
||||
groups = list(self.groups)
|
||||
|
||||
# check default group list
|
||||
self.check_group(groups)
|
||||
|
||||
groups.append(group4)
|
||||
self.run_client_cmd('group add %s' % group4['Group'])
|
||||
self.check_group(groups)
|
||||
|
||||
groups.append(group5)
|
||||
self.run_client_cmd('group add %s' % group5['Group'])
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('group remove %s' % group5['Group'])
|
||||
groups.remove(group5)
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('group remove %s' % group4['Group'])
|
||||
groups.remove(group4)
|
||||
self.check_group(groups)
|
||||
|
||||
def test_group_add_host(self):
|
||||
groups = list(self.groups)
|
||||
|
||||
host1 = 'test_host1'
|
||||
host2 = 'test_host2'
|
||||
group_name = 'compute'
|
||||
|
||||
group = None
|
||||
for test_group in groups:
|
||||
if test_group['Group'] == group_name:
|
||||
group = test_group
|
||||
|
||||
groupname = group['Group']
|
||||
hosts = group['Hosts']
|
||||
|
||||
self.run_client_cmd('host add %s' % host1)
|
||||
|
||||
hosts.append(host1)
|
||||
self.run_client_cmd('group addhost %s %s' % (groupname, host1))
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('host add %s' % host2)
|
||||
|
||||
hosts.append(host2)
|
||||
self.run_client_cmd('group addhost %s %s' % (groupname, host2))
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('group removehost %s %s' % (groupname, host2))
|
||||
hosts.remove(host2)
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('group removehost %s %s' % (groupname, host1))
|
||||
hosts.remove(host1)
|
||||
self.check_group(groups)
|
||||
|
||||
def test_group_add_service(self):
|
||||
groups = list(self.groups)
|
||||
|
||||
group_name = 'compute'
|
||||
|
||||
group = None
|
||||
for test_group in groups:
|
||||
if test_group['Group'] == group_name:
|
||||
group = test_group
|
||||
|
||||
groupname = group['Group']
|
||||
services = group['Services']
|
||||
|
||||
service1 = 'ndb'
|
||||
service2 = 'rabbitmq'
|
||||
|
||||
services.append(service1)
|
||||
self.run_client_cmd('group addservice %s %s' % (groupname, service1))
|
||||
self.check_group(groups)
|
||||
|
||||
services.append(service2)
|
||||
self.run_client_cmd('group addservice %s %s' % (groupname, service2))
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('group removeservice %s %s'
|
||||
% (groupname, service2))
|
||||
services.remove(service2)
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('group removeservice %s %s'
|
||||
% (groupname, service1))
|
||||
services.remove(service1)
|
||||
self.check_group(groups)
|
||||
|
||||
def check_group(self, groups):
|
||||
"""check groups
|
||||
|
||||
group listhosts -f json:
|
||||
group listhosts -f json
|
||||
[{"Group Name": "compute", "Hosts": []},
|
||||
{"Group Name": "control", "Hosts": ["ub-target1"]},
|
||||
{"Group Name": "network", "Hosts": []}]
|
||||
|
||||
group listservices -f json:
|
||||
[{"Group Name": "compute", "Services": []},
|
||||
{"Group Name": "control",
|
||||
"Services": ["glance", "keystone", "ndb",
|
||||
"nova", "rabbitmq"]},
|
||||
{"Group Name": "network", "Services": ["haproxy", "neutron"]}]
|
||||
"""
|
||||
# check hosts in groups
|
||||
msg = self.run_client_cmd('group listhosts -f json')
|
||||
cli_groups = json.loads(msg)
|
||||
self.assertEqual(len(cli_groups), len(groups),
|
||||
'# of groups in cli not equal to expected groups.' +
|
||||
'\nexpected: %s, \ncli: %s' % (groups, cli_groups))
|
||||
|
||||
for cli_group in cli_groups:
|
||||
cli_hosts = cli_group['Hosts']
|
||||
for group in groups:
|
||||
if group['Group'] != cli_group['Group']:
|
||||
continue
|
||||
group_name = group['Group']
|
||||
group_hosts = group['Hosts']
|
||||
self.assertEqual(len(cli_hosts), len(group_hosts),
|
||||
'Group: %s. # of hosts in cli ' % group_name +
|
||||
'not equal to expected hosts, ' +
|
||||
'\nexpected: %s, \ncli: %s'
|
||||
% (group_hosts, cli_hosts))
|
||||
for group_host in group_hosts:
|
||||
self.assertIn(group_host, cli_hosts,
|
||||
'Group: %s' % group_name +
|
||||
'\nexpected_hosts: %s, \nnot in cli: %s '
|
||||
% (group_host, cli_hosts))
|
||||
|
||||
# check services in group
|
||||
msg = self.run_client_cmd('group listservices -f json')
|
||||
cli_groups = json.loads(msg)
|
||||
|
||||
for cli_group in cli_groups:
|
||||
cli_services = cli_group['Services']
|
||||
for group in groups:
|
||||
if group['Group'] != cli_group['Group']:
|
||||
continue
|
||||
group_name = group['Group']
|
||||
group_services = group['Services']
|
||||
self.assertEqual(len(cli_services), len(group_services),
|
||||
'Group: %s. # of services in cli'
|
||||
% group_name +
|
||||
' not equal to expected services,' +
|
||||
'\nexpected: %s, \ncli: %s'
|
||||
% (group_services, cli_services))
|
||||
for group_service in group_services:
|
||||
self.assertIn(group_service, cli_services,
|
||||
'Group: %s' % group_name +
|
||||
'\nexpected_services: %s, \nnot in cli: %s '
|
||||
% (group_service, cli_services))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -31,33 +31,19 @@ class TestFunctional(KollaCliTest):
|
|||
host2 = 'host_test2'
|
||||
|
||||
group1 = 'control'
|
||||
group2 = 'network'
|
||||
group3 = 'compute'
|
||||
|
||||
hosts.add(host1)
|
||||
hosts.add_group(host1, group1)
|
||||
self.run_client_cmd('host add %s %s' % (host1, group1))
|
||||
msg = self.run_client_cmd('host list -f json')
|
||||
self._check_cli_output(hosts, msg)
|
||||
|
||||
hosts.add_group(host1, group2)
|
||||
self.run_client_cmd('host add %s %s' % (host1, group2))
|
||||
msg = self.run_client_cmd('host list -f json')
|
||||
self._check_cli_output(hosts, msg)
|
||||
|
||||
hosts.remove_group(host1, group1)
|
||||
self.run_client_cmd('host remove %s %s' % (host1, group1))
|
||||
self.run_client_cmd('host add %s' % host1)
|
||||
msg = self.run_client_cmd('host list -f json')
|
||||
self._check_cli_output(hosts, msg)
|
||||
|
||||
hosts.add(host2)
|
||||
hosts.add_group(host2, group3)
|
||||
self.run_client_cmd('host add %s %s' % (host2, group3))
|
||||
self.run_client_cmd('host add %s' % host2)
|
||||
msg = self.run_client_cmd('host list -f json')
|
||||
self._check_cli_output(hosts, msg)
|
||||
|
||||
hosts.remove(host2)
|
||||
self.run_client_cmd('host remove %s %s' % (host2, group3))
|
||||
self.run_client_cmd('host remove %s' % host2)
|
||||
msg = self.run_client_cmd('host list -f json')
|
||||
self._check_cli_output(hosts, msg)
|
||||
|
||||
|
@ -66,6 +52,19 @@ class TestFunctional(KollaCliTest):
|
|||
msg = self.run_client_cmd('host list -f json')
|
||||
self._check_cli_output(hosts, msg)
|
||||
|
||||
# check groups in host list
|
||||
hosts.add(host1)
|
||||
hosts.add_group(host1, group1)
|
||||
self.run_client_cmd('host add %s' % host1)
|
||||
self.run_client_cmd('group addhost %s %s' % (group1, host1))
|
||||
msg = self.run_client_cmd('host list -f json')
|
||||
self._check_cli_output(hosts, msg)
|
||||
|
||||
hosts.remove_group(host1, group1)
|
||||
self.run_client_cmd('group removehost %s %s' % (group1, host1))
|
||||
msg = self.run_client_cmd('host list -f json')
|
||||
self._check_cli_output(hosts, msg)
|
||||
|
||||
def test_host_install(self):
|
||||
test_hosts = TestHosts()
|
||||
test_hosts.load()
|
||||
|
@ -77,7 +76,7 @@ class TestFunctional(KollaCliTest):
|
|||
hostname = test_hosts.get_hostnames()[0]
|
||||
pwd = test_hosts.get_password(hostname)
|
||||
|
||||
self.run_client_cmd('host add %s control' % (hostname))
|
||||
self.run_client_cmd('host add %s' % hostname)
|
||||
|
||||
# check if host is installed
|
||||
msg = self.run_client_cmd('host check %s' % hostname, True)
|
||||
|
@ -109,7 +108,7 @@ class TestFunctional(KollaCliTest):
|
|||
The host list cli output looks like this:
|
||||
|
||||
$ host list -f json
|
||||
[{"Host Name": "foo", "Groups": ["control", "network"]}]
|
||||
[{"Host": "foo", "Groups": ["control", "network"]}]
|
||||
"""
|
||||
# check for any host in cli output that shouldn't be there
|
||||
cli_hosts = json.loads(cli_output)
|
||||
|
@ -117,13 +116,13 @@ class TestFunctional(KollaCliTest):
|
|||
exp_hostnames = exp_hosts.get_hostnames()
|
||||
if not exp_hostnames:
|
||||
if len(cli_hosts) == 1:
|
||||
cli_hostname = cli_hosts[0]['Host Name']
|
||||
cli_hostname = cli_hosts[0]['Host']
|
||||
if not cli_hostname:
|
||||
# both cli and expected hosts are None
|
||||
return
|
||||
|
||||
for cli_host in cli_hosts:
|
||||
cli_hostname = cli_host['Host Name']
|
||||
cli_hostname = cli_host['Host']
|
||||
self.assertIn(cli_hostname, exp_hostnames,
|
||||
'unexpected host: %s, found in cli output: %s'
|
||||
% (cli_hostname, cli_output))
|
||||
|
@ -132,7 +131,7 @@ class TestFunctional(KollaCliTest):
|
|||
for exp_hostname in exp_hosts.get_hostnames():
|
||||
exp_host_found = False
|
||||
for cli_host in cli_hosts:
|
||||
if exp_hostname == cli_host['Host Name']:
|
||||
if exp_hostname == cli_host['Host']:
|
||||
exp_host_found = True
|
||||
cli_groups = cli_host['Groups']
|
||||
exp_groups = exp_hosts.get_groups(exp_hostname)
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
# Copyright(c) 2015, Oracle and/or its affiliates. All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
from common import KollaCliTest
|
||||
import unittest
|
||||
|
||||
|
||||
class TestFunctional(KollaCliTest):
|
||||
|
||||
def test_zone_add_remove(self):
|
||||
msg = self.run_client_cmd('zone list')
|
||||
self.assertEqual('', msg.strip(), 'zone list output is not empty: %s'
|
||||
% msg)
|
||||
|
||||
zone1 = 'zone_test1'
|
||||
self.run_client_cmd('zone add %s' % zone1)
|
||||
|
||||
msg = self.run_client_cmd('zone list')
|
||||
self.assertEqual(zone1, msg.strip(), 'zone: %s not in cli output: %s'
|
||||
% (zone1, msg))
|
||||
|
||||
zone2 = 'zone_test2'
|
||||
self.run_client_cmd('zone add %s' % zone2)
|
||||
|
||||
msg = self.run_client_cmd('zone list')
|
||||
exp_out = ('%s, %s' % (zone1, zone2))
|
||||
self.assertEqual(exp_out, msg.strip(),
|
||||
'zones: %s & %s not in cli output: %s'
|
||||
% (zone1, zone2, msg))
|
||||
|
||||
self.run_client_cmd('zone remove %s' % zone2)
|
||||
|
||||
msg = self.run_client_cmd('zone list')
|
||||
self.assertEqual(zone1, msg.strip())
|
||||
|
||||
self.run_client_cmd('zone remove %s' % zone1)
|
||||
|
||||
msg = self.run_client_cmd('zone list')
|
||||
self.assertEqual('', msg.strip())
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue