test_snapshot_state.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import time
  2. import uuid
  3. from test import helpers
  4. from test.helpers import ProviderTestBase
  5. from test.helpers import standard_interface_tests as sit
  6. from cloudbridge.cloud.interfaces import SnapshotState
  7. from cloudbridge.cloud.interfaces import VolumeState
  8. from cloudbridge.cloud.interfaces.resources import AttachmentInfo
  9. import six
  10. class CloudSnapshotServiceTestCase(ProviderTestBase):
  11. def test_crud_snapshot_a(self):
  12. name = "cb_crudsnap-{0}".format(helpers.get_uuid())
  13. test_vol = self.provider.block_store.volumes.create(
  14. name,
  15. 1,
  16. helpers.get_provider_test_data(self.provider, "placement"))
  17. with helpers.cleanup_action(lambda: test_vol.delete()):
  18. test_vol.wait_till_ready()
  19. snap_name = "cb_snap-{0}".format(name)
  20. test_snap = test_vol.create_snapshot(name=snap_name,
  21. description=snap_name)
  22. def cleanup_snap(snap):
  23. snap.delete()
  24. snap.wait_for(
  25. [SnapshotState.UNKNOWN],
  26. terminal_states=[SnapshotState.ERROR])
  27. with helpers.cleanup_action(lambda: cleanup_snap(test_snap)):
  28. test_snap.wait_till_ready()
  29. print(test_snap.state)
  30. for x in range(0, 20):
  31. list_objs = self.provider.block_store.snapshots.list()
  32. all_records = list_objs
  33. while list_objs.is_truncated:
  34. list_objs = self.provider.block_store.snapshots.list(marker=list_objs.marker)
  35. all_records += list_objs
  36. match_objs = [o for o in all_records if o.id == test_snap.id]
  37. print("List - " + match_objs[0].state)
  38. time.sleep(5)
  39. # obj = self.provider.block_store.snapshots.get(test_snap.id)
  40. # print("Get - " + obj.state)