本文整理汇总了Python中nova.cells.utils.add_cell_to_service函数的典型用法代码示例。如果您正苦于以下问题:Python add_cell_to_service函数的具体用法?Python add_cell_to_service怎么用?Python add_cell_to_service使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_cell_to_service函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_service_get_all
def test_service_get_all(self):
responses = []
expected_response = []
# 3 cells... so 3 responses. Each response is a list of services.
# Manager should turn these into a single list of responses.
for i in xrange(3):
cell_name = 'path!to!cell%i' % i
services = []
for service in FAKE_SERVICES:
services.append(copy.deepcopy(service))
expected_service = copy.deepcopy(service)
cells_utils.add_cell_to_service(expected_service, cell_name)
expected_response.append(expected_service)
response = messaging.Response(self.ctxt, cell_name, services,
False)
responses.append(response)
self.mox.StubOutWithMock(self.msg_runner,
'service_get_all')
self.msg_runner.service_get_all(self.ctxt,
'fake-filters').AndReturn(responses)
self.mox.ReplayAll()
response = self.cells_manager.service_get_all(self.ctxt,
filters='fake-filters')
self.assertEqual(expected_response, response)
示例2: test_service_get_all
def test_service_get_all(self):
responses = []
expected_response = []
# 3 cells... so 3 responses. Each response is a list of services.
# Manager should turn these into a single list of responses.
for i in range(3):
cell_name = 'path!to!cell%i' % i
services = []
for service in FAKE_SERVICES:
fake_service = objects.Service(**service)
services.append(fake_service)
expected_service = cells_utils.ServiceProxy(fake_service,
cell_name)
expected_response.append(
(cell_name, expected_service, fake_service))
response = messaging.Response(self.ctxt, cell_name, services,
False)
responses.append(response)
self.mox.StubOutWithMock(self.msg_runner,
'service_get_all')
self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
self.msg_runner.service_get_all(self.ctxt,
'fake-filters').AndReturn(responses)
# Calls are done by cells, so we need to sort the list by the cell name
expected_response.sort(key=lambda k: k[0])
for cell_name, service_proxy, service in expected_response:
cells_utils.add_cell_to_service(
service, cell_name).AndReturn(service_proxy)
self.mox.ReplayAll()
response = self.cells_manager.service_get_all(self.ctxt,
filters='fake-filters')
self.assertEqual([proxy for cell, proxy, service in expected_response],
response)
示例3: service_get_by_compute_host
def service_get_by_compute_host(self, ctxt, host_name):
"""Return a service entry for a compute host in a certain cell."""
cell_name, host_name = cells_utils.split_cell_and_item(host_name)
response = self.msg_runner.service_get_by_compute_host(ctxt, cell_name, host_name)
service = response.value_or_raise()
cells_utils.add_cell_to_service(service, response.cell_name)
return service
示例4: service_get_all
def service_get_all(self, ctxt, filters):
"""Return services in this cell and in all child cells."""
responses = self.msg_runner.service_get_all(ctxt, filters)
ret_services = []
# 1 response per cell. Each response is a list of services.
for response in responses:
services = response.value_or_raise()
for service in services:
cells_utils.add_cell_to_service(service, response.cell_name)
ret_services.append(service)
return ret_services
示例5: test_service_get_by_compute_host
def test_service_get_by_compute_host(self):
self.mox.StubOutWithMock(self.msg_runner, "service_get_by_compute_host")
fake_cell = "fake-cell"
fake_response = messaging.Response(fake_cell, FAKE_SERVICES[0], False)
expected_response = copy.deepcopy(FAKE_SERVICES[0])
cells_utils.add_cell_to_service(expected_response, fake_cell)
cell_and_host = cells_utils.cell_with_item("fake-cell", "fake-host")
self.msg_runner.service_get_by_compute_host(self.ctxt, fake_cell, "fake-host").AndReturn(fake_response)
self.mox.ReplayAll()
response = self.cells_manager.service_get_by_compute_host(self.ctxt, host_name=cell_and_host)
self.assertEqual(expected_response, response)
示例6: service_update
def service_update(self, ctxt, host_name, binary, params_to_update):
"""Used to enable/disable a service. For compute services, setting to
disabled stops new builds arriving on that host.
:param host_name: the name of the host machine that the service is
running
:param binary: The name of the executable that the service runs as
:param params_to_update: eg. {'disabled': True}
:returns: the service reference
"""
cell_name, host_name = cells_utils.split_cell_and_item(host_name)
response = self.msg_runner.service_update(
ctxt, cell_name, host_name, binary, params_to_update)
service = response.value_or_raise()
cells_utils.add_cell_to_service(service, response.cell_name)
return service
示例7: test_service_update
def test_service_update(self):
fake_cell = "fake-cell"
fake_response = messaging.Response(fake_cell, FAKE_SERVICES[0], False)
expected_response = copy.deepcopy(FAKE_SERVICES[0])
cells_utils.add_cell_to_service(expected_response, fake_cell)
cell_and_host = cells_utils.cell_with_item("fake-cell", "fake-host")
params_to_update = {"disabled": True}
self.mox.StubOutWithMock(self.msg_runner, "service_update")
self.msg_runner.service_update(self.ctxt, fake_cell, "fake-host", "nova-api", params_to_update).AndReturn(
fake_response
)
self.mox.ReplayAll()
response = self.cells_manager.service_update(
self.ctxt, host_name=cell_and_host, binary="nova-api", params_to_update=params_to_update
)
self.assertEqual(expected_response, response)
示例8: test_service_get_by_compute_host
def test_service_get_by_compute_host(self):
fake_cell = 'fake-cell'
fake_service = objects.Service(**FAKE_SERVICES[0])
fake_response = messaging.Response(self.ctxt, fake_cell,
fake_service,
False)
expected_response = cells_utils.ServiceProxy(fake_service, fake_cell)
cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')
self.mox.StubOutWithMock(self.msg_runner,
'service_get_by_compute_host')
self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
self.msg_runner.service_get_by_compute_host(self.ctxt,
fake_cell, 'fake-host').AndReturn(fake_response)
cells_utils.add_cell_to_service(fake_service, fake_cell).AndReturn(
expected_response)
self.mox.ReplayAll()
response = self.cells_manager.service_get_by_compute_host(self.ctxt,
host_name=cell_and_host)
self.assertEqual(expected_response, response)
示例9: test_service_update
def test_service_update(self):
fake_cell = 'fake-cell'
fake_service = objects.Service(**FAKE_SERVICES[0])
fake_response = messaging.Response(
self.ctxt, fake_cell, fake_service, False)
expected_response = cells_utils.ServiceProxy(fake_service, fake_cell)
cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')
params_to_update = {'disabled': True}
self.mox.StubOutWithMock(self.msg_runner, 'service_update')
self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
self.msg_runner.service_update(self.ctxt,
fake_cell, 'fake-host', 'nova-api',
params_to_update).AndReturn(fake_response)
cells_utils.add_cell_to_service(fake_service, fake_cell).AndReturn(
expected_response)
self.mox.ReplayAll()
response = self.cells_manager.service_update(
self.ctxt, host_name=cell_and_host, binary='nova-api',
params_to_update=params_to_update)
self.assertEqual(expected_response, response)
示例10: test_add_cell_to_service_with_compute_node
def test_add_cell_to_service_with_compute_node(self):
fake_service = objects.Service(id=1, host='fake')
fake_service.compute_node = objects.ComputeNode(id=1, host='fake')
cell_path = 'fake_path'
proxy = cells_utils.add_cell_to_service(fake_service, cell_path)
self.assertIsInstance(proxy, cells_utils.ServiceProxy)
self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
proxy.host)
self.assertRaises(AttributeError,
getattr, proxy, 'compute_node')
示例11: test_add_cell_to_service_no_compute_node
def test_add_cell_to_service_no_compute_node(self, mock_get_by_id):
fake_service = objects.Service(id=1, host='fake')
mock_get_by_id.side_effect = exception.ServiceNotFound(service_id=1)
cell_path = 'fake_path'
proxy = cells_utils.add_cell_to_service(fake_service, cell_path)
self.assertIsInstance(proxy, cells_utils.ServiceProxy)
self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
proxy.host)
self.assertRaises(AttributeError,
getattr, proxy, 'compute_node')