コード例 #1
0
    def test_throwExceptionIntoGenerator(self):
        """
        L{pb.CopiedFailure.throwExceptionIntoGenerator} will throw a
        L{RemoteError} into the given paused generator at the point where it
        last yielded.
        """
        original = pb.CopyableFailure(AttributeError("foo"))
        copy = jelly.unjelly(jelly.jelly(original, invoker=DummyInvoker()))
        exception = []

        def generatorFunc():
            try:
                yield None
            except pb.RemoteError as exc:
                exception.append(exc)
            else:
                self.fail("RemoteError not raised")

        gen = generatorFunc()
        gen.send(None)
        self.assertRaises(StopIteration, copy.throwExceptionIntoGenerator, gen)
        self.assertEqual(len(exception), 1)
        exc = exception[0]
        self.assertEqual(exc.remoteType, qual(AttributeError).encode("ascii"))
        self.assertEqual(exc.args, ("foo", ))
        self.assertEqual(exc.remoteTraceback, 'Traceback unavailable\n')
コード例 #2
0
 def test_twiceUnjelliedFailureCheck(self):
     """
     The object which results from jellying a L{CopyableFailure}, unjellying
     the result, creating a new L{CopyableFailure} from the result of that,
     jellying it, and finally unjellying the result of that has a check
     method which behaves the same way as the original L{CopyableFailure}'s
     check method.
     """
     original = pb.CopyableFailure(ZeroDivisionError())
     self.assertIs(original.check(ZeroDivisionError), ZeroDivisionError)
     self.assertIs(original.check(ArithmeticError), ArithmeticError)
     copiedOnce = jelly.unjelly(jelly.jelly(original, invoker=DummyInvoker()))
     derivative = pb.CopyableFailure(copiedOnce)
     copiedTwice = jelly.unjelly(jelly.jelly(derivative, invoker=DummyInvoker()))
     self.assertIs(copiedTwice.check(ZeroDivisionError), ZeroDivisionError)
     self.assertIs(copiedTwice.check(ArithmeticError), ArithmeticError)
コード例 #3
0
 def test_unjelliedFailureCheck(self):
     """
     An unjellied L{CopyableFailure} has a check method which behaves the
     same way as the original L{CopyableFailure}'s check method.
     """
     original = pb.CopyableFailure(ZeroDivisionError())
     self.assertIs(original.check(ZeroDivisionError), ZeroDivisionError)
     self.assertIs(original.check(ArithmeticError), ArithmeticError)
     copied = jelly.unjelly(jelly.jelly(original, invoker=DummyInvoker()))
     self.assertIs(copied.check(ZeroDivisionError), ZeroDivisionError)
     self.assertIs(copied.check(ArithmeticError), ArithmeticError)
コード例 #4
0
ファイル: test_pbfailure.py プロジェクト: DT021/wau
 def test_printTracebackIncludesValue(self):
     """
     When L{CopiedFailure.printTraceback} is used to print a copied failure
     which was unjellied from a L{CopyableFailure} with C{unsafeTracebacks}
     set to C{False}, the string representation of the exception value is
     included in the output.
     """
     original = pb.CopyableFailure(Exception("some reason"))
     copied = jelly.unjelly(jelly.jelly(original, invoker=DummyInvoker()))
     output = StringIO()
     copied.printTraceback(output)
     self.assertEqual(
         "Traceback from remote host -- Traceback unavailable\n"
         "exceptions.Exception: some reason\n", output.getvalue())
コード例 #5
0
        def _doDbWork():
            """
            return device object (either new or existing), and flag indicating
            whether device was newly created, or just updated
            """
            try:
                netroot = getNetworkRoot(self.dmd,
                    kw.get('performanceMonitor', 'localhost'))
                netobj = netroot.getNet(ip)
                netmask = 24
                if netobj is not None:
                    netmask = netobj.netmask
                else:
                    defaultNetmasks = getattr(netroot, 'zDefaultNetworkTree', [])
                    if defaultNetmasks:
                        netmask = defaultNetmasks[0]
                autoDiscover = getattr(netobj, 'zAutoDiscover', True)
                # If we're not supposed to discover this IP, return None
                if not force and not autoDiscover:
                    return None, False
                kw['manageIp'] = ipunwrap(ip)
                dev = manage_createDevice(self.dmd, **kw)
                netroot.createIp(ip, netmask)
                return dev, True
            except DeviceExistsError as e:
                # Update device with latest info from zendisc
                # (if necessary)
                if not e.dev.getManageIp():
                    e.dev.setManageIp(kw['manageIp'])

                # only overwrite title if it has not been set
                if not e.dev.title or isip(e.dev.title):
                    if not isip(kw.get('deviceName')):
                        e.dev.setTitle(kw['deviceName'])

                # copy kw->updateAttributes, to keep kw intact in case
                # we need to retry transaction
                updateAttributes = {}
                for k,v in kw.items():
                    if k not in ('manageIp', 'deviceName', 'devicePath',
                            'discoverProto', 'performanceMonitor', 'productionState'):
                        updateAttributes[k] = v
                # use updateDevice so we don't clobber existing device properties.
                e.dev.updateDevice(**updateAttributes)
                return e.dev, False
            except Exception as ex:
                log.exception("IP address %s (kw = %s) encountered error", ipunwrap(ip), kw)
                raise pb.CopyableFailure(ex)
コード例 #6
0
ファイル: test_pbfailure.py プロジェクト: DT021/wau
    def test_throwExceptionIntoGenerator(self):
        """
        L{pb.CopiedFailure.throwExceptionIntoGenerator} will throw a
        L{RemoteError} into the given paused generator at the point where it
        last yielded.
        """
        original = pb.CopyableFailure(AttributeError("foo"))
        copy = jelly.unjelly(jelly.jelly(original, invoker=DummyInvoker()))
        exception = []

        def generatorFunc():
            try:
                yield None
            except pb.RemoteError, exc:
                exception.append(exc)
            else:
コード例 #7
0
ファイル: base.py プロジェクト: pmisik/buildbot
 def commandComplete(self, failure):
     if failure:
         log.msg("WorkerForBuilder.commandFailed", self.command)
         log.err(failure)
         # failure, if present, is a failure.Failure. To send it across
         # the wire, we must turn it into a pb.CopyableFailure.
         failure = pb.CopyableFailure(failure)
         failure.unsafeTracebacks = True
     else:
         # failure is None
         log.msg("WorkerForBuilder.commandComplete", self.command)
     self.command = None
     if not self.running:
         log.msg(" but we weren't running, quitting silently")
         return
     if self.command_ref:
         d = self.protocol_complete(failure)
         d.addCallback(self.ackComplete)
         d.addErrback(self._ackFailed, "sendComplete")
         self.command_ref = None
コード例 #8
0
ファイル: base.py プロジェクト: DalavanCloud/buildbot-1
 def commandComplete(self, failure):
     if failure:
         log.msg("WorkerForBuilder.commandFailed", self.command)
         log.err(failure)
         # failure, if present, is a failure.Failure. To send it across
         # the wire, we must turn it into a pb.CopyableFailure.
         failure = pb.CopyableFailure(failure)
         failure.unsafeTracebacks = True
     else:
         # failure is None
         log.msg("WorkerForBuilder.commandComplete", self.command)
     self.command = None
     if not self.running:
         log.msg(" but we weren't running, quitting silently")
         return
     if self.remoteStep:
         self.remoteStep.dontNotifyOnDisconnect(self.lostRemoteStep)
         d = self.remoteStep.callRemote("complete", failure)
         d.addCallback(self.ackComplete)
         d.addErrback(self._ackFailed, "sendComplete")
         self.remoteStep = None
コード例 #9
0
    def command_complete(self, failure):
        if failure:
            log.msg("ProtocolCommandBase.command_complete (failure)",
                    self.command)
            log.err(failure)
            # failure, if present, is a failure.Failure. To send it across
            # the wire, we must turn it into a pb.CopyableFailure.
            failure = pb.CopyableFailure(failure)
            failure.unsafeTracebacks = True
        else:
            # failure is None
            log.msg("ProtocolCommandBase.command_complete (success)",
                    self.command)

        self.on_command_complete()
        if not self.builder_is_running:
            log.msg(" but we weren't running, quitting silently")
            return
        if not self.is_complete:
            d = self.protocol_complete(failure)
            d.addErrback(self._ack_failed,
                         "ProtocolCommandBase.command_complete")
            self.is_complete = True
コード例 #10
0
 def commandComplete(self, failure):
     running_metric.set(False, {'builder': self.name})
     steps_metric.increment({'builder': self.name, 'success': not failure})
     if failure:
         log.msg("SlaveBuilder.commandFailed", self.command)
         log.err(failure)
         # failure, if present, is a failure.Failure. To send it across
         # the wire, we must turn it into a pb.CopyableFailure.
         failure = pb.CopyableFailure(failure)
         failure.unsafeTracebacks = True
     else:
         # failure is None
         log.msg("SlaveBuilder.commandComplete", self.command)
     self.command = None
     if not self.running:
         log.msg(" but we weren't running, quitting silently")
         return
     if self.remoteStep:
         self.remoteStep.dontNotifyOnDisconnect(self.lostRemoteStep)
         d = self.remoteStep.callRemote("complete", failure)
         d.addCallback(self.ackComplete)
         d.addErrback(self._ackFailed, "sendComplete")
         self.remoteStep = None
コード例 #11
0
ファイル: DiscoverService.py プロジェクト: c0ns0le/zenoss-4
    def remote_createDevice(self, ip, force=False, **kw):
        """Create a device.

        @param ip: The manageIp of the device
        @param kw: The args to manage_createDevice.
        """
        # During discovery, if the device
        # shares an id with another device
        # with a different ip, set the device
        # title to the supplied id and replace
        # the id with the ip
        deviceName = kw['deviceName']
        if deviceName:
            device = self.dmd.Devices.findDeviceByIdExact(deviceName)
            if device and ip != device.manageIp:
                kw['deviceName'] = ip
                kw['title'] = deviceName

        from Products.ZenModel.Device import getNetworkRoot

        @transact
        def _doDbWork():
            """
            return device object (either new or existing), and flag indicating
            whether device was newly created, or just updated
            """
            try:
                netroot = getNetworkRoot(
                    self.dmd, kw.get('performanceMonitor', 'localhost'))
                netobj = netroot.getNet(ip)
                netmask = 24
                if netobj is not None:
                    netmask = netobj.netmask
                else:
                    defaultNetmasks = getattr(netroot, 'zDefaultNetworkTree',
                                              [])
                    if defaultNetmasks:
                        netmask = defaultNetmasks[0]
                netroot.createIp(ip, netmask)
                autoDiscover = getattr(netobj, 'zAutoDiscover', True)
                # If we're not supposed to discover this IP, return None
                if not force and not autoDiscover:
                    return None, False
                kw['manageIp'] = ipunwrap(ip)
                dev = manage_createDevice(self.dmd, **kw)
                return dev, True
            except DeviceExistsError, e:
                # Update device with latest info from zendisc
                e.dev.setManageIp(kw['manageIp'])

                # only overwrite title if it has not been set
                if not e.dev.title or isip(e.dev.title):
                    if not isip(kw.get('deviceName')):
                        e.dev.setTitle(kw['deviceName'])

                # copy kw->updateAttributes, to keep kw intact in case
                # we need to retry transaction
                updateAttributes = {}
                for k, v in kw.items():
                    if k not in ('manageIp', 'deviceName', 'devicePath',
                                 'discoverProto'):
                        updateAttributes[k] = v
                # use updateDevice so we don't clobber existing device properties.
                e.dev.updateDevice(**updateAttributes)
                return e.dev, False
            except Exception, ex:
                log.exception("IP address %s (kw = %s) encountered error",
                              ipunwrap(ip), kw)
                raise pb.CopyableFailure(ex)