Ejemplo n.º 1
0
    def testIgnoring(self):
        tmpdir = tempfile.mkdtemp()
        fullname = os.path.join(tmpdir, 'ac194fc5-f317-412e-8611-fb290629f624')
        with open(fullname, 'a'):
            os.utime(fullname, None)
        self.addCleanup(lambda: os.unlink(fullname) and os.rmdir(tmpdir))
        w = worker.Worker(0, mock.Mock(), ignore_directory=tmpdir)

        tenant_id = '98dd9c41-d3ac-4fd6-8927-567afa0b8fc3'
        router_id = 'ac194fc5-f317-412e-8611-fb290629f624'
        msg = event.Event(
            tenant_id=tenant_id,
            router_id=router_id,
            crud=event.CREATE,
            body={'key': 'value'},
        )
        # Create the router manager and state machine so we can
        # replace the send_message() method with a mock.
        trm = w._get_trms(tenant_id)[0]
        sm = trm.get_state_machines(msg, worker.WorkerContext())[0]
        with mock.patch.object(sm, 'send_message') as meth:
            # The router id is being ignored, so the send_message()
            # method shouldn't ever be invoked.
            meth.side_effect = AssertionError('send_message was called')
            w.handle_message(tenant_id, msg)
Ejemplo n.º 2
0
def fake_worker_context():
    """Patches client API libs in the worker context.
    Caller should addCleanup(mock.patch.stopall).
    """
    fake_neutron_obj = mock.patch.object(neutron, 'Neutron',
                                         autospec=True).start()
    mock.patch.object(neutron, 'Neutron',
                      return_value=fake_neutron_obj).start()
    fake_nova_obj = mock.patch.object(nova, 'Nova', autospec=True).start()
    mock.patch.object(nova, 'Nova', return_value=fake_nova_obj).start()
    return worker.WorkerContext()
Ejemplo n.º 3
0
    def setUp(self):
        super(TestUpdateStateMachine, self).setUp()

        self.conf = mock.patch.object(vm_manager.cfg, 'CONF').start()
        self.conf.boot_timeout = 1
        self.conf.akanda_mgt_service_port = 5000
        self.conf.max_retries = 3
        self.conf.management_prefix = 'fdca:3ba5:a17a:acda::/64'

        mock.patch('akanda.rug.worker.nova').start()
        mock.patch('akanda.rug.worker.quantum').start()

        self.worker_context = worker.WorkerContext()

        self.addCleanup(mock.patch.stopall)
Ejemplo n.º 4
0
def debug_one_router(args=sys.argv[1:]):

    main.register_and_load_opts()

    # Add our extra option for specifying the router-id to debug
    cfg.CONF.register_cli_opts([
        cfg.StrOpt(
            'router-id',
            required=True,
            help='The UUID for the router to debug',
        ),
    ])
    cfg.CONF(args, project='akanda-rug')
    cfg.CONF.set_override('boot_timeout', 60000)

    logging.basicConfig(
        level=logging.DEBUG,
        format=':'.join(
            '%(' + n + ')s' for n in
            ['processName', 'threadName', 'name', 'levelname', 'message']),
    )

    log = logging.getLogger(__name__)
    log.debug('Proxy settings: %r', os.getenv('no_proxy'))

    context = worker.WorkerContext()
    router_obj = context.neutron.get_router_detail(cfg.CONF.router_id)
    a = state.Automaton(
        router_id=cfg.CONF.router_id,
        tenant_id=router_obj.tenant_id,
        delete_callback=delete_callback,
        bandwidth_callback=bandwidth_callback,
        worker_context=context,
        queue_warning_threshold=100,
        reboot_error_threshold=1,
    )

    a.send_message(Fake('update'))

    import pdb
    pdb.set_trace()

    a.update(context)
Ejemplo n.º 5
0
 def test_global_debug_no_message_sent(self):
     self.dbapi.enable_global_debug()
     tenant_id = '98dd9c41-d3ac-4fd6-8927-567afa0b8fc3'
     resource_id = 'ac194fc5-f317-412e-8611-fb290629f624'
     msg = event.Event(
         resource=event.Resource(router.Router.RESOURCE_NAME,
                                 resource_id,
                                 tenant_id),
         crud=event.CREATE,
         body={'key': 'value'},
     )
     # Create the router manager and state machine so we can
     # replace the send_message() method with a mock.
     trm = self.w._get_trms(tenant_id)[0]
     sm = trm.get_state_machines(msg, worker.WorkerContext())[0]
     with mock.patch.object(sm, 'send_message') as meth:
         # The tenant id is being ignored, so the send_message()
         # method shouldn't ever be invoked.
         meth.side_effect = AssertionError('send_message was called')
         self.w.handle_message(tenant_id, msg)
Ejemplo n.º 6
0
    def testDebugging(self):
        self.w._debug_routers = set(['ac194fc5-f317-412e-8611-fb290629f624'])

        tenant_id = '98dd9c41-d3ac-4fd6-8927-567afa0b8fc3'
        router_id = 'ac194fc5-f317-412e-8611-fb290629f624'
        msg = event.Event(
            tenant_id=tenant_id,
            router_id=router_id,
            crud=event.CREATE,
            body={'key': 'value'},
        )
        # Create the router manager and state machine so we can
        # replace the send_message() method with a mock.
        trm = self.w._get_trms(tenant_id)[0]
        sm = trm.get_state_machines(msg, worker.WorkerContext())[0]
        with mock.patch.object(sm, 'send_message') as meth:
            # The router id is being ignored, so the send_message()
            # method shouldn't ever be invoked.
            meth.side_effect = AssertionError('send_message was called')
            self.w.handle_message(tenant_id, msg)
Ejemplo n.º 7
0
 def setUp(self):
     super(TestUpdateStateMachine, self).setUp()
     self.worker_context = worker.WorkerContext()
Ejemplo n.º 8
0
 def test_message_enqueued(self):
     self.w.handle_message(self.tenant_id, self.msg)
     trm = self.w.tenant_managers[self.tenant_id]
     sm = trm.get_state_machines(self.msg, worker.WorkerContext())[0]
     self.assertEqual(len(sm._queue), 1)
Ejemplo n.º 9
0
 def setUp(self):
     super(TestResourceCache, self).setUp()
     self.resource_cache = worker.TenantResourceCache()
     self.worker_context = worker.WorkerContext()