def test_create_snapshot(self): # setup drive with default configuration # and return the mock HTTP LeftHand client mock_client = self.setup_driver() mock_client.getVolumeByName.return_value = {'id': self.volume_id} # execute create_snapshot self.driver.create_snapshot(self.snapshot) expected = self.driver_startup_call_stack + [ mock.call.getVolumeByName('fakevolume'), mock.call.createSnapshot('fakeshapshot', 1, {'inheritAccess': True}) ] # validate call chain mock_client.assert_has_calls(expected) # mock HTTPServerError (array failure) mock_client.getVolumeByName.side_effect = hpexceptions.HTTPNotFound() # ensure the raised exception is a cinder exception self.assertRaises(exception.VolumeBackendAPIException, self.driver.create_snapshot, self.snapshot)
def test_terminate_connection(self): # setup drive with default configuration # and return the mock HTTP LeftHand client mock_client = self.setup_driver() mock_client.getVolumeByName.return_value = {'id': self.volume_id} mock_client.getServerByName.return_value = {'id': self.server_id} # execute terminate_connection self.driver.terminate_connection(self.volume, self.connector) expected = self.driver_startup_call_stack + [ mock.call.getVolumeByName('fakevolume'), mock.call.getServerByName('fakehost'), mock.call.removeServerAccess(1, 0) ] # validate call chain mock_client.assert_has_calls(expected) mock_client.getVolumeByName.side_effect = hpexceptions.HTTPNotFound() # ensure the raised exception is a cinder exception self.assertRaises(exception.VolumeBackendAPIException, self.driver.terminate_connection, self.volume, self.connector)
def test_initialize_connection_with_chaps(self): # setup drive with default configuration # and return the mock HTTP LeftHand client mock_client = self.setup_driver() # mock return value of getVolumeByName mock_client.getServerByName.side_effect = hpexceptions.HTTPNotFound() mock_client.createServer.return_value = { 'id': self.server_id, 'chapAuthenticationRequired': True, 'chapTargetSecret': 'dont_tell' } mock_client.getVolumeByName.return_value = {'id': self.volume_id} # execute initialize_connection result = self.driver.initialize_connection(self.volume, self.connector) # validate self.assertEqual(result['driver_volume_type'], 'iscsi') self.assertEqual(result['data']['target_discovered'], False) self.assertEqual(result['data']['volume_id'], self.volume_id) self.assertEqual(result['data']['auth_method'], 'CHAP') expected = self.driver_startup_call_stack + [ mock.call.getServerByName('fakehost'), mock.call.createServer('fakehost', 'iqn.1993-08.org.debian:01:222', None), mock.call.getVolumeByName('fakevolume'), mock.call.addServerAccess(1, 0) ] # validate call chain mock_client.assert_has_calls(expected)
def test_delete_volume(self): # setup drive with default configuration # and return the mock HTTP LeftHand client mock_client = self.setup_driver() # mock return value of getVolumeByName mock_client.getVolumeByName.return_value = {'id': self.volume_id} # execute delete_volume self.driver.delete_volume(self.volume) expected = self.driver_startup_call_stack + [ mock.call.getVolumeByName('fakevolume'), mock.call.deleteVolume(self.volume_id) ] mock_client.assert_has_calls(expected) # mock HTTPNotFound (volume not found) mock_client.getVolumeByName.side_effect = hpexceptions.HTTPNotFound() # no exception should escape method self.driver.delete_volume(self.volume) # mock HTTPConflict mock_client.deleteVolume.side_effect = hpexceptions.HTTPConflict() # ensure the raised exception is a cinder exception self.assertRaises(exception.VolumeBackendAPIException, self.driver.delete_volume, self.volume_id)
def test_delete_snapshot(self): # setup drive with default configuration # and return the mock HTTP LeftHand client mock_client = self.setup_driver() mock_client.getSnapshotByName.return_value = {'id': self.snapshot_id} # execute delete_snapshot self.driver.delete_snapshot(self.snapshot) expected = self.driver_startup_call_stack + [ mock.call.getSnapshotByName('fakeshapshot'), mock.call.deleteSnapshot(3) ] # validate call chain mock_client.assert_has_calls(expected) mock_client.getSnapshotByName.side_effect = hpexceptions.HTTPNotFound() # no exception is thrown, just error msg is logged self.driver.delete_snapshot(self.snapshot) # mock HTTPServerError (array failure) ex = hpexceptions.HTTPServerError({'message': 'Some message.'}) mock_client.getSnapshotByName.side_effect = ex # ensure the raised exception is a cinder exception self.assertRaises(exception.VolumeBackendAPIException, self.driver.delete_snapshot, self.snapshot) # mock HTTPServerError because the snap is in use ex = hpexceptions.HTTPServerError({ 'message': 'Hey, dude cannot be deleted because it is a clone point duh.' }) mock_client.getSnapshotByName.side_effect = ex # ensure the raised exception is a cinder exception self.assertRaises(exception.SnapshotIsBusy, self.driver.delete_snapshot, self.snapshot)
def test_initialize_connection(self): # setup drive with default configuration # and return the mock HTTP LeftHand client mock_client = self.setup_driver() # mock return value of getVolumeByName mock_client.getServerByName.side_effect = hpexceptions.HTTPNotFound() mock_client.createServer.return_value = {'id': self.server_id} mock_client.getVolumeByName.return_value = {'id': self.volume_id} # execute initialize_connection result = self.driver.initialize_connection(self.volume, self.connector) # validate self.assertEqual(result['driver_volume_type'], 'iscsi') self.assertEqual(result['data']['target_discovered'], False) self.assertEqual(result['data']['volume_id'], self.volume_id) self.assertTrue('auth_method' not in result['data']) expected = self.driver_startup_call_stack + [ mock.call.getServerByName('fakehost'), mock.call.createServer('fakehost', 'iqn.1993-08.org.debian:01:222', None), mock.call.getVolumeByName('fakevolume'), mock.call.addServerAccess(1, 0) ] # validate call chain mock_client.assert_has_calls(expected) # mock HTTPServerError (array failure) mock_client.createServer.side_effect = hpexceptions.HTTPServerError() # ensure the raised exception is a cinder exception self.assertRaises(exception.VolumeBackendAPIException, self.driver.initialize_connection, self.volume, self.connector)