test_image_service.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import uuid
  2. from test import helpers
  3. from test.helpers import ProviderTestBase
  4. from test.helpers import standard_interface_tests as sit
  5. from cloudbridge.cloud.interfaces import MachineImageState
  6. from cloudbridge.cloud.interfaces import TestMockHelperMixin
  7. class CloudImageServiceTestCase(ProviderTestBase):
  8. @helpers.skipIfNoService(['compute.images', 'network',
  9. 'compute.instances'])
  10. def test_create_and_list_image(self):
  11. """
  12. Create a new image and check whether that image can be listed.
  13. This covers waiting till the image is ready, checking that the image
  14. name is the expected one and whether list_images is functional.
  15. """
  16. instance_name = "CBImageTest-{0}-{1}".format(
  17. self.provider.name,
  18. uuid.uuid4())
  19. # Declare these variables and late binding will allow
  20. # the cleanup method access to the most current values
  21. test_instance = None
  22. net = None
  23. with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
  24. test_instance, net)):
  25. net, subnet = helpers.create_test_network(
  26. self.provider, instance_name)
  27. test_instance = helpers.get_test_instance(
  28. self.provider, instance_name, subnet=subnet)
  29. name = "CBUnitTestListImg-{0}".format(uuid.uuid4())
  30. test_image = test_instance.create_image(name)
  31. def cleanup_img(img):
  32. img.delete()
  33. img.wait_for(
  34. [MachineImageState.UNKNOWN, MachineImageState.ERROR])
  35. with helpers.cleanup_action(lambda: cleanup_img(test_image)):
  36. test_image.wait_till_ready()
  37. sit.check_standard_behaviour(
  38. self, self.provider.compute.images, test_image)
  39. # TODO: Fix moto so that the BDM is populated correctly
  40. if not isinstance(self.provider, TestMockHelperMixin):
  41. # check image size
  42. test_image.refresh()
  43. self.assertGreater(test_image.min_disk, 0, "Minimum disk"
  44. " size required by image is invalid")
  45. # TODO: Images take a long time to deregister on EC2. Needs
  46. # investigation
  47. sit.check_delete(self, self.provider.compute.images, test_image)