def test_create_volume_invalidates(self, cinder_mock): fake_volb4 = fakes.FakeVolume('volume1', 'available', 'Volume 1 Display Name') fake_volb4_dict = _utils.normalize_volumes( [meta.obj_to_dict(fake_volb4)])[0] cinder_mock.volumes.list.return_value = [fake_volb4] self.assertEqual([fake_volb4_dict], self.cloud.list_volumes()) volume = dict(display_name='junk_vol', size=1, display_description='test junk volume') fake_vol = fakes.FakeVolume('12345', 'creating', '') fake_vol_dict = meta.obj_to_dict(fake_vol) fake_vol_dict = _utils.normalize_volumes([meta.obj_to_dict(fake_vol) ])[0] cinder_mock.volumes.create.return_value = fake_vol cinder_mock.volumes.list.return_value = [fake_volb4, fake_vol] def creating_available(): def now_available(): fake_vol.status = 'available' fake_vol_dict['status'] = 'available' return mock.DEFAULT cinder_mock.volumes.list.side_effect = now_available return mock.DEFAULT cinder_mock.volumes.list.side_effect = creating_available self.cloud.create_volume(wait=True, timeout=None, **volume) self.assertTrue(cinder_mock.volumes.create.called) self.assertEqual(3, cinder_mock.volumes.list.call_count) # If cache was not invalidated, we would not see our own volume here # because the first volume was available and thus would already be # cached. self.assertEqual([fake_volb4_dict, fake_vol_dict], self.cloud.list_volumes()) # And now delete and check same thing since list is cached as all # available fake_vol.status = 'deleting' fake_vol_dict = meta.obj_to_dict(fake_vol) def deleting_gone(): def now_gone(): cinder_mock.volumes.list.return_value = [fake_volb4] return mock.DEFAULT cinder_mock.volumes.list.side_effect = now_gone return mock.DEFAULT cinder_mock.volumes.list.return_value = [fake_volb4, fake_vol] cinder_mock.volumes.list.side_effect = deleting_gone cinder_mock.volumes.delete.return_value = fake_vol_dict self.cloud.delete_volume('12345') self.assertEqual([fake_volb4_dict], self.cloud.list_volumes())
def test_create_volume_invalidates(self, cinder_mock): fake_volb4 = fakes.FakeVolume('volume1', 'available', 'Volume 1 Display Name') fake_volb4_dict = _utils.normalize_volumes( [meta.obj_to_dict(fake_volb4)])[0] cinder_mock.volumes.list.return_value = [fake_volb4] self.assertEqual([fake_volb4_dict], self.cloud.list_volumes()) volume = dict(display_name='junk_vol', size=1, display_description='test junk volume') fake_vol = fakes.FakeVolume('12345', 'creating', '') fake_vol_dict = meta.obj_to_dict(fake_vol) fake_vol_dict = _utils.normalize_volumes( [meta.obj_to_dict(fake_vol)])[0] cinder_mock.volumes.create.return_value = fake_vol cinder_mock.volumes.list.return_value = [fake_volb4, fake_vol] def creating_available(): def now_available(): fake_vol.status = 'available' fake_vol_dict['status'] = 'available' return mock.DEFAULT cinder_mock.volumes.list.side_effect = now_available return mock.DEFAULT cinder_mock.volumes.list.side_effect = creating_available self.cloud.create_volume(wait=True, timeout=None, **volume) self.assertTrue(cinder_mock.volumes.create.called) self.assertEqual(3, cinder_mock.volumes.list.call_count) # If cache was not invalidated, we would not see our own volume here # because the first volume was available and thus would already be # cached. self.assertEqual([fake_volb4_dict, fake_vol_dict], self.cloud.list_volumes()) # And now delete and check same thing since list is cached as all # available fake_vol.status = 'deleting' fake_vol_dict = meta.obj_to_dict(fake_vol) def deleting_gone(): def now_gone(): cinder_mock.volumes.list.return_value = [fake_volb4] return mock.DEFAULT cinder_mock.volumes.list.side_effect = now_gone return mock.DEFAULT cinder_mock.volumes.list.return_value = [fake_volb4, fake_vol] cinder_mock.volumes.list.side_effect = deleting_gone cinder_mock.volumes.delete.return_value = fake_vol_dict self.cloud.delete_volume('12345') self.assertEqual([fake_volb4_dict], self.cloud.list_volumes())
def test_list_volumes_creating_invalidates(self, cinder_mock): fake_volume = fakes.FakeVolume('volume1', 'creating', 'Volume 1 Display Name') fake_volume_dict = _utils.normalize_volumes( [meta.obj_to_dict(fake_volume)])[0] cinder_mock.volumes.list.return_value = [fake_volume] self.assertEqual([fake_volume_dict], self.cloud.list_volumes()) fake_volume2 = fakes.FakeVolume('volume2', 'available', 'Volume 2 Display Name') fake_volume2_dict = _utils.normalize_volumes( [meta.obj_to_dict(fake_volume2)])[0] cinder_mock.volumes.list.return_value = [fake_volume, fake_volume2] self.assertEqual([fake_volume_dict, fake_volume2_dict], self.cloud.list_volumes())
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_normalize_volumes_v2(self): vol = dict( display_name='test', display_description='description', bootable=False, multiattach=True, ) expected = dict( name=vol['display_name'], display_name=vol['display_name'], description=vol['display_description'], display_description=vol['display_description'], bootable=False, multiattach=True, ) retval = _utils.normalize_volumes([vol]) self.assertEqual([expected], retval)
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"])