Ejemplo n.º 1
0
Archivo: models.py Proyecto: no2a/trove
    def find_by_instance_id(cls, instance_id):
        if instance_id is None:
            raise exception.ModelNotFoundError(instance_id=instance_id)

        try:
            return cls.find_by(instance_id=instance_id)

        except exception.NotFound:
            LOG.exception(_("Error finding instance %s"), instance_id)
            raise exception.ModelNotFoundError(instance_id=instance_id)
Ejemplo n.º 2
0
Archivo: models.py Proyecto: no2a/trove
    def find_all_by_version(cls, guest_agent_version, deleted=0):
        if guest_agent_version is None:
            raise exception.ModelNotFoundError()

        heartbeats = cls.find_all(guest_agent_version=guest_agent_version,
                                  deleted=deleted)

        if heartbeats is None or heartbeats.count() == 0:
            raise exception.ModelNotFoundError(
                guest_agent_version=guest_agent_version)

        return heartbeats
Ejemplo n.º 3
0
    def find_by(cls, context=None, **conditions):
        model = cls.get_by(**conditions)

        if model is None:
            raise exception.ModelNotFoundError(_("%s Not Found") %
                                               cls.__name__)

        if ((context and not context.is_admin and hasattr(model, 'tenant_id')
             and model.tenant_id != context.tenant)):
            LOG.error("Tenant %s tried to access %s, owned by %s."
                      % (context.tenant, cls.__name__, model.tenant_id))
            raise exception.ModelNotFoundError(_("%s Not Found") %
                                               cls.__name__)

        return model
Ejemplo n.º 4
0
    def load(context, module_id):
        module = None
        try:
            if context.is_admin:
                module = DBModule.find_by(id=module_id, deleted=False)
            else:
                module = DBModule.find_by(
                    id=module_id, tenant_id=context.tenant, visible=True,
                    deleted=False)
        except exception.ModelNotFoundError:
            # See if we have the module in the 'all' tenant section
            if not context.is_admin:
                try:
                    module = DBModule.find_by(
                        id=module_id, tenant_id=None, visible=True,
                        deleted=False)
                except exception.ModelNotFoundError:
                    pass  # fall through to the raise below

        if not module:
            msg = _("Module with ID %s could not be found.") % module_id
            raise exception.ModelNotFoundError(msg)

        # Save the encrypted contents in case we need to put it back
        # when updating the record
        module.encrypted_contents = module.contents
        module.contents = Module.deprocess_contents(module.contents)
        return module
Ejemplo n.º 5
0
 def test_check_for_heartbeat_exception(self, mock_agent):
     # TODO(juice): maybe it would be ok to extend the test to validate
     # the is_active method on the heartbeat
     mock_agent.find_by.side_effect = exception.ModelNotFoundError("Uh Oh!")
     # execute
     self.assertRaises(exception.GuestTimeout, self.api._check_for_hearbeat)
     # validate
     self.assertEqual(mock_agent.is_active.call_count, 0)
Ejemplo n.º 6
0
 def setUp(self):
     super(SecurityGroupDeleteTest, self).setUp()
     inst_model.CONF = mock()
     self.context = mock()
     self.original_find_by = (
         sec_mod.SecurityGroupInstanceAssociation.find_by)
     self.original_delete = sec_mod.SecurityGroupInstanceAssociation.delete
     self.fException = Mock(side_effect=lambda *args, **kwargs: self._raise(
         exception.ModelNotFoundError()))
Ejemplo n.º 7
0
    def find_by(cls, context=None, **conditions):
        model = cls.get_by(**conditions)

        if model is None:
            raise exception.ModelNotFoundError(_("%(s_name)s Not Found") %
                                               {"s_name": cls.__name__})

        if ((context and not context.is_admin and hasattr(model, 'tenant_id')
             and model.tenant_id != context.tenant)):
            msg = _("Tenant %(s_tenant)s tried to access "
                    "%(s_name)s, owned by %(s_owner)s.") % {
                "s_tenant": context.tenant, "s_name": cls.__name__,
                "s_owner": model.tenant_id}

            LOG.error(msg)
            raise exception.ModelNotFoundError(msg)

        return model
Ejemplo n.º 8
0
 def setUp(self):
     super(SecurityGroupDeleteTest, self).setUp()
     self.inst_model_conf_patch = patch.object(inst_model, 'CONF')
     self.inst_model_conf_mock = self.inst_model_conf_patch.start()
     self.addCleanup(self.inst_model_conf_patch.stop)
     self.context = trove_testtools.TroveTestContext(self)
     self.original_find_by = (
         sec_mod.SecurityGroupInstanceAssociation.find_by)
     self.original_delete = sec_mod.SecurityGroupInstanceAssociation.delete
     self.fException = Mock(side_effect=lambda *args, **kwargs: self._raise(
         exception.ModelNotFoundError()))
Ejemplo n.º 9
0
 def find_by(cls, **conditions):
     model = cls.get_by(**conditions)
     if model is None:
         raise exception.ModelNotFoundError(_("%s Not Found") %
                                            cls.__name__)
     return model