Exemple #1
0
    def neighbordb_pattern(self):
        try:
            log.info('START: neighbordb_patterns')
            tag = 'tag=%s, fn=%s' % (self.tag, self.filename)

            (valid, failed) = self._validate_neighbordb()

            if self.invalid_patterns:
                failed_names = sorted([p[1] for p in failed])
                self.assertEqual(failed_names, 
                                 sorted(self.invalid_patterns),
                                 tag)
                self.assertEqual(len(failed), len(self.invalid_patterns), tag)

            p_all = self.valid_patterns.get('nodes') + \
                    self.valid_patterns.get('globals')
            if p_all:
                valid_actual = sorted([str(p[1]) for p in valid])
                valid_configured = sorted([str(x) for x in p_all])

                self.assertEqual(valid_actual, valid_configured, tag)

            log.info('END: neighbordb_pattern')
        except AssertionError as exc:
            print exc
            print traceback.format_exc()
            debug(exc)
Exemple #2
0
    def neighbordb_topology(self):
        try:
            log.info('START: neighbordb_test')
            tag = 'tag=%s, fn=%s' % (self.tag, self.filename)

            topo = self._load_neighbordb()
            self.assertIsNotNone(topo, tag)

            p_nodes = [p.name for p in topo.get_patterns() 
                       if topo.is_node_pattern(p)]
            p_globals = [p.name for p in topo.get_patterns()
                         if topo.is_global_pattern(p)]

            self.assertEqual(sorted(self.valid_patterns['nodes']),
                             sorted(p_nodes),
                             tag)
            self.assertEqual(sorted(self.valid_patterns['globals']),
                             sorted(p_globals),
                             tag)

            log.info('END: neighbordb_test')
            return topo
        except AssertionError as exc:
            print exc
            print traceback.format_exc()
            debug(exc)
Exemple #3
0
def load_tests(loader, tests, pattern):      # pylint: disable=W0613
    try:
        log.info('Start ndb tests')

        suite = unittest.TestSuite()
        test_list = get_test_list(TEST_DIR)
        log.info('Test list is %s', test_list)

        for test in test_list:
            log.info('Starting test harness %s', test)

            harness = yaml.load(open(test))
            if harness.get('debug'):
                enable_handler_console()

            tests = harness.get('tests', ['topology'])

            name = harness.get('ndb', 'neighbordb')
            filename = name.split('/')[-1]
            if filename in harness:
                ndb = harness.get(filename)
            else:
                assert os.path.exists(name)
                ndb = yaml.load(open(name))

            kwargs = dict()
            kwargs['valid_patterns'] = harness.get('valid_patterns', dict())
            kwargs['invalid_patterns'] = harness.get('invalid_patterns')
            kwargs['tag'] = harness.get('tag', filename)
            kwargs['filename'] = test

            for test in tests:
                assert test in ['pattern', 'topology']
                suite.addTest(NeighbordbTest('neighbordb_%s' % test, 
                                             ndb, **kwargs))

            if 'nodes' in harness and 'topology' in tests:
                for key in harness['nodes'].keys():
                    assert key in ['pass', 'fail']
                    entries = harness['nodes'][key]
                    if not entries is None:
                        for entry in entries:
                            filename = entry['name'].split('/')[-1]
                            kwargs['node'] = harness.get(filename, 
                                                         entry['name'])
                            kwargs['match'] = entry.get('match')
                            kwargs['tag'] = '%s:%s' % (harness.get('tag'), 
                                                       filename)
                            log.info('Adding node %s', name)
                            suite.addTest(NeighbordbTest('node_%s' % key, 
                                                         ndb, **kwargs))

    except Exception as exc:      # pylint: disable=W0703
        log.exception('Unexpected error trying to execute load_tests: %s' %
                      exc)
    else:
        return suite
Exemple #4
0
    def node_fail(self):
        try:
            log.info('START: node_fail')
            tag = 'tag=%s, fn=%s' % (self.tag, self.filename)

            node = load_node(self.node)
            self.assertIsNotNone(node, tag)

            neighbordb = self._load_neighbordb()
            self.assertIsNotNone(neighbordb, tag)

            result = neighbordb.match_node(node)

            self.assertFalse(result, tag)
            log.info('END: node_fail')
        except AssertionError as exc:
            print exc
            print traceback.format_exc()
            debug(exc)