summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-09-21 00:21:03 +0000
committerGerrit Code Review <review@openstack.org>2018-09-21 00:21:03 +0000
commit9b2a1f2b2b96eb16a33c8d16cf50ffc6b64f520a (patch)
tree38a80656402039af7ca9b902eb76178719056f81
parent8676f39469264506942442b9eb1004758c3df218 (diff)
parent62464883e1c2ba98e1fddb1284171ca5bef4d8e1 (diff)
downloadnova-9b2a1f2b2b96eb16a33c8d16cf50ffc6b64f520a.tar.gz
Merge "Filter out instances without a host when populating AZ" into stable/pike
-rw-r--r--nova/objects/instance.py3
-rw-r--r--nova/tests/functional/db/test_instance.py11
2 files changed, 10 insertions, 4 deletions
diff --git a/nova/objects/instance.py b/nova/objects/instance.py
index 1810c12a94..da6df09ad1 100644
--- a/nova/objects/instance.py
+++ b/nova/objects/instance.py
@@ -1222,7 +1222,10 @@ def _make_instance_list(context, inst_list, db_inst_list, expected_attrs):
@db_api.pick_context_manager_writer
def populate_missing_availability_zones(context, count):
+ # instances without host have no reasonable AZ to set
+ not_empty_host = models.Instance.host != None # noqa E711
instances = (context.session.query(models.Instance).
+ filter(not_empty_host).
filter_by(availability_zone=None).limit(count).all())
count_all = len(instances)
count_hit = 0
diff --git a/nova/tests/functional/db/test_instance.py b/nova/tests/functional/db/test_instance.py
index 38b530134a..4394f557b4 100644
--- a/nova/tests/functional/db/test_instance.py
+++ b/nova/tests/functional/db/test_instance.py
@@ -50,17 +50,20 @@ class InstanceObjectTestCase(test.TestCase):
uuid1 = inst1.uuid
inst2 = self._create_instance(availability_zone="fake",
host="fake-host2")
+ # ... and one without a host (simulating failed spawn)
+ self._create_instance(host=None)
+
self.assertIsNone(inst1.availability_zone)
self.assertEqual("fake", inst2.availability_zone)
count_all, count_hit = (objects.instance.
populate_missing_availability_zones(self.context, 10))
- # we get only the instance whose avz was None.
+ # we get only the instance whose avz was None and where host is set
self.assertEqual(1, count_all)
self.assertEqual(1, count_hit)
+ # since instance has no avz, avz is set by get_host_availability_zone
+ # to CONF.default_availability_zone i.e 'nova' which is the default
+ # zone for compute services.
inst1 = objects.Instance.get_by_uuid(self.context, uuid1)
- # since instance.host was None, avz is set to
- # CONF.default_availability_zone i.e 'nova' which is the default zone
- # for compute services.
self.assertEqual('nova', inst1.availability_zone)
# create an instance with avz as None on a host that has avz.