|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import nova.context |
| 14 | +from nova.db import api as db |
| 15 | +from nova import objects |
| 16 | +from nova import test |
| 17 | + |
| 18 | + |
| 19 | +class InstanceListWithOldDeletedServiceTestCase(test.TestCase): |
| 20 | + |
| 21 | + def setUp(self): |
| 22 | + super(InstanceListWithOldDeletedServiceTestCase, self).setUp() |
| 23 | + self.context = nova.context.RequestContext('fake-user', 'fake-project') |
| 24 | + |
| 25 | + def test_instance_list_old_deleted_service_with_no_uuid(self): |
| 26 | + # Create a nova-compute service record with a host that will match the |
| 27 | + # instance's host, with no uuid. We can't do this through the |
| 28 | + # Service object because it will automatically generate a uuid. |
| 29 | + # Use service version 9, which is too old compared to the minimum |
| 30 | + # version in the rest of the deployment. |
| 31 | + service = db.service_create(self.context, {'host': 'fake-host', |
| 32 | + 'binary': 'nova-compute', |
| 33 | + 'version': 9}) |
| 34 | + self.assertIsNone(service['uuid']) |
| 35 | + |
| 36 | + # Now delete it. |
| 37 | + db.service_destroy(self.context, service['id']) |
| 38 | + |
| 39 | + # Create a new service with the same host name that has a UUID and a |
| 40 | + # current version. |
| 41 | + new_service = objects.Service(context=self.context, host='fake-host', |
| 42 | + binary='nova-compute') |
| 43 | + new_service.create() |
| 44 | + |
| 45 | + # Create an instance whose host will match both services, including the |
| 46 | + # deleted one. |
| 47 | + inst = objects.Instance(context=self.context, |
| 48 | + project_id=self.context.project_id, |
| 49 | + host='fake-host') |
| 50 | + inst.create() |
| 51 | + |
| 52 | + # TODO(melwitt): Remove this assert when the bug is fixed. |
| 53 | + self.assertRaises(nova.exception.ServiceTooOld, |
| 54 | + objects.InstanceList.get_by_filters, |
| 55 | + self.context, {}, expected_attrs=['services']) |
| 56 | + |
| 57 | + # TODO(melwitt): Uncomment these asserts when the bug is fixed. |
| 58 | + # insts = objects.InstanceList.get_by_filters( |
| 59 | + # self.context, {}, expected_attrs=['services']) |
| 60 | + # self.assertEqual(1, len(insts)) |
| 61 | + # self.assertEqual(2, len(insts[0].services)) |
| 62 | + # Deleted service should not have a UUID |
| 63 | + # for service in insts[0].services: |
| 64 | + # if service.deleted: |
| 65 | + # self.assertNotIn('uuid', service) |
| 66 | + # else: |
| 67 | + # self.assertIsNotNone(service.uuid) |
0 commit comments