test_image_service.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 import TestMockHelperMixin
  6. class CloudImageServiceTestCase(ProviderTestBase):
  7. @helpers.skipIfNoService(['compute.images', 'network',
  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. with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
  21. test_instance, net)):
  22. net, subnet = helpers.create_test_network(
  23. self.provider, instance_name)
  24. test_instance = helpers.get_test_instance(
  25. self.provider, instance_name, subnet=subnet)
  26. name = "cb_listimg-{0}".format(helpers.get_uuid())
  27. test_image = test_instance.create_image(name)
  28. def cleanup_img(img):
  29. img.delete()
  30. img.wait_for(
  31. [MachineImageState.UNKNOWN, MachineImageState.ERROR])
  32. with helpers.cleanup_action(lambda: cleanup_img(test_image)):
  33. test_image.wait_till_ready()
  34. sit.check_standard_behaviour(
  35. self, self.provider.compute.images, test_image)
  36. # TODO: Fix moto so that the BDM is populated correctly
  37. if not isinstance(self.provider, TestMockHelperMixin):
  38. # check image size
  39. test_image.refresh()
  40. self.assertGreater(test_image.min_disk, 0, "Minimum disk"
  41. " size required by image is invalid")
  42. # TODO: Images take a long time to deregister on EC2. Needs
  43. # investigation
  44. sit.check_delete(self, self.provider.compute.images, test_image)