def test_create_volume_snapshot_with_timeout(self): """ Test that a timeout while waiting for the volume snapshot to create raises an exception in create_volume_snapshot. """ snapshot_id = '5678' volume_id = '1234' build_snapshot = fakes.FakeVolumeSnapshot(snapshot_id, 'creating', 'foo', 'derpysnapshot') build_snapshot_dict = meta.obj_to_munch(build_snapshot) self.register_uris([ dict(method='POST', uri=self.get_mock_url('volumev2', 'public', append=['snapshots']), json={'snapshot': build_snapshot_dict}, validate=dict( json={'snapshot': { 'force': False, 'volume_id': '1234' }})), dict(method='GET', uri=self.get_mock_url('volumev2', 'public', append=['snapshots', snapshot_id]), json={'snapshot': build_snapshot_dict}) ]) self.assertRaises(exc.OpenStackCloudTimeout, self.cloud.create_volume_snapshot, volume_id=volume_id, wait=True, timeout=0.01) self.assert_calls(do_count=False)
def test_delete_volume_snapshot_with_error(self): """ Test that a exception while deleting a volume snapshot will cause an OpenStackCloudException. """ fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available', 'foo', 'derpysnapshot') fake_snapshot_dict = meta.obj_to_munch(fake_snapshot) self.register_uris([ dict(method='GET', uri=self.get_mock_url('volumev2', 'public', append=['snapshots', 'detail']), json={'snapshots': [fake_snapshot_dict]}), dict(method='DELETE', uri=self.get_mock_url( 'volumev2', 'public', append=['snapshots', fake_snapshot_dict['id']]), status_code=404) ]) self.assertRaises(exc.OpenStackCloudException, self.cloud.delete_volume_snapshot, name_or_id='1234') self.assert_calls()
def test_delete_volume_snapshot_with_timeout(self): """ Test that a timeout while waiting for the volume snapshot to delete raises an exception in delete_volume_snapshot. """ fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available', 'foo', 'derpysnapshot') fake_snapshot_dict = meta.obj_to_munch(fake_snapshot) self.register_uris([ dict(method='GET', uri=self.get_mock_url('volumev2', 'public', append=['snapshots', 'detail']), json={'snapshots': [fake_snapshot_dict]}), dict(method='DELETE', uri=self.get_mock_url( 'volumev2', 'public', append=['snapshots', fake_snapshot_dict['id']])) ]) self.assertRaises(exc.OpenStackCloudTimeout, self.cloud.delete_volume_snapshot, name_or_id='1234', wait=True, timeout=0.01) self.assert_calls(do_count=False)
def test_delete_volume_snapshot(self): """ Test that delete_volume_snapshot without a wait returns True instance when the volume snapshot deletes. """ fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available', 'foo', 'derpysnapshot') fake_snapshot_dict = meta.obj_to_munch(fake_snapshot) self.register_uris([ dict(method='GET', uri=self.get_mock_url('volumev2', 'public', append=['snapshots', 'detail']), json={'snapshots': [fake_snapshot_dict]}), dict(method='DELETE', uri=self.get_mock_url( 'volumev2', 'public', append=['snapshots', fake_snapshot_dict['id']])) ]) self.assertTrue( self.cloud.delete_volume_snapshot(name_or_id='1234', wait=False)) self.assert_calls()
def test_create_volume_snapshot_wait(self): """ Test that create_volume_snapshot with a wait returns the volume snapshot when its status changes to "available". """ snapshot_id = '5678' volume_id = '1234' build_snapshot = fakes.FakeVolumeSnapshot(snapshot_id, 'creating', 'foo', 'derpysnapshot') build_snapshot_dict = meta.obj_to_munch(build_snapshot) fake_snapshot = fakes.FakeVolumeSnapshot(snapshot_id, 'available', 'foo', 'derpysnapshot') fake_snapshot_dict = meta.obj_to_munch(fake_snapshot) self.register_uris([ dict(method='POST', uri=self.get_mock_url('volumev2', 'public', append=['snapshots']), json={'snapshot': build_snapshot_dict}, validate=dict( json={'snapshot': { 'force': False, 'volume_id': '1234' }})), dict(method='GET', uri=self.get_mock_url('volumev2', 'public', append=['snapshots', snapshot_id]), json={'snapshot': build_snapshot_dict}), dict(method='GET', uri=self.get_mock_url('volumev2', 'public', append=['snapshots', snapshot_id]), json={'snapshot': fake_snapshot_dict}) ]) self.assertEqual( self.cloud._normalize_volume(fake_snapshot_dict), self.cloud.create_volume_snapshot(volume_id=volume_id, wait=True)) self.assert_calls()