test_image_service.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from cloudbridge.cloud.interfaces import MachineImageState
  2. from cloudbridge.cloud.interfaces.resources import MachineImage
  3. from test import helpers
  4. from test.helpers import ProviderTestBase
  5. from test.helpers import standard_interface_tests as sit
  6. class CloudImageServiceTestCase(ProviderTestBase):
  7. _multiprocess_can_split_ = True
  8. @helpers.skipIfNoService(['compute.images', 'networking.networks',
  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. label is the expected one and whether list_images is functional.
  15. """
  16. instance_label = "cb_crudimage-{0}".format(helpers.get_uuid())
  17. # Declare these variables and late binding will allow
  18. # the cleanup method access to the most current values
  19. test_instance = None
  20. net = None
  21. subnet = None
  22. def create_img(label):
  23. return test_instance.create_image(label=label)
  24. def cleanup_img(img):
  25. if img:
  26. img.delete()
  27. img.wait_for(
  28. [MachineImageState.UNKNOWN, MachineImageState.ERROR])
  29. def extra_tests(img):
  30. # check image size
  31. img.refresh()
  32. self.assertGreater(img.min_disk, 0, "Minimum disk"
  33. " size required by image is invalid")
  34. with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
  35. test_instance, net)):
  36. net, subnet = helpers.create_test_network(
  37. self.provider, instance_label)
  38. test_instance = helpers.get_test_instance(
  39. self.provider, instance_label, subnet=subnet)
  40. sit.check_crud(self, self.provider.compute.images, MachineImage,
  41. "cb_listimg", create_img, cleanup_img,
  42. extra_test_func=extra_tests)