def test_create_volume_snapshot_wait(self, mock_cinder): """ Test that create_volume_snapshot with a wait returns the volume snapshot when its status changes to "available". """ build_snapshot = fakes.FakeVolumeSnapshot('1234', 'creating', 'foo', 'derpysnapshot') fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available', 'foo', 'derpysnapshot') mock_cinder.volume_snapshots.create.return_value = build_snapshot mock_cinder.volume_snapshots.get.return_value = fake_snapshot mock_cinder.volume_snapshots.list.return_value = [ build_snapshot, fake_snapshot] self.assertEqual( _utils.normalize_volumes( [meta.obj_to_dict(fake_snapshot)])[0], self.client.create_volume_snapshot(volume_id='1234', wait=True) ) mock_cinder.volume_snapshots.create.assert_called_with( force=False, volume_id='1234' ) mock_cinder.volume_snapshots.get.assert_called_with( snapshot_id=meta.obj_to_dict(build_snapshot)['id'] )
def test_create_volume_snapshot_with_error(self, mock_cinder): """ Test that a error status while waiting for the volume snapshot to create raises an exception in create_volume_snapshot. """ build_snapshot = fakes.FakeVolumeSnapshot('1234', 'creating', 'bar', 'derpysnapshot') error_snapshot = fakes.FakeVolumeSnapshot('1234', 'error', 'blah', 'derpysnapshot') mock_cinder.volume_snapshots.create.return_value = build_snapshot mock_cinder.volume_snapshots.get.return_value = error_snapshot mock_cinder.volume_snapshots.list.return_value = [error_snapshot] self.assertRaises( OpenStackCloudException, self.client.create_volume_snapshot, volume_id='1234', wait=True, timeout=5) mock_cinder.volume_snapshots.create.assert_called_with( force=False, volume_id='1234' ) mock_cinder.volume_snapshots.get.assert_called_with( snapshot_id=meta.obj_to_dict(build_snapshot)['id'] )
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_dict(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_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_dict(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_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(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_dict(build_snapshot) fake_snapshot = fakes.FakeVolumeSnapshot(snapshot_id, 'available', 'foo', 'derpysnapshot') fake_snapshot_dict = meta.obj_to_dict(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()
def test_delete_volume_snapshot(self, mock_cinder): """ Test that delete_volume_snapshot without a wait returns True instance when the volume snapshot deletes. """ fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available', 'foo', 'derpysnapshot') mock_cinder.volume_snapshots.list.return_value = [fake_snapshot] self.assertEqual( True, self.cloud.delete_volume_snapshot(name_or_id='1234', wait=False)) mock_cinder.volume_snapshots.list.assert_called_with(detailed=True, search_opts=None)
def test_delete_volume_snapshot_with_error(self, mock_cinder): """ Test that a exception while deleting a volume snapshot will cause an OpenStackCloudException. """ fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available', 'foo', 'derpysnapshot') mock_cinder.volume_snapshots.delete.side_effect = Exception( "exception") mock_cinder.volume_snapshots.list.return_value = [fake_snapshot] self.assertRaises(exc.OpenStackCloudException, self.cloud.delete_volume_snapshot, name_or_id='1234') mock_cinder.volume_snapshots.delete.assert_called_with(snapshot='1234')
def test_delete_volume_snapshot_with_timeout(self, mock_cinder): """ 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') mock_cinder.volume_snapshots.list.return_value = [fake_snapshot] self.assertRaises(exc.OpenStackCloudTimeout, self.cloud.delete_volume_snapshot, name_or_id='1234', wait=True, timeout=0.01) mock_cinder.volume_snapshots.list.assert_called_with(detailed=True, search_opts=None)
def test_create_volume_snapshot_with_timeout(self, mock_cinder): """ Test that a timeout while waiting for the volume snapshot to create raises an exception in create_volume_snapshot. """ build_snapshot = fakes.FakeVolumeSnapshot('1234', 'creating', 'foo', 'derpysnapshot') mock_cinder.volume_snapshots.create.return_value = build_snapshot mock_cinder.volume_snapshots.get.return_value = build_snapshot mock_cinder.volume_snapshots.list.return_value = [build_snapshot] self.assertRaises(OpenStackCloudTimeout, self.cloud.create_volume_snapshot, volume_id='1234', wait=True, timeout=0.01) mock_cinder.volume_snapshots.create.assert_called_with( force=False, volume_id='1234') mock_cinder.volume_snapshots.get.assert_called_with( snapshot_id=meta.obj_to_dict(build_snapshot)['id'])