test_image_service.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from test import helpers
  2. from test.helpers import ProviderTestBase
  3. from test.helpers import standard_interface_tests as sit
  4. from cloudbridge.cloud.interfaces import MachineImageState
  5. from cloudbridge.cloud.interfaces.resources import MachineImage
  6. class CloudImageServiceTestCase(ProviderTestBase):
  7. @helpers.skipIfNoService(['compute.images', 'networking.networks',
  8. 'compute.instances'])
  9. def test_create_and_list_image(self):
  10. """
  11. Create a new image and check whether that image can be listed.
  12. This covers waiting till the image is ready, checking that the image
  13. name is the expected one and whether list_images is functional.
  14. """
  15. instance_name = "cb_crudimage-{0}".format(helpers.get_uuid())
  16. # Declare these variables and late binding will allow
  17. # the cleanup method access to the most current values
  18. test_instance = None
  19. net = None
  20. def create_img(name):
  21. return test_instance.create_image(name)
  22. def cleanup_img(img):
  23. img.delete()
  24. img.wait_for(
  25. [MachineImageState.UNKNOWN, MachineImageState.ERROR])
  26. def extra_tests(img):
  27. # check image size
  28. img.refresh()
  29. self.assertGreater(img.min_disk, 0, "Minimum disk"
  30. " size required by image is invalid")
  31. with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
  32. test_instance, net)):
  33. net, subnet = helpers.create_test_network(
  34. self.provider, instance_name)
  35. test_instance = helpers.get_test_instance(
  36. self.provider, instance_name, subnet=subnet)
  37. sit.check_crud(self, self.provider.compute.images, MachineImage,
  38. "cb_listimg", create_img, cleanup_img,
  39. extra_test_func=extra_tests)