test_aggregates should choose available compute node

This is to make test_aggregates choose an available compute node
to avoid testcase fail when it happens to choose an unavailable
node among all compute nodes.

Change-Id: I1aeff9a48a85c42108d42992b1f988b72a7c467a
Closes-Bug: #1582134
diff --git a/tempest/api/compute/admin/test_aggregates.py b/tempest/api/compute/admin/test_aggregates.py
index a2b1e2f..3b43b9f 100644
--- a/tempest/api/compute/admin/test_aggregates.py
+++ b/tempest/api/compute/admin/test_aggregates.py
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import testtools
+
 from tempest.api.compute import base
 from tempest.common import tempest_fixtures as fixtures
 from tempest.common.utils import data_utils
@@ -36,10 +38,16 @@
         cls.aggregate_name_prefix = 'test_aggregate'
         cls.az_name_prefix = 'test_az'
 
-        hosts_all = cls.os_adm.hosts_client.list_hosts()['hosts']
-        hosts = map(lambda x: x['host_name'],
-                    filter(lambda y: y['service'] == 'compute', hosts_all))
-        cls.host = hosts[0]
+        cls.host = None
+        hypers = cls.os_adm.hypervisor_client.list_hypervisors()['hypervisors']
+        hypers_available = [hyper['hypervisor_hostname'] for hyper in hypers
+                            if (hyper['state'] == 'up' and
+                                hyper['status'] == 'enabled')]
+        if hypers_available:
+            cls.host = hypers_available[0]
+        else:
+            raise testtools.TestCase.failureException(
+                "no available compute node found")
 
     def _try_delete_aggregate(self, aggregate_id):
         # delete aggregate, if it exists