コード例 #1
0
ファイル: test_congress.py プロジェクト: MustWin/congress
    def test_datasource_api_model(self):
        """Test the datasource api model.

        Same as test_multiple except we use the api interface
        instead of the DSE interface.
        """
        self.skipTest("Move to test/api/api_model and use fake driver...")
        # FIXME(arosen): we should break out these tests into
        # congress/tests/api/test_datasource.py
        with mock.patch("congress.managers.datasource.DataSourceDriverManager."
                        "get_datasource_drivers_info") as get_info:
            get_info.return_value = [{'datasource_driver': 'neutron'},
                                     {'datasource_driver': 'neutron2'},
                                     {'datasource_driver': 'nova'}]
            api = self.api
            engine = self.engine
            # Insert formula (which creates neutron services)
            net_formula = test_neutron.create_networkXnetwork_group('p')
            LOG.debug("Sending formula: %s", net_formula)
            context = {'policy_id': engine.DEFAULT_THEORY}
            api['rule'].add_item(
                {'rule': str(net_formula)}, {}, context=context)
            datasources = api['datasource'].get_items({})['results']
            datasources = [d['datasource_driver'] for d in datasources]
            self.assertEqual(set(datasources),
                             set(['neutron', 'neutron2', 'nova']))
コード例 #2
0
    def test_datasource_api_model(self):
        """Test the datasource api model.

        Same as test_multiple except we use the api interface
        instead of the DSE interface.
        """
        self.skipTest("Move to test/api/api_model and use fake driver...")
        # FIXME(arosen): we should break out these tests into
        # congress/tests/api/test_datasource.py
        with mock.patch("congress.managers.datasource.DataSourceDriverManager."
                        "get_datasource_drivers_info") as get_info:
            get_info.return_value = [{
                'datasource_driver': 'neutron'
            }, {
                'datasource_driver': 'neutron2'
            }, {
                'datasource_driver': 'nova'
            }]
            api = self.api
            engine = self.engine
            # Insert formula (which creates neutron services)
            net_formula = test_neutron.create_networkXnetwork_group('p')
            LOG.debug("Sending formula: %s", net_formula)
            context = {'policy_id': engine.DEFAULT_THEORY}
            (id1, rule) = api['rule'].add_item({'rule': str(net_formula)}, {},
                                               context=context)
            datasources = api['datasource'].get_items({})['results']
            datasources = [d['datasource_driver'] for d in datasources]
            self.assertEqual(set(datasources),
                             set(['neutron', 'neutron2', 'nova']))
コード例 #3
0
    def test_rule_api_model(self):
        """Test the rule api model.

        Same as test_multiple except we use the api interface
        instead of the DSE interface.
        """
        api = self.api
        cage = self.cage
        engine = self.engine
        policy = engine.DEFAULT_THEORY

        # Insert formula
        net_formula = test_neutron.create_networkXnetwork_group('p')
        LOG.debug("Sending formula: %s", net_formula)
        engine.debug_mode()
        context = {'policy_id': engine.DEFAULT_THEORY}
        (id1, rule) = api['rule'].add_item({'rule': str(net_formula)}, {},
                                           context=context)
        # Poll
        neutron = cage.service_object('neutron')
        neutron2 = cage.service_object('neutron2')
        neutron.poll()
        neutron2.poll()
        # Insert a second formula
        other_formula = engine.parse1('q(x,y) :- p(x,y)')
        (id2, rule) = api['rule'].add_item({'rule': str(other_formula)}, {},
                                           context=context)
        ans1 = ('p("240ff9df-df35-43ae-9df5-27fae87f2492",  '
                '  "240ff9df-df35-43ae-9df5-27fae87f2492") ')
        ans2 = ('q("240ff9df-df35-43ae-9df5-27fae87f2492",  '
                '  "240ff9df-df35-43ae-9df5-27fae87f2492") ')
        # Wait for first query so messages can be delivered.
        #    But once the p table has its data, no need to wait anymore.
        helper.retry_check_db_equal(engine, 'p(x,y)', ans1, target=policy)
        e = helper.db_equal(engine.select('q(x,y)', target=policy), ans2)
        self.assertTrue(e, "Insert rule-api 2")
        # Get formula
        ruleobj = api['rule'].get_item(id1, {}, context=context)
        self.assertTrue(e, net_formula == engine.parse1(ruleobj['rule']))
        # Get all formulas
        ds = api['rule'].get_items({}, context=context)['results']
        self.assertEqual(len(ds), 2)
        ids = set([x['id'] for x in ds])
        rules = set([engine.parse1(x['rule']) for x in ds])
        self.assertEqual(ids, set([id1, id2]))
        self.assertEqual(rules, set([net_formula, other_formula]))
        # Delete formula
        api['rule'].delete_item(id1, {}, context=context)
        # Get all formulas
        ds = api['rule'].get_items({}, context=context)['results']
        self.assertEqual(len(ds), 1)
        ids = sorted([x['id'] for x in ds])
        self.assertEqual(ids, sorted([id2]))
コード例 #4
0
ファイル: test_congress.py プロジェクト: ekcs/congress
    def test_rule_api_model(self):
        """Test the rule api model.

        Same as test_multiple except we use the api interface
        instead of the DSE interface.
        """
        api = self.api
        cage = self.cage
        engine = self.engine
        policy = engine.DEFAULT_THEORY

        # Insert formula
        net_formula = test_neutron.create_networkXnetwork_group('p')
        LOG.debug("Sending formula: %s", net_formula)
        engine.debug_mode()
        context = {'policy_id': engine.DEFAULT_THEORY}
        (id1, _) = api['rule'].add_item(
            {'rule': str(net_formula)}, {}, context=context)
        # Poll
        neutron = cage.service_object('neutron')
        neutron2 = cage.service_object('neutron2')
        neutron.poll()
        neutron2.poll()
        # Insert a second formula
        other_formula = engine.parse1('q(x,y) :- p(x,y)')
        (id2, _) = api['rule'].add_item(
            {'rule': str(other_formula)}, {}, context=context)
        ans1 = ('p("240ff9df-df35-43ae-9df5-27fae87f2492",  '
                '  "240ff9df-df35-43ae-9df5-27fae87f2492") ')
        ans2 = ('q("240ff9df-df35-43ae-9df5-27fae87f2492",  '
                '  "240ff9df-df35-43ae-9df5-27fae87f2492") ')
        # Wait for first query so messages can be delivered.
        #    But once the p table has its data, no need to wait anymore.
        helper.retry_check_db_equal(engine, 'p(x,y)', ans1, target=policy)
        e = helper.db_equal(engine.select('q(x,y)', target=policy), ans2)
        self.assertTrue(e, "Insert rule-api 2")
        # Get formula
        ruleobj = api['rule'].get_item(id1, {}, context=context)
        self.assertTrue(e, net_formula == engine.parse1(ruleobj['rule']))
        # Get all formulas
        ds = api['rule'].get_items({}, context=context)['results']
        self.assertEqual(len(ds), 2)
        ids = set([x['id'] for x in ds])
        rules = set([engine.parse1(x['rule']) for x in ds])
        self.assertEqual(ids, set([id1, id2]))
        self.assertEqual(rules, set([net_formula, other_formula]))
        # Delete formula
        api['rule'].delete_item(id1, {}, context=context)
        # Get all formulas
        ds = api['rule'].get_items({}, context=context)['results']
        self.assertEqual(len(ds), 1)
        ids = sorted([x['id'] for x in ds])
        self.assertEqual(ids, sorted([id2]))
コード例 #5
0
    def test_datasource_api_model(self):
        """Test the datasource api model.

        Same as test_multiple except we use the api interface
        instead of the DSE interface.
        """
        api = self.api
        engine = self.engine
        # Insert formula (which creates neutron services)
        net_formula = test_neutron.create_networkXnetwork_group('p')
        LOG.debug("Sending formula: %s", net_formula)
        context = {'policy_id': engine.DEFAULT_THEORY}
        (id1, rule) = api['rule'].add_item({'rule': str(net_formula)}, {},
                                           context=context)
        datasources = api['datasource'].get_items({})['results']
        datasources = [d['id'] for d in datasources]
        self.assertEqual(set(datasources), set(['neutron', 'neutron2',
                                                'nova']))
コード例 #6
0
    def test_multiple(self):
        """Test polling and publishing of multiple neutron instances."""
        api = self.api
        cage = self.cage
        engine = self.engine
        policy = engine.DEFAULT_THEORY

        # Send formula
        formula = test_neutron.create_networkXnetwork_group('p')
        api['rule'].publish('policy-update',
                            [agnostic.Event(formula, target=policy)])
        helper.retry_check_nonempty_last_policy_change(engine)
        # poll datasources
        neutron = cage.service_object('neutron')
        neutron2 = cage.service_object('neutron2')
        neutron.poll()
        neutron2.poll()
        # check answer
        ans = ('p("240ff9df-df35-43ae-9df5-27fae87f2492",  '
               '  "240ff9df-df35-43ae-9df5-27fae87f2492") ')
        helper.retry_check_db_equal(engine, 'p(x,y)', ans, target=policy)
コード例 #7
0
ファイル: test_congress.py プロジェクト: gongwayne/Openstack
    def test_multiple(self):
        """Test polling and publishing of multiple neutron instances."""
        api = self.api
        cage = self.cage
        engine = self.engine
        policy = engine.DEFAULT_THEORY

        # Send formula
        formula = test_neutron.create_networkXnetwork_group('p')
        api['rule'].publish(
            'policy-update', [compile.Event(formula, target=policy)])
        helper.retry_check_nonempty_last_policy_change(engine)
        # poll datasources
        neutron = cage.service_object('neutron')
        neutron2 = cage.service_object('neutron2')
        neutron.poll()
        neutron2.poll()
        # check answer
        ans = ('p("240ff9df-df35-43ae-9df5-27fae87f2492",  '
               '  "240ff9df-df35-43ae-9df5-27fae87f2492") ')
        helper.retry_check_db_equal(engine, 'p(x,y)', ans, target=policy)