def setUp(self): super(TestDataSourceManager, self).setUp() cfg.CONF.set_override( 'drivers', ['congress.tests.fake_datasource.FakeDataSource']) self.datasource_mgr = datasource_manager.DataSourceManager self.datasource_mgr.validate_configured_drivers() self.cage = harness.create(helper.root_path(), helper.state_path())
def setUp(self): super(TestDsePerformance, self).setUp() self.cage = harness.create( helper.root_path(), helper.state_path(), config_override={}) self.api = {'policy': self.cage.service_object('api-policy'), 'rule': self.cage.service_object('api-rule'), 'table': self.cage.service_object('api-table'), 'row': self.cage.service_object('api-row'), 'datasource': self.cage.service_object('api-datasource'), 'status': self.cage.service_object('api-status'), 'schema': self.cage.service_object('api-schema')} self.engine = self.cage.service_object('engine')
def setUp(self): """Setup tests that use multiple mock neutron instances.""" super(TestCongress, self).setUp() # create neutron mock and tell cage to use that mock # https://code.google.com/p/pymox/wiki/MoxDocumentation mock_factory = mox.Mox() neutron_mock = mock_factory.CreateMock( neutronclient.v2_0.client.Client) neutron_mock2 = mock_factory.CreateMock( neutronclient.v2_0.client.Client) override = {} override['neutron'] = {'client': neutron_mock, 'poll_time': 0} override['neutron2'] = {'client': neutron_mock2, 'poll_time': 0} override['nova'] = {'poll_time': 0} cage = harness.create(helper.root_path(), helper.state_path(), helper.datasource_config_path(), override) 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')} # Turn off schema checking engine.module_schema = None # initialize neutron_mocks network1 = test_neutron.network_response port_response = test_neutron.port_response router_response = test_neutron.router_response sg_group_response = test_neutron.security_group_response neutron_mock.list_networks().InAnyOrder().AndReturn(network1) neutron_mock.list_ports().InAnyOrder().AndReturn(port_response) neutron_mock.list_routers().InAnyOrder().AndReturn(router_response) neutron_mock.list_security_groups().InAnyOrder().AndReturn( sg_group_response) neutron_mock2.list_networks().InAnyOrder().AndReturn(network1) neutron_mock2.list_ports().InAnyOrder().AndReturn(port_response) neutron_mock2.list_routers().InAnyOrder().AndReturn(router_response) neutron_mock2.list_security_groups().InAnyOrder().AndReturn( sg_group_response) mock_factory.ReplayAll() self.cage = cage self.engine = engine self.api = api
def setUp(self): super(TestDsePerformance, self).setUp() self.cage = harness.create(helper.root_path(), helper.state_path(), config_override={}) self.api = { 'policy': self.cage.service_object('api-policy'), 'rule': self.cage.service_object('api-rule'), 'table': self.cage.service_object('api-table'), 'row': self.cage.service_object('api-row'), 'datasource': self.cage.service_object('api-datasource'), 'status': self.cage.service_object('api-status'), 'schema': self.cage.service_object('api-schema') } self.engine = self.cage.service_object('engine')
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 setUp(self): super(TestStatusModel, self).setUp() # Here we load the fake driver cfg.CONF.set_override( 'drivers', ['congress.tests.fake_datasource.FakeDataSource']) # NOTE(arosen): this set of tests, tests to deeply. We don't have # any tests currently testing cage. Once we do we should mock out # cage so we don't have to create one here. self.cage = harness.create(helper.root_path(), helper.state_path()) self.datasource_mgr = datasource_manager.DataSourceManager self.datasource_mgr.validate_configured_drivers() req = {'driver': 'fake_datasource', 'name': 'fake_datasource'} req['config'] = {'auth_url': 'foo', 'username': '******', 'password': '******', 'tenant_name': 'foo'} self.datasource = self.datasource_mgr.add_datasource(req) engine = self.cage.service_object('engine') self.status_model = status_model.StatusModel("status_schema", {}, policy_engine=engine)
def setUp(self): """Setup tests that use multiple mock neutron instances.""" super(TestCongress, self).setUp() # create neutron mock and tell cage to use that mock # https://code.google.com/p/pymox/wiki/MoxDocumentation mock_factory = mox.Mox() neutron_mock = mock_factory.CreateMock( neutronclient.v2_0.client.Client) neutron_mock2 = mock_factory.CreateMock( neutronclient.v2_0.client.Client) config_override = { 'neutron2': { 'username': '******', 'tenant_name': 'demo', 'password': '******', 'auth_url': 'http://127.0.0.1:5000/v2.0', 'module': 'datasources/neutron_driver.py' }, 'nova': { 'username': '******', 'tenant_name': 'demo', 'password': '******', 'auth_url': 'http://127.0.0.1:5000/v2.0', 'module': 'datasources/nova_driver.py' }, 'neutron': { 'username': '******', 'tenant_name': 'demo', 'password': '******', 'auth_url': 'http://127.0.0.1:5000/v2.0', 'module': 'datasources/neutron_driver.py' } } cage = harness.create(helper.root_path(), helper.state_path(), config_override) # Disable synchronizer because the this test creates # datasources without also inserting them into the database. # The synchronizer would delete these datasources. cage.service_object('synchronizer').set_poll_time(0) 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') } config = { 'username': '******', 'auth_url': 'http://127.0.0.1:5000/v2.0', 'tenant_name': 'demo', 'password': '******', 'module': 'datasources/neutron_driver.py', 'poll_time': 0 } # FIXME(arosen): remove all this code # monkey patch engine.create_policy('neutron') engine.create_policy('neutron2') engine.create_policy('nova') harness.load_data_service('neutron', config, cage, os.path.join(helper.root_path(), "congress"), 1) service = cage.service_object('neutron') engine.set_schema('neutron', service.get_schema()) harness.load_data_service('neutron2', config, cage, os.path.join(helper.root_path(), "congress"), 2) engine.set_schema('neutron2', service.get_schema()) config['module'] = 'datasources/nova_driver.py' harness.load_data_service('nova', config, cage, os.path.join(helper.root_path(), "congress"), 3) engine.set_schema('nova', service.get_schema()) cage.service_object('neutron').neutron = neutron_mock cage.service_object('neutron2').neutron = neutron_mock2 # delete all policies that aren't builtin, so we have clean slate names = set(engine.policy_names()) - engine.builtin_policy_names for name in names: try: api['policy'].delete_item(name, {}) except KeyError: pass # Turn off schema checking engine.module_schema = None # initialize neutron_mocks network1 = test_neutron.network_response port_response = test_neutron.port_response router_response = test_neutron.router_response sg_group_response = test_neutron.security_group_response neutron_mock.list_networks().InAnyOrder().AndReturn(network1) neutron_mock.list_ports().InAnyOrder().AndReturn(port_response) neutron_mock.list_routers().InAnyOrder().AndReturn(router_response) neutron_mock.list_security_groups().InAnyOrder().AndReturn( sg_group_response) neutron_mock2.list_networks().InAnyOrder().AndReturn(network1) neutron_mock2.list_ports().InAnyOrder().AndReturn(port_response) neutron_mock2.list_routers().InAnyOrder().AndReturn(router_response) neutron_mock2.list_security_groups().InAnyOrder().AndReturn( sg_group_response) mock_factory.ReplayAll() self.cage = cage self.engine = engine self.api = api
def state_path(): """Return path to the dir at which policy contents are stored.""" path = helper.state_path() if not os.path.exists(path): os.makedirs(path) return path
def setUp(self): """Setup tests that use multiple mock neutron instances.""" super(TestCongress, self).setUp() # create neutron mock and tell cage to use that mock # https://code.google.com/p/pymox/wiki/MoxDocumentation mock_factory = mox.Mox() neutron_mock = mock_factory.CreateMock( neutronclient.v2_0.client.Client) neutron_mock2 = mock_factory.CreateMock( neutronclient.v2_0.client.Client) override = {} override['neutron'] = {'poll_time': 0} override['neutron2'] = {'poll_time': 0} override['nova'] = {'poll_time': 0} cage = harness.create(helper.root_path(), helper.state_path(), helper.datasource_config_path(), override) 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') } # monkey patch cage.service_object('neutron').neutron = neutron_mock cage.service_object('neutron2').neutron = neutron_mock2 # delete all policies that aren't builtin, so we have clean slate names = set(engine.policy_names()) - engine.builtin_policy_names for name in names: try: api['policy'].delete_item(name, {}) except KeyError: pass # Turn off schema checking engine.module_schema = None # initialize neutron_mocks network1 = test_neutron.network_response port_response = test_neutron.port_response router_response = test_neutron.router_response sg_group_response = test_neutron.security_group_response neutron_mock.list_networks().InAnyOrder().AndReturn(network1) neutron_mock.list_ports().InAnyOrder().AndReturn(port_response) neutron_mock.list_routers().InAnyOrder().AndReturn(router_response) neutron_mock.list_security_groups().InAnyOrder().AndReturn( sg_group_response) neutron_mock2.list_networks().InAnyOrder().AndReturn(network1) neutron_mock2.list_ports().InAnyOrder().AndReturn(port_response) neutron_mock2.list_routers().InAnyOrder().AndReturn(router_response) neutron_mock2.list_security_groups().InAnyOrder().AndReturn( sg_group_response) mock_factory.ReplayAll() self.cage = cage self.engine = engine self.api = api
def setUp(self): """Setup tests that use multiple mock neutron instances.""" super(TestCongress, self).setUp() # create neutron mock and tell cage to use that mock # https://code.google.com/p/pymox/wiki/MoxDocumentation mock_factory = mox.Mox() neutron_mock = mock_factory.CreateMock( neutronclient.v2_0.client.Client) neutron_mock2 = mock_factory.CreateMock( neutronclient.v2_0.client.Client) config_override = {'neutron2': {'username': '******', 'tenant_name': 'demo', 'password': '******', 'auth_url': 'http://127.0.0.1:5000/v2.0', 'module': 'datasources/neutron_driver.py'}, 'nova': {'username': '******', 'tenant_name': 'demo', 'password': '******', 'auth_url': 'http://127.0.0.1:5000/v2.0', 'module': 'datasources/nova_driver.py'}, 'neutron': {'username': '******', 'tenant_name': 'demo', 'password': '******', 'auth_url': 'http://127.0.0.1:5000/v2.0', 'module': 'datasources/neutron_driver.py'}} cage = harness.create(helper.root_path(), helper.state_path(), config_override) 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')} config = {'username': '******', 'auth_url': 'http://127.0.0.1:5000/v2.0', 'tenant_name': 'demo', 'password': '******', 'module': 'datasources/neutron_driver.py', 'poll_time': 0} # FIXME(arosen): remove all this code # monkey patch engine.create_policy('neutron') engine.create_policy('neutron2') engine.create_policy('nova') harness.load_data_service( 'neutron', config, cage, os.path.join(helper.root_path(), "congress")) service = cage.service_object('neutron') engine.set_schema('neutron', service.get_schema()) harness.load_data_service( 'neutron2', config, cage, os.path.join(helper.root_path(), "congress")) engine.set_schema('neutron2', service.get_schema()) config['module'] = 'datasources/nova_driver.py' harness.load_data_service( 'nova', config, cage, os.path.join(helper.root_path(), "congress")) engine.set_schema('nova', service.get_schema()) cage.service_object('neutron').neutron = neutron_mock cage.service_object('neutron2').neutron = neutron_mock2 # delete all policies that aren't builtin, so we have clean slate names = set(engine.policy_names()) - engine.builtin_policy_names for name in names: try: api['policy'].delete_item(name, {}) except KeyError: pass # Turn off schema checking engine.module_schema = None # initialize neutron_mocks network1 = test_neutron.network_response port_response = test_neutron.port_response router_response = test_neutron.router_response sg_group_response = test_neutron.security_group_response neutron_mock.list_networks().InAnyOrder().AndReturn(network1) neutron_mock.list_ports().InAnyOrder().AndReturn(port_response) neutron_mock.list_routers().InAnyOrder().AndReturn(router_response) neutron_mock.list_security_groups().InAnyOrder().AndReturn( sg_group_response) neutron_mock2.list_networks().InAnyOrder().AndReturn(network1) neutron_mock2.list_ports().InAnyOrder().AndReturn(port_response) neutron_mock2.list_routers().InAnyOrder().AndReturn(router_response) neutron_mock2.list_security_groups().InAnyOrder().AndReturn( sg_group_response) mock_factory.ReplayAll() self.cage = cage self.engine = engine self.api = api