summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_volumes.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_volumes.py')
-rw-r--r--novaclient/tests/unit/v2/test_volumes.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_volumes.py b/novaclient/tests/unit/v2/test_volumes.py
new file mode 100644
index 0000000..52b81ab
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_volumes.py
@@ -0,0 +1,93 @@
1# Copyright 2013 IBM Corp.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from novaclient.tests.unit import utils
17from novaclient.tests.unit.v2 import fakes
18from novaclient.v2 import volumes
19
20
21cs = fakes.FakeClient()
22
23
24class VolumesTest(utils.TestCase):
25
26 def test_list_servers(self):
27 vl = cs.volumes.list()
28 cs.assert_called('GET', '/volumes/detail')
29 [self.assertIsInstance(v, volumes.Volume) for v in vl]
30
31 def test_list_volumes_undetailed(self):
32 vl = cs.volumes.list(detailed=False)
33 cs.assert_called('GET', '/volumes')
34 [self.assertIsInstance(v, volumes.Volume) for v in vl]
35
36 def test_get_volume_details(self):
37 vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
38 v = cs.volumes.get(vol_id)
39 cs.assert_called('GET', '/volumes/%s' % vol_id)
40 self.assertIsInstance(v, volumes.Volume)
41 self.assertEqual(v.id, vol_id)
42
43 def test_create_volume(self):
44 v = cs.volumes.create(
45 size=2,
46 display_name="My volume",
47 display_description="My volume desc",
48 )
49 cs.assert_called('POST', '/volumes')
50 self.assertIsInstance(v, volumes.Volume)
51
52 def test_delete_volume(self):
53 vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
54 v = cs.volumes.get(vol_id)
55 v.delete()
56 cs.assert_called('DELETE', '/volumes/%s' % vol_id)
57 cs.volumes.delete(vol_id)
58 cs.assert_called('DELETE', '/volumes/%s' % vol_id)
59 cs.volumes.delete(v)
60 cs.assert_called('DELETE', '/volumes/%s' % vol_id)
61
62 def test_create_server_volume(self):
63 v = cs.volumes.create_server_volume(
64 server_id=1234,
65 volume_id='15e59938-07d5-11e1-90e3-e3dffe0c5983',
66 device='/dev/vdb'
67 )
68 cs.assert_called('POST', '/servers/1234/os-volume_attachments')
69 self.assertIsInstance(v, volumes.Volume)
70
71 def test_update_server_volume(self):
72 vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
73 v = cs.volumes.update_server_volume(
74 server_id=1234,
75 attachment_id='Work',
76 new_volume_id=vol_id
77 )
78 cs.assert_called('PUT', '/servers/1234/os-volume_attachments/Work')
79 self.assertIsInstance(v, volumes.Volume)
80
81 def test_get_server_volume(self):
82 v = cs.volumes.get_server_volume(1234, 'Work')
83 cs.assert_called('GET', '/servers/1234/os-volume_attachments/Work')
84 self.assertIsInstance(v, volumes.Volume)
85
86 def test_list_server_volumes(self):
87 vl = cs.volumes.get_server_volumes(1234)
88 cs.assert_called('GET', '/servers/1234/os-volume_attachments')
89 [self.assertIsInstance(v, volumes.Volume) for v in vl]
90
91 def test_delete_server_volume(self):
92 cs.volumes.delete_server_volume(1234, 'Work')
93 cs.assert_called('DELETE', '/servers/1234/os-volume_attachments/Work')