本文整理汇总了Python中neutron_lib.context.Context方法的典型用法代码示例。如果您正苦于以下问题:Python context.Context方法的具体用法?Python context.Context怎么用?Python context.Context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neutron_lib.context
的用法示例。
在下文中一共展示了context.Context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_vpnservice
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def _create_vpnservice(self, fmt, name,
admin_state_up,
router_id, subnet_id,
expected_res_status=None, **kwargs):
tenant_id = kwargs.get('tenant_id', self._tenant_id)
data = {'vpnservice': {'name': name,
'subnet_id': subnet_id,
'router_id': router_id,
'admin_state_up': admin_state_up,
'tenant_id': tenant_id}}
if kwargs.get('description') is not None:
data['vpnservice']['description'] = kwargs['description']
if kwargs.get('flavor_id') is not None:
data['vpnservice']['flavor_id'] = kwargs['flavor_id']
vpnservice_req = self.new_create_request('vpnservices', data, fmt)
if (kwargs.get('set_context') and
'tenant_id' in kwargs):
# create a specific auth context for this request
vpnservice_req.environ['neutron.context'] = context.Context(
'', kwargs['tenant_id'])
vpnservice_res = vpnservice_req.get_response(self.ext_api)
if expected_res_status:
self.assertEqual(vpnservice_res.status_int, expected_res_status)
return vpnservice_res
示例2: test_neutron_context_overwrite
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_neutron_context_overwrite(self):
ctx1 = context.Context('user_id', 'tenant_id')
self.assertEqual(ctx1.request_id,
oslo_context.get_current().request_id)
# If overwrite is not specified, request_id should be updated.
ctx2 = context.Context('user_id', 'tenant_id')
self.assertNotEqual(ctx2.request_id, ctx1.request_id)
self.assertEqual(ctx2.request_id,
oslo_context.get_current().request_id)
# If overwrite is specified, request_id should be kept.
ctx3 = context.Context('user_id', 'tenant_id', overwrite=False)
self.assertNotEqual(ctx3.request_id, ctx2.request_id)
self.assertEqual(ctx2.request_id,
oslo_context.get_current().request_id)
示例3: test_to_policy_values
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_to_policy_values(self):
values = {
'user_id': 'user_id',
'tenant_id': 'tenant_id',
'is_admin': 'is_admin',
'tenant_name': 'tenant_name',
'user_name': 'user_name',
'domain': 'domain',
'user_domain': 'user_domain',
'project_domain': 'project_domain',
'user_name': 'user_name',
}
additional_values = {
'user': 'user_id',
'tenant': 'tenant_id',
'project_id': 'tenant_id',
'project_name': 'tenant_name',
}
ctx = context.Context(**values)
# apply dict() to get a real dictionary, needed for newer oslo.context
# that returns _DeprecatedPolicyValues object instead
policy_values = dict(ctx.to_policy_values())
self.assertDictSupersetOf(values, policy_values)
self.assertDictSupersetOf(additional_values, policy_values)
示例4: _test_update
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def _test_update(self, func, args, additional_info=None):
ctxt = n_ctx.Context('', 'somebody')
with mock.patch.object(self.driver.agent_rpc.client, 'cast'
) as rpc_mock, \
mock.patch.object(self.driver.agent_rpc.client, 'prepare'
) as prepare_mock:
prepare_mock.return_value = self.driver.agent_rpc.client
func(ctxt, *args)
prepare_args = {'server': 'fake_host', 'version': '1.0'}
prepare_mock.assert_called_once_with(**prepare_args)
rpc_mock.assert_called_once_with(ctxt, 'vpnservice_updated',
**additional_info)
示例5: test_store_gw_ips_on_service_create
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_store_gw_ips_on_service_create(self):
vpnservice = mock.Mock()
self.svc_plugin._get_vpnservice.return_value = vpnservice
vpnservice.router.gw_port = {'fixed_ips': [{'ip_address': '10.0.0.99'},
{'ip_address': '2001::1'}]}
ctxt = n_ctx.Context('', 'somebody')
vpnservice_dict = {'id': FAKE_SERVICE_ID,
'router_id': FAKE_ROUTER_ID}
self.driver.create_vpnservice(ctxt, vpnservice_dict)
self.svc_plugin.set_external_tunnel_ips.assert_called_once_with(
ctxt, FAKE_SERVICE_ID, v4_ip='10.0.0.99', v6_ip='2001::1')
示例6: setUp
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def setUp(self):
super(TestVpnValidation, self).setUp()
self.l3_plugin = mock.Mock()
self.core_plugin = mock.Mock()
directory.add_plugin(nconstants.CORE, self.core_plugin)
directory.add_plugin(nconstants.L3, self.l3_plugin)
self.context = n_ctx.Context('some_user', 'some_tenant')
self.validator = vpn_validator.VpnReferenceValidator()
self.router = mock.Mock()
self.router.gw_port = {'fixed_ips': [{'ip_address': '10.0.0.99'}]}
示例7: test_context_is_passed_as_args
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_context_is_passed_as_args(self, _):
operation = mock.MagicMock()
operation.__name__ = 'test'
self.thread.register_operation(operation)
self.thread.execute_ops(forced=True)
# This tests that only ONE args is passed, and no kwargs
operation.assert_called_with(mock.ANY)
# This tests that it's a context
kall = operation.call_args
args, kwargs = kall
self.assertIsInstance(args[0], context.Context)
示例8: setUp
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def setUp(self, plugin=None,
driver=('networking_bgpvpn.neutron.services.service_drivers.'
'bagpipe.bagpipe.BaGPipeBGPVPNDriver')):
self.mocked_rpc = mock.patch(
'networking_bagpipe.agent.bgpvpn.rpc_client'
'.BGPVPNAgentNotifyApi').start().return_value
self.mock_attach_rpc = self.mocked_rpc.attach_port_on_bgpvpn
self.mock_detach_rpc = self.mocked_rpc.detach_port_from_bgpvpn
self.mock_update_rpc = self.mocked_rpc.update_bgpvpn
self.mock_delete_rpc = self.mocked_rpc.delete_bgpvpn
mock.patch(
'neutron_lib.rpc.get_client').start().return_value
if not plugin:
plugin = '%s.%s' % (__name__, TestCorePluginWithAgents.__name__)
super(TestBagpipeCommon, self).setUp(service_provider=driver,
core_plugin=plugin)
self.ctxt = n_context.Context('fake_user', self._tenant_id)
n_dict = {"name": "netfoo",
"tenant_id": self._tenant_id,
"admin_state_up": True,
"router:external": True,
"shared": True}
self.external_net = {'network':
self.plugin.create_network(self.ctxt,
{'network': n_dict})}
示例9: test_create_floatingip_with_normal_user
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_create_floatingip_with_normal_user(self):
normal_context = nctx.Context(is_admin=False, overwrite=False)
kwargs = {'arg_list': ('router:external',),
'router:external': True}
with self.network(**kwargs) as n:
with self.subnet(network=n):
floatingip = self.l3p.create_floatingip(
normal_context,
{'floatingip': {'floating_network_id': n['network']['id'],
'tenant_id': n['network']['tenant_id']}})
self.assertTrue(floatingip)
示例10: test_neutron_context_create
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_neutron_context_create(self):
ctx = context.Context('user_id', 'tenant_id')
self.assertEqual('user_id', ctx.user_id)
self.assertEqual('tenant_id', ctx.project_id)
self.assertEqual('tenant_id', ctx.tenant_id)
request_id = ctx.request_id
if isinstance(request_id, bytes):
request_id = request_id.decode('utf-8')
self.assertThat(request_id, matchers.StartsWith('req-'))
self.assertEqual('user_id', ctx.user)
self.assertEqual('tenant_id', ctx.tenant)
self.assertIsNone(ctx.user_name)
self.assertIsNone(ctx.tenant_name)
self.assertIsNone(ctx.project_name)
self.assertIsNone(ctx.auth_token)
示例11: test_neutron_context_getter_setter
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_neutron_context_getter_setter(self):
ctx = context.Context('Anakin', 'Skywalker')
self.assertEqual('Anakin', ctx.user_id)
self.assertEqual('Skywalker', ctx.tenant_id)
ctx.user_id = 'Darth'
ctx.tenant_id = 'Vader'
self.assertEqual('Darth', ctx.user_id)
self.assertEqual('Vader', ctx.tenant_id)
示例12: test_neutron_context_create_with_name
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_neutron_context_create_with_name(self):
ctx = context.Context('user_id', 'tenant_id',
tenant_name='tenant_name', user_name='user_name')
# Check name is set
self.assertEqual('user_name', ctx.user_name)
self.assertEqual('tenant_name', ctx.tenant_name)
self.assertEqual('tenant_name', ctx.project_name)
# Check user/tenant contains its ID even if user/tenant_name is passed
self.assertEqual('user_id', ctx.user)
self.assertEqual('tenant_id', ctx.tenant)
示例13: test_neutron_context_create_with_request_id
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_neutron_context_create_with_request_id(self):
ctx = context.Context('user_id', 'tenant_id', request_id='req_id_xxx')
self.assertEqual('req_id_xxx', ctx.request_id)
示例14: test_neutron_context_create_with_timestamp
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_neutron_context_create_with_timestamp(self):
now = "Right Now!"
ctx = context.Context('user_id', 'tenant_id', timestamp=now)
self.assertEqual(now, ctx.timestamp)
示例15: test_neutron_context_create_with_auth_token
# 需要导入模块: from neutron_lib import context [as 别名]
# 或者: from neutron_lib.context import Context [as 别名]
def test_neutron_context_create_with_auth_token(self):
ctx = context.Context('user_id', 'tenant_id',
auth_token='auth_token_xxx')
self.assertEqual('auth_token_xxx', ctx.auth_token)