Skip to content

Commit 1c097b7

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add support for volume transfer request list"
2 parents 81718be + 2178ced commit 1c097b7

10 files changed

Lines changed: 471 additions & 4 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=======================
2+
volume transfer request
3+
=======================
4+
5+
Block Storage v1, v2
6+
7+
volume transfer request list
8+
----------------------------
9+
10+
Lists all volume transfer requests.
11+
12+
.. program:: volume transfer request list
13+
.. code:: bash
14+
15+
os volume transfer request list
16+
--all-projects
17+
18+
.. option:: --all-projects
19+
20+
Shows detail for all projects. Admin only.
21+
(defaults to False)

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ referring to both Compute and Volume quotas.
137137
* ``volume qos``: (**Volume**) quality-of-service (QoS) specification for volumes
138138
* ``volume type``: (**Volume**) deployment-specific types of volumes available
139139
* ``volume service``: (**Volume**) services to manage block storage operations
140+
* ``volume transfer request``: (**Volume**) volume owner transfer request
140141

141142

142143
Plugin Objects

openstackclient/tests/volume/v1/fakes.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,57 @@
129129
}
130130

131131

132+
class FakeTransferClient(object):
133+
134+
def __init__(self, **kwargs):
135+
136+
self.transfers = mock.Mock()
137+
self.transfers.resource_class = fakes.FakeResource(None, {})
138+
139+
140+
class TestTransfer(utils.TestCommand):
141+
142+
def setUp(self):
143+
super(TestTransfer, self).setUp()
144+
145+
self.app.client_manager.volume = FakeTransferClient(
146+
endpoint=fakes.AUTH_URL,
147+
token=fakes.AUTH_TOKEN
148+
)
149+
150+
151+
class FakeTransfer(object):
152+
"""Fake one or more Transfer."""
153+
154+
@staticmethod
155+
def create_one_transfer(attrs=None):
156+
"""Create a fake transfer.
157+
158+
:param Dictionary attrs:
159+
A dictionary with all attributes of Transfer Request
160+
:retrun:
161+
A FakeResource object with volume_id, name, id.
162+
"""
163+
# Set default attribute
164+
transfer_info = {
165+
'volume_id': 'ce26708d-a7f8-4b4b-9861-4a80256615a7',
166+
'name': 'fake_transfer_name',
167+
'id': '731a7f53-aa92-4fbd-9de3-6f7d729c926b'
168+
}
169+
170+
# Overwrite default attributes if there are some attributes set
171+
attrs = attrs or {}
172+
173+
transfer_info.update(attrs)
174+
175+
transfer = fakes.FakeResource(
176+
None,
177+
transfer_info,
178+
loaded=True)
179+
180+
return transfer
181+
182+
132183
class FakeServiceClient(object):
133184

134185
def __init__(self, **kwargs):
@@ -171,8 +222,8 @@ def create_one_service(attrs=None):
171222
}
172223

173224
# Overwrite default attributes if there are some attributes set
174-
if attrs is None:
175-
attrs = {}
225+
attrs = attrs or {}
226+
176227
service_info.update(attrs)
177228

178229
service = fakes.FakeResource(
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
#
14+
15+
16+
from openstackclient.tests.volume.v1 import fakes as transfer_fakes
17+
from openstackclient.volume.v1 import volume_transfer_request
18+
19+
20+
class TestTransfer(transfer_fakes.TestTransfer):
21+
22+
def setUp(self):
23+
super(TestTransfer, self).setUp()
24+
25+
# Get a shortcut to the TransferManager Mock
26+
self.transfer_mock = self.app.client_manager.volume.transfers
27+
self.transfer_mock.reset_mock()
28+
29+
30+
class TestTransferList(TestTransfer):
31+
32+
# The Transfers to be listed
33+
volume_transfers = transfer_fakes.FakeTransfer.create_one_transfer()
34+
35+
def setUp(self):
36+
super(TestTransferList, self).setUp()
37+
38+
self.transfer_mock.list.return_value = [self.volume_transfers]
39+
40+
# Get the command object to test
41+
self.cmd = volume_transfer_request.ListTransferRequests(self.app, None)
42+
43+
def test_transfer_list_without_argument(self):
44+
arglist = []
45+
verifylist = []
46+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
47+
48+
# In base command class Lister in cliff, abstract method take_action()
49+
# returns a tuple containing the column names and an iterable
50+
# containing the data to be listed.
51+
columns, data = self.cmd.take_action(parsed_args)
52+
53+
expected_columns = [
54+
'ID',
55+
'Volume',
56+
'Name',
57+
]
58+
59+
# confirming if all expected columns are present in the result.
60+
self.assertEqual(expected_columns, columns)
61+
62+
datalist = ((
63+
self.volume_transfers.id,
64+
self.volume_transfers.volume_id,
65+
self.volume_transfers.name,
66+
), )
67+
68+
# confirming if all expected values are present in the result.
69+
self.assertEqual(datalist, tuple(data))
70+
71+
# checking if proper call was made to list volume_transfers
72+
self.transfer_mock.list.assert_called_with(
73+
detailed=True,
74+
search_opts={'all_tenants': 0}
75+
)
76+
77+
def test_transfer_list_with_argument(self):
78+
arglist = [
79+
"--all-projects"
80+
]
81+
verifylist = [
82+
("all_projects", True)
83+
]
84+
85+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
86+
87+
# In base command class Lister in cliff, abstract method take_action()
88+
# returns a tuple containing the column names and an iterable
89+
# containing the data to be listed.
90+
columns, data = self.cmd.take_action(parsed_args)
91+
92+
expected_columns = [
93+
'ID',
94+
'Volume',
95+
'Name',
96+
]
97+
98+
# confirming if all expected columns are present in the result.
99+
self.assertEqual(expected_columns, columns)
100+
101+
datalist = ((
102+
self.volume_transfers.id,
103+
self.volume_transfers.volume_id,
104+
self.volume_transfers.name,
105+
), )
106+
107+
# confirming if all expected values are present in the result.
108+
self.assertEqual(datalist, tuple(data))
109+
110+
# checking if proper call was made to list volume_transfers
111+
self.transfer_mock.list.assert_called_with(
112+
detailed=True,
113+
search_opts={'all_tenants': 1}
114+
)

openstackclient/tests/volume/v2/fakes.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,57 @@
232232
}
233233

234234

235+
class FakeTransferClient(object):
236+
237+
def __init__(self, **kwargs):
238+
239+
self.transfers = mock.Mock()
240+
self.transfers.resource_class = fakes.FakeResource(None, {})
241+
242+
243+
class TestTransfer(utils.TestCommand):
244+
245+
def setUp(self):
246+
super(TestTransfer, self).setUp()
247+
248+
self.app.client_manager.volume = FakeTransferClient(
249+
endpoint=fakes.AUTH_URL,
250+
token=fakes.AUTH_TOKEN
251+
)
252+
253+
254+
class FakeTransfer(object):
255+
"""Fake one or more Transfer."""
256+
257+
@staticmethod
258+
def create_one_transfer(attrs=None):
259+
"""Create a fake transfer.
260+
261+
:param Dictionary attrs:
262+
A dictionary with all attributes of Transfer Request
263+
:retrun:
264+
A FakeResource object with volume_id, name, id.
265+
"""
266+
# Set default attribute
267+
transfer_info = {
268+
'volume_id': 'ce26708d-a7f8-4b4b-9861-4a80256615a7',
269+
'name': 'fake_transfer_name',
270+
'id': '731a7f53-aa92-4fbd-9de3-6f7d729c926b'
271+
}
272+
273+
# Overwrite default attributes if there are some attributes set
274+
attrs = attrs or {}
275+
276+
transfer_info.update(attrs)
277+
278+
transfer = fakes.FakeResource(
279+
None,
280+
transfer_info,
281+
loaded=True)
282+
283+
return transfer
284+
285+
235286
class FakeServiceClient(object):
236287

237288
def __init__(self, **kwargs):
@@ -274,8 +325,8 @@ def create_one_service(attrs=None):
274325
}
275326

276327
# Overwrite default attributes if there are some attributes set
277-
if attrs is None:
278-
attrs = {}
328+
attrs = attrs or {}
329+
279330
service_info.update(attrs)
280331

281332
service = fakes.FakeResource(
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
#
14+
15+
16+
from openstackclient.tests.volume.v2 import fakes as transfer_fakes
17+
from openstackclient.volume.v2 import volume_transfer_request
18+
19+
20+
class TestTransfer(transfer_fakes.TestTransfer):
21+
22+
def setUp(self):
23+
super(TestTransfer, self).setUp()
24+
25+
# Get a shortcut to the TransferManager Mock
26+
self.transfer_mock = self.app.client_manager.volume.transfers
27+
self.transfer_mock.reset_mock()
28+
29+
30+
class TestTransferList(TestTransfer):
31+
32+
# The Transfers to be listed
33+
volume_transfers = transfer_fakes.FakeTransfer.create_one_transfer()
34+
35+
def setUp(self):
36+
super(TestTransferList, self).setUp()
37+
38+
self.transfer_mock.list.return_value = [self.volume_transfers]
39+
40+
# Get the command object to test
41+
self.cmd = volume_transfer_request.ListTransferRequests(self.app, None)
42+
43+
def test_transfer_list_without_argument(self):
44+
arglist = []
45+
verifylist = []
46+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
47+
48+
# In base command class Lister in cliff, abstract method take_action()
49+
# returns a tuple containing the column names and an iterable
50+
# containing the data to be listed.
51+
columns, data = self.cmd.take_action(parsed_args)
52+
53+
expected_columns = [
54+
'ID',
55+
'Volume',
56+
'Name',
57+
]
58+
59+
# confirming if all expected columns are present in the result.
60+
self.assertEqual(expected_columns, columns)
61+
62+
datalist = ((
63+
self.volume_transfers.id,
64+
self.volume_transfers.volume_id,
65+
self.volume_transfers.name,
66+
), )
67+
68+
# confirming if all expected values are present in the result.
69+
self.assertEqual(datalist, tuple(data))
70+
71+
# checking if proper call was made to list volume_transfers
72+
self.transfer_mock.list.assert_called_with(
73+
detailed=True,
74+
search_opts={'all_tenants': 0}
75+
)
76+
77+
def test_transfer_list_with_argument(self):
78+
arglist = [
79+
"--all-projects"
80+
]
81+
verifylist = [
82+
("all_projects", True)
83+
]
84+
85+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
86+
87+
# In base command class Lister in cliff, abstract method take_action()
88+
# returns a tuple containing the column names and an iterable
89+
# containing the data to be listed.
90+
columns, data = self.cmd.take_action(parsed_args)
91+
92+
expected_columns = [
93+
'ID',
94+
'Volume',
95+
'Name',
96+
]
97+
98+
# confirming if all expected columns are present in the result.
99+
self.assertEqual(expected_columns, columns)
100+
101+
datalist = ((
102+
self.volume_transfers.id,
103+
self.volume_transfers.volume_id,
104+
self.volume_transfers.name,
105+
), )
106+
107+
# confirming if all expected values are present in the result.
108+
self.assertEqual(datalist, tuple(data))
109+
110+
# checking if proper call was made to list volume_transfers
111+
self.transfer_mock.list.assert_called_with(
112+
detailed=True,
113+
search_opts={'all_tenants': 1}
114+
)

0 commit comments

Comments
 (0)