Exemplo n.º 1
0
 def setUp(self):
     core.initialize()
     core.ModelBase.metadata.create_all(core.get_engine())
     self.context = context.Context()
     self.project_id = 'test_project'
     self.context.tenant = self.project_id
     self.controller = action.VolumeActionController(self.project_id, '')
Exemplo n.º 2
0
    def setUp(self):
        core.initialize()
        core.ModelBase.metadata.create_all(core.get_engine())
        self.context = context.Context()
        self.project_id = 'test_pm_project'
        self.az_name_2 = 'b_az_pm_2'
        self.az_name_1 = 'b_az_pm_1'
        self.pod_manager = driver.DriverManager(
            namespace='trio2o.common.schedulers',
            name='pod_manager',
            invoke_on_load=True).driver
        self.b_pod_1 = {
            'pod_id': 'b_pod_pm_uuid_1',
            'pod_name': 'b_region_pm_1',
            'az_name': self.az_name_1
        }

        self.b_pod_2 = {
            'pod_id': 'b_pod_pm_uuid_2',
            'pod_name': 'b_region_pm_2',
            'az_name': self.az_name_2
        }

        self.b_pod_3 = {
            'pod_id': 'b_pod_pm_uuid_3',
            'pod_name': 'b_region_pm_3',
            'az_name': self.az_name_2
        }

        self.b_pod_4 = {
            'pod_id': 'b_pod_pm_uuid_4',
            'pod_name': 'b_region_pm_4',
            'az_name': self.az_name_2
        }
Exemplo n.º 3
0
    def setUp(self):
        core.initialize()
        core.ModelBase.metadata.create_all(core.get_engine())
        # enforce foreign key constraint for sqlite
        core.get_engine().execute('pragma foreign_keys=on')
        self.context = context.Context()

        pod_dict = {
            'pod_id': FAKE_SITE_ID,
            'pod_name': FAKE_SITE_NAME,
            'az_name': FAKE_AZ
        }
        config_dict = {
            'service_id': FAKE_SERVICE_ID,
            'pod_id': FAKE_SITE_ID,
            'service_type': FAKE_TYPE,
            'service_url': FAKE_URL
        }
        api.create_pod(self.context, pod_dict)
        api.create_pod_service_configuration(self.context, config_dict)

        global FAKE_RESOURCES
        FAKE_RESOURCES = [{'name': 'res1'}, {'name': 'res2'}]

        cfg.CONF.set_override(name='top_pod_name', override=FAKE_SITE_NAME,
                              group='client')
        self.client = client.Client()
        self.client.resource_service_map[FAKE_RESOURCE] = FAKE_TYPE
        self.client.operation_resources_map['list'].add(FAKE_RESOURCE)
        self.client.operation_resources_map['create'].add(FAKE_RESOURCE)
        self.client.operation_resources_map['delete'].add(FAKE_RESOURCE)
        self.client.operation_resources_map['action'].add(FAKE_RESOURCE)
        self.client.service_handle_map[FAKE_TYPE] = FakeResHandle(None)
Exemplo n.º 4
0
 def setUp(self):
     super(PolicyTestCase, self).setUp()
     rules = oslo_policy.Rules.from_dict({
         "true":
         '@',
         "example:allowed":
         '@',
         "example:denied":
         "!",
         "example:my_file":
         "role:admin or "
         "project_id:%(project_id)s",
         "example:early_and_fail":
         "! and @",
         "example:early_or_success":
         "@ or !",
         "example:lowercase_admin":
         "role:admin or role:sysadmin",
         "example:uppercase_admin":
         "role:ADMIN or role:sysadmin",
     })
     policy.reset()
     policy.init()
     policy.set_rules(rules)
     self.context = context.Context(user_id='fake',
                                    tenant_id='fake',
                                    roles=['member'])
     self.target = None
Exemplo n.º 5
0
    def _update_endpoint_from_keystone(self, cxt, is_internal):
        """Update the database by querying service endpoint url from Keystone

        :param cxt: context object
        :param is_internal: if True, this method utilizes pre-configured admin
        username and password to apply an new admin token, this happens only
        when auto_refresh_endpoint is set to True. if False, token in cxt is
        directly used, users should prepare admin token themselves
        :return: None
        """
        if is_internal:
            admin_context = trio2o_context.Context()
            admin_context.auth_token = self._get_admin_token()
            endpoint_map = self._get_endpoint_from_keystone(admin_context)
        else:
            endpoint_map = self._get_endpoint_from_keystone(cxt)

        for region in endpoint_map:
            # use region name to query pod
            pod_filters = [{
                'key': 'pod_name',
                'comparator': 'eq',
                'value': region
            }]
            pod_list = api.list_pods(cxt, pod_filters)
            # skip region/pod not registered in cascade service
            if len(pod_list) != 1:
                continue
            for service in endpoint_map[region]:
                pod_id = pod_list[0]['pod_id']
                config_filters = [{
                    'key': 'pod_id',
                    'comparator': 'eq',
                    'value': pod_id
                }, {
                    'key': 'service_type',
                    'comparator': 'eq',
                    'value': service
                }]
                config_list = api.list_pod_service_configurations(
                    cxt, config_filters)

                if len(config_list) > 1:
                    raise exceptions.EndpointNotUnique(pod_id, service)
                if len(config_list) == 1:
                    config_id = config_list[0]['service_id']
                    update_dict = {
                        'service_url': endpoint_map[region][service]
                    }
                    api.update_pod_service_configuration(
                        cxt, config_id, update_dict)
                else:
                    config_dict = {
                        'service_id': str(uuid.uuid4()),
                        'pod_id': pod_id,
                        'service_type': service,
                        'service_url': endpoint_map[region][service]
                    }
                    api.create_pod_service_configuration(cxt, config_dict)
Exemplo n.º 6
0
 def test_ignore_case_role_check(self):
     lowercase_action = "example:lowercase_admin"
     uppercase_action = "example:uppercase_admin"
     admin_context = context.Context(user_id='fake',
                                     tenant_id='fake',
                                     roles=['AdMiN'])
     result = policy.enforce(admin_context, lowercase_action, self.target)
     self.assertEqual(result, True)
     result = policy.enforce(admin_context, uppercase_action, self.target)
     self.assertEqual(result, True)
Exemplo n.º 7
0
 def setUp(self):
     core.initialize()
     core.ModelBase.metadata.create_all(core.get_engine())
     # enforce foreign key constraint for sqlite
     core.get_engine().execute('pragma foreign_keys=on')
     for opt in xservice.common_opts:
         if opt.name in ('worker_handle_timeout', 'job_run_expire',
                         'worker_sleep_time'):
             cfg.CONF.register_opt(opt)
     self.context = context.Context()
     self.xmanager = FakeXManager()
Exemplo n.º 8
0
    def setUp(self):
        super(DefaultPolicyTestCase, self).setUp()

        self.rules = oslo_policy.Rules.from_dict({
            "default": '',
            "example:exist": "!",
        })

        self._set_rules('default')

        self.context = context.Context(user_id='fake', tenant_id='fake')
Exemplo n.º 9
0
    def setUp(self):
        core.initialize()
        core.ModelBase.metadata.create_all(core.get_engine())
        # enforce foreign key constraint for sqlite
        core.get_engine().execute('pragma foreign_keys=on')
        self.context = context.Context()

        top_pod = {
            'pod_id': FAKE_TOP_ID,
            'pod_name': FAKE_TOP_NAME,
            'az_name': ''
        }

        config_dict_top = {
            'service_id': FAKE_TOP_SERVICE_ID,
            'pod_id': FAKE_TOP_ID,
            'service_type': FAKE_SERVICE_TYPE,
            'service_url': FAKE_TOP_ENDPOINT
        }

        pod_dict = {
            'pod_id': FAKE_SITE_ID,
            'pod_name': FAKE_SITE_NAME,
            'az_name': FAKE_AZ
        }

        pod_dict2 = {
            'pod_id': FAKE_SITE_ID_2,
            'pod_name': FAKE_SITE_NAME_2,
            'az_name': FAKE_AZ
        }

        config_dict = {
            'service_id': FAKE_SERVICE_ID,
            'pod_id': FAKE_SITE_ID,
            'service_type': FAKE_SERVICE_TYPE,
            'service_url': FAKE_SERVICE_ENDPOINT
        }

        config_dict2 = {
            'service_id': FAKE_SERVICE_ID_2,
            'pod_id': FAKE_SITE_ID_2,
            'service_type': FAKE_SERVICE_TYPE,
            'service_url': FAKE_SERVICE_ENDPOINT_2
        }

        api.create_pod(self.context, pod_dict)
        api.create_pod(self.context, pod_dict2)
        api.create_pod(self.context, top_pod)
        api.create_pod_service_configuration(self.context, config_dict)
        api.create_pod_service_configuration(self.context, config_dict2)
        api.create_pod_service_configuration(self.context, config_dict_top)
Exemplo n.º 10
0
    def _init_db(self):
        core.initialize()
        core.ModelBase.metadata.create_all(core.get_engine())
        # enforce foreign key constraint for sqlite
        core.get_engine().execute('pragma foreign_keys=on')
        self.context = context.Context()

        pod_dict = {
            'pod_id': 'fake_pod_id',
            'pod_name': 'fake_pod_name',
            'az_name': FAKE_AZ
        }

        config_dict = {
            'service_id': 'fake_service_id',
            'pod_id': 'fake_pod_id',
            'service_type': cons.ST_NOVA,
            'service_url': 'http://127.0.0.1:8774/v2/$(tenant_id)s'
        }

        pod_dict2 = {
            'pod_id': 'fake_pod_id' + '2',
            'pod_name': 'fake_pod_name' + '2',
            'az_name': FAKE_AZ + '2'
        }

        config_dict2 = {
            'service_id': 'fake_service_id' + '2',
            'pod_id': 'fake_pod_id' + '2',
            'service_type': cons.ST_CINDER,
            'service_url': 'http://10.0.0.2:8774/v2/$(tenant_id)s'
        }

        top_pod = {
            'pod_id': 'fake_top_pod_id',
            'pod_name': 'RegionOne',
            'az_name': ''
        }

        top_config = {
            'service_id': 'fake_top_service_id',
            'pod_id': 'fake_top_pod_id',
            'service_type': cons.ST_CINDER,
            'service_url': 'http://127.0.0.1:19998/v2/$(tenant_id)s'
        }

        db_api.create_pod(self.context, pod_dict)
        db_api.create_pod(self.context, pod_dict2)
        db_api.create_pod(self.context, top_pod)
        db_api.create_pod_service_configuration(self.context, config_dict)
        db_api.create_pod_service_configuration(self.context, config_dict2)
        db_api.create_pod_service_configuration(self.context, top_config)
Exemplo n.º 11
0
def _extract_context_from_environ(environ):
    context_paras = {
        'auth_token': 'HTTP_X_AUTH_TOKEN',
        'user': '******',
        'tenant': 'HTTP_X_TENANT_ID',
        'user_name': 'HTTP_X_USER_NAME',
        'tenant_name': 'HTTP_X_PROJECT_NAME',
        'domain': 'HTTP_X_DOMAIN_ID',
        'user_domain': 'HTTP_X_USER_DOMAIN_ID',
        'project_domain': 'HTTP_X_PROJECT_DOMAIN_ID',
        'request_id': 'openstack.request_id'
    }
    for key in context_paras:
        context_paras[key] = environ.get(context_paras[key])
    role = environ.get('HTTP_X_ROLE')
    # TODO(zhiyuan): replace with policy check
    context_paras['is_admin'] = role == 'admin'
    return t_context.Context(**context_paras)
Exemplo n.º 12
0
 def setUp(self):
     core.initialize()
     core.ModelBase.metadata.create_all(core.get_engine())
     self.context = context.Context()
Exemplo n.º 13
0
 def setUp(self):
     core.initialize()
     core.ModelBase.metadata.create_all(core.get_engine())
     # enforce foreign key constraint for sqlite
     core.get_engine().execute('pragma foreign_keys=on')
     self.context = context.Context()
Exemplo n.º 14
0
def fake_non_admin_context():
    context_paras = {}
    return context.Context(**context_paras)
Exemplo n.º 15
0
def fake_admin_context():
    context_paras = {'is_admin': True}
    return context.Context(**context_paras)
Exemplo n.º 16
0
 def setUp(self):
     core.initialize()
     core.ModelBase.metadata.create_all(core.get_engine())
     self.context = context.Context()
     self.project_id = 'test_project'
     self.controller = FakeServerController(self.project_id)