本文整理汇总了Python中nova.context.get_context函数的典型用法代码示例。如果您正苦于以下问题:Python get_context函数的具体用法?Python get_context怎么用?Python get_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_context函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get_context_no_overwrite
def test_get_context_no_overwrite(self):
# If there is already a context in the cache creating another context
# should not overwrite it.
ctx1 = context.RequestContext('111',
'222',
overwrite=True)
context.get_context()
self.assertIs(ctx1, o_context.get_current())
开发者ID:arbrandes,项目名称:nova,代码行数:8,代码来源:test_context.py
示例2: test_scatter_gather_cells
def test_scatter_gather_cells(self, mock_get_inst, mock_target_cell):
ctxt = context.get_context()
mapping = objects.CellMapping(database_connection='fake://db',
transport_url='fake://mq',
uuid=uuids.cell)
mappings = objects.CellMappingList(objects=[mapping])
# Use a mock manager to assert call order across mocks.
manager = mock.Mock()
manager.attach_mock(mock_get_inst, 'get_inst')
manager.attach_mock(mock_target_cell, 'target_cell')
filters = {'deleted': False}
context.scatter_gather_cells(
ctxt, mappings, 60, objects.InstanceList.get_by_filters, filters,
sort_dir='foo')
# NOTE(melwitt): This only works without the SpawnIsSynchronous fixture
# because when the spawn is treated as synchronous and the thread
# function is called immediately, it will occur inside the target_cell
# context manager scope when it wouldn't with a real spawn.
# Assert that InstanceList.get_by_filters was called before the
# target_cell context manager exited.
get_inst_call = mock.call.get_inst(
mock_target_cell.return_value.__enter__.return_value, filters,
sort_dir='foo')
expected_calls = [get_inst_call,
mock.call.target_cell().__exit__(None, None, None)]
manager.assert_has_calls(expected_calls)
开发者ID:arbrandes,项目名称:nova,代码行数:30,代码来源:test_context.py
示例3: _setup_cells
def _setup_cells(self):
"""Setup a normal cellsv2 environment.
This sets up the CellDatabase fixture with two cells, one cell0
and one normal cell. CellMappings are created for both so that
cells-aware code can find those two databases.
"""
celldbs = nova_fixtures.CellDatabases()
celldbs.add_cell_database(objects.CellMapping.CELL0_UUID)
celldbs.add_cell_database(uuids.cell1, default=True)
self.useFixture(celldbs)
ctxt = context.get_context()
fake_transport = 'fake://nowhere/'
c0 = objects.CellMapping(
context=ctxt,
uuid=objects.CellMapping.CELL0_UUID,
name='cell0',
transport_url=fake_transport,
database_connection=objects.CellMapping.CELL0_UUID)
c0.create()
c1 = objects.CellMapping(
context=ctxt,
uuid=uuids.cell1,
name=CELL1_NAME,
transport_url=fake_transport,
database_connection=uuids.cell1)
c1.create()
self.cell_mappings = {cm.name: cm for cm in (c0, c1)}
开发者ID:vmturbo,项目名称:nova,代码行数:32,代码来源:test.py
示例4: test_scatter_gather_cells_timeout
def test_scatter_gather_cells_timeout(self, mock_get_inst,
mock_get_result, mock_timeout,
mock_log_warning):
# This is needed because we're mocking get_by_filters.
self.useFixture(nova_fixtures.SpawnIsSynchronousFixture())
ctxt = context.get_context()
mapping0 = objects.CellMapping(database_connection='fake://db0',
transport_url='none:///',
uuid=objects.CellMapping.CELL0_UUID)
mapping1 = objects.CellMapping(database_connection='fake://db1',
transport_url='fake://mq1',
uuid=uuids.cell1)
mappings = objects.CellMappingList(objects=[mapping0, mapping1])
# Simulate cell1 not responding.
mock_get_result.side_effect = [(mapping0.uuid,
mock.sentinel.instances),
exception.CellTimeout()]
results = context.scatter_gather_cells(
ctxt, mappings, 30, objects.InstanceList.get_by_filters)
self.assertEqual(2, len(results))
self.assertIn(mock.sentinel.instances, results.values())
self.assertIn(context.did_not_respond_sentinel, results.values())
mock_timeout.assert_called_once_with(30, exception.CellTimeout)
self.assertTrue(mock_log_warning.called)
开发者ID:arbrandes,项目名称:nova,代码行数:26,代码来源:test_context.py
示例5: test_fallback
def test_fallback(self):
# Convert RequestContext, should get a dict.
primitive = rpc.JsonPayloadSerializer.fallback(context.get_context())
self.assertIsInstance(primitive, dict)
# Convert anything else, should get a string.
primitive = rpc.JsonPayloadSerializer.fallback(mock.sentinel.entity)
self.assertIsInstance(primitive, six.text_type)
开发者ID:mahak,项目名称:nova,代码行数:7,代码来源:test_rpc.py
示例6: test_new_websocket_client_db
def test_new_websocket_client_db(
self, mock_ca_check, mock_validate_port, mock_inst_get,
mock_validate, internal_access_path=None,
instance_not_found=False):
db_obj = self._fake_console_db(
host='node1',
port=10000,
console_type='novnc',
access_url_base='https://example.net:6080',
internal_access_path=internal_access_path,
instance_uuid=uuids.instance,
# This is set by ConsoleAuthToken.validate
token='123-456-789'
)
ctxt = nova_context.get_context()
obj = nova.objects.ConsoleAuthToken._from_db_object(
ctxt, nova.objects.ConsoleAuthToken(), db_obj)
mock_validate.return_value = obj
if instance_not_found:
mock_inst_get.side_effect = exception.InstanceNotFound(
instance_id=uuids.instance)
if internal_access_path is None:
self.wh.socket.return_value = '<socket>'
else:
tsock = mock.MagicMock()
tsock.recv.return_value = "HTTP/1.1 200 OK\r\n\r\n"
self.wh.socket.return_value = tsock
self.wh.path = "http://127.0.0.1/?token=123-456-789"
self.wh.headers = self.fake_header
if instance_not_found:
self.assertRaises(exception.InvalidToken,
self.wh.new_websocket_client)
else:
with mock.patch('nova.context.get_admin_context',
return_value=ctxt):
self.wh.new_websocket_client()
mock_validate.called_once_with(ctxt, '123-456-789')
mock_validate_port.assert_called_once_with(
ctxt, mock_inst_get.return_value, str(db_obj['port']),
db_obj['console_type'])
mock_ca_check.assert_not_called()
self.wh.socket.assert_called_with('node1', 10000, connect=True)
if internal_access_path is None:
self.wh.do_proxy.assert_called_with('<socket>')
else:
self.wh.do_proxy.assert_called_with(tsock)
开发者ID:mahak,项目名称:nova,代码行数:54,代码来源:test_websocketproxy.py
示例7: test_cinderclient_unsupported_v2
def test_cinderclient_unsupported_v2(self, get_api_version):
"""Tests that we fail if trying to use Cinder v2."""
self.flags(catalog_info='volumev2:cinderv2:publicURL', group='cinder')
# setup mocks
get_endpoint = mock.Mock(
return_value='http://localhost:8776/v2/%(project_id)s')
fake_session = mock.Mock(get_endpoint=get_endpoint)
ctxt = context.get_context()
with mock.patch.object(cinder, '_SESSION', fake_session):
self.assertRaises(exception.UnsupportedCinderAPIVersion,
cinder.cinderclient, ctxt)
get_api_version.assert_called_once_with(get_endpoint.return_value)
开发者ID:klmitch,项目名称:nova,代码行数:12,代码来源:test_cinder.py
示例8: start_service
def start_service(self, name, host=None, **kwargs):
svc = self.useFixture(
nova_fixtures.ServiceFixture(name, host, **kwargs))
if name == 'compute' and self.USES_DB:
ctxt = context.get_context()
cell = self.cell_mappings[kwargs.pop('cell', CELL1_NAME)]
hm = objects.HostMapping(context=ctxt,
host=svc.service.host,
cell_mapping=cell)
hm.create()
self.host_mappings[hm.host] = hm
return svc.service
开发者ID:vmturbo,项目名称:nova,代码行数:14,代码来源:test.py
示例9: test_scatter_gather_single_cell
def test_scatter_gather_single_cell(self, mock_scatter):
ctxt = context.get_context()
mapping0 = objects.CellMapping(database_connection='fake://db0',
transport_url='none:///',
uuid=objects.CellMapping.CELL0_UUID)
filters = {'deleted': False}
context.scatter_gather_single_cell(ctxt, mapping0,
objects.InstanceList.get_by_filters, filters, sort_dir='foo')
mock_scatter.assert_called_once_with(
ctxt, [mapping0], context.CELL_TIMEOUT,
objects.InstanceList.get_by_filters, filters,
sort_dir='foo')
开发者ID:arbrandes,项目名称:nova,代码行数:14,代码来源:test_context.py
示例10: test_scatter_gather_cells
def test_scatter_gather_cells(self, mock_get_inst, mock_target_cell):
self.useFixture(nova_fixtures.SpawnIsSynchronousFixture())
ctxt = context.get_context()
mapping = objects.CellMapping(database_connection='fake://db',
transport_url='fake://mq',
uuid=uuids.cell)
mappings = objects.CellMappingList(objects=[mapping])
filters = {'deleted': False}
context.scatter_gather_cells(
ctxt, mappings, 60, objects.InstanceList.get_by_filters, filters,
sort_dir='foo')
mock_get_inst.assert_called_once_with(
mock_target_cell.return_value.__enter__.return_value, filters,
sort_dir='foo')
开发者ID:Juniper,项目名称:nova,代码行数:16,代码来源:test_context.py
示例11: start_service
def start_service(self, name, host=None, **kwargs):
if name == 'compute' and self.USES_DB:
# NOTE(danms): We need to create the HostMapping first, because
# otherwise we'll fail to update the scheduler while running
# the compute node startup routines below.
ctxt = context.get_context()
cell = self.cell_mappings[kwargs.pop('cell', CELL1_NAME)]
hm = objects.HostMapping(context=ctxt,
host=host or name,
cell_mapping=cell)
hm.create()
self.host_mappings[hm.host] = hm
svc = self.useFixture(
nova_fixtures.ServiceFixture(name, host, **kwargs))
return svc.service
开发者ID:sapcc,项目名称:nova,代码行数:17,代码来源:test.py
示例12: test_scatter_gather_skip_cell0
def test_scatter_gather_skip_cell0(self, mock_get_all, mock_scatter):
ctxt = context.get_context()
mapping0 = objects.CellMapping(database_connection='fake://db0',
transport_url='none:///',
uuid=objects.CellMapping.CELL0_UUID)
mapping1 = objects.CellMapping(database_connection='fake://db1',
transport_url='fake://mq1',
uuid=uuids.cell1)
mock_get_all.return_value = objects.CellMappingList(
objects=[mapping0, mapping1])
filters = {'deleted': False}
context.scatter_gather_skip_cell0(
ctxt, objects.InstanceList.get_by_filters, filters, sort_dir='foo')
mock_scatter.assert_called_once_with(
ctxt, [mapping1], 60, objects.InstanceList.get_by_filters, filters,
sort_dir='foo')
开发者ID:arbrandes,项目名称:nova,代码行数:18,代码来源:test_context.py
示例13: test_target_cell_caching
def test_target_cell_caching(self, mock_create_cm, mock_create_tport):
mock_create_cm.return_value = mock.sentinel.db_conn_obj
mock_create_tport.return_value = mock.sentinel.mq_conn_obj
ctxt = context.get_context()
mapping = objects.CellMapping(database_connection='fake://db',
transport_url='fake://mq',
uuid=uuids.cell)
# First call should create new connection objects.
with context.target_cell(ctxt, mapping) as cctxt:
self.assertEqual(mock.sentinel.db_conn_obj, cctxt.db_connection)
self.assertEqual(mock.sentinel.mq_conn_obj, cctxt.mq_connection)
mock_create_cm.assert_called_once_with('fake://db')
mock_create_tport.assert_called_once_with('fake://mq')
# Second call should use cached objects.
mock_create_cm.reset_mock()
mock_create_tport.reset_mock()
with context.target_cell(ctxt, mapping) as cctxt:
self.assertEqual(mock.sentinel.db_conn_obj, cctxt.db_connection)
self.assertEqual(mock.sentinel.mq_conn_obj, cctxt.mq_connection)
mock_create_cm.assert_not_called()
mock_create_tport.assert_not_called()
开发者ID:arbrandes,项目名称:nova,代码行数:21,代码来源:test_context.py
示例14: start_service
def start_service(self, name, host=None, **kwargs):
cell = None
if name == 'compute' and self.USES_DB:
# NOTE(danms): We need to create the HostMapping first, because
# otherwise we'll fail to update the scheduler while running
# the compute node startup routines below.
ctxt = context.get_context()
cell_name = kwargs.pop('cell', CELL1_NAME) or CELL1_NAME
cell = self.cell_mappings[cell_name]
hm = objects.HostMapping(context=ctxt,
host=host or name,
cell_mapping=cell)
hm.create()
self.host_mappings[hm.host] = hm
if host is not None:
# Make sure that CONF.host is relevant to the right hostname
self.useFixture(nova_fixtures.ConfPatcher(host=host))
svc = self.useFixture(
nova_fixtures.ServiceFixture(name, host, cell=cell, **kwargs))
return svc.service
开发者ID:openstack,项目名称:nova,代码行数:21,代码来源:test.py
示例15: test_scatter_gather_cells_exception
def test_scatter_gather_cells_exception(self, mock_get_inst,
mock_log_exception):
# This is needed because we're mocking get_by_filters.
self.useFixture(nova_fixtures.SpawnIsSynchronousFixture())
ctxt = context.get_context()
mapping0 = objects.CellMapping(database_connection='fake://db0',
transport_url='none:///',
uuid=objects.CellMapping.CELL0_UUID)
mapping1 = objects.CellMapping(database_connection='fake://db1',
transport_url='fake://mq1',
uuid=uuids.cell1)
mappings = objects.CellMappingList(objects=[mapping0, mapping1])
# Simulate cell1 raising an exception.
mock_get_inst.side_effect = [mock.sentinel.instances,
test.TestingException()]
results = context.scatter_gather_cells(
ctxt, mappings, 30, objects.InstanceList.get_by_filters)
self.assertEqual(2, len(results))
self.assertIn(mock.sentinel.instances, results.values())
self.assertIn(context.raised_exception_sentinel, results.values())
self.assertTrue(mock_log_exception.called)
开发者ID:soulxu,项目名称:nova-v3-api-doc,代码行数:23,代码来源:test_context.py
示例16: _setup_cells
def _setup_cells(self):
"""Setup a normal cellsv2 environment.
This sets up the CellDatabase fixture with two cells, one cell0
and one normal cell. CellMappings are created for both so that
cells-aware code can find those two databases.
"""
celldbs = nova_fixtures.CellDatabases()
ctxt = context.get_context()
fake_transport = 'fake://nowhere/'
c0 = objects.CellMapping(
context=ctxt,
uuid=objects.CellMapping.CELL0_UUID,
name='cell0',
transport_url=fake_transport,
database_connection=objects.CellMapping.CELL0_UUID)
c0.create()
self.cell_mappings[c0.name] = c0
celldbs.add_cell_database(objects.CellMapping.CELL0_UUID)
for x in range(self.NUMBER_OF_CELLS):
name = 'cell%i' % (x + 1)
uuid = getattr(uuids, name)
cell = objects.CellMapping(
context=ctxt,
uuid=uuid,
name=name,
transport_url=fake_transport,
database_connection=uuid)
cell.create()
self.cell_mappings[name] = cell
# cell1 is the default cell
celldbs.add_cell_database(uuid, default=(x == 0))
self.useFixture(celldbs)
开发者ID:openstack,项目名称:nova,代码行数:37,代码来源:test.py
示例17: test_scatter_gather_cells_exception
def test_scatter_gather_cells_exception(self, mock_get_inst,
mock_log_exception):
# This is needed because we're mocking get_by_filters.
self.useFixture(nova_fixtures.SpawnIsSynchronousFixture())
ctxt = context.get_context()
mapping0 = objects.CellMapping(database_connection='fake://db0',
transport_url='none:///',
uuid=objects.CellMapping.CELL0_UUID)
mapping1 = objects.CellMapping(database_connection='fake://db1',
transport_url='fake://mq1',
uuid=uuids.cell1)
mappings = objects.CellMappingList(objects=[mapping0, mapping1])
# Simulate cell1 raising an exception.
mock_get_inst.side_effect = [mock.sentinel.instances,
test.TestingException()]
results = context.scatter_gather_cells(
ctxt, mappings, 30, objects.InstanceList.get_by_filters)
self.assertEqual(2, len(results))
self.assertIn(mock.sentinel.instances, results.values())
self.assertIsInstance(results[mapping1.uuid], Exception)
# non-NovaException gets logged
self.assertTrue(mock_log_exception.called)
# Now run it again with a NovaException to see it's not logged.
mock_log_exception.reset_mock()
mock_get_inst.side_effect = [mock.sentinel.instances,
exception.NotFound()]
results = context.scatter_gather_cells(
ctxt, mappings, 30, objects.InstanceList.get_by_filters)
self.assertEqual(2, len(results))
self.assertIn(mock.sentinel.instances, results.values())
self.assertIsInstance(results[mapping1.uuid], exception.NovaException)
# NovaExceptions are not logged, the caller should handle them.
mock_log_exception.assert_not_called()
开发者ID:arbrandes,项目名称:nova,代码行数:37,代码来源:test_context.py
示例18: test_get_context
def test_get_context(self):
ctxt = context.get_context()
self.assertIsNone(ctxt.user_id)
self.assertIsNone(ctxt.project_id)
self.assertFalse(ctxt.is_admin)
开发者ID:arbrandes,项目名称:nova,代码行数:5,代码来源:test_context.py
示例19: setUp
def setUp(self):
super(SchedulerUtilsTestCase, self).setUp()
self.context = nova_context.get_context()
开发者ID:soulxu,项目名称:nova-v3-api-doc,代码行数:3,代码来源:test_scheduler_utils.py
注:本文中的nova.context.get_context函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论