當前位置: 首頁>>代碼示例>>Python>>正文


Python context.Context方法代碼示例

本文整理匯總了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 
開發者ID:openstack,項目名稱:neutron-vpnaas,代碼行數:26,代碼來源:test_vpn_db.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:18,代碼來源:test_context.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:26,代碼來源:test_context.py

示例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) 
開發者ID:openstack,項目名稱:neutron-vpnaas,代碼行數:16,代碼來源:test_ipsec.py

示例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') 
開發者ID:openstack,項目名稱:neutron-vpnaas,代碼行數:13,代碼來源:test_ipsec.py

示例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'}]} 
開發者ID:openstack,項目名稱:neutron-vpnaas,代碼行數:12,代碼來源:test_vpn_validator.py

示例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) 
開發者ID:openstack,項目名稱:networking-odl,代碼行數:16,代碼來源:test_periodic_task.py

示例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})} 
開發者ID:openstack,項目名稱:networking-bgpvpn,代碼行數:34,代碼來源:test_bagpipe.py

示例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) 
開發者ID:openstack,項目名稱:dragonflow,代碼行數:13,代碼來源:test_l3_router_plugin.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:17,代碼來源:test_context.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:10,代碼來源:test_context.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:12,代碼來源:test_context.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:5,代碼來源:test_context.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:6,代碼來源:test_context.py

示例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) 
開發者ID:openstack,項目名稱:neutron-lib,代碼行數:6,代碼來源:test_context.py


注:本文中的neutron_lib.context.Context方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。