Exemplo n.º 1
0
    def do_call_method(self, args, **kwargs):
        method = args[0]
        if method == 'help':
            raise Error("Did you mean '{0.name} --help'?".format(self))
        if method not in self.choices:
            raise Error('Unknown {0.name} method {1}'.format(self, method))

        destination = kwargs.get('destination')
        timeout = kwargs.get('timeout') or self.choices[method][0]
        if destination and isinstance(destination, string_t):
            destination = [dest.strip() for dest in destination.split(',')]

        try:
            handler = getattr(self, method)
        except AttributeError:
            handler = self.call

        replies = handler(method,
                          *args[1:],
                          timeout=timeout,
                          destination=destination,
                          callback=self.say_remote_command_reply)
        if not replies:
            raise Error('No nodes replied within time constraint.',
                        status=EX_UNAVAILABLE)
        return replies
Exemplo n.º 2
0
 def run(self, what=None, *_, **kw):
     topics = {'bindings': self.list_bindings}
     available = ', '.join(topics)
     if not what:
         raise Error('You must specify one of {0}'.format(available))
     if what not in topics:
         raise Error('unknown topic {0!r} (choose one of: {1})'.format(
             what, available))
     with self.app.connection() as conn:
         self.app.amqp.TaskConsumer(conn).declare()
         topics[what](conn.manager)
Exemplo n.º 3
0
    def test_execute(self):
        x = CeleryCommand(app=self.app)
        Help = x.commands['help'] = Mock()
        help = Help.return_value = Mock()
        x.execute('fooox', ['a'])
        help.run_from_argv.assert_called_with(x.prog_name, [], command='help')
        help.reset()
        x.execute('help', ['help'])
        help.run_from_argv.assert_called_with(x.prog_name, [], command='help')

        Dummy = x.commands['dummy'] = Mock()
        dummy = Dummy.return_value = Mock()
        exc = dummy.run_from_argv.side_effect = Error(
            'foo', status='EX_FAILURE',
        )
        x.on_error = Mock(name='on_error')
        help.reset()
        x.execute('dummy', ['dummy'])
        x.on_error.assert_called_with(exc)
        dummy.run_from_argv.assert_called_with(
            x.prog_name, [], command='dummy',
        )
        help.run_from_argv.assert_called_with(
            x.prog_name, [], command='help',
        )

        exc = dummy.run_from_argv.side_effect = x.UsageError('foo')
        x.on_usage_error = Mock()
        x.execute('dummy', ['dummy'])
        x.on_usage_error.assert_called_with(exc)
Exemplo n.º 4
0
    def list_bindings(self, management):
        try:
            bindings = management.get_bindings()
        except NotImplementedError:
            raise Error('Your transport cannot list bindings.')

        fmt = lambda q, e, r: self.out('{0:<28} {1:<28} {2}'.format(q, e, r))
        fmt('Queue', 'Exchange', 'Routing Key')
        fmt('-' * 16, '-' * 16, '-' * 16)
        for b in bindings:
            fmt(b['destination'], b['source'], b['routing_key'])
Exemplo n.º 5
0
 def run(self, *args, **kwargs):
     I = inspect(app=self.app,
                 no_color=kwargs.get('no_color', False),
                 stdout=self.stdout,
                 stderr=self.stderr,
                 show_reply=False,
                 show_body=False,
                 quiet=True)
     replies = I.run('ping', **kwargs)
     if not replies:
         raise Error('No nodes replied within time constraint',
                     status=EX_UNAVAILABLE)
     nodecount = len(replies)
     if not kwargs.get('quiet', False):
         self.out('\n{0} {1} online.'.format(
             nodecount, text.pluralize(nodecount, 'node')))
Exemplo n.º 6
0
 def run(self, *args, **kwargs):
     if not args:
         raise Error('Missing {0.name} method. See --help'.format(self))
     return self.do_call_method(args, **kwargs)
Exemplo n.º 7
0
 def error_run():
     raise Error('error', EX_FAILURE)
Exemplo n.º 8
0
 def test_Error_repr(self):
     x = Error('something happened')
     self.assertIsNotNone(x.status)
     self.assertTrue(x.reason)
     self.assertTrue(str(x))
Exemplo n.º 9
0
 def test_Error_repr(self):
     x = Error('something happened')
     assert x.status is not None
     assert x.reason
     assert str(x)