Add functional regression test for bug 1778305

This tests the scenario where an operator has upgraded from Ocata =>
Pike but has old, deleted services that share the same hostname with
currently existing, running services. The current behavior is that
ServiceTooOld is raised when we try to generate a UUID for the old,
deleted service while querying for a list of instances. After the bug
is fixed, we should be able to successfully query for a list of
instances.

Related-Bug: #1778305

Change-Id: I1c62a0a5be6c44176b5714af00cc181eb5437585
(cherry picked from commit 1d9aaef3d1)
This commit is contained in:
melanie witt 2018-07-12 20:46:24 +00:00 committed by Matt Riedemann
parent 44709cfb5c
commit 06ae1ff214
1 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,67 @@
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import nova.context
from nova.db import api as db
from nova import objects
from nova import test
class InstanceListWithOldDeletedServiceTestCase(test.TestCase):
def setUp(self):
super(InstanceListWithOldDeletedServiceTestCase, self).setUp()
self.context = nova.context.RequestContext('fake-user', 'fake-project')
def test_instance_list_old_deleted_service_with_no_uuid(self):
# Create a nova-compute service record with a host that will match the
# instance's host, with no uuid. We can't do this through the
# Service object because it will automatically generate a uuid.
# Use service version 9, which is too old compared to the minimum
# version in the rest of the deployment.
service = db.service_create(self.context, {'host': 'fake-host',
'binary': 'nova-compute',
'version': 9})
self.assertIsNone(service['uuid'])
# Now delete it.
db.service_destroy(self.context, service['id'])
# Create a new service with the same host name that has a UUID and a
# current version.
new_service = objects.Service(context=self.context, host='fake-host',
binary='nova-compute')
new_service.create()
# Create an instance whose host will match both services, including the
# deleted one.
inst = objects.Instance(context=self.context,
project_id=self.context.project_id,
host='fake-host')
inst.create()
# TODO(melwitt): Remove this assert when the bug is fixed.
self.assertRaises(nova.exception.ServiceTooOld,
objects.InstanceList.get_by_filters,
self.context, {}, expected_attrs=['services'])
# TODO(melwitt): Uncomment these asserts when the bug is fixed.
# insts = objects.InstanceList.get_by_filters(
# self.context, {}, expected_attrs=['services'])
# self.assertEqual(1, len(insts))
# self.assertEqual(2, len(insts[0].services))
# Deleted service should not have a UUID
# for service in insts[0].services:
# if service.deleted:
# self.assertNotIn('uuid', service)
# else:
# self.assertIsNotNone(service.uuid)