Beispiel #1
0
    def test_parse_only_alive_interfaces(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.find_all(types=container.types)[0]
        collector = SystemMetaCollector(object=os_obj)
        collector.collect()

        # get interfaces info
        all_interfaces = netifaces.interfaces()
        alive_interfaces = set()
        down_interfaces = set()
        for interface_name, interface in psutil.net_if_stats().iteritems():
            if interface.isup:
                alive_interfaces.add(interface_name)
            else:
                down_interfaces.add(interface_name)

        # check interfaces
        collected_interfaces = os_obj.metad.current['network']['interfaces']
        for interface_info in collected_interfaces:
            assert_that(interface_info, has_key('name'))
            assert_that(interface_info, has_key('mac'))

            assert_that(interface_info, has_key('ipv4'))
            ipv4 = interface_info['ipv4']
            assert_that(ipv4, has_key('netmask'))
            assert_that(ipv4, has_key('address'))
            assert_that(ipv4, has_key('prefixlen'))

            name = interface_info['name']
            assert_that(all_interfaces, has_item(name))
            assert_that(alive_interfaces, has_item(name))
            assert_that(down_interfaces, not_(has_item(name)))
Beispiel #2
0
    def test_parse_only_alive_interfaces(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.find_all(types=container.types)[0]
        collector = SystemMetaCollector(object=os_obj)
        collector.collect()

        # get interfaces info
        all_interfaces = netifaces.interfaces()
        alive_interfaces = set()
        down_interfaces = set()
        for interface_name, interface in psutil.net_if_stats().iteritems():
            if interface.isup:
                alive_interfaces.add(interface_name)
            else:
                down_interfaces.add(interface_name)

        # check interfaces
        collected_interfaces = os_obj.metad.current['network']['interfaces']
        for interface_info in collected_interfaces:
            assert_that(interface_info, has_key('name'))
            assert_that(interface_info, has_key('mac'))

            assert_that(interface_info, has_key('ipv4'))
            ipv4 = interface_info['ipv4']
            assert_that(ipv4, has_key('netmask'))
            assert_that(ipv4, has_key('address'))
            assert_that(ipv4, has_key('prefixlen'))

            name = interface_info['name']
            assert_that(all_interfaces, has_item(name))
            assert_that(alive_interfaces, has_item(name))
            assert_that(down_interfaces, not_(has_item(name)))
Beispiel #3
0
 def get_collector(self, collect=True):
     manager = SystemManager()
     manager._discover_objects()
     obj = manager.objects.find_all(types=manager.types)[0]
     collector = SystemMetaCollector(object=obj)
     if collect:
         collector.collect()
     return collector
Beispiel #4
0
    def test_collect_each_interface_once(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.find_all(types=container.types)[0]
        collector = SystemMetaCollector(object=os_obj)

        num_interfaces = len(psutil.net_if_stats())
        for x in xrange(3):
            collector.collect()
            collected_interfaces = os_obj.metad.current['network']['interfaces']
            assert_that(collected_interfaces, only_contains(contains_inanyorder('mac', 'name', 'ipv4', 'ipv6')))
            assert_that(collected_interfaces, has_length(num_interfaces))
Beispiel #5
0
    def test_special_parse_restrictions(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.find_all(types=container.types)[0]
        collector = SystemMetaCollector(object=os_obj)
        assert_that(not_(collector.in_container))

        collector.collect()
        collected_meta = os_obj.metad.current

        assert_that(collected_meta, has_key('boot'))
        assert_that(collected_meta, has_key('hostname'))
        assert_that(collected_meta, has_key('ec2'))
Beispiel #6
0
    def test_special_parse_restrictions(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.find_all(types=container.types)[0]
        collector = SystemMetaCollector(object=os_obj)
        assert_that(not_(collector.in_container))

        collector.collect()
        collected_meta = os_obj.metad.current

        assert_that(collected_meta, has_key('boot'))
        assert_that(collected_meta, has_key('hostname'))
        assert_that(collected_meta, has_key('ec2'))
Beispiel #7
0
    def test_default_interface(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.find_all(types=container.types)[0]
        collector = SystemMetaCollector(object=os_obj)
        collector.collect()

        default_from_netstat, _ = subp.call(
            'netstat -nr | egrep -i "^0.0.0.0|default" | head -1 | sed "s/.*[ ]\([^ ][^ ]*\)$/\\1/"'
        )[0]

        default_interface = os_obj.metad.current['network']['default']

        assert_that(default_interface, equal_to(default_from_netstat))
Beispiel #8
0
    def test_collect_each_interface_once(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.find_all(types=container.types)[0]
        collector = SystemMetaCollector(object=os_obj)

        num_interfaces = len(psutil.net_if_stats())
        for x in xrange(3):
            collector.collect()
            collected_interfaces = os_obj.metad.current['network'][
                'interfaces']
            assert_that(collected_interfaces,
                        only_contains(contains_inanyorder('mac', 'name')))
            assert_that(collected_interfaces, has_length(num_interfaces))
Beispiel #9
0
    def test_default_interface(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.find_all(types=container.types)[0]
        collector = SystemMetaCollector(object=os_obj)
        collector.collect()

        default_from_netstat, _ = subp.call(
            'netstat -nr | egrep -i "^0.0.0.0|default" | head -1 | sed "s/.*[ ]\([^ ][^ ]*\)$/\\1/"'
        )[0]

        default_interface = os_obj.metad.current['network']['default']

        assert_that(default_interface, equal_to(default_from_netstat))