Skip to content

Commit 5361652

Browse files
author
Amey Bhide
committed
Add support for volume v2 API
Added following commands for volume V2 API: volume show volume delete volume type show volume type delete snapshot show snapshot delete backup show backup delete Implements: blueprint volume-v2 Change-Id: I68bd303c194f304ad15f899d335b72a8bf3ebe10
1 parent 211c14c commit 5361652

13 files changed

Lines changed: 771 additions & 1 deletion

File tree

openstackclient/tests/volume/v2/__init__.py

Whitespace-only changes.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
import mock
16+
17+
from openstackclient.tests import fakes
18+
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
19+
from openstackclient.tests import utils
20+
21+
volume_id = "ce26708d-a7f8-4b4b-9861-4a80256615a6"
22+
volume_name = "fake_volume"
23+
volume_description = "fake description"
24+
volume_status = "available"
25+
volume_size = 20
26+
volume_type = "fake_lvmdriver-1"
27+
volume_metadata = {
28+
"foo": "bar"
29+
}
30+
volume_snapshot_id = 1
31+
volume_availability_zone = "nova"
32+
volume_attachments = ["fake_attachments"]
33+
34+
VOLUME = {
35+
"id": volume_id,
36+
"name": volume_name,
37+
"description": volume_description,
38+
"status": volume_status,
39+
"size": volume_size,
40+
"volume_type": volume_type,
41+
"metadata": volume_metadata,
42+
"snapshot_id": volume_snapshot_id,
43+
"availability_zone": volume_availability_zone,
44+
"attachments": volume_attachments
45+
}
46+
47+
VOLUME_columns = tuple(sorted(VOLUME))
48+
VOLUME_data = tuple((VOLUME[x] for x in sorted(VOLUME)))
49+
50+
51+
snapshot_id = "cb2d364e-4d1c-451a-8c68-b5bbcb340fb2"
52+
snapshot_name = "fake_snapshot"
53+
snapshot_description = "fake description"
54+
snapshot_size = 10
55+
snapshot_metadata = {
56+
"foo": "bar"
57+
}
58+
snapshot_volume_id = "bdbae8dc-e6ca-43c0-8076-951cc1b093a4"
59+
60+
SNAPSHOT = {
61+
"id": snapshot_id,
62+
"name": snapshot_name,
63+
"description": snapshot_description,
64+
"size": snapshot_size,
65+
"metadata": snapshot_metadata
66+
}
67+
68+
SNAPSHOT_columns = tuple(sorted(SNAPSHOT))
69+
SNAPSHOT_data = tuple((SNAPSHOT[x] for x in sorted(SNAPSHOT)))
70+
71+
72+
type_id = "5520dc9e-6f9b-4378-a719-729911c0f407"
73+
type_description = "fake description"
74+
type_name = "fake-lvmdriver-1"
75+
type_extra_specs = {
76+
"foo": "bar"
77+
}
78+
79+
TYPE = {
80+
'id': type_id,
81+
'name': type_name,
82+
'description': type_description,
83+
'extra_specs': type_extra_specs
84+
}
85+
86+
TYPE_columns = tuple(sorted(TYPE))
87+
TYPE_data = tuple((TYPE[x] for x in sorted(TYPE)))
88+
89+
backup_id = "3c409fe6-4d03-4a06-aeab-18bdcdf3c8f4"
90+
backup_volume_id = "bdbae8dc-e6ca-43c0-8076-951cc1b093a4"
91+
backup_name = "fake_backup"
92+
backup_description = "fake description"
93+
backup_object_count = None
94+
backup_container = None
95+
backup_size = 10
96+
97+
BACKUP = {
98+
"id": backup_id,
99+
"name": backup_name,
100+
"volume_id": backup_volume_id,
101+
"description": backup_description,
102+
"object_count": backup_object_count,
103+
"container": backup_container,
104+
"size": backup_size
105+
}
106+
107+
BACKUP_columns = tuple(sorted(BACKUP))
108+
BACKUP_data = tuple((BACKUP[x] for x in sorted(BACKUP)))
109+
110+
111+
class FakeVolumeClient(object):
112+
def __init__(self, **kwargs):
113+
self.volumes = mock.Mock()
114+
self.volumes.resource_class = fakes.FakeResource(None, {})
115+
self.volume_snapshots = mock.Mock()
116+
self.volume_snapshots.resource_class = fakes.FakeResource(None, {})
117+
self.backups = mock.Mock()
118+
self.backups.resource_class = fakes.FakeResource(None, {})
119+
self.volume_types = mock.Mock()
120+
self.volume_types.resource_class = fakes.FakeResource(None, {})
121+
self.auth_token = kwargs['token']
122+
self.management_url = kwargs['endpoint']
123+
124+
125+
class TestVolume(utils.TestCommand):
126+
def setUp(self):
127+
super(TestVolume, self).setUp()
128+
129+
self.app.client_manager.volume = FakeVolumeClient(
130+
endpoint=fakes.AUTH_URL,
131+
token=fakes.AUTH_TOKEN
132+
)
133+
self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client(
134+
endpoint=fakes.AUTH_URL,
135+
token=fakes.AUTH_TOKEN
136+
)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
import copy
16+
17+
from openstackclient.tests import fakes
18+
from openstackclient.tests.volume.v2 import fakes as volume_fakes
19+
from openstackclient.volume.v2 import backup
20+
21+
22+
class TestBackup(volume_fakes.TestVolume):
23+
24+
def setUp(self):
25+
super(TestBackup, self).setUp()
26+
27+
self.backups_mock = self.app.client_manager.volume.backups
28+
self.backups_mock.reset_mock()
29+
30+
31+
class TestBackupShow(TestBackup):
32+
def setUp(self):
33+
super(TestBackupShow, self).setUp()
34+
35+
self.backups_mock.get.return_value = fakes.FakeResource(
36+
None,
37+
copy.deepcopy(volume_fakes.BACKUP),
38+
loaded=True)
39+
# Get the command object to test
40+
self.cmd = backup.ShowBackup(self.app, None)
41+
42+
def test_backup_show(self):
43+
arglist = [
44+
volume_fakes.backup_id
45+
]
46+
verifylist = [
47+
("backup", volume_fakes.backup_id)
48+
]
49+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
50+
51+
columns, data = self.cmd.take_action(parsed_args)
52+
self.backups_mock.get.assert_called_with(volume_fakes.backup_id)
53+
54+
self.assertEqual(volume_fakes.BACKUP_columns, columns)
55+
self.assertEqual(volume_fakes.BACKUP_data, data)
56+
57+
58+
class TestBackupDelete(TestBackup):
59+
def setUp(self):
60+
super(TestBackupDelete, self).setUp()
61+
62+
self.backups_mock.get.return_value = fakes.FakeResource(
63+
None,
64+
copy.deepcopy(volume_fakes.BACKUP),
65+
loaded=True)
66+
self.backups_mock.delete.return_value = None
67+
68+
# Get the command object to mock
69+
self.cmd = backup.DeleteBackup(self.app, None)
70+
71+
def test_backup_delete(self):
72+
arglist = [
73+
volume_fakes.backup_id
74+
]
75+
verifylist = [
76+
("backups", [volume_fakes.backup_id])
77+
]
78+
79+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
80+
81+
self.cmd.take_action(parsed_args)
82+
self.backups_mock.delete.assert_called_with(volume_fakes.backup_id)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
import copy
16+
17+
from openstackclient.tests import fakes
18+
from openstackclient.tests.volume.v2 import fakes as volume_fakes
19+
from openstackclient.volume.v2 import snapshot
20+
21+
22+
class TestSnapshot(volume_fakes.TestVolume):
23+
24+
def setUp(self):
25+
super(TestSnapshot, self).setUp()
26+
27+
self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
28+
self.snapshots_mock.reset_mock()
29+
30+
31+
class TestSnapshotShow(TestSnapshot):
32+
def setUp(self):
33+
super(TestSnapshotShow, self).setUp()
34+
35+
self.snapshots_mock.get.return_value = fakes.FakeResource(
36+
None,
37+
copy.deepcopy(volume_fakes.SNAPSHOT),
38+
loaded=True)
39+
# Get the command object to test
40+
self.cmd = snapshot.ShowSnapshot(self.app, None)
41+
42+
def test_snapshot_show(self):
43+
arglist = [
44+
volume_fakes.snapshot_id
45+
]
46+
verifylist = [
47+
("snapshot", volume_fakes.snapshot_id)
48+
]
49+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
50+
51+
columns, data = self.cmd.take_action(parsed_args)
52+
self.snapshots_mock.get.assert_called_with(volume_fakes.snapshot_id)
53+
54+
self.assertEqual(volume_fakes.SNAPSHOT_columns, columns)
55+
self.assertEqual(volume_fakes.SNAPSHOT_data, data)
56+
57+
58+
class TestSnapshotDelete(TestSnapshot):
59+
def setUp(self):
60+
super(TestSnapshotDelete, self).setUp()
61+
62+
self.snapshots_mock.get.return_value = fakes.FakeResource(
63+
None,
64+
copy.deepcopy(volume_fakes.SNAPSHOT),
65+
loaded=True)
66+
self.snapshots_mock.delete.return_value = None
67+
68+
# Get the command object to mock
69+
self.cmd = snapshot.DeleteSnapshot(self.app, None)
70+
71+
def test_snapshot_delete(self):
72+
arglist = [
73+
volume_fakes.snapshot_id
74+
]
75+
verifylist = [
76+
("snapshots", [volume_fakes.snapshot_id])
77+
]
78+
79+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
80+
81+
self.cmd.take_action(parsed_args)
82+
self.snapshots_mock.delete.assert_called_with(volume_fakes.snapshot_id)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
import copy
16+
17+
from openstackclient.tests import fakes
18+
from openstackclient.tests.volume.v2 import fakes as volume_fakes
19+
from openstackclient.volume.v2 import volume_type
20+
21+
22+
class TestType(volume_fakes.TestVolume):
23+
24+
def setUp(self):
25+
super(TestType, self).setUp()
26+
27+
self.types_mock = self.app.client_manager.volume.volume_types
28+
self.types_mock.reset_mock()
29+
30+
31+
class TestTypeShow(TestType):
32+
def setUp(self):
33+
super(TestTypeShow, self).setUp()
34+
35+
self.types_mock.get.return_value = fakes.FakeResource(
36+
None,
37+
copy.deepcopy(volume_fakes.TYPE),
38+
loaded=True)
39+
# Get the command object to test
40+
self.cmd = volume_type.ShowVolumeType(self.app, None)
41+
42+
def test_type_show(self):
43+
arglist = [
44+
volume_fakes.type_id
45+
]
46+
verifylist = [
47+
("volume_type", volume_fakes.type_id)
48+
]
49+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
50+
51+
columns, data = self.cmd.take_action(parsed_args)
52+
self.types_mock.get.assert_called_with(volume_fakes.type_id)
53+
54+
self.assertEqual(volume_fakes.TYPE_columns, columns)
55+
self.assertEqual(volume_fakes.TYPE_data, data)
56+
57+
58+
class TestTypeDelete(TestType):
59+
def setUp(self):
60+
super(TestTypeDelete, self).setUp()
61+
62+
self.types_mock.get.return_value = fakes.FakeResource(
63+
None,
64+
copy.deepcopy(volume_fakes.TYPE),
65+
loaded=True)
66+
self.types_mock.delete.return_value = None
67+
68+
# Get the command object to mock
69+
self.cmd = volume_type.DeleteVolumeType(self.app, None)
70+
71+
def test_type_delete(self):
72+
arglist = [
73+
volume_fakes.type_id
74+
]
75+
verifylist = [
76+
("volume_type", volume_fakes.type_id)
77+
]
78+
79+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
80+
81+
self.cmd.take_action(parsed_args)
82+
self.types_mock.delete.assert_called_with(volume_fakes.type_id)

0 commit comments

Comments
 (0)