OpenStack Compute (Nova) Client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_volumes.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. from novaclient.tests.unit import utils
  16. from novaclient.tests.unit.v1_1 import fakes
  17. from novaclient.v1_1 import volumes
  18. cs = fakes.FakeClient()
  19. class VolumesTest(utils.TestCase):
  20. def test_list_servers(self):
  21. vl = cs.volumes.list()
  22. cs.assert_called('GET', '/volumes/detail')
  23. [self.assertIsInstance(v, volumes.Volume) for v in vl]
  24. def test_list_volumes_undetailed(self):
  25. vl = cs.volumes.list(detailed=False)
  26. cs.assert_called('GET', '/volumes')
  27. [self.assertIsInstance(v, volumes.Volume) for v in vl]
  28. def test_get_volume_details(self):
  29. vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
  30. v = cs.volumes.get(vol_id)
  31. cs.assert_called('GET', '/volumes/%s' % vol_id)
  32. self.assertIsInstance(v, volumes.Volume)
  33. self.assertEqual(v.id, vol_id)
  34. def test_create_volume(self):
  35. v = cs.volumes.create(
  36. size=2,
  37. display_name="My volume",
  38. display_description="My volume desc",
  39. )
  40. cs.assert_called('POST', '/volumes')
  41. self.assertIsInstance(v, volumes.Volume)
  42. def test_delete_volume(self):
  43. vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
  44. v = cs.volumes.get(vol_id)
  45. v.delete()
  46. cs.assert_called('DELETE', '/volumes/%s' % vol_id)
  47. cs.volumes.delete(vol_id)
  48. cs.assert_called('DELETE', '/volumes/%s' % vol_id)
  49. cs.volumes.delete(v)
  50. cs.assert_called('DELETE', '/volumes/%s' % vol_id)
  51. def test_create_server_volume(self):
  52. v = cs.volumes.create_server_volume(
  53. server_id=1234,
  54. volume_id='15e59938-07d5-11e1-90e3-e3dffe0c5983',
  55. device='/dev/vdb'
  56. )
  57. cs.assert_called('POST', '/servers/1234/os-volume_attachments')
  58. self.assertIsInstance(v, volumes.Volume)
  59. def test_update_server_volume(self):
  60. vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
  61. v = cs.volumes.update_server_volume(
  62. server_id=1234,
  63. attachment_id='Work',
  64. new_volume_id=vol_id
  65. )
  66. cs.assert_called('PUT', '/servers/1234/os-volume_attachments/Work')
  67. self.assertIsInstance(v, volumes.Volume)
  68. def test_get_server_volume(self):
  69. v = cs.volumes.get_server_volume(1234, 'Work')
  70. cs.assert_called('GET', '/servers/1234/os-volume_attachments/Work')
  71. self.assertIsInstance(v, volumes.Volume)
  72. def test_list_server_volumes(self):
  73. vl = cs.volumes.get_server_volumes(1234)
  74. cs.assert_called('GET', '/servers/1234/os-volume_attachments')
  75. [self.assertIsInstance(v, volumes.Volume) for v in vl]
  76. def test_delete_server_volume(self):
  77. cs.volumes.delete_server_volume(1234, 'Work')
  78. cs.assert_called('DELETE', '/servers/1234/os-volume_attachments/Work')