change group add/remove api to take list of groups

- makes it consistent with similar methods.

Jira-Issue: OSTACKDEV-17
This commit is contained in:
Steve Noyes 2016-03-30 17:02:09 -04:00
parent 6f695e5fef
commit 144a9f8f82
3 changed files with 23 additions and 22 deletions

View File

@ -127,31 +127,34 @@ class GroupApi(object):
inventory.remove_host(hostname, self.name)
Inventory.save(inventory)
def group_add(self, groupname):
"""Add a group to the inventory
def group_add(self, groupnames):
"""Add groups to the inventory
:param groupname: name of the group to add to the inventory
:type groupname: string
:param groupnames: names of the groups to add to the inventory
:type groupnames: list of strings
"""
check_arg(groupname, u._('Group name'), str)
groupname = safe_decode(groupname)
check_arg(groupnames, u._('Group names'), list)
groupnames = safe_decode(groupnames)
inventory = Inventory.load()
inventory.add_group(groupname)
for groupname in groupnames:
inventory.add_group(groupname)
Inventory.save(inventory)
def group_remove(self, groupname):
"""Remove a group from the inventory
def group_remove(self, groupnames):
"""Remove groups from the inventory
:param groupname: name of the group to remove from the inventory
:type groupname: string
:param groupnames: names of the groups to remove from the inventory
:type groupnames: list of strings
"""
check_arg(groupname, u._('Group name'), str)
check_arg(groupnames, u._('Group names'), list)
groupnames = safe_decode(groupnames)
inventory = Inventory.load()
groupname = safe_decode(groupname)
inventory.remove_group(groupname)
for groupname in groupnames:
inventory.remove_group(groupname)
Inventory.save(inventory)
def group_get_all(self):

View File

@ -37,7 +37,7 @@ class GroupAdd(Command):
try:
groupname = parsed_args.groupname.strip()
CLIENT.group_add(groupname)
CLIENT.group_add([groupname])
except ClientException as e:
raise CommandError(str(e))
except Exception as e:
@ -57,7 +57,7 @@ class GroupRemove(Command):
try:
groupname = parsed_args.groupname.strip()
CLIENT.group_remove(groupname)
CLIENT.group_remove([groupname])
except ClientException as e:
raise CommandError(str(e))
except Exception as e:

View File

@ -117,8 +117,7 @@ class TestFunctional(KollaCliTest):
group1 = 'group_test1'
group2 = 'group_test2'
exp_groups = sorted([group1, group2])
CLIENT.group_add(group1)
CLIENT.group_add(group2)
CLIENT.group_add(exp_groups)
groups = CLIENT.group_get([group1])
groupnames = []
for group in groups:
@ -133,8 +132,7 @@ class TestFunctional(KollaCliTest):
groupnames.append(group.name)
self.assertEqual(exp_groups, sorted(groupnames), 'groups mismatch')
CLIENT.group_remove(group1)
CLIENT.group_remove(group2)
CLIENT.group_remove(exp_groups)
try:
CLIENT.group_get(exp_groups)
self.assertTrue(False, 'Failed to raise NotInInventory exception')
@ -144,8 +142,8 @@ class TestFunctional(KollaCliTest):
raise e
# check the type checking logic
self.check_types(CLIENT.group_add, [str])
self.check_types(CLIENT.group_remove, [str])
self.check_types(CLIENT.group_add, [list])
self.check_types(CLIENT.group_remove, [list])
def check_group(self, groups):
"""check groups