Exemple #1
0
    def testRenderHTTPAllowDefault(self):
        streamer = FakeStreamer(mediumClass=FakeAuthFailingMedium)
        httpauth = HTTPAuthentication(streamer)
        resource = resources.HTTPStreamingResource(streamer, httpauth)
        httpauth.setBouncerName('fakebouncer')

        streamer.caps = True
        self.failUnless(resource.isReady())

        d = defer.Deferred()

        def wrongToken(_):
            request = FakeRequest(user='******')
            return self.deferAssertUnauthorized(httpauth, request)

        def errorDisallowDefault(_, error):
            streamer.medium.failure = error
            request = FakeRequest(user='******')
            return self.deferAssertInternalServerError(httpauth, request)

        def errorAllowDefault(_, error):
            streamer.medium.failure = error
            httpauth.setAllowDefault(True)
            request = FakeRequest(user='******')
            return self.deferAssertAuthorized(httpauth, request)

        d.addCallback(wrongToken)
        d.addCallback(errorDisallowDefault, errors.NotConnectedError())
        d.addCallback(errorDisallowDefault, errors.UnknownComponentError())
        d.addCallback(errorAllowDefault, errors.NotConnectedError())
        d.addCallback(errorAllowDefault, errors.UnknownComponentError())

        d.callback(None)
        return d
Exemple #2
0
    def perspective_upstreamList(self, avatarId):
        """
        List a component and its upstream components along with
        types and worker hosts.

        @param avatarId: the component avatar id
        @type  avatarId: str
        """

        def get_eaters_ids(eaters_dic):
            avatars = []
            for flow in eaters_dic.keys():
                comps = eaters_dic[flow]
                for c in comps:
                    (name, what) = c[0].split(':')
                    avatars.append('/%s/%s' % (flow, name))
            return avatars

        def create_response(components, workers):
            comps = []
            for c in components:
                workerName = c.get('workerName')
                host = "unknown"
                for w in workers:
                    if workerName == w.get('name'):
                        host = w.get('host')
                        break
                comps.append((c.get('name'), c.get('type'), host))
            return comps

        component = util.findComponent(self.vishnu.state, avatarId)
        if not component:
            self.warning('No component with avatar id %s' % avatarId)
            raise errors.UnknownComponentError(avatarId)

        eaters = component.get('config').get('eater', {})
        eaters_id = get_eaters_ids(eaters)
        comps = [component]
        while len(eaters_id) > 0:
            eaters = {}
            for i in eaters_id:
                try:
                    compState = util.findComponent(self.vishnu.state, i)
                    comps.append(compState)
                    eaters.update(compState.get('config').get('eater', {}))
                except Exception, e:
                    self.debug(log.getExceptionMessage(e))
                    emsg = "Error retrieving component '%s'" % i
                    raise errors.UnknownComponentError(emsg)
            eaters_id = get_eaters_ids(eaters)
Exemple #3
0
    def perspective_keepAlive(self, bouncerName, issuerName, ttl):
        """
        Resets the expiry timeout for keycards issued by issuerName. See
        L{flumotion.component.bouncers.bouncer} for more information.

        @since: 0.4.3

        @param bouncerName: the name of the atmosphere bouncer, or None
        @type  bouncerName: str or None
        @param issuerName: the issuer for which keycards should be kept
                           alive; that is to say, keycards with the
                           attribute 'issuerName' set to this value will
                           have their ttl values reset.
        @type  issuerName: str
        @param ttl: the new expiry timeout
        @type  ttl: number

        @returns: a deferred which will fire success or failure.
        """
        self.debug('keycards keepAlive on behalf of %s, ttl=%d', issuerName,
                   ttl)

        if not bouncerName:
            return self.vishnu.bouncer.keepAlive(issuerName, ttl)

        self.debug('looking for bouncer %s in atmosphere', bouncerName)
        avatarId = common.componentId('atmosphere', bouncerName)
        if not self.heaven.hasAvatar(avatarId):
            self.warning('No bouncer with id %s registered', avatarId)
            raise errors.UnknownComponentError(avatarId)

        bouncerAvatar = self.heaven.getAvatar(avatarId)
        return bouncerAvatar.keepAlive(issuerName, ttl)
Exemple #4
0
    def perspective_authenticate(self, bouncerName, keycard):
        """
        Authenticate the given keycard.
        If no bouncerName given, authenticate against the manager's bouncer.
        If a bouncerName is given, authenticate against the given bouncer
        in the atmosphere.

        @since: 0.3.1

        @param bouncerName: the name of the atmosphere bouncer, or None
        @type  bouncerName: str or None
        @param keycard:     the keycard to authenticate
        @type  keycard:     L{flumotion.common.keycards.Keycard}

        @returns: a deferred, returning the keycard or None.
        """
        if not bouncerName:
            self.debug(
                'asked to authenticate keycard %r using manager bouncer' %
                keycard)
            return self.vishnu.bouncer.authenticate(keycard)

        self.debug('asked to authenticate keycard %r using bouncer %s' %
                   (keycard, bouncerName))
        avatarId = common.componentId('atmosphere', bouncerName)
        if not self.heaven.hasAvatar(avatarId):
            self.warning('No bouncer with id %s registered' % avatarId)
            raise errors.UnknownComponentError(avatarId)

        bouncerAvatar = self.heaven.getAvatar(avatarId)
        return bouncerAvatar.authenticate(keycard)
Exemple #5
0
    def killJobByPid(self, pid, signum):
        if pid not in self._jobInfos:
            raise errors.UnknownComponentError(pid)

        jobInfo = self._jobInfos[pid]
        self.debug("Sending signal %d to job %s at pid %d", signum,
                   jobInfo.avatarId, jobInfo.pid)
        signalPid(jobInfo.pid, signum)
Exemple #6
0
    def perspective_componentInvoke(self, avatarId, methodName,
                                    *args, **kwargs):
        """
        Call a remote method on the component.

        @param avatarId: the component avatar id
        @type  avatarId: str
        @param methodName: name of the method to call
        @type  methodName: str
        """
        component = util.findComponent(self.vishnu.state, avatarId)
        if not component:
            self.warning('No component with avatar id %s' % avatarId)
            raise errors.UnknownComponentError(avatarId)
        return self.perspective_componentCallRemote(component, methodName,
                                                    *args, **kwargs)
Exemple #7
0
    def perspective_removeKeycardId(self, bouncerName, keycardId):
        """
        Remove a keycard on the given bouncer on behalf of a
        component's medium.

        This is requested by a component that created the keycard.

        @type  bouncerName: str
        @param keycardId:   id of keycard to remove
        @type  keycardId:   str
        """
        avatarId = common.componentId('atmosphere', bouncerName)
        if not self.heaven.hasAvatar(avatarId):
            self.warning('No bouncer with id %s registered', avatarId)
            raise errors.UnknownComponentError(avatarId)

        return self.heaven.getAvatar(avatarId).removeKeycardId(keycardId)
Exemple #8
0
    def perspective_componentCallRemote(self, componentState, methodName,
                                        *args, **kwargs):
        """
        Call a method on the given component on behalf of an admin client.

        @param componentState: state of the component to call the method on
        @type  componentState: L{planet.ManagerComponentState}
        @param methodName:     name of the method to call.  Gets proxied to
                               L{flumotion.component.component.""" \
                               """BaseComponentMedium}'s remote_(methodName)
        @type  methodName:     str

        @rtype: L{twisted.internet.defer.Deferred}
        """
        assert isinstance(componentState, planet.ManagerComponentState), \
            "%r is not a componentState" % componentState

        if methodName == "start":
            self.warning('forwarding "start" to perspective_componentStart')
            return self.perspective_componentStart(componentState)

        m = self.vishnu.getComponentMapper(componentState)
        if not m:
            self.warning('Component not mapped. Maybe deleted.')
            raise errors.UnknownComponentError(componentState)

        avatar = m.avatar

        if not avatar:
            self.warning('No avatar for %s, cannot call remote' %
                componentState.get('name'))
            raise errors.SleepingComponentError(componentState)

        # XXX: Maybe we need to have a prefix, so we can limit what an
        # admin interface can call on a component
        try:
            return avatar.mindCallRemote(methodName, *args, **kwargs)
        except Exception, e:
            msg = "exception on remote call %s: %s" % (methodName,
                log.getExceptionMessage(e))
            self.warning(msg)
            raise errors.RemoteMethodError(methodName,
                log.getExceptionMessage(e))
Exemple #9
0
    def perspective_expireKeycard(self, requesterId, keycardId):
        """
        Expire a keycard (and thus the requester's connection)
        issued to the given requester.

        This is called by the bouncer component that authenticated the keycard.

        @param requesterId: name (avatarId) of the component that originally
                              requested authentication for the given keycardId
        @type  requesterId: str
        @param keycardId:     id of keycard to expire
        @type  keycardId:     str
        """
        # FIXME: we should also be able to expire manager bouncer keycards
        if not self.heaven.hasAvatar(requesterId):
            self.warning(
                'asked to expire keycard %s for requester %s, '
                'but no such component registered', keycardId, requesterId)
            raise errors.UnknownComponentError(requesterId)

        return self.heaven.getAvatar(requesterId).expireKeycard(keycardId)
Exemple #10
0
    def perspective_expireKeycards(self, requesterId, keycardIds):
        """
        Expire multiple keycards (and thus the requester's connections)
        issued to the given requester.

        This is called by the bouncer component that authenticated
        the keycards.

        @param requesterId: name (avatarId) of the component that originally
                            requested authentication for the given keycardId
        @type  requesterId: str
        @param keycardIds:  sequence of id of keycards to expire
        @type  keycardIds:  sequence of str
        """
        if not self.heaven.hasAvatar(requesterId):
            self.warning(
                'asked to expire %d keycards for requester %s, '
                'but no such component registered', len(keycardIds),
                requesterId)
            raise errors.UnknownComponentError(requesterId)

        return self.heaven.getAvatar(requesterId).expireKeycards(keycardIds)