Remove direct assignments of context attributes
Context attributes should be set by its __init__ only. Change-Id: I7c5b0b21e27384adec7049a6f5bb8454fa81ffb8
This commit is contained in:
parent
573fb0cc1f
commit
485f8a1606
@ -43,6 +43,15 @@ class BaseContext(object):
|
||||
else:
|
||||
raise AttributeError(name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
# NOTE(yorik-sar): only the very first assignment for __values is
|
||||
# allowed. All context arguments should be set at the time the context
|
||||
# object is being created.
|
||||
if not self.__dict__:
|
||||
super(BaseContext, self).__setattr__(name, value)
|
||||
else:
|
||||
raise Exception(self.__dict__, name, value)
|
||||
|
||||
def __enter__(self):
|
||||
try:
|
||||
stack = self._context_stack.stack
|
||||
|
@ -51,12 +51,13 @@ class TestTrusts(tests.TestCase):
|
||||
|
||||
def test_create_ctx_from_trust(self):
|
||||
fake_item = self.client().service_catalog.catalog.__getitem__()
|
||||
fake_ctx_dict = {'_BaseContext__values': {},
|
||||
'auth_token': self.client().auth_token,
|
||||
'service_catalog': fake_item,
|
||||
'tenant_id': self.client().tenant_id,
|
||||
'tenant_name': 'admin',
|
||||
'user_name': 'admin'}
|
||||
fake_ctx_dict = {'_BaseContext__values': {
|
||||
'auth_token': self.client().auth_token,
|
||||
'service_catalog': fake_item,
|
||||
'tenant_id': self.client().tenant_id,
|
||||
'tenant_name': 'admin',
|
||||
'user_name': 'admin',
|
||||
}}
|
||||
|
||||
ctx = self.trusts.create_ctx_from_trust('1')
|
||||
|
||||
|
@ -48,9 +48,10 @@ def delete_trust(lease):
|
||||
|
||||
def create_ctx_from_trust(trust_id):
|
||||
"""Return context built from given trust."""
|
||||
ctx = context.ClimateContext()
|
||||
ctx.user_name = CONF.os_admin_username
|
||||
ctx.tenant_name = CONF.os_admin_tenant_name
|
||||
ctx = context.ClimateContext(
|
||||
user_name=CONF.os_admin_username,
|
||||
tenant_name=CONF.os_admin_tenant_name,
|
||||
)
|
||||
auth_url = "%s://%s:%s/v3" % (CONF.os_auth_protocol,
|
||||
CONF.os_auth_host,
|
||||
CONF.os_auth_port)
|
||||
@ -58,12 +59,13 @@ def create_ctx_from_trust(trust_id):
|
||||
password=CONF.os_admin_password,
|
||||
trust_id=trust_id,
|
||||
auth_url=auth_url,
|
||||
ctx=ctx
|
||||
ctx=ctx,
|
||||
)
|
||||
|
||||
ctx.auth_token = client.auth_token
|
||||
ctx.service_catalog = client.service_catalog.catalog['catalog']
|
||||
ctx.tenant_id = client.tenant_id
|
||||
|
||||
# use 'with ctx' statement in the place you need context from trust
|
||||
return ctx
|
||||
return context.ClimateContext(
|
||||
ctx,
|
||||
auth_token=client.auth_token,
|
||||
service_catalog=client.service_catalog.catalog['catalog'],
|
||||
tenant_id=client.tenant_id,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user