Exemplo n.º 1
0
    def test_register_multiple_callbacks(self):
        evt = libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE

        called = [False] * NUM

        def _cb(conn, dom, opaque):
            called[opaque] = True

        conn = connection.Connection()
        for idx in range(NUM):
            conn.domainEventRegisterAny(None, evt, _cb, None)

        self.assertFalse(all(called))
        for idx in range(NUM):
            events.fire(evt, None, idx)
        self.assertTrue(all(called))
Exemplo n.º 2
0
    def test_register_any(self):
        libvirt_events = (
            libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
            libvirt.VIR_DOMAIN_EVENT_ID_REBOOT,
            libvirt.VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
            libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON,
            libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS,
            libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
            libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG,
        )

        conn = connection.Connection()
        for ev in libvirt_events:
            conn.domainEventRegisterAny(None, ev, _handler, ev)

        self.assertEquals(tuple(sorted(libvirt_events)),
                          tuple(sorted(events.root.registered)))
Exemplo n.º 3
0
    def test_domain_all_present(self):
        evt = libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE

        delivered = []

        def _cb(*args, **kwargs):
            delivered.append(args)

        conn = connection.Connection()
        with conttestlib.tmp_run_dir():
            dom = conn.defineXML(conttestlib.minimal_dom_xml(), 0)
            conn.domainEventRegisterAny(dom, evt, _cb, None)

            def _fake_get_all():
                return [dom.runtimeUUIDString()]

            monitoring.watchdog(_fake_get_all)

        self.assertEqual(delivered, [])
Exemplo n.º 4
0
    def test_monitor_domains_missing(self):
        evt = libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE

        delivered = []

        def _cb(*args, **kwargs):
            delivered.append(args)

        conn = connection.Connection()
        with conttestlib.tmp_run_dir():
            dom = conn.defineXML(conttestlib.minimal_dom_xml(), 0)
            conn.domainEventRegisterAny(dom, evt, _cb, None)
            containers.monitorAllDomains()

        expected = [
            (conn, dom, libvirt.VIR_DOMAIN_EVENT_STOPPED,
             libvirt.VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN),
        ]

        self.assertEqual(delivered, expected)
Exemplo n.º 5
0
    def test_domain_disappeared(self):
        evt = libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE

        delivered = []

        def _cb(*args, **kwargs):
            delivered.append(args)

        conn = connection.Connection()
        with conttestlib.tmp_run_dir():
            dom = conn.defineXML(conttestlib.minimal_dom_xml(), 0)
            conn.domainEventRegisterAny(dom, evt, _cb, None)
            monitoring.watchdog(lambda: [])

        self.assertEqual(delivered, [(
            conn,
            dom,
            libvirt.VIR_DOMAIN_EVENT_STOPPED,
            libvirt.VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN,
        )])
Exemplo n.º 6
0
    def test_register_specific_dom(self):
        evt = libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE

        called = [False]

        def _cb(*args, **kwargs):
            called[0] = True

        conn = connection.Connection()
        dom = domain.Domain(conttestlib.minimal_dom_xml())
        conn.domainEventRegisterAny(dom, evt, _cb, None)

        # FIXME
        self.assertEquals(tuple(),
                          tuple(sorted(events.root.registered)))
        self.assertEquals((evt,),
                          tuple(sorted(dom.events.registered)))

        dom.events.fire(evt, None)
        self.assertTrue(called[0])