def test_parse_only_alive_interfaces(self):
        container = SystemContainer()
        container.discover_objects()

        os_obj = container.objects.values().pop()
        collector = SystemCommonMetaCollector(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 intefaces
        collected_interfaces = os_obj.metad.current['network']['interfaces']
        for interface_info in collected_interfaces:
            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)))
    def etc_release(meta):
        SystemCommonMetaCollector.etc_release(meta)

        # centos6 has different  *-release format
        # for example: CentOS release 6.7 (Final)
        if meta['release']['version_id'] is None and meta['release']['version'] is None:
            etc_release_out, _ = subp.call('cat /etc/centos-release')
            for line in etc_release_out:
                r = re.match('(\w+)\s+(\w+)\s+([\d\.]+)\s+([\w\(\)]+)', line)
                if r:
                    meta['release']['name'] = r.group(1)
                    meta['release']['version_id'] = r.group(3)
                    meta['release']['version'] = '%s %s' % (r.group(3), r.group(4))
    def test_default_interface(self):
        container = SystemContainer()
        container.discover_objects()

        os_obj = container.objects.values().pop()
        collector = SystemCommonMetaCollector(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))