def test_create_cloned_volume(self, _copy_volume): TEST_SRC = obj_volume.Volume(id=fake.VOLUME_ID, name_id=fake.VOLUME_NAME_ID, size=1, provider_location='/dev/loop1') TEST_VOLUME = obj_volume.Volume(name_id=fake.VOLUME2_NAME_ID, size=1, display_name='vol1') with mock.patch.object(self.drv, 'find_appropriate_size_device', return_value='/dev/loop2') as fasd_mocked: with mock.patch.object(self.drv, '_get_devices_sizes', return_value={'/dev/loop2': 2}) as \ gds_mocked: with mock.patch.object(self.drv, 'local_path', return_value='/dev/loop1') as \ lp_mocked: with mock.patch.object(self.drv, '_update_provider_location') as \ upl_mocked: volutils.copy_volume('/dev/loop1', fasd_mocked, 2, mock.sentinel, execute=self.drv._execute) self.drv.create_cloned_volume(TEST_VOLUME, TEST_SRC) fasd_mocked.assert_called_once_with(TEST_SRC.size) lp_mocked.assert_called_once_with(TEST_SRC) gds_mocked.assert_called_once_with(['/dev/loop2']) upl_mocked.assert_called_once_with( TEST_VOLUME, '/dev/loop2')
def test_create_cloned_volume(self, mock_random, mock_volume_list): mock_random.sample.return_value = fake.VOLUME_ID mock_volume_list.return_value = [] self.mock_client_service.service.snapVol.return_value = \ FAKE_GENERIC_POSITIVE_RESPONSE self.mock_client_service.service.cloneVol.return_value = \ FAKE_GENERIC_POSITIVE_RESPONSE self.mock_client_service.service.getVolInfo.return_value = \ FAKE_GET_VOL_INFO_RESPONSE self.mock_client_service.service.getNetConfig.return_value = \ FAKE_POSITIVE_NETCONFIG_RESPONSE volume = obj_volume.Volume(context.get_admin_context(), id=fake.VOLUME_ID, size=5.0, _name_id=None, display_name='', volume_type_id=FAKE_TYPE_ID ) src_volume = obj_volume.Volume(context.get_admin_context(), id=fake.VOLUME2_ID, _name_id=None, size=5.0) self.assertEqual({ 'provider_location': '172.18.108.21:3260 iqn.test 0', 'provider_auth': None}, self.driver.create_cloned_volume(volume, src_volume)) expected_calls = [mock.call.service.snapVol( request={ 'vol': "volume-" + fake.VOLUME2_ID, 'snapAttr': {'name': 'openstack-clone-volume-' + fake.VOLUME_ID + "-" + fake.VOLUME_ID, 'description': ''}, 'sid': 'a9b9aba7'}), mock.call.service.cloneVol( request={ 'snap-name': 'openstack-clone-volume-' + fake.VOLUME_ID + "-" + fake.VOLUME_ID, 'attr': {'snap-quota': sys.maxsize, 'name': 'volume-' + fake.VOLUME_ID, 'quota': 5368709120, 'reserve': 5368709120, 'online': True, 'warn-level': 4294967296, 'encryptionAttr': {'cipher': 2}, 'multi-initiator': 'false', 'perfpol-name': 'default', 'agent-type': 5}, 'name': 'volume-' + fake.VOLUME2_ID, 'sid': 'a9b9aba7'})] self.mock_client_service.assert_has_calls(expected_calls)
def test_initialize_connection_different_hosts(self, _init_conn): TEST_CONNECTOR = {'host': 'localhost1'} TEST_VOLUME2 = obj_volume.Volume(host='localhost2', provider_location='1 2 3 /dev/loop2', provider_auth='d e f', attached_mode='rw', id=fake.VOLUME2_ID) _init_conn.return_value = 'data' data = self.drv.initialize_connection(TEST_VOLUME2, TEST_CONNECTOR) expected_data = { 'data': { 'auth_method': 'd', 'auth_password': '******', 'auth_username': '******', 'encrypted': False, 'target_discovered': False, 'target_iqn': '2', 'target_lun': 3, 'target_portal': '1', 'volume_id': fake.VOLUME2_ID } } self.assertEqual(expected_data['data'], data['data'])
def test_create_volume_from_snapshot(self, _copy_volume): TEST_SNAP = obj_snap.Snapshot(volume_id=fake.VOLUME_ID, volume_size=1024, provider_location='/dev/loop1') TEST_VOLUME = obj_volume.Volume(id=fake.VOLUME_ID, name_id=fake.VOLUME_NAME_ID, size=1, display_name='vol1', provider_location='/dev/loop2') with mock.patch.object(self.drv, 'find_appropriate_size_device', return_value='/dev/loop2') as fasd_mocked: with mock.patch.object(self.drv, '_get_devices_sizes', return_value={'/dev/loop2': 1024}) as \ gds_mocked: with mock.patch.object(self.drv, '_update_provider_location') as \ upl_mocked: volutils.copy_volume('/dev/loop1', fasd_mocked, 1024, mock.sentinel, execute=self.drv._execute) self.drv.create_volume_from_snapshot( TEST_VOLUME, TEST_SNAP) fasd_mocked.assert_called_once_with(TEST_SNAP.volume_size) gds_mocked.assert_called_once_with(['/dev/loop2']) upl_mocked.assert_called_once_with(TEST_VOLUME, '/dev/loop2')
def test_delete_path_is_not_in_list_of_available_devices(self): TEST_VOLUME2 = obj_volume.Volume(provider_location='/dev/loop0') with mock.patch.object(self.drv, 'local_path', return_value='/dev/loop0') as lp_mocked: self.drv.delete_volume(TEST_VOLUME2) lp_mocked.assert_called_once_with(TEST_VOLUME2)
def test_obj_load_attr(self, volume_get_by_id): snapshot = snapshot_obj.Snapshot._from_db_object( self.context, snapshot_obj.Snapshot(), fake_snapshot) volume = volume_obj.Volume(context=self.context, id=2) volume_get_by_id.return_value = volume self.assertEqual(volume, snapshot.volume) volume_get_by_id.assert_called_once_with(self.context, snapshot.volume_id)
def test_obj_fields(self): volume = volume_obj.Volume(context=self.context, id=2, _name_id=2) snapshot = snapshot_obj.Snapshot(context=self.context, id=1, volume=volume) self.assertEqual(['name', 'volume_name'], snapshot.obj_extra_fields) self.assertEqual('snapshot-1', snapshot.name) self.assertEqual('volume-2', snapshot.volume_name)
def test__update_provider_location(self): TEST_VOLUME = obj_volume.Volume(name_id=fake.VOLUME_NAME_ID, size=1, display_name='vol1') with mock.patch.object(obj_volume.Volume, 'update') as update_mocked, \ mock.patch.object(obj_volume.Volume, 'save') as save_mocked: self.drv._update_provider_location(TEST_VOLUME, 'dev_path') self.assertEqual(1, update_mocked.call_count) save_mocked.assert_called_once_with()
def test_create_volume(self): TEST_VOLUME = obj_volume.Volume(name_id=fake.VOLUME_NAME_ID, size=1, display_name='vol1') with mock.patch.object(self.drv, 'find_appropriate_size_device', return_value='dev_path') as fasd_mocked: with mock.patch.object(self.drv, '_update_provider_location') as \ upl_mocked: self.drv.create_volume(TEST_VOLUME) fasd_mocked.assert_called_once_with(TEST_VOLUME.size) upl_mocked.assert_called_once_with(TEST_VOLUME, 'dev_path')
def test_initialize_connection(self): TEST_VOLUME1 = obj_volume.Volume(host='localhost1', provider_location='1 2 3 /dev/loop1', provider_auth='a b c', attached_mode='rw', id=fake.VOLUME_ID) TEST_CONNECTOR = {'host': 'localhost1'} data = self.drv.initialize_connection(TEST_VOLUME1, TEST_CONNECTOR) expected_data = {'data': {'device_path': '/dev/loop1'}, 'driver_volume_type': 'local'} self.assertEqual(expected_data, data)
def test_create_snapshot_with_not_available_volume(self): TEST_VOLUME = obj_volume.Volume(id=fake.VOLUME_ID, name_id=fake.VOLUME_NAME_ID, size=1, display_name='vol1', status='in use', provider_location='/dev/loop1') TEST_SNAP = obj_snap.Snapshot(id=fake.SNAPSHOT_ID, volume_id=fake.VOLUME_ID, volume_size=1024, provider_location='/dev/loop2', volume=TEST_VOLUME) self.assertRaises(cinder.exception.CinderException, self.drv.create_snapshot, TEST_SNAP)
def test_copy_image_to_volume(self, _fetch_to_raw): TEST_VOLUME = obj_volume.Volume(name_id=fake.VOLUME_NAME_ID, size=1, provider_location='/dev/loop1') TEST_IMAGE_SERVICE = "image_service" TEST_IMAGE_ID = "image_id" with mock.patch.object(self.drv, 'local_path', return_value='/dev/loop1') as lp_mocked: self.drv.copy_image_to_volume(context, TEST_VOLUME, TEST_IMAGE_SERVICE, TEST_IMAGE_ID) lp_mocked.assert_called_once_with(TEST_VOLUME) _fetch_to_raw.assert_called_once_with(context, TEST_IMAGE_SERVICE, TEST_IMAGE_ID, '/dev/loop1', 1234, size=1)
def test_is_volume_backup_clone(self): self.mock_client_service.service.getVolInfo.return_value = \ FAKE_GET_VOL_INFO_BACKUP_RESPONSE self.mock_client_service.service.getSnapInfo.return_value = \ FAKE_GET_SNAP_INFO_BACKUP_RESPONSE volume = obj_volume.Volume(context.get_admin_context(), id=fake.VOLUME_ID, _name_id=None) self.assertEqual(("test-backup-snap", "volume-" + fake.VOLUME_ID), self.driver.is_volume_backup_clone(volume)) expected_calls = [ mock.call.service.getVolInfo( request={'name': 'volume-' + fake.VOLUME_ID, 'sid': 'a9b9aba7'}), mock.call.service.getSnapInfo( request={'sid': 'a9b9aba7', 'vol': 'volume-' + fake.VOLUME2_ID, 'name': 'test-backup-snap'}) ] self.mock_client_service.assert_has_calls(expected_calls)
def test_delete_volume_path_exist(self, _clear_volume, _exists): TEST_VOLUME = obj_volume.Volume(name_id=fake.VOLUME_NAME_ID, size=1, provider_location='/dev/loop1', display_name='vol1', status='available') with mock.patch.object(self.drv, 'local_path', return_value='/dev/loop1') as lp_mocked: with mock.patch.object(self.drv, '_get_devices_sizes', return_value={'/dev/loop1': 1}) as \ gds_mocked: volutils.clear_volume(gds_mocked, lp_mocked) self.drv.delete_volume(TEST_VOLUME) lp_mocked.assert_called_once_with(TEST_VOLUME) gds_mocked.assert_called_once_with(['/dev/loop1']) self.assertTrue(_exists.called) self.assertTrue(_clear_volume.called)
def test_delete_not_volume_provider_location(self, _clear_volume, _local_path): TEST_VOLUME2 = obj_volume.Volume(provider_location=None) self.drv.delete_volume(TEST_VOLUME2) _local_path.assert_called_once_with(TEST_VOLUME2)