def _set_share_state_and_notify(self, method, state, context, ex, request_spec, action=None): LOG.error("Failed to schedule %(method)s: %(ex)s", {"method": method, "ex": ex}) properties = request_spec.get('share_properties', {}) share_id = request_spec.get('share_id', None) if share_id: db.share_update(context, share_id, state) if action: self.message_api.create( context, action, context.project_id, resource_type=message_field.Resource.SHARE, resource_id=share_id, exception=ex) payload = dict(request_spec=request_spec, share_properties=properties, share_id=share_id, state=state, method=method, reason=ex) rpc.get_notifier("scheduler").error( context, 'scheduler.' + method, payload)
def test_share_host_update_db(self): self.mox.StubOutWithMock(timeutils, 'utcnow') self.mox.StubOutWithMock(db, 'share_update') timeutils.utcnow().AndReturn('fake-now') db.share_update(self.context, 31337, {'host': 'fake_host', 'scheduled_at': 'fake-now'}) self.mox.ReplayAll() driver.share_update_db(self.context, 31337, 'fake_host')
def test_delete_error(self): date = datetime.datetime(2, 2, 2, 2, 2, 2) self.mock_utcnow.return_value = date share = fake_share("fakeid", status="error") options = {"status": "deleting", "terminated_at": date} deleting_share = share.copy() deleting_share.update(options) self.mox.StubOutWithMock(db_driver, "share_update") db_driver.share_update(self.context, share["id"], options).AndReturn(deleting_share) self.share_rpcapi.delete_share(self.context, deleting_share) self.mox.ReplayAll() self.api.delete(self.context, share) self.mox.UnsetStubs() self.mox.VerifyAll()
def share_update_db(context, share_id, host): '''Set the host and set the scheduled_at field of a share. :returns: A Share with the updated fields set properly. ''' now = timeutils.utcnow() values = {'host': host, 'scheduled_at': now} return db.share_update(context, share_id, values)
def share_update_db(context, share_id, host): """Set the host and set the scheduled_at field of a share. :returns: A Share with the updated fields set properly. """ now = timeutils.utcnow() values = {"host": host, "scheduled_at": now} return db.share_update(context, share_id, values)
def test_delete_available(self): date = datetime.datetime(2, 2, 2, 2, 2, 2) timeutils.set_time_override(override_time=date) share = fake_share('fakeid', status='available') options = {'status': 'deleting', 'terminated_at': date} deleting_share = share.copy() deleting_share.update(options) self.mox.StubOutWithMock(db_driver, 'share_update') db_driver.share_update(self.context, share['id'], options).\ AndReturn(deleting_share) self.share_rpcapi.delete_share(self.context, deleting_share) self.mox.ReplayAll() self.api.delete(self.context, share) self.mox.UnsetStubs() self.mox.VerifyAll()
def test_delete_error(self): date = datetime.datetime(2, 2, 2, 2, 2, 2) self.mock_utcnow.return_value = date share = fake_share('fakeid', status='error') options = {'status': 'deleting', 'terminated_at': date} deleting_share = share.copy() deleting_share.update(options) self.mox.StubOutWithMock(db_driver, 'share_update') db_driver.share_update(self.context, share['id'], options).\ AndReturn(deleting_share) self.share_rpcapi.delete_share(self.context, deleting_share) self.mox.ReplayAll() self.api.delete(self.context, share) self.mox.UnsetStubs() self.mox.VerifyAll()
def _set_share_error_state_and_notify(self, method, context, ex, request_spec): LOG.error(_LE("Failed to schedule_%(method)s: %(ex)s"), {"method": method, "ex": ex}) share_state = {"status": "error"} properties = request_spec.get("share_properties", {}) share_id = request_spec.get("share_id", None) if share_id: db.share_update(context, share_id, share_state) payload = dict( request_spec=request_spec, share_properties=properties, share_id=share_id, state=share_state, method=method, reason=ex, ) rpc.get_notifier("scheduler").error(context, "scheduler." + method, payload)
def _set_share_error_state_and_notify(self, method, context, ex, request_spec): LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals()) share_state = {'status': 'error'} properties = request_spec.get('share_properties', {}) share_id = request_spec.get('share_id', None) if share_id: db.share_update(context, share_id, share_state) payload = dict(request_spec=request_spec, share_properties=properties, share_id=share_id, state=share_state, method=method, reason=ex) notifier.notify(context, notifier.publisher_id("scheduler"), 'scheduler.' + method, notifier.ERROR, payload)
def _set_share_error_state_and_notify(self, method, context, ex, request_spec): LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals()) share_state = {'status': 'error'} properties = request_spec.get('share_properties', {}) share_id = request_spec.get('share_id', None) if share_id: db.share_update(context, share_id, share_state) payload = dict(request_spec=request_spec, share_properties=properties, share_id=share_id, state=share_state, method=method, reason=ex) rpc.get_notifier("scheduler").error( context, 'scheduler.' + method, payload)
def _set_share_state_and_notify(self, method, state, context, ex, request_spec): LOG.error(_LE("Failed to schedule %(method)s: %(ex)s"), {"method": method, "ex": six.text_type(ex)}) properties = request_spec.get('share_properties', {}) share_id = request_spec.get('share_id', None) if share_id: db.share_update(context, share_id, state) payload = dict(request_spec=request_spec, share_properties=properties, share_id=share_id, state=state, method=method, reason=ex) rpc.get_notifier("scheduler").error( context, 'scheduler.' + method, payload)
def test_create_share_exception_puts_share_in_error_state(self): """Test that a NoValideHost exception for create_share. Puts the share in 'error' state and eats the exception. """ fake_share_id = 1 self._mox_schedule_method_helper('schedule_create_share') self.mox.StubOutWithMock(db, 'share_update') topic = 'fake_topic' share_id = fake_share_id request_spec = {'share_id': fake_share_id} self.manager.driver.schedule_create_share( self.context, request_spec, {}).AndRaise(exception.NoValidHost(reason="")) db.share_update(self.context, fake_share_id, {'status': 'error'}) self.mox.ReplayAll() self.manager.create_share(self.context, topic, share_id, request_spec=request_spec, filter_properties={})
def _set_share_error_state_and_notify(self, method, context, ex, request_spec): LOG.warning(_LW("Failed to schedule_%(method)s: %(ex)s"), {"method": method, "ex": ex}) share_state = {'status': 'error'} properties = request_spec.get('share_properties', {}) share_id = request_spec.get('share_id', None) if share_id: db.share_update(context, share_id, share_state) payload = dict(request_spec=request_spec, share_properties=properties, share_id=share_id, state=share_state, method=method, reason=ex) rpc.get_notifier("scheduler").error( context, 'scheduler.' + method, payload)
def _update(self, *args, **kwargs): db.share_update(*args, **kwargs)