def test_detach_volumes_detach_failure_errors_not_allowed( self, mock_create_meta, mock_is_attached, mock_begin, mock_term, mock_detach, mock_get, mock_set_meta, mock_session): volume_id = '111111111-0000-0000-0000-000000000003' volumes = [volume_id] connector = {'foo': 'bar'} mock_create_meta.return_value = {'bar': 'baz'} mock_is_attached.return_value = True mock_get.return_value = mock.Mock(attachments=[{ 'server_id': self.node.uuid, 'attachment_id': 'qux' }]) mock_detach.side_effect = cinder_exceptions.NotAcceptable( http_client.NOT_ACCEPTABLE) with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises(exception.StorageError, cinder.detach_volumes, task, volumes, connector, allow_errors=False) mock_detach.assert_called_once_with(mock.ANY, volume_id, 'qux') self.assertFalse(mock_set_meta.called)
def test_attach_volumes_reserve_failure(self, mock_is_attached, mock_reserve, mock_get, mock_set_meta, mock_session): volumes = ['111111111-0000-0000-0000-000000000003'] connector = {'foo': 'bar'} volume = mock.Mock(attachments=[]) mock_get.return_value = volume mock_is_attached.return_value = False mock_reserve.side_effect = cinder_exceptions.NotAcceptable(406) with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises(exception.StorageError, cinder.attach_volumes, task, volumes, connector) mock_is_attached.assert_called_once_with(mock.ANY, volume)
def test_attach_volumes_attach_set_meta_failure( self, mock_log, mock_create_meta, mock_is_attached, mock_reserve, mock_init, mock_attach, mock_get, mock_set_meta, mock_session): """Attach a volume and tolerate set_metadata failure.""" expected = [{ 'driver_volume_type': 'iscsi', 'data': { 'target_iqn': 'iqn.2010-10.org.openstack:volume-00000002', 'target_portal': '127.0.0.0.1:3260', 'volume_id': '111111111-0000-0000-0000-000000000003', 'target_lun': 2, 'ironic_volume_uuid': '000-000' } }] volume_id = '111111111-0000-0000-0000-000000000003' volumes = [volume_id] connector = {'foo': 'bar'} mock_create_meta.return_value = {'bar': 'baz'} mock_is_attached.return_value = False mock_get.return_value = mock.Mock(attachments=[], id='000-000') mock_init.return_value = { 'driver_volume_type': 'iscsi', 'data': { 'target_iqn': 'iqn.2010-10.org.openstack:volume-00000002', 'target_portal': '127.0.0.0.1:3260', 'target_lun': 2 } } mock_set_meta.side_effect = cinder_exceptions.NotAcceptable( http_client.NOT_ACCEPTABLE) with task_manager.acquire(self.context, self.node.uuid) as task: attachments = cinder.attach_volumes(task, volumes, connector) self.assertEqual(expected, attachments) mock_reserve.assert_called_once_with(mock.ANY, volume_id) mock_init.assert_called_once_with(mock.ANY, volume_id, connector) mock_attach.assert_called_once_with(mock.ANY, volume_id, self.node.instance_uuid, self.mount_point) mock_set_meta.assert_called_once_with(mock.ANY, volume_id, {'bar': 'baz'}) mock_get.assert_called_once_with(mock.ANY, volume_id) mock_is_attached.assert_called_once_with(mock.ANY, mock_get.return_value) self.assertTrue(mock_log.warning.called)
def test_detach_volumes_term_failure(self, mock_create_meta, mock_is_attached, mock_begin, mock_term, mock_get, mock_set_meta, mock_session): volume_id = '111111111-0000-0000-0000-000000000003' volumes = [volume_id] connector = {'foo': 'bar'} mock_create_meta.return_value = {'bar': 'baz'} mock_is_attached.return_value = True mock_get.return_value = {'id': volume_id, 'attachments': []} mock_term.side_effect = cinder_exceptions.NotAcceptable(406) with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises(exception.StorageError, cinder.detach_volumes, task, volumes, connector) mock_begin.assert_called_once_with(mock.ANY, volume_id) mock_term.assert_called_once_with(mock.ANY, volume_id, connector) cinder.detach_volumes(task, volumes, connector, allow_errors=True) self.assertFalse(mock_set_meta.called)
def test_attach_volumes_initialize_connection_failure( self, mock_create_meta, mock_is_attached, mock_reserve, mock_init, mock_get, mock_set_meta, mock_session): """Fail attachment upon an initialization failure.""" volume_id = '111111111-0000-0000-0000-000000000003' volumes = [volume_id] connector = {'foo': 'bar'} mock_create_meta.return_value = {'bar': 'baz'} mock_is_attached.return_value = False mock_get.return_value = mock.Mock(attachments=[]) mock_init.side_effect = cinder_exceptions.NotAcceptable(406) with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises(exception.StorageError, cinder.attach_volumes, task, volumes, connector) mock_get.assert_called_once_with(mock.ANY, volume_id) mock_reserve.assert_called_once_with(mock.ANY, volume_id) mock_init.assert_called_once_with(mock.ANY, volume_id, connector)