Esempio n. 1
0
    def setUp(self):
        # create DSE and add vm-placement engine and fake datasource
        super(TestSetPolicy, self).setUp()
        self.cage = d6cage.d6Cage()
        config = {
            "vmplace": {"module": "congress/policy_engines/vm_placement.py"},
            "fake": {"poll_time": 0, "module": "congress/tests/fake_datasource.py"},
        }

        harness.load_data_service("vmplace", config["vmplace"], self.cage, helper.root_path(), 1)
        harness.load_data_service("fake", config["fake"], self.cage, helper.root_path(), 2)

        self.vmplace = self.cage.service_object("vmplace")
        self.vmplace.debug_mode()
        self.fake = self.cage.service_object("fake")
Esempio n. 2
0
    def setUp(self):
        # create DSE and add vm-placement engine and fake datasource
        super(TestSetPolicy, self).setUp()
        self.cage = d6cage.d6Cage()
        config = {
            'vmplace': {
                'module': "congress/policy_engines/vm_placement.py"
            },
            'fake': {
                'poll_time': 0,
                'module': "congress/tests/fake_datasource.py"
            }
        }

        harness.load_data_service("vmplace", config['vmplace'], self.cage,
                                  helper.root_path(), 1)
        harness.load_data_service("fake", config['fake'], self.cage,
                                  helper.root_path(), 2)

        self.vmplace = self.cage.service_object('vmplace')
        self.vmplace.debug_mode()
        self.fake = self.cage.service_object('fake')
Esempio n. 3
0
    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
Esempio n. 4
0
    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(), 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',
                             kind=datalog_base.DATASOURCE_POLICY_TYPE)
        engine.create_policy('neutron2',
                             kind=datalog_base.DATASOURCE_POLICY_TYPE)
        engine.create_policy('nova',
                             kind=datalog_base.DATASOURCE_POLICY_TYPE)
        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