Merge "[TrivialFix] Use tempest.config instead of oslo_config.cfg"
diff --git a/patrole_tempest_plugin/rbac_utils.py b/patrole_tempest_plugin/rbac_utils.py
index 1ada69b..b3cb271 100644
--- a/patrole_tempest_plugin/rbac_utils.py
+++ b/patrole_tempest_plugin/rbac_utils.py
@@ -216,7 +216,7 @@
     def skip_rbac_checks(cls):
         if not CONF.patrole.enable_rbac:
             raise cls.skipException(
-                '%s skipped as Patrole testing not enabled.' % cls.__name__)
+                'Patrole testing not enabled so skipping %s.' % cls.__name__)
 
     @classmethod
     def setup_rbac_utils(cls):
diff --git a/patrole_tempest_plugin/tests/api/compute/test_aggregates_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_aggregates_rbac.py
index 12ac058..b7cd392 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_aggregates_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_aggregates_rbac.py
@@ -13,7 +13,10 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import testtools
+
 from tempest.common import utils
+from tempest import config
 from tempest.lib.common.utils import data_utils
 from tempest.lib.common.utils import test_utils
 from tempest.lib import decorators
@@ -21,6 +24,8 @@
 from patrole_tempest_plugin import rbac_rule_validation
 from patrole_tempest_plugin.tests.api.compute import rbac_base
 
+CONF = config.CONF
+
 
 class AggregatesRbacTest(rbac_base.BaseV2ComputeRbacTest):
 
@@ -36,6 +41,29 @@
         super(AggregatesRbacTest, cls).setup_clients()
         cls.hosts_client = cls.os_primary.hosts_client
 
+    @classmethod
+    def resource_setup(cls):
+        super(AggregatesRbacTest, cls).resource_setup()
+        cls.host = None
+        hypers = cls.hypervisor_client.list_hypervisors(
+            detail=True)['hypervisors']
+
+        if CONF.compute.hypervisor_type:
+            hypers = [hyper for hyper in hypers
+                      if (hyper['hypervisor_type'] ==
+                          CONF.compute.hypervisor_type)]
+
+        hosts_available = [hyper['service']['host'] for hyper in hypers
+                           if (hyper['state'] == 'up' and
+                               hyper['status'] == 'enabled')]
+        if hosts_available:
+            cls.host = hosts_available[0]
+        else:
+            msg = "no available compute node found"
+            if CONF.compute.hypervisor_type:
+                msg += " for hypervisor_type %s" % CONF.compute.hypervisor_type
+            raise testtools.TestCase.failureException(msg)
+
     def _create_aggregate(self):
         agg_name = data_utils.rand_name(self.__class__.__name__ + '-aggregate')
         aggregate = self.aggregates_client.create_aggregate(name=agg_name)
@@ -46,13 +74,11 @@
         return aggregate_id
 
     def _add_host_to_aggregate(self, aggregate_id):
-        host_name = self.hosts_client.list_hosts()['hosts'][0]['host_name']
-        self.aggregates_client.add_host(aggregate_id, host=host_name)
+        self.aggregates_client.add_host(aggregate_id, host=self.host)
         self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                         self.aggregates_client.remove_host,
                         aggregate_id,
-                        host=host_name)
-        return host_name
+                        host=self.host)
 
     @rbac_rule_validation.action(
         service="nova", rule="os_compute_api:os-aggregates:create")
@@ -107,9 +133,9 @@
     @decorators.idempotent_id('5b035a25-75d2-4d72-b4d6-0f0337335628')
     def test_remove_host_from_aggregate_rbac(self):
         aggregate_id = self._create_aggregate()
-        host_name = self._add_host_to_aggregate(aggregate_id)
+        self._add_host_to_aggregate(aggregate_id)
         with self.rbac_utils.override_role(self):
-            self.aggregates_client.remove_host(aggregate_id, host=host_name)
+            self.aggregates_client.remove_host(aggregate_id, host=self.host)
 
     @rbac_rule_validation.action(
         service="nova", rule="os_compute_api:os-aggregates:set_metadata")
diff --git a/patrole_tempest_plugin/tests/api/compute/test_server_volume_attachments_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_server_volume_attachments_rbac.py
index ed0c7a2..b803fe3 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_server_volume_attachments_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_server_volume_attachments_rbac.py
@@ -12,6 +12,7 @@
 #    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 testtools
 
 from tempest.common import waiters
 from tempest import config
@@ -72,6 +73,8 @@
                 self.server['id'], attachment['id'])
 
     @decorators.attr(type='slow')
+    @testtools.skipUnless(CONF.compute_feature_enabled.swap_volume,
+                          'In-place swapping of volumes not supported.')
     @rbac_rule_validation.action(
         service="nova",
         rule="os_compute_api:os-volumes-attachments:update")
diff --git a/patrole_tempest_plugin/tests/unit/test_rbac_utils.py b/patrole_tempest_plugin/tests/unit/test_rbac_utils.py
index 55db501..5e730d3 100644
--- a/patrole_tempest_plugin/tests/unit/test_rbac_utils.py
+++ b/patrole_tempest_plugin/tests/unit/test_rbac_utils.py
@@ -254,6 +254,6 @@
 
         with testtools.ExpectedException(
                 testtools.TestCase.skipException,
-                value_re=('%s skipped as Patrole testing not enabled.'
+                value_re=('Patrole testing not enabled so skipping %s.'
                           % ChildRbacTest.__name__)):
             child_test.setUpClass()