diff options
| author | Phil Day <philip.day@hp.com> | 2013-03-27 12:01:01 +0000 |
|---|---|---|
| committer | Phil Day <philip.day@hp.com> | 2013-03-27 15:15:38 +0000 |
| commit | ea663f3627ff11eea90e457c3b53432d640c63b2 (patch) | |
| tree | 9a7b91da1118b3be90af350b41c015b33b04326f /nova | |
| parent | 0bf532237382360666499e4c568f0a161ff31afe (diff) | |
List AZs fails if there are disabled services
Trying to list availability zones when there is a disabled
services fails with a 500 error
Fixes bug #1160841
Change-Id: Ibdb639f0d6a1a69a6a6331ee053c75449a16fc8f
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/availability_zones.py | 4 | ||||
| -rw-r--r-- | nova/tests/test_availability_zones.py | 77 |
2 files changed, 62 insertions, 19 deletions
diff --git a/nova/availability_zones.py b/nova/availability_zones.py index 45b790081..a0af628af 100644 --- a/nova/availability_zones.py +++ b/nova/availability_zones.py @@ -80,8 +80,8 @@ def get_availability_zones(context): available_zones.append(zone) not_available_zones = [] - zones = [service['available_zones'] for service in disabled_services - if service['available_zones'] not in available_zones] + zones = [service['availability_zone'] for service in disabled_services + if service['availability_zone'] not in available_zones] for zone in zones: if zone not in not_available_zones: not_available_zones.append(zone) diff --git a/nova/tests/test_availability_zones.py b/nova/tests/test_availability_zones.py index 85dc1eefd..4bc6db58b 100644 --- a/nova/tests/test_availability_zones.py +++ b/nova/tests/test_availability_zones.py @@ -43,39 +43,44 @@ class AvailabilityZoneTestCases(test.TestCase): self.default_az = CONF.default_availability_zone self.default_in_az = CONF.internal_service_availability_zone self.context = context.get_admin_context() - - agg = {'name': 'agg1'} - self.agg = db.aggregate_create(self.context, agg) - - metadata = {'availability_zone': self.availability_zone} - db.aggregate_metadata_add(self.context, self.agg['id'], metadata) + self.agg = self._create_az('az_agg', self.availability_zone) def tearDown(self): db.aggregate_delete(self.context, self.agg['id']) super(AvailabilityZoneTestCases, self).tearDown() - def _create_service_with_topic(self, topic): + def _create_az(self, agg_name, az_name): + agg_meta = {'name': agg_name} + agg = db.aggregate_create(self.context, agg_meta) + + metadata = {'availability_zone': az_name} + db.aggregate_metadata_add(self.context, agg['id'], metadata) + + return agg + + def _create_service_with_topic(self, topic, host, disabled=False): values = { 'binary': 'bin', - 'host': self.host, + 'host': host, 'topic': topic, + 'disabled': disabled, } return db.service_create(self.context, values) def _destroy_service(self, service): return db.service_destroy(self.context, service['id']) - def _add_to_aggregate(self, service): + def _add_to_aggregate(self, service, aggregate): return db.aggregate_host_add(self.context, - self.agg['id'], service['host']) + aggregate['id'], service['host']) - def _delete_from_aggregate(self, service): + def _delete_from_aggregate(self, service, aggregate): return db.aggregate_host_delete(self.context, - self.agg['id'], service['host']) + self.aggregate['id'], service['host']) def test_set_availability_zone_compute_service(self): """Test for compute service get right availability zone.""" - service = self._create_service_with_topic('compute') + service = self._create_service_with_topic('compute', self.host) services = db.service_get_all(self.context) # The service is not add into aggregate, so confirm it is default @@ -86,7 +91,7 @@ class AvailabilityZoneTestCases(test.TestCase): # The service is added into aggregate, confirm return the aggregate # availability zone. - self._add_to_aggregate(service) + self._add_to_aggregate(service, self.agg) new_service = az.set_availability_zones(self.context, services)[0] self.assertEquals(new_service['availability_zone'], self.availability_zone) @@ -95,7 +100,7 @@ class AvailabilityZoneTestCases(test.TestCase): def test_set_availability_zone_not_compute_service(self): """Test not compute service get right availability zone.""" - service = self._create_service_with_topic('network') + service = self._create_service_with_topic('network', self.host) services = db.service_get_all(self.context) new_service = az.set_availability_zones(self.context, services)[0] self.assertEquals(new_service['availability_zone'], @@ -107,8 +112,46 @@ class AvailabilityZoneTestCases(test.TestCase): self.assertEquals(self.default_az, az.get_host_availability_zone(self.context, self.host)) - service = self._create_service_with_topic('compute') - self._add_to_aggregate(service) + service = self._create_service_with_topic('compute', self.host) + self._add_to_aggregate(service, self.agg) self.assertEquals(self.availability_zone, az.get_host_availability_zone(self.context, self.host)) + + def test_get_availability_zones(self): + """Test get_availability_zones.""" + + # get_availability_zones returns two lists, zones with at least one + # enabled services, and zones with no enabled services. + # Use the following test data: + # + # zone host enabled + # nova-test host1 Yes + # nova-test host2 No + # nova-test2 host3 Yes + # nova-test3 host4 No + # <default> host5 No + + agg2 = self._create_az('agg-az2', 'nova-test2') + agg3 = self._create_az('agg-az3', 'nova-test3') + + service1 = self._create_service_with_topic('compute', 'host1', + disabled=False) + service2 = self._create_service_with_topic('compute', 'host2', + disabled=True) + service3 = self._create_service_with_topic('compute', 'host3', + disabled=False) + service4 = self._create_service_with_topic('compute', 'host4', + disabled=True) + service5 = self._create_service_with_topic('compute', 'host5', + disabled=True) + + self._add_to_aggregate(service1, self.agg) + self._add_to_aggregate(service2, self.agg) + self._add_to_aggregate(service3, agg2) + self._add_to_aggregate(service4, agg3) + + zones, not_zones = az.get_availability_zones(self.context) + + self.assertEquals(zones, ['nova-test', 'nova-test2']) + self.assertEquals(not_zones, ['nova-test3', 'nova']) |
