def setUp(self):
        super(BenchmarkDatasource, self).setUp()
        config = {'benchmark': {
                  'module': helper.data_module_path('benchmark_driver.py'),
                  'poll_time': 0}}
        cage = harness.create(helper.root_path(), None, config)
        engine = cage.service_object('engine')
        api = {'policy': cage.service_object('api-policy'),
               'rule': cage.service_object('api-rule'),
               'table': cage.service_object('api-table'),
               'row': cage.service_object('api-row'),
               'datasource': cage.service_object('api-datasource'),
               'status': cage.service_object('api-status'),
               'schema': cage.service_object('api-schema')}
        helper.retry_check_subscriptions(engine, [(api['rule'].name,
                                         'policy-update')])
        helper.retry_check_subscribers(api['rule'], [(engine.name,
                                       'policy-update')])
        self.assertTrue('benchmark' in cage.services)
        datasource = cage.service_object('benchmark')
        table_name = datasource.BENCHTABLE

        self.assertEqual(datasource.state, {})

        # add a subscriber to ensure the updates end up in datasource.dataPath
        pubdata = datasource.pubdata.setdefault(table_name,
                                                dataobj.pubData(table_name))
        pubdata.addsubscriber(self.__class__.__name__, "push", "")
        self.assertTrue(datasource.pubdata[table_name])

        self.cage = cage
        self.engine = engine
        self.api = api
        self.table_name = table_name
        self.datasource = datasource
示例#2
0
 def test_startup(self):
     """Test that everything is properly loaded at startup."""
     engine = self.engine
     api = self.api
     helper.retry_check_subscriptions(engine,
                                      [(api['rule'].name, 'policy-update')])
     helper.retry_check_subscribers(api['rule'],
                                    [(engine.name, 'policy-update')])
示例#3
0
 def test_startup(self):
     """Test that everything is properly loaded at startup."""
     engine = self.engine
     api = self.api
     helper.retry_check_subscriptions(
         engine, [(api['rule'].name, 'policy-update')])
     helper.retry_check_subscribers(
         api['rule'], [(engine.name, 'policy-update')])
示例#4
0
 def test_policy_subscriptions(self):
     """Test that policy engine subscriptions adjust to policy changes."""
     engine = self.engine
     api = self.api
     cage = self.cage
     # Send formula
     formula = create_network_group('p')
     LOG.debug("Sending formula: %s", formula)
     api['rule'].publish('policy-update', [runtime.Event(formula)])
     # check we have the proper subscriptions
     self.assertTrue('neutron' in cage.services)
     neutron = cage.service_object('neutron')
     helper.retry_check_subscriptions(engine, [('neutron', 'networks')])
     helper.retry_check_subscribers(neutron, [(engine.name, 'networks')])
示例#5
0
    def test_policy_subscriptions(self):
        """Test that policy engine subscriptions adjust to policy changes."""
        engine = self.engine
        api = self.api
        cage = self.cage
        policy = engine.DEFAULT_THEORY

        # Send formula
        formula = test_neutron.create_network_group('p')
        LOG.debug("Sending formula: %s", formula)
        api['rule'].publish('policy-update',
                            [agnostic.Event(formula, target=policy)])
        # check we have the proper subscriptions
        self.assertTrue('neutron' in cage.services)
        neutron = cage.service_object('neutron')
        helper.retry_check_subscriptions(engine, [('neutron', 'networks')])
        helper.retry_check_subscribers(neutron, [(engine.name, 'networks')])
示例#6
0
    def setUp(self):
        super(BenchmarkDatasource, self).setUp()
        config = {
            'benchmark': {
                'module': helper.data_module_path('benchmark_driver.py'),
                'poll_time': 0
            }
        }
        cage = harness.create(helper.root_path(), helper.state_path(), None,
                              config)
        engine = cage.service_object('engine')
        api = {
            'policy': cage.service_object('api-policy'),
            'rule': cage.service_object('api-rule'),
            'table': cage.service_object('api-table'),
            'row': cage.service_object('api-row'),
            'datasource': cage.service_object('api-datasource'),
            'status': cage.service_object('api-status'),
            'schema': cage.service_object('api-schema')
        }
        helper.retry_check_subscriptions(engine,
                                         [(api['rule'].name, 'policy-update')])
        helper.retry_check_subscribers(api['rule'],
                                       [(engine.name, 'policy-update')])
        self.assertTrue('benchmark' in cage.services)
        datasource = cage.service_object('benchmark')
        table_name = datasource.BENCHTABLE

        self.assertEqual(datasource.state, {})

        # add a subscriber to ensure the updates end up in datasource.dataPath
        pubdata = datasource.pubdata.setdefault(table_name,
                                                dataobj.pubData(table_name))
        pubdata.addsubscriber(self.__class__.__name__, "push", "")
        self.assertTrue(datasource.pubdata[table_name])

        self.cage = cage
        self.engine = engine
        self.api = api
        self.table_name = table_name
        self.datasource = datasource
    def benchmark_datasource_to_policy_update(self, size):
        """Benchmark small datsource update to policy propagation.

        Time the propagation of a datasource update from datasource.poll() to
        completion of a simple policy update.
        """
        LOG.info("%s:: benchmarking datasource update of %d rows", size)
        self.datasource.datarows = size
        table_name = self.table_name

        # dummy policy only intended to produce a subscriber for the table
        key_to_index = self.datasource.get_column_map(table_name)
        id_index = 'x%d' % list(key_to_index.items())[0][1]
        max_index = max(key_to_index.values())
        args = ['x%d' % i for i in range(max_index + 1)]
        formula = compile.parse1('p(%s) :- benchmark:%s(%s)' % (id_index,
                                 table_name, ','.join(args)))

        # publish the formula and verify we see a subscription
        LOG.debug('%s:: sending formula: %s', self.__class__.__name__, formula)
        self.api['rule'].publish('policy-update', [agnostic.Event(formula)])
        helper.retry_check_subscriptions(
            self.engine, [('benchmark', table_name)])
        helper.retry_check_subscribers(
            self.datasource, [(self.engine.name, table_name)])

        # intercept inbox.task_done() so we know when it's finished. Sadly,
        # eventlet doesn't have a condition-like object.
        fake_condition = eventlet.Queue()
        fake_notify = functools.partial(fake_condition.put_nowait, True)
        self.mox.StubOutWithMock(self.engine.inbox, "task_done")
        self.engine.inbox.task_done().WithSideEffects(fake_notify)
        self.mox.ReplayAll()

        LOG.info("%s:: polling datasource", self.__class__.__name__)
        self.datasource.poll()
        fake_condition.get(timeout=30)
        self.mox.VerifyAll()
示例#8
0
    def benchmark_datasource_to_policy_update(self, size):
        """Benchmark small datsource update to policy propagation.

        Time the propagation of a datasource update from datasource.poll() to
        completion of a simple policy update.
        """
        LOG.info("%s:: benchmarking datasource update of %d rows", size)
        self.datasource.datarows = size
        table_name = self.table_name

        # dummy policy only intended to produce a subscriber for the table
        key_to_index = self.datasource.get_column_map(table_name)
        id_index = 'x%d' % key_to_index.items()[0][1]
        max_index = max(key_to_index.values())
        args = ['x%d' % i for i in xrange(max_index + 1)]
        formula = compile.parse1('p(%s) :- benchmark:%s(%s)' %
                                 (id_index, table_name, ','.join(args)))

        # publish the formula and verify we see a subscription
        LOG.debug('%s:: sending formula: %s', self.__class__.__name__, formula)
        self.api['rule'].publish('policy-update', [agnostic.Event(formula)])
        helper.retry_check_subscriptions(self.engine,
                                         [('benchmark', table_name)])
        helper.retry_check_subscribers(self.datasource,
                                       [(self.engine.name, table_name)])

        # intercept inbox.task_done() so we know when it's finished. Sadly,
        # eventlet doesn't have a condition-like object.
        fake_condition = eventlet.Queue()
        fake_notify = functools.partial(fake_condition.put_nowait, True)
        self.mox.StubOutWithMock(self.engine.inbox, "task_done")
        self.engine.inbox.task_done().WithSideEffects(fake_notify)
        self.mox.ReplayAll()

        LOG.info("%s:: polling datasource", self.__class__.__name__)
        self.datasource.poll()
        fake_condition.get(timeout=30)
        self.mox.VerifyAll()
示例#9
0
 def test_set_policy_subscriptions(self):
     self.vmplace.set_policy('p(x) :- fake:q(x)')
     helper.retry_check_subscriptions(
         self.vmplace, [(self.fake.name, 'q')])
     helper.retry_check_subscribers(
         self.fake, [(self.vmplace.name, 'q')])
示例#10
0
 def test_set_policy_subscriptions(self):
     self.vmplace.set_policy('p(x) :- fake:q(x)')
     helper.retry_check_subscriptions(self.vmplace, [(self.fake.name, 'q')])
     helper.retry_check_subscribers(self.fake, [(self.vmplace.name, 'q')])