Added limit/marker support for config group lists
Added support in the CLI for limit and marker to the configuration-list and configuration-instances command. Changed the python API to use the _pagination function instead of _list. Modified the unit tests to test this change. Change-Id: I46d8258eab81d1510707244547e31cd5707a22ce Closes-Bug: bug/1638352
This commit is contained in:
parent
c4d9ebb66d
commit
2377c0ca55
@ -0,0 +1,3 @@
|
||||
features:
|
||||
- Added pagination support (limit and marker) to the CLI for
|
||||
configuration-list and configuration-instances.
|
@ -96,11 +96,13 @@ class ConfigurationsTest(testtools.TestCase):
|
||||
self.assertRaises(Exception, self.configurations.delete, 34)
|
||||
|
||||
def test_list(self):
|
||||
def side_effect_func(path, user, limit, marker):
|
||||
return path
|
||||
|
||||
self.configurations._list = mock.Mock(side_effect=side_effect_func)
|
||||
self.assertEqual('/configurations', self.configurations.list(1))
|
||||
page_mock = mock.Mock()
|
||||
self.configurations._paginated = page_mock
|
||||
limit = "test-limit"
|
||||
marker = "test-marker"
|
||||
self.configurations.list(limit, marker)
|
||||
page_mock.assert_called_with("/configurations", "configurations",
|
||||
limit, marker)
|
||||
|
||||
def test_get(self):
|
||||
def side_effect_func(path, config):
|
||||
@ -111,11 +113,15 @@ class ConfigurationsTest(testtools.TestCase):
|
||||
self.configurations.get(123))
|
||||
|
||||
def test_instances(self):
|
||||
def side_effect_func(path, config, limit, marker):
|
||||
return path
|
||||
self.configurations._list = mock.Mock(side_effect=side_effect_func)
|
||||
self.assertEqual('/configurations/configuration1/instances',
|
||||
self.configurations.instances(123))
|
||||
page_mock = mock.Mock()
|
||||
self.configurations._paginated = page_mock
|
||||
limit = "test-limit"
|
||||
marker = "test-marker"
|
||||
configuration = "configuration1"
|
||||
self.configurations.instances(configuration, limit, marker)
|
||||
page_mock.assert_called_with(
|
||||
"/configurations/" + configuration + "/instances",
|
||||
"instances", limit, marker)
|
||||
|
||||
def test_update(self):
|
||||
self.configurations.api.client.put = self._get_mock_method()
|
||||
|
@ -43,16 +43,17 @@ class Configurations(base.ManagerWithFind):
|
||||
|
||||
:rtype: :class:`Configurations`
|
||||
"""
|
||||
return self._list("/configurations/%s/instances" %
|
||||
base.getid(configuration),
|
||||
"instances", limit, marker)
|
||||
return self._paginated("/configurations/%s/instances" %
|
||||
base.getid(configuration),
|
||||
"instances", limit, marker)
|
||||
|
||||
def list(self, limit=None, marker=None):
|
||||
"""Get a list of all configurations.
|
||||
|
||||
:rtype: list of :class:`Configurations`.
|
||||
"""
|
||||
return self._list("/configurations", "configurations", limit, marker)
|
||||
return self._paginated("/configurations", "configurations",
|
||||
limit, marker)
|
||||
|
||||
def create(self, name, values, description=None, datastore=None,
|
||||
datastore_version=None):
|
||||
|
@ -1579,18 +1579,32 @@ def do_configuration_patch(cs, args):
|
||||
|
||||
@utils.arg('configuration_group', metavar='<configuration_group>',
|
||||
help=_('ID or name of the configuration group.'))
|
||||
@utils.arg('--limit', metavar='<limit>', type=int, default=None,
|
||||
help=_('Limit the number of results displayed.'))
|
||||
@utils.arg('--marker', metavar='<ID>', type=str, default=None,
|
||||
help=_('Begin displaying the results for IDs greater than the '
|
||||
'specified marker. When used with --limit, set this to '
|
||||
'the last ID displayed in the previous run.'))
|
||||
@utils.service_type('database')
|
||||
def do_configuration_instances(cs, args):
|
||||
"""Lists all instances associated with a configuration group."""
|
||||
configuration = _find_configuration(cs, args.configuration_group)
|
||||
params = cs.configurations.instances(configuration)
|
||||
params = cs.configurations.instances(configuration,
|
||||
limit=args.limit,
|
||||
marker=args.marker)
|
||||
utils.print_list(params, ['id', 'name'])
|
||||
|
||||
|
||||
@utils.arg('--limit', metavar='<limit>', type=int, default=None,
|
||||
help=_('Limit the number of results displayed.'))
|
||||
@utils.arg('--marker', metavar='<ID>', type=str, default=None,
|
||||
help=_('Begin displaying the results for IDs greater than the '
|
||||
'specified marker. When used with --limit, set this to '
|
||||
'the last ID displayed in the previous run.'))
|
||||
@utils.service_type('database')
|
||||
def do_configuration_list(cs, args):
|
||||
"""Lists all configuration groups."""
|
||||
config_grps = cs.configurations.list()
|
||||
config_grps = cs.configurations.list(limit=args.limit, marker=args.marker)
|
||||
utils.print_list(config_grps, [
|
||||
'id', 'name', 'description',
|
||||
'datastore_name', 'datastore_version_name'])
|
||||
|
Loading…
Reference in New Issue
Block a user