Adding image stores info command · openstack/python-openstackclient@18a6199 · GitHub
Skip to content

Commit 18a6199

Browse files
author
Mridula Joshi
committed
Adding image stores info command
This is an equivalent for ``glance stores-info``. Depends-on: https://review.opendev.org/c/openstack/openstacksdk/+/883493 Change-Id: I15d2c2c523ace1cfb32045328ecee8ce8beea63f
1 parent 7dc1276 commit 18a6199

5 files changed

Lines changed: 124 additions & 0 deletions

File tree

openstackclient/image/v2/image.py

Lines changed: 45 additions & 0 deletions

openstackclient/tests/unit/image/v2/fakes.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(self, **kwargs):
5757
self.get_task = mock.Mock()
5858

5959
self.get_import_info = mock.Mock()
60+
self.stores = mock.Mock()
6061

6162
self.auth_token = kwargs['token']
6263
self.management_url = kwargs['endpoint']
@@ -171,6 +172,38 @@ def create_one_import_info(attrs=None):
171172
return _service_info.Import(**import_info)
172173

173174

175+
def create_one_stores_info(attrs=None):
176+
"""Create a fake stores info.
177+
178+
:param attrs: A dictionary with all attributes of stores
179+
:type attrs: dict
180+
:return: A fake Store object list.
181+
:rtype: `openstack.image.v2.service_info.Store`
182+
"""
183+
attrs = attrs or {}
184+
185+
stores_info = {
186+
"stores": [
187+
{
188+
"id": "reliable",
189+
"description": "More expensive store with data redundancy",
190+
},
191+
{
192+
"id": "fast",
193+
"description": "Provides quick access to your image data",
194+
"default": True,
195+
},
196+
{
197+
"id": "cheap",
198+
"description": "Less expensive store for seldom-used images",
199+
},
200+
]
201+
}
202+
stores_info.update(attrs)
203+
204+
return _service_info.Store(**stores_info)
205+
206+
174207
def create_one_task(attrs=None):
175208
"""Create a fake task.
176209

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,3 +2101,43 @@ def test_get_data_from_stdin__interactive(self):
21012101
test_fd = _image.get_data_from_stdin()
21022102

21032103
self.assertIsNone(test_fd)
2104+
2105+
2106+
class TestStoresInfo(TestImage):
2107+
stores_info = image_fakes.create_one_stores_info()
2108+
2109+
def setUp(self):
2110+
super().setUp()
2111+
2112+
self.client.stores.return_value = self.stores_info
2113+
2114+
self.cmd = _image.StoresInfo(self.app, None)
2115+
2116+
def test_stores_info(self):
2117+
arglist = []
2118+
parsed_args = self.check_parser(self.cmd, arglist, [])
2119+
self.cmd.take_action(parsed_args)
2120+
2121+
self.client.stores.assert_called()
2122+
2123+
def test_stores_info_with_detail(self):
2124+
arglist = ['--detail']
2125+
parsed_args = self.check_parser(self.cmd, arglist, [])
2126+
self.cmd.take_action(parsed_args)
2127+
2128+
self.client.stores.assert_called_with(details=True)
2129+
2130+
def test_stores_info_neg(self):
2131+
arglist = []
2132+
parsed_args = self.check_parser(self.cmd, arglist, [])
2133+
self.client.stores.side_effect = sdk_exceptions.ResourceNotFound()
2134+
2135+
exc = self.assertRaises(
2136+
exceptions.CommandError,
2137+
self.cmd.take_action,
2138+
parsed_args,
2139+
)
2140+
self.assertIn(
2141+
"Multi Backend support not enabled",
2142+
str(exc),
2143+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
features:
2+
- |
3+
Add ``image stores info`` command, allowing users to know available backends.

setup.cfg

Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)