def test_get_availability_zones(self):
        """Test get_availability_zones."""

        # When the param get_only_available of get_availability_zones is set
        # to default False, it returns two lists, zones with at least one
        # enabled services, and zones with no enabled services,
        # when get_only_available is set to True, only return a list of zones
        # with at least one 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)
        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)

        host_api = compute_api.HostAPI()
        zones, not_zones = az.get_availability_zones(self.context, host_api)

        self.assertEqual(['nova-test', 'nova-test2'], zones)
        self.assertEqual(['nova', 'nova-test3'], not_zones)

        zones = az.get_availability_zones(self.context,
                                          host_api,
                                          get_only_available=True)

        self.assertEqual(['nova-test', 'nova-test2'], zones)

        zones, not_zones = az.get_availability_zones(self.context,
                                                     host_api,
                                                     with_hosts=True)

        self.assertJsonEqual(zones, [(u'nova-test2', set([u'host3'])),
                                     (u'nova-test', set([u'host1']))])
        self.assertJsonEqual(not_zones, [(u'nova-test3', set([u'host4'])),
                                         (u'nova', set([u'host5']))])
Exemplo n.º 2
0
    def test_get_availability_zones(self):
        """Test get_availability_zones."""

        # When the param get_only_available of get_availability_zones is set
        # to default False, it returns two lists, zones with at least one
        # enabled services, and zones with no enabled services,
        # when get_only_available is set to True, only return a list of zones
        # with at least one 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)
        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.assertEqual(['nova-test', 'nova-test2'], zones)
        self.assertEqual(['nova-test3', 'nova'], not_zones)

        zones = az.get_availability_zones(self.context, True)

        self.assertEqual(['nova-test', 'nova-test2'], zones)

        zones, not_zones = az.get_availability_zones(self.context,
                                                     with_hosts=True)

        self.assertJsonEqual(zones,
                         [(u'nova-test2', set([u'host3'])),
                                 (u'nova-test', set([u'host1']))])
        self.assertJsonEqual(not_zones,
                         [(u'nova-test3', set([u'host4'])),
                                 (u'nova', set([u'host5']))])
Exemplo n.º 3
0
    def _describe_availability_zones_verbose(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = availability_zones.get_availability_zones(ctxt)

        # Available services
        enabled_services = db.service_get_all(context, False)
        enabled_services = availability_zones.set_availability_zones(context, enabled_services)
        zone_hosts = {}
        host_services = {}
        for service in enabled_services:
            zone_hosts.setdefault(service["availability_zone"], [])
            if service["host"] not in zone_hosts[service["availability_zone"]]:
                zone_hosts[service["availability_zone"]].append(service["host"])

            host_services.setdefault(service["availability_zone"] + service["host"], [])
            host_services[service["availability_zone"] + service["host"]].append(service)

        result = []
        for zone in available_zones:
            hosts = {}
            for host in zone_hosts[zone]:
                hosts[host] = {}
                for service in host_services[zone + host]:
                    alive = self.servicegroup_api.service_is_up(service)
                    hosts[host][service["binary"]] = {
                        "available": alive,
                        "active": True != service["disabled"],
                        "updated_at": service["updated_at"],
                    }
            result.append({"zoneName": zone, "zoneState": {"available": True}, "hosts": hosts})

        for zone in not_available_zones:
            result.append({"zoneName": zone, "zoneState": {"available": False}, "hosts": None})
        return {"availabilityZoneInfo": result}
Exemplo n.º 4
0
    def _describe_availability_zones(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = availability_zones.get_availability_zones(ctxt)

        filtered_available_zones = self._get_filtered_availability_zones(available_zones, True)
        filtered_not_available_zones = self._get_filtered_availability_zones(not_available_zones, False)
        return {"availabilityZoneInfo": filtered_available_zones + filtered_not_available_zones}
Exemplo n.º 5
0
    def _describe_availability_zones(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = \
            availability_zones.get_availability_zones(ctxt)

        result = []
        for zone in available_zones:
            # Hide internal_service_availability_zone
            if zone == CONF.internal_service_availability_zone:
                continue
            result.append({
                'zoneName': zone,
                'zoneState': {
                    'available': True
                },
                "hosts": None
            })
        for zone in not_available_zones:
            result.append({
                'zoneName': zone,
                'zoneState': {
                    'available': False
                },
                "hosts": None
            })
        return {'availabilityZoneInfo': result}
Exemplo n.º 6
0
def get_available_zones(zone_names=None, include_internal=False):
    def filter_availability_zones(zones):
        result = []
        for zone in zones:
            if zone[0] == CONF.internal_service_availability_zone:
                continue
            result.append(zone)
        return result

    available_zones, not_available_zones = \
        availability_zones.get_availability_zones(ctx, with_hosts=True)

    if include_internal:
        all_available_zones = available_zones + not_available_zones
    else:

        filtered_available_zones = \
            filter_availability_zones(available_zones)
        filtered_not_available_zones = \
            filter_availability_zones(not_available_zones)

        all_available_zones = filtered_available_zones + \
                              filtered_not_available_zones

    if zone_names:
        if not isinstance(zone_names, (list, tuple)):
            zone_names = [zone_names]

        all_available_zones = [
            az for az in all_available_zones if az[0] in zone_names
        ]

    return all_available_zones
Exemplo n.º 7
0
    def _describe_availability_zones_verbose(self, context, **kwargs):
        ctxt = context.elevated()

        # Available services
        enabled_services = self.host_api.service_get_all(context,
                                                         {'disabled': False},
                                                         set_zones=True,
                                                         all_cells=True)

        available_zones, not_available_zones = (
            availability_zones.get_availability_zones(
                ctxt, enabled_services=enabled_services,
                hostapi=self.host_api))

        zone_hosts = {}
        host_services = {}
        api_services = ('nova-osapi_compute', 'nova-metadata')
        for service in enabled_services:
            if service.binary in api_services:
                # Skip API services in the listing since they are not
                # maintained in the same way as other services
                continue
            zone_hosts.setdefault(service['availability_zone'], set())
            zone_hosts[service['availability_zone']].add(service['host'])

            host_services.setdefault(
                service['availability_zone'] + service['host'], [])
            host_services[service['availability_zone'] + service['host']].\
                    append(service)

        result = []
        for zone in available_zones:
            hosts = {}
            for host in zone_hosts.get(zone, []):
                hosts[host] = {}
                for service in host_services[zone + host]:
                    alive = self.servicegroup_api.service_is_up(service)
                    hosts[host][service['binary']] = {
                        'available': alive,
                        'active': True != service['disabled'],
                        'updated_at': service['updated_at']
                    }
            result.append({
                'zoneName': zone,
                'zoneState': {
                    'available': True
                },
                "hosts": hosts
            })

        for zone in not_available_zones:
            result.append({
                'zoneName': zone,
                'zoneState': {
                    'available': False
                },
                "hosts": None
            })
        return {'availabilityZoneInfo': result}
Exemplo n.º 8
0
    def test_get_availability_zones(self):
        """Test get_availability_zones."""

        # When the param get_only_available of get_availability_zones is set
        # to default False, it returns two lists, zones with at least one
        # enabled services, and zones with no enabled services,
        # when get_only_available is set to True, only return a list of zones
        # with at least one 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)
        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.assertEqual(zones, ["nova-test", "nova-test2"])
        self.assertEqual(not_zones, ["nova-test3", "nova"])

        zones = az.get_availability_zones(self.context, True)

        self.assertEqual(zones, ["nova-test", "nova-test2"])

        zones, not_zones = az.get_availability_zones(self.context, with_hosts=True)

        self.assertJsonEqual(zones, [(u"nova-test2", set([u"host3"])), (u"nova-test", set([u"host1"]))])
        self.assertJsonEqual(not_zones, [(u"nova-test3", set([u"host4"])), (u"nova", set([u"host5"]))])
Exemplo n.º 9
0
    def _describe_availability_zones(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = \
            availability_zones.get_availability_zones(ctxt)

        filtered_available_zones = \
            self._get_filtered_availability_zones(available_zones, True)
        filtered_not_available_zones = \
            self._get_filtered_availability_zones(not_available_zones, False)
        return {'availability_zone_info': filtered_available_zones +
                                        filtered_not_available_zones}
Exemplo n.º 10
0
    def _describe_availability_zones_verbose(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = \
            availability_zones.get_availability_zones(ctxt)

        # Available services
        enabled_services = objects.ServiceList.get_all(context,
                                                       disabled=False,
                                                       set_zones=True)
        zone_hosts = {}
        host_services = {}
        for service in enabled_services:
            zone_hosts.setdefault(service['availability_zone'], [])
            if service['host'] not in zone_hosts[service['availability_zone']]:
                zone_hosts[service['availability_zone']].append(
                    service['host'])

            host_services.setdefault(
                service['availability_zone'] + service['host'], [])
            host_services[service['availability_zone'] + service['host']].\
                    append(service)

        result = []
        for zone in available_zones:
            hosts = {}
            for host in zone_hosts.get(zone, []):
                hosts[host] = {}
                for service in host_services[zone + host]:
                    alive = self.servicegroup_api.service_is_up(service)
                    hosts[host][service['binary']] = {
                        'available': alive,
                        'active': True != service['disabled'],
                        'updated_at': service['updated_at']
                    }
            result.append({
                'zoneName': zone,
                'zoneState': {
                    'available': True
                },
                "hosts": hosts
            })

        for zone in not_available_zones:
            result.append({
                'zoneName': zone,
                'zoneState': {
                    'available': False
                },
                "hosts": None
            })
        return {'availabilityZoneInfo': result}
Exemplo n.º 11
0
    def _describe_availability_zones_verbose(self, context, **kwargs):
        ctxt = context.elevated()

        # Available services
        enabled_services = self.host_api.service_get_all(
            context, {'disabled': False}, set_zones=True, all_cells=True)

        available_zones, not_available_zones = (
            availability_zones.get_availability_zones(
                ctxt, self.host_api, enabled_services=enabled_services))

        zone_hosts = {}
        host_services = {}
        api_services = ('nova-osapi_compute', 'nova-metadata')
        for service in enabled_services:
            if service.binary in api_services:
                # Skip API services in the listing since they are not
                # maintained in the same way as other services
                continue
            zone_hosts.setdefault(service['availability_zone'], set())
            zone_hosts[service['availability_zone']].add(service['host'])

            host_services.setdefault(service['availability_zone'] +
                    service['host'], [])
            host_services[service['availability_zone'] + service['host']].\
                    append(service)

        result = []
        for zone in available_zones:
            hosts = {}
            for host in zone_hosts.get(zone, []):
                hosts[host] = {}
                for service in host_services[zone + host]:
                    alive = self.servicegroup_api.service_is_up(service)
                    hosts[host][service['binary']] = {
                        'available': alive,
                        'active': service['disabled'] is not True,
                        'updated_at': service['updated_at']
                    }
            result.append({'zoneName': zone,
                           'zoneState': {'available': True},
                           "hosts": hosts})

        for zone in not_available_zones:
            result.append({'zoneName': zone,
                           'zoneState': {'available': False},
                           "hosts": None})
        return {'availabilityZoneInfo': result}
Exemplo n.º 12
0
    def _describe_availability_zones(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = \
            availability_zones.get_availability_zones(ctxt)

        result = []
        for zone in available_zones:
            # Hide internal_service_availability_zone
            if zone == CONF.internal_service_availability_zone:
                continue
            result.append({'zoneName': zone,
                           'zoneState': {'available': True},
                           "hosts": None})
        for zone in not_available_zones:
            result.append({'zoneName': zone,
                           'zoneState': {'available': False},
                           "hosts": None})
        return {'availabilityZoneInfo': result}
Exemplo n.º 13
0
    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'])
Exemplo n.º 14
0
    def _describe_availability_zones_verbose(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = \
            availability_zones.get_availability_zones(ctxt)

        # Available services
        enabled_services = db.service_get_all(context, False)
        enabled_services = availability_zones.set_availability_zones(context,
                enabled_services)
        zone_hosts = {}
        host_services = {}
        for service in enabled_services:
            zone_hosts.setdefault(service['availability_zone'], [])
            if service['host'] not in zone_hosts[service['availability_zone']]:
                zone_hosts[service['availability_zone']].append(
                    service['host'])

            host_services.setdefault(service['availability_zone'] +
                    service['host'], [])
            host_services[service['availability_zone'] + service['host']].\
                    append(service)

        result = []
        for zone in available_zones:
            hosts = {}
            for host in zone_hosts.get(zone, []):
                hosts[host] = {}
                for service in host_services[zone + host]:
                    alive = self.servicegroup_api.service_is_up(service)
                    hosts[host][service['binary']] = {'available': alive,
                                      'active': True != service['disabled'],
                                      'updated_at': service['updated_at']}
            result.append({'zone_name': zone,
                           'zone_state': {'available': True},
                           "hosts": hosts})

        for zone in not_available_zones:
            result.append({'zone_name': zone,
                           'zone_state': {'available': False},
                           "hosts": None})
        return {'availability_zone_info': result}
Exemplo n.º 15
0
    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'])