def fake_ctx_from_headers(headers):
     if not headers:
         return context.ClimateContext(
             user_id='fake', project_id='fake', roles=['member'])
     roles = headers.get('X-Roles', six.text_type('member')).split(',')
     return context.ClimateContext(
         user_id=headers.get('X-User-Id', 'fake'),
         project_id=headers.get('X-Project-Id', 'fake'),
         auth_token=headers.get('X-Auth-Token', None),
         service_catalog=None,
         user_name=headers.get('X-User-Name', 'fake'),
         project_name=headers.get('X-Project-Name', 'fake'),
         roles=roles,
     )
    def setUp(self):
        super(ReservationPoolTestCase, self).setUp()
        self.pool_name = 'pool-name-xxx'
        self.project_id = 'project-uuid'
        self.fake_aggregate = AggregateFake(i=123,
                                            name='fooname',
                                            hosts=['host1', 'host2'])
        conf = cfg.CONF[host_plugin.RESOURCE_TYPE]
        self.freepool_name = conf.aggregate_freepool_name
        self.project_id_key = conf.project_id_key
        self.climate_owner = conf.climate_owner
        self.climate_az_prefix = conf.climate_az_prefix

        self.fake_freepool = AggregateFake(i=456,
                                           name=self.freepool_name,
                                           hosts=['host3'])

        self.set_context(context.ClimateContext(project_id=self.project_id))

        self.nova_client = nova_client
        self.nova = self.patch(self.nova_client, 'Client').return_value

        self.patch(self.nova.aggregates, 'set_metadata')
        self.patch(self.nova.aggregates, 'remove_host')

        self.patch(base, 'url_for').return_value = 'http://foo.bar'
        self.pool = rp.ReservationPool()

        self.p_name = self.patch(self.pool, '_generate_aggregate_name')
        self.p_name.return_value = self.pool_name
Exemple #3
0
def create_ctx_from_trust(trust_id):
    """Return context built from given trust."""
    ctx = context.ClimateContext(
        user_name=CONF.os_admin_username,
        project_name=CONF.os_admin_project_name,
    )
    auth_url = "%s://%s:%s/v3" % (CONF.os_auth_protocol, CONF.os_auth_host,
                                  CONF.os_auth_port)
    client = keystone.ClimateKeystoneClient(
        password=CONF.os_admin_password,
        trust_id=trust_id,
        auth_url=auth_url,
        ctx=ctx,
    )

    # use 'with ctx' statement in the place you need context from trust
    return context.ClimateContext(
        ctx,
        auth_token=client.auth_token,
        service_catalog=client.service_catalog.catalog['catalog'],
        project_id=client.tenant_id,
    )
Exemple #4
0
def ctx_from_headers(headers):
    try:
        service_catalog = json.loads(headers['X-Service-Catalog'])
    except KeyError:
        raise exceptions.ServiceCatalogNotFound()
    except TypeError:
        raise exceptions.WrongFormat()

    return context.ClimateContext(
        user_id=headers['X-User-Id'],
        project_id=headers['X-Project-Id'],
        auth_token=headers['X-Auth-Token'],
        service_catalog=service_catalog,
        user_name=headers['X-User-Name'],
        project_name=headers['X-Project-Name'],
        roles=map(unicode.strip, headers['X-Roles'].split(',')),
    )
    def setUp(self):
        super(DefaultPolicyTestCase, self).setUp()

        self.rules = """
        {
            "default": "",
            "example:exist": "!",
            "example:allowed": "@",
            "example:my_file": "role:admin or \
                               project_id:%(project_id)s"
        }
        """

        self.default_rule = None
        policy.reset()
        self.read_cached_file.return_value = (True, self.rules)
        self.context = context.ClimateContext(user_id='fake',
                                              project_id='fake',
                                              roles=['member'])
Exemple #6
0
 def test_elevated(self):
     with context.ClimateContext(user_id="user", project_id="project"):
         ctx = context.ClimateContext.elevated()
         self.assertEqual(ctx.user_id, "user")
         self.assertEqual(ctx.project_id, "project")
         self.assertEqual(ctx.is_admin, True)
Exemple #7
0
 def decorator(*args, **kwargs):
     with context.ClimateContext():
         return func(*args, **kwargs)
Exemple #8
0
 def run_method(__ctx, **kwargs):
     with context.ClimateContext(**__ctx):
         return method(**kwargs)
Exemple #9
0
    def setUp(self):
        super(ClimatePolicyTestCase, self).setUp()

        self.context = context.ClimateContext(user_id='fake',
                                              project_id='fake',
                                              roles=['member'])