예제 #1
0
파일: netlinkTests.py 프로젝트: Caez83/vdsm
    def test_events_keys(self):
        def _expected_events(nic, address, cidr):
            return deque([
                {'event': 'new_link', 'name': nic},
                {'event': 'new_addr', 'address': address + '/' + cidr},
                {'event': 'new_link', 'name': nic},
                {'event': 'new_addr', 'family': 'inet6'},
                {'event': 'new_link', 'name': nic},
                {'event': 'del_neigh'},
                {'event': 'del_addr', 'family': 'inet6'},
                {'address': address + '/' + cidr, 'event': 'del_addr'},
                {'destination': address, 'event': 'del_route'},
                {'event': 'del_link', 'name': nic}])

        with monitor.Monitor(timeout=self.TIMEOUT,
                             silent_timeout=True) as mon:
            dummy_name = dummy.create()
            dummy.setIP(dummy_name, IP_ADDRESS, IP_CIDR)
            dummy.setLinkUp(dummy_name)
            dummy.remove(dummy_name)

            expected_events = _expected_events(dummy_name, IP_ADDRESS, IP_CIDR)

            expected = expected_events.popleft()
            for event in mon:
                if _is_subdict(expected, event):
                    expected = expected_events.popleft()
                    if len(expected_events) == 0:
                        break

        self.assertEqual(0, len(expected_events), '%d expected events have not'
                         ' been caught (in the right order)'
                         % (1 + len(expected_events)))
예제 #2
0
    def test_events_keys(self):
        def _expected_events(nic, address, cidr):
            return deque([
                {'event': 'new_link', 'name': nic},
                {'event': 'new_addr', 'address': address + '/' + cidr},
                {'event': 'new_link', 'name': nic},
                {'event': 'new_link', 'name': nic},
                {'event': 'new_addr', 'family': 'inet6'},
                {'event': 'new_link', 'name': nic},
                {'event': 'del_neigh'},
                {'event': 'del_addr', 'family': 'inet6'},
                {'address': address + '/' + cidr, 'event': 'del_addr'},
                {'destination': address, 'event': 'del_route'},
                {'event': 'del_link', 'name': nic}])

        with monitor.Monitor(timeout=self.TIMEOUT,
                             silent_timeout=True) as mon:
            dummy_name = dummy.create()
            dummy.setIP(dummy_name, IP_ADDRESS, IP_CIDR)
            dummy.setLinkUp(dummy_name)
            dummy.remove(dummy_name)

            expected_events = _expected_events(dummy_name, IP_ADDRESS, IP_CIDR)

            expected = expected_events.popleft()
            for event in mon:
                if _is_subdict(expected, event):
                    expected = expected_events.popleft()
                    if len(expected_events) == 0:
                        break

        self.assertEqual(0, len(expected_events), '%d expected events have not'
                         ' been caught (in the right order)'
                         % (1 + len(expected_events)))
예제 #3
0
    def test_events_keys(self):
        def _simplify_event(event):
            """ Strips event keys except event, address, name, destination,
            family.
            """
            allow = set(['event', 'address', 'name', 'destination', 'family'])
            return {k: v for (k, v) in event.items() if k in allow}

        def _expected_events(nic, address, cidr):
            events_add = [
                {'event': 'new_link', 'name': nic},
                {'event': 'new_addr', 'address': address + '/' + cidr},
                {'event': 'new_link', 'name': nic}]
            events_del = [
                {'address': address + '/' + cidr, 'event': 'del_addr'},
                {'destination': address, 'event': 'del_route'},
                {'event': 'del_link', 'name': nic}]
            events_ipv6 = [
                {'event': 'new_addr', 'family': 'inet6'},
                {'event': 'del_neigh'},
                {'event': 'del_addr', 'family': 'inet6'}]
            if is_disabled_ipv6():
                return deque(events_add + events_del)
            else:
                return deque(events_add + events_ipv6 + events_del)

        with monitor.Monitor(timeout=self.TIMEOUT,
                             silent_timeout=True) as mon:
            dummy_name = dummy.create()
            dummy.setIP(dummy_name, IP_ADDRESS, IP_CIDR)
            dummy.setLinkUp(dummy_name)
            dummy.remove(dummy_name)

            expected_events = _expected_events(dummy_name, IP_ADDRESS, IP_CIDR)
            _expected = list(expected_events)
            _caught = []

            expected = expected_events.popleft()
            for event in mon:
                _caught.append(event)
                if _is_subdict(expected, event):
                    expected = expected_events.popleft()
                    if len(expected_events) == 0:
                        break

        self.assertEqual(0, len(expected_events), 'Expected events have not '
                         'been caught (in the right order).\n'
                         'Expected:\n%s.\nCaught:\n%s.' %
                         ('\n'.join([str(d) for d in _expected]),
                          '\n'.join([str(_simplify_event(d))
                                     for d in _caught])))
예제 #4
0
파일: netlinkTests.py 프로젝트: kvaps/vdsm
    def test_event_groups(self):
        with monitor.Monitor(timeout=self.TIMEOUT, groups=("ipv4-ifaddr",)) as mon_a:
            with monitor.Monitor(timeout=self.TIMEOUT, groups=("link", "ipv4-route")) as mon_l_r:
                dummy_name = dummy.create()
                dummy.setIP(dummy_name, IP_ADDRESS, IP_CIDR)
                dummy.setLinkUp(dummy_name)
                dummy.remove(dummy_name)

        for event in mon_a:
            self.assertIn("_addr", event["event"], "Caught event '%s' is not " "related to address." % event["event"])

        for event in mon_l_r:
            link_or_route = "_link" in event["event"] or "_route" in event["event"]
            self.assertTrue(link_or_route, "Caught event '%s' is not related " "to link or route." % event["event"])
예제 #5
0
파일: netlinkTests.py 프로젝트: Caez83/vdsm
    def test_event_groups(self):
        with monitor.Monitor(timeout=self.TIMEOUT,
                             groups=('ipv4-ifaddr',)) as mon_a:
            with monitor.Monitor(timeout=self.TIMEOUT,
                                 groups=('link', 'ipv4-route')) as mon_l_r:
                dummy_name = dummy.create()
                dummy.setIP(dummy_name, IP_ADDRESS, IP_CIDR)
                dummy.setLinkUp(dummy_name)
                dummy.remove(dummy_name)

        for event in mon_a:
            self.assertIn('_addr', event['event'], "Caught event '%s' is not "
                          "related to address." % event['event'])

        for event in mon_l_r:
            link_or_route = ('_link' in event['event'] or
                             '_route' in event['event'])
            self.assertTrue(link_or_route, "Caught event '%s' is not related "
                            "to link or route." % event['event'])
예제 #6
0
    def test_event_groups(self):
        with monitor.Monitor(timeout=self.TIMEOUT,
                             groups=('ipv4-ifaddr',)) as mon_a:
            with monitor.Monitor(timeout=self.TIMEOUT,
                                 groups=('link', 'ipv4-route')) as mon_l_r:
                dummy_name = dummy.create()
                dummy.setIP(dummy_name, IP_ADDRESS, IP_CIDR)
                dummy.setLinkUp(dummy_name)
                dummy.remove(dummy_name)

        for event in mon_a:
            self.assertIn('_addr', event['event'], "Caught event '%s' is not "
                          "related to address." % event['event'])

        for event in mon_l_r:
            link_or_route = ('_link' in event['event'] or
                             '_route' in event['event'])
            self.assertTrue(link_or_route, "Caught event '%s' is not related "
                            "to link or route." % event['event'])
예제 #7
0
파일: netlinkTests.py 프로젝트: kvaps/vdsm
    def test_events_keys(self):
        def _expected_events(nic, address, cidr):
            events_add = [
                {"event": "new_link", "name": nic},
                {"event": "new_addr", "address": address + "/" + cidr},
                {"event": "new_link", "name": nic},
            ]
            events_del = [
                {"address": address + "/" + cidr, "event": "del_addr"},
                {"destination": address, "event": "del_route"},
                {"event": "del_link", "name": nic},
            ]
            events_ipv6 = [
                {"event": "new_addr", "family": "inet6"},
                {"event": "del_neigh"},
                {"event": "del_addr", "family": "inet6"},
            ]
            if is_disabled_ipv6():
                return deque(events_add + events_del)
            else:
                return deque(events_add + events_ipv6 + events_del)

        with monitor.Monitor(timeout=self.TIMEOUT, silent_timeout=True) as mon:
            dummy_name = dummy.create()
            dummy.setIP(dummy_name, IP_ADDRESS, IP_CIDR)
            dummy.setLinkUp(dummy_name)
            dummy.remove(dummy_name)

            expected_events = _expected_events(dummy_name, IP_ADDRESS, IP_CIDR)

            expected = expected_events.popleft()
            for event in mon:
                if _is_subdict(expected, event):
                    expected = expected_events.popleft()
                    if len(expected_events) == 0:
                        break

        self.assertEqual(
            0,
            len(expected_events),
            "%d expected events have not" " been caught (in the right order)" % (1 + len(expected_events)),
        )
예제 #8
0
 def _set_and_remove_device():
     time.sleep(.2)
     dummy.setLinkUp(dummy_name)
     dummy.remove(dummy_name)
예제 #9
0
파일: netlinkTests.py 프로젝트: Caez83/vdsm
 def _set_and_remove_device():
     time.sleep(.2)
     dummy.setLinkUp(dummy_name)
     dummy.remove(dummy_name)