Add filter options to list and snapshot-list

Change-Id: I9a8b538ad53960700ae7a57d1ceb09b05e3dc468
This commit is contained in:
Clay Gerrard 2012-09-05 14:51:57 +00:00
parent a153f10b2b
commit 9ba6ed5a90
5 changed files with 90 additions and 11 deletions

@ -117,11 +117,25 @@ def _extract_metadata(arg_list):
type=int, type=int,
const=1, const=1,
help=argparse.SUPPRESS) help=argparse.SUPPRESS)
@utils.arg(
'--display-name',
metavar='<display-name>',
default=None,
help='Filter results by display-name')
@utils.arg(
'--status',
metavar='<status>',
default=None,
help='Filter results by status')
@utils.service_type('volume') @utils.service_type('volume')
def do_list(cs, args): def do_list(cs, args):
"""List all the volumes.""" """List all the volumes."""
all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants))
search_opts = {'all_tenants': all_tenants} search_opts = {
'all_tenants': all_tenants,
'display_name': args.display_name,
'status': args.status,
}
volumes = cs.volumes.list(search_opts=search_opts) volumes = cs.volumes.list(search_opts=search_opts)
_translate_volume_keys(volumes) _translate_volume_keys(volumes)
@ -240,11 +254,31 @@ def do_delete(cs, args):
type=int, type=int,
const=1, const=1,
help=argparse.SUPPRESS) help=argparse.SUPPRESS)
@utils.arg(
'--display-name',
metavar='<display-name>',
default=None,
help='Filter results by display-name')
@utils.arg(
'--status',
metavar='<status>',
default=None,
help='Filter results by status')
@utils.arg(
'--volume-id',
metavar='<volume-id>',
default=None,
help='Filter results by volume-id')
@utils.service_type('volume') @utils.service_type('volume')
def do_snapshot_list(cs, args): def do_snapshot_list(cs, args):
"""List all the snapshots.""" """List all the snapshots."""
all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants))
search_opts = {'all_tenants': all_tenants} search_opts = {
'all_tenants': all_tenants,
'display_name': args.display_name,
'status': args.status,
'volume_id': args.volume_id,
}
snapshots = cs.volume_snapshots.list(search_opts=search_opts) snapshots = cs.volume_snapshots.list(search_opts=search_opts)
_translate_volume_snapshot_keys(snapshots) _translate_volume_snapshot_keys(snapshots)

@ -17,6 +17,7 @@
Volume snapshot interface (1.1 extension). Volume snapshot interface (1.1 extension).
""" """
import urllib
from cinderclient import base from cinderclient import base

@ -20,18 +20,18 @@ def assert_has_keys(dict, required=[], optional=[]):
class FakeClient(object): class FakeClient(object):
def assert_called(self, method, url, body=None, pos=-1): def assert_called(self, method, url, body=None, pos=-1, **kwargs):
""" """
Assert than an API method was just called. Assert than an API method was just called.
""" """
expected = (method, url) expected = (method, url)
called = self.client.callstack[pos][0:2] called = self.client.callstack[pos][0:2]
assert(self.client.callstack, assert self.client.callstack, ("Expected %s %s but no calls "
"Expected %s %s but no calls were made." % expected) "were made." % expected)
assert (expected == called, 'Expected %s %s; got %s %s' % assert expected == called, 'Expected %s %s; got %s %s' % (
(expected + called)) expected + called)
if body is not None: if body is not None:
assert self.client.callstack[pos][2] == body assert self.client.callstack[pos][2] == body
@ -42,8 +42,8 @@ class FakeClient(object):
""" """
expected = (method, url) expected = (method, url)
assert(self.client.callstack, assert self.client.callstack, ("Expected %s %s but no calls "
"Expected %s %s but no calls were made." % expected) "were made." % expected)
found = False found = False
for entry in self.client.callstack: for entry in self.client.callstack:
@ -51,8 +51,8 @@ class FakeClient(object):
found = True found = True
break break
assert(found, 'Expected %s %s; got %s' % assert found, 'Expected %s %s; got %s' % (
(expected, self.client.callstack)) expected, self.client.callstack)
if body is not None: if body is not None:
try: try:

@ -21,6 +21,20 @@ from cinderclient.v1 import client
from tests import fakes from tests import fakes
def _stub_snapshot(**kwargs):
snapshot = {
"created_at": "2012-08-28T16:30:31.000000",
"display_description": None,
"display_name": None,
"id": '11111111-1111-1111-1111-111111111111',
"size": 1,
"status": "available",
"volume_id": '00000000-0000-0000-0000-000000000000',
}
snapshot.update(kwargs)
return snapshot
class FakeClient(fakes.FakeClient, client.Client): class FakeClient(fakes.FakeClient, client.Client):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -122,6 +136,15 @@ class FakeHTTPClient(base_client.HTTPClient):
"maxPersonality": 5, "maxPersonality": 5,
"maxPersonalitySize": 10240}, }, }) "maxPersonalitySize": 10240}, }, })
#
# Snapshots
#
def get_snapshots_detail(self, **kw):
return (200, {'snapshots': [
_stub_snapshot(),
]})
# #
# Servers # Servers
# #

@ -69,9 +69,30 @@ class ShellTest(utils.TestCase):
# NOTE(jdg): we default to detail currently # NOTE(jdg): we default to detail currently
self.assert_called('GET', '/volumes/detail') self.assert_called('GET', '/volumes/detail')
def test_list_filter_status(self):
self.run_command('list --status=available')
self.assert_called('GET', '/volumes/detail?status=available')
def test_list_filter_display_name(self):
self.run_command('list --display-name=1234')
self.assert_called('GET', '/volumes/detail?display_name=1234')
def test_list_all_tenants(self):
self.run_command('list --all-tenants=1')
self.assert_called('GET', '/volumes/detail?all_tenants=1')
def test_show(self): def test_show(self):
self.run_command('show 1234') self.run_command('show 1234')
self.assert_called('GET', '/volumes/1234') self.assert_called('GET', '/volumes/1234')
def test_delete(self): def test_delete(self):
self.run_command('delete 1234') self.run_command('delete 1234')
def test_snapshot_list_filter_volume_id(self):
self.run_command('snapshot-list --volume-id=1234')
self.assert_called('GET', '/snapshots/detail?volume_id=1234')
def test_snapshot_list_filter_status_and_volume_id(self):
self.run_command('snapshot-list --status=available --volume-id=1234')
self.assert_called('GET', '/snapshots/detail?'
'status=available&volume_id=1234')