Merge "Add an optional parameter --detail"
This commit is contained in:
@@ -150,8 +150,44 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stores_info_detail_response = {
|
||||||
|
"stores": [
|
||||||
|
{
|
||||||
|
"default": "true",
|
||||||
|
"id": "ceph1",
|
||||||
|
"type": "rbd",
|
||||||
|
"description": "RBD backend for glance.",
|
||||||
|
"properties": {
|
||||||
|
"pool": "pool1",
|
||||||
|
"chunk_size": "4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "file2",
|
||||||
|
"type": "file",
|
||||||
|
"description": "Filesystem backend for glance.",
|
||||||
|
"properties": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "file1",
|
||||||
|
"type": "file",
|
||||||
|
"description": "Filesystem backend for gkance.",
|
||||||
|
"properties": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "ceph2",
|
||||||
|
"type": "rbd",
|
||||||
|
"description": "RBD backend for glance.",
|
||||||
|
"properties": {
|
||||||
|
"pool": "pool2",
|
||||||
|
"chunk_size": "4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
def test_do_stores_info(self):
|
def test_do_stores_info(self):
|
||||||
args = []
|
args = self._make_args({'detail': False})
|
||||||
with mock.patch.object(self.gc.images,
|
with mock.patch.object(self.gc.images,
|
||||||
'get_stores_info') as mocked_list:
|
'get_stores_info') as mocked_list:
|
||||||
mocked_list.return_value = self.stores_info_response
|
mocked_list.return_value = self.stores_info_response
|
||||||
@@ -166,7 +202,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
def test_neg_stores_info(
|
def test_neg_stores_info(
|
||||||
self, mock_stdin, mock_utils_exit):
|
self, mock_stdin, mock_utils_exit):
|
||||||
expected_msg = ('Multi Backend support is not enabled')
|
expected_msg = ('Multi Backend support is not enabled')
|
||||||
args = []
|
args = self._make_args({'detail': False})
|
||||||
mock_utils_exit.side_effect = self._mock_utils_exit
|
mock_utils_exit.side_effect = self._mock_utils_exit
|
||||||
with mock.patch.object(self.gc.images,
|
with mock.patch.object(self.gc.images,
|
||||||
'get_stores_info') as mocked_info:
|
'get_stores_info') as mocked_info:
|
||||||
@@ -178,6 +214,18 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
pass
|
pass
|
||||||
mock_utils_exit.assert_called_once_with(expected_msg)
|
mock_utils_exit.assert_called_once_with(expected_msg)
|
||||||
|
|
||||||
|
def test_do_stores_info_with_detail(self):
|
||||||
|
args = self._make_args({'detail': True})
|
||||||
|
with mock.patch.object(self.gc.images,
|
||||||
|
'get_stores_info_detail') as mocked_list:
|
||||||
|
mocked_list.return_value = self.stores_info_detail_response
|
||||||
|
|
||||||
|
test_shell.do_stores_info(self.gc, args)
|
||||||
|
|
||||||
|
mocked_list.assert_called_once_with()
|
||||||
|
utils.print_dict.assert_called_once_with(
|
||||||
|
self.stores_info_detail_response)
|
||||||
|
|
||||||
@mock.patch('sys.stderr')
|
@mock.patch('sys.stderr')
|
||||||
def test_image_create_missing_disk_format(self, __):
|
def test_image_create_missing_disk_format(self, __):
|
||||||
e = self.assertRaises(exc.CommandError, self._run_command,
|
e = self.assertRaises(exc.CommandError, self._run_command,
|
||||||
|
@@ -322,6 +322,13 @@ class Controller(object):
|
|||||||
resp, body = self.http_client.get(url)
|
resp, body = self.http_client.get(url)
|
||||||
return body, resp
|
return body, resp
|
||||||
|
|
||||||
|
@utils.add_req_id_to_object()
|
||||||
|
def get_stores_info_detail(self):
|
||||||
|
"""Get available stores info from discovery endpoint."""
|
||||||
|
url = '/v2/info/stores/detail'
|
||||||
|
resp, body = self.http_client.get(url)
|
||||||
|
return body, resp
|
||||||
|
|
||||||
@utils.add_req_id_to_object()
|
@utils.add_req_id_to_object()
|
||||||
def delete_from_store(self, store_id, image_id):
|
def delete_from_store(self, store_id, image_id):
|
||||||
"""Delete image data from specific store."""
|
"""Delete image data from specific store."""
|
||||||
|
@@ -583,11 +583,15 @@ def do_import_info(gc, args):
|
|||||||
else:
|
else:
|
||||||
utils.print_dict(import_info)
|
utils.print_dict(import_info)
|
||||||
|
|
||||||
|
@utils.arg('--detail', default=False, action='store_true',
|
||||||
|
help='Shows details of stores. Admin only.')
|
||||||
def do_stores_info(gc, args):
|
def do_stores_info(gc, args):
|
||||||
"""Print available backends from Glance."""
|
"""Print available backends from Glance."""
|
||||||
try:
|
try:
|
||||||
stores_info = gc.images.get_stores_info()
|
if args.detail:
|
||||||
|
stores_info = gc.images.get_stores_info_detail()
|
||||||
|
else:
|
||||||
|
stores_info = gc.images.get_stores_info()
|
||||||
except exc.HTTPNotFound:
|
except exc.HTTPNotFound:
|
||||||
utils.exit('Multi Backend support is not enabled')
|
utils.exit('Multi Backend support is not enabled')
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user