예제 #1
0
    def test_start_netflow_collection_fault2(self):
        logger = logging.getLogger("crawlutils")
        logger.info('>>> Testcase: collector fails to start')

        fc = FprobeContainerCrawler()
        assert fc.get_feature() == 'fprobe'

        # with fprobe failing to start, we won't get data
        res = []
        for data in fc.crawl(self.container['Id'], avoid_setns=False,
                             **self.params):
            res.append(data)
        assert len(res) == 0
예제 #2
0
    def test_crawl_outcontainer_fprobe(self):
        logger = logging.getLogger("crawlutils")
        logger.info('>>> Testcase: expecting collector output')

        fc = FprobeContainerCrawler()
        assert fc.get_feature() == 'fprobe'

        # the fake collector writes the single frame immediately
        res = []
        for data in fc.crawl(self.container['Id'], avoid_setns=False,
                             **self.params):
            res.append(data)
        assert len(res) == 1
예제 #3
0
    def test_remove_stale_files(self):
        logger = logging.getLogger("crawlutils")
        logger.info('>>> Testcase: stale file being removed')

        fc = FprobeContainerCrawler()
        assert fc.get_feature() == 'fprobe'

        # we pretend that an interface test.eth0 existed
        ifname = 'test.eth0'
        FprobeContainerCrawler.fprobes_started[ifname] = 1234

        self.params['output_filepattern'] = 'fprobe-{ifname}-{timestamp}'

        # have the fake socket-datacollector write a file with the ifname in
        # the filename
        fc.setup_outputdir(self.output_dir, os.getuid(), os.getgid())

        written_file = os.path.join(self.output_dir, 'test.output')
        with open(written_file, 'a') as f:
            f.write('hello')

        assert os.path.isfile(written_file)

        # mock the stale file timeout so that our file will get removed
        # with in reasonable time
        FprobeContainerCrawler.STALE_FILE_TIMEOUT = 5

        # calling fc.crawl() will not trigger a cleanup of that file
        # the first time
        logger.info('1st crawl')
        fc.crawl(self.container['Id'], avoid_setns=False, **self.params)

        # file should still be here
        assert os.path.isfile(written_file)

        # the next time we will crawl, the file will be removed
        FprobeContainerCrawler.next_cleanup = time.time()
        time.sleep(FprobeContainerCrawler.STALE_FILE_TIMEOUT + 1)

        logger.info('2nd crawl')
        fc.crawl(self.container['Id'], avoid_setns=False, **self.params)

        # file should be gone now
        assert not os.path.isfile(written_file)
예제 #4
0
    def test_remove_datafiles(self):
        logger = logging.getLogger("crawlutils")
        logger.info('>>> Testcase: datafiles of disappeared interface '
                    'being removed')

        fc = FprobeContainerCrawler()
        assert fc.get_feature() == 'fprobe'

        # we pretend that an interface test.eth0 existed
        ifname = 'test.eth0'
        FprobeContainerCrawler.fprobes_started[ifname] = 1234

        self.params['output_filepattern'] = 'fprobe-{ifname}-{timestamp}'

        # create a datafile for this fake interface
        timestamp = int(time.time())
        filepattern = 'fprobe-{ifname}-{timestamp}'.format(ifname=ifname,
                                                           timestamp=timestamp)
        params = [
            'socket-datacollector',
            '--dir', self.output_dir,
            '--filepattern', filepattern,
        ]

        # have the fake socket-datacollector write a file with the ifname in
        # the filename
        fc.setup_outputdir(self.output_dir, os.getuid(), os.getgid())
        simulate_socket_datacollector(params)
        written_file = os.path.join(self.output_dir, filepattern)
        assert os.path.isfile(written_file)

        FprobeContainerCrawler.next_cleanup = 0
        # calling fc.crawl() will trigger a cleanup of that file
        # since our fake interface never existed
        fc.crawl(self.container['Id'], avoid_setns=False, **self.params)

        # file should be gone now
        assert not os.path.isfile(written_file)
예제 #5
0
 def test_interfaces_with_fprobes(self):
     logger = logging.getLogger("crawlutils")
     logger.info('>>> Testcase: determine interfaces on which flow probes '
                 'are running')
     s = FprobeContainerCrawler.interfaces_with_fprobes()
     assert 'test.eth0' in s.keys()