1
0
mirror of https://github.com/gryf/openstack.git synced 2025-12-17 11:30:24 +01:00

Fixed allow compute node patch

This commit is contained in:
Roman Dobosz
2018-01-17 13:38:57 +01:00
parent b63c5cc36d
commit 3275e4aaae

View File

@@ -1,30 +1,28 @@
From cc4070f78b764af439b429908a97f82e620803c9 Mon Sep 17 00:00:00 2001 From 0f820a60994586debef47a59ebf8d9eef225b69c Mon Sep 17 00:00:00 2001
From: Roman Dobosz <roman.dobosz@intel.com> From: Roman Dobosz <roman.dobosz@intel.com>
Date: Wed, 27 Dec 2017 13:51:25 +0100 Date: Wed, 27 Dec 2017 13:51:25 +0100
Subject: [PATCH] allow compute nodes to be associated with host agg Subject: [PATCH 1/3] allow compute nodes to be associated with host agg
This is basically an Ocata backport patch from Jay Pipes: This is basically an Ocata backport patch from Jay Pipes:
https://review.openstack.org/#/c/526753 https://review.openstack.org/#/c/526753
--- ---
nova/compute/api.py | 37 +++++- nova/compute/api.py | 36 +++++-
nova/tests/functional/compute/__init__.py | 0 nova/tests/functional/compute/__init__.py | 0
.../tests/functional/compute/test_aggregate_api.py | 139 +++++++++++++++++++++ .../tests/functional/compute/test_aggregate_api.py | 127 +++++++++++++++++++++
nova/tests/unit/compute/test_compute.py | 4 +- 3 files changed, 159 insertions(+), 4 deletions(-)
4 files changed, 174 insertions(+), 6 deletions(-)
create mode 100644 nova/tests/functional/compute/__init__.py create mode 100644 nova/tests/functional/compute/__init__.py
create mode 100644 nova/tests/functional/compute/test_aggregate_api.py create mode 100644 nova/tests/functional/compute/test_aggregate_api.py
diff --git a/nova/compute/api.py b/nova/compute/api.py diff --git a/nova/compute/api.py b/nova/compute/api.py
index 36de3abc34..b064f26a45 100644 index 6f1371b45f..39437e6c16 100644
--- a/nova/compute/api.py --- a/nova/compute/api.py
+++ b/nova/compute/api.py +++ b/nova/compute/api.py
@@ -4540,6 +4540,32 @@ class AggregateAPI(base.Base): @@ -4548,6 +4548,31 @@ class AggregateAPI(base.Base):
availability_zones.update_host_availability_zone_cache(context, availability_zones.update_host_availability_zone_cache(context,
host_name) host_name)
+ def _service_or_compute_node_exists(self, ctx, host_or_node): + def _service_or_compute_node_exists(self, ctx, host_or_node):
+ """ + """Returns True if a service host or compute node record could be found
+ Returns True if a service host or compute node record could be found
+ for the supplied host_or_node string. We first check to see if a + for the supplied host_or_node string. We first check to see if a
+ service record can be found with the host matching the host_or_node + service record can be found with the host matching the host_or_node
+ parameter by looking at the host mapping records in the API database. + parameter by looking at the host mapping records in the API database.
@@ -36,7 +34,7 @@ index 36de3abc34..b064f26a45 100644
+ try: + try:
+ objects.Service.get_by_compute_host(ctx, host_or_node) + objects.Service.get_by_compute_host(ctx, host_or_node)
+ return True + return True
+ except exception.HostMappingNotFound: + except exception.ComputeHostNotFound:
+ pass + pass
+ +
+ found_nodes = (len(objects.ComputeNodeList + found_nodes = (len(objects.ComputeNodeList
@@ -51,7 +49,7 @@ index 36de3abc34..b064f26a45 100644
@wrap_exception() @wrap_exception()
def add_host_to_aggregate(self, context, aggregate_id, host_name): def add_host_to_aggregate(self, context, aggregate_id, host_name):
"""Adds the host to an aggregate.""" """Adds the host to an aggregate."""
@@ -4548,8 +4574,9 @@ class AggregateAPI(base.Base): @@ -4556,8 +4581,9 @@ class AggregateAPI(base.Base):
compute_utils.notify_about_aggregate_update(context, compute_utils.notify_about_aggregate_update(context,
"addhost.start", "addhost.start",
aggregate_payload) aggregate_payload)
@@ -63,7 +61,7 @@ index 36de3abc34..b064f26a45 100644
aggregate = objects.Aggregate.get_by_id(context, aggregate_id) aggregate = objects.Aggregate.get_by_id(context, aggregate_id)
self.is_safe_to_update_az(context, aggregate.metadata, self.is_safe_to_update_az(context, aggregate.metadata,
@@ -4575,8 +4602,10 @@ class AggregateAPI(base.Base): @@ -4583,8 +4609,10 @@ class AggregateAPI(base.Base):
compute_utils.notify_about_aggregate_update(context, compute_utils.notify_about_aggregate_update(context,
"removehost.start", "removehost.start",
aggregate_payload) aggregate_payload)
@@ -81,10 +79,10 @@ new file mode 100644
index 0000000000..e69de29bb2 index 0000000000..e69de29bb2
diff --git a/nova/tests/functional/compute/test_aggregate_api.py b/nova/tests/functional/compute/test_aggregate_api.py diff --git a/nova/tests/functional/compute/test_aggregate_api.py b/nova/tests/functional/compute/test_aggregate_api.py
new file mode 100644 new file mode 100644
index 0000000000..aeaf3958f2 index 0000000000..7946fddcfe
--- /dev/null --- /dev/null
+++ b/nova/tests/functional/compute/test_aggregate_api.py +++ b/nova/tests/functional/compute/test_aggregate_api.py
@@ -0,0 +1,139 @@ @@ -0,0 +1,127 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may +# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain +# not use this file except in compliance with the License. You may obtain
+# a copy of the License at +# a copy of the License at
@@ -118,9 +116,7 @@ index 0000000000..aeaf3958f2
+ self.agg_api = compute_api.AggregateAPI() + self.agg_api = compute_api.AggregateAPI()
+ self.useFixture(nova_fixtures.Database(database='api')) + self.useFixture(nova_fixtures.Database(database='api'))
+ celldbs = nova_fixtures.CellDatabases() + celldbs = nova_fixtures.CellDatabases()
+ celldbs.add_cell_database(objects.CellMapping.CELL0_UUID) + celldbs.add_cell_database(objects.CellMapping.CELL0_UUID, default=True)
+ celldbs.add_cell_database(uuids.cell1, default=True)
+ celldbs.add_cell_database(uuids.cell2)
+ self.useFixture(celldbs) + self.useFixture(celldbs)
+ +
+ self.ctxt = context.get_admin_context() + self.ctxt = context.get_admin_context()
@@ -129,40 +125,31 @@ index 0000000000..aeaf3958f2
+ database_connection=objects.CellMapping.CELL0_UUID, + database_connection=objects.CellMapping.CELL0_UUID,
+ transport_url='none:///') + transport_url='none:///')
+ cell0.create() + cell0.create()
+ cell1 = objects.CellMapping( + self.cell_mappings = (cell0,)
+ context=self.ctxt, uuid=uuids.cell1,
+ database_connection=uuids.cell1, transport_url='none:///')
+ cell1.create()
+ cell2 = objects.CellMapping(
+ context=self.ctxt, uuid=uuids.cell2,
+ database_connection=uuids.cell2, transport_url='none:///')
+ cell2.create()
+ self.cell_mappings = (cell0, cell1, cell2)
+ +
+ # create two Ironic nodes managed by a single nova-compute service host + # create two Ironic nodes
+ # in each of the non-cell0 cells + for id_ in (1, 2):
+ for cell_id, cell in enumerate(self.cell_mappings[1:]): + hostname = 'ironic_host_%s' % id_
+ with context.target_cell(self.ctxt, cell) as cctxt: + with context.target_cell(self.ctxt, cell0) as cctxt:
+ hostname = 'ironic_host_cell%s' % (cell_id + 1)
+ svc = objects.Service(cctxt, host=hostname, + svc = objects.Service(cctxt, host=hostname,
+ binary='nova-compute', + binary='nova-compute',
+ topic='nova-compute') + topic='nova-compute')
+ svc.create() + svc.create()
+ for node_id in (1, 2): +
+ nodename = 'ironic_node_cell%s_%s' % (cell_id + 1, node_id) + nodename = 'ironic_node_%s' % id_
+ compute_node_uuid = getattr(uuids, nodename) + compute_node_uuid = getattr(uuids, nodename)
+ node = objects.ComputeNode( + node = objects.ComputeNode(
+ cctxt, uuid=compute_node_uuid, host=hostname, + cctxt, uuid=compute_node_uuid, host=hostname,
+ vcpus=2, memory_mb=2048, local_gb=128, vcpus_used=0, + vcpus=2, memory_mb=2048, local_gb=128, vcpus_used=0,
+ memory_mb_used=0, local_gb_used=0, cpu_info='{}', + memory_mb_used=0, local_gb_used=0, cpu_info='{}',
+ hypervisor_type='ironic', hypervisor_version=10, + hypervisor_type='ironic', hypervisor_version=10,
+ hypervisor_hostname=nodename) + hypervisor_hostname=nodename)
+ node.create() + node.create()
+ +
+ # create a compute node for VMs along with a corresponding nova-compute + # create a compute node for VMs along with a corresponding nova-compute
+ # service host in cell1 + # service host in cell1
+ with context.target_cell(self.ctxt, cell1) as cctxt: + with context.target_cell(self.ctxt, cell0) as cctxt:
+ hostname = 'vm_host_cell1_1' + hostname = 'vm_host_1'
+ svc = objects.Service(cctxt, host=hostname, + svc = objects.Service(cctxt, host=hostname,
+ binary='nova-compute', + binary='nova-compute',
+ topic='nova-compute') + topic='nova-compute')
@@ -194,7 +181,7 @@ index 0000000000..aeaf3958f2
+ self.agg_api.remove_host_from_aggregate, self.ctxt, + self.agg_api.remove_host_from_aggregate, self.ctxt,
+ agg_id, 'unknown_host_cell1') + agg_id, 'unknown_host_cell1')
+ +
+ hosts = ('ironic_host_cell1', 'ironic_host_cell2', 'vm_host_cell1_1') + hosts = ('ironic_host_1', 'vm_host_1')
+ for service_host in hosts: + for service_host in hosts:
+ self.agg_api.add_host_to_aggregate(self.ctxt, agg_id, service_host) + self.agg_api.add_host_to_aggregate(self.ctxt, agg_id, service_host)
+ self.agg_api.remove_host_from_aggregate(self.ctxt, agg_id, + self.agg_api.remove_host_from_aggregate(self.ctxt, agg_id,
@@ -218,30 +205,11 @@ index 0000000000..aeaf3958f2
+ self.agg_api.remove_host_from_aggregate, self.ctxt, + self.agg_api.remove_host_from_aggregate, self.ctxt,
+ agg_id, getattr(uuids, 'unknown_host_cell1')) + agg_id, getattr(uuids, 'unknown_host_cell1'))
+ +
+ nodenames = ('ironic_node_cell1_2', 'ironic_node_cell2_1', + nodenames = ('ironic_node_2', 'ironic_node_1', 'vm_host_')
+ 'vm_host_cell1_1')
+ for nodename in nodenames: + for nodename in nodenames:
+ self.agg_api.add_host_to_aggregate(self.ctxt, agg_id, nodename) + self.agg_api.add_host_to_aggregate(self.ctxt, agg_id, nodename)
+ self.agg_api.remove_host_from_aggregate(self.ctxt, agg_id, + self.agg_api.remove_host_from_aggregate(self.ctxt, agg_id,
+ nodename) + nodename)
diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py
index a71f337eb5..a1c26d6e4d 100644
--- a/nova/tests/unit/compute/test_compute.py
+++ b/nova/tests/unit/compute/test_compute.py
@@ -11193,11 +11193,11 @@ class ComputeAPIAggrTestCase(BaseTestCase):
mock_az.assert_called_with(self.context, host_to_remove)
def test_remove_host_from_aggregate_raise_not_found(self):
- # Ensure ComputeHostNotFound is raised when removing invalid host.
+ # Ensure HostMappingNotFound is raised when removing invalid host.
_create_service_entries(self.context, [['fake_zone', ['fake_host']]])
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
'fake_zone')
- self.assertRaises(exception.ComputeHostNotFound,
+ self.assertRaises(exception.HostMappingNotFound,
self.api.remove_host_from_aggregate,
self.context, aggr.id, 'invalid_host')
-- --
2.13.6 2.13.6