Merge "make testing neutron api extensions optional"
diff --git a/tempest/api/network/admin/test_agent_management.py b/tempest/api/network/admin/test_agent_management.py
index b05f275..342bc6a 100644
--- a/tempest/api/network/admin/test_agent_management.py
+++ b/tempest/api/network/admin/test_agent_management.py
@@ -14,7 +14,7 @@
 
 from tempest.api.network import base
 from tempest.common import tempest_fixtures as fixtures
-from tempest.test import attr
+from tempest import test
 
 
 class AgentManagementTestJSON(base.BaseAdminNetworkTest):
@@ -23,11 +23,14 @@
     @classmethod
     def setUpClass(cls):
         super(AgentManagementTestJSON, cls).setUpClass()
+        if not test.is_extension_enabled('agent', 'network'):
+            msg = "agent extension not enabled."
+            raise cls.skipException(msg)
         resp, body = cls.admin_client.list_agents()
         agents = body['agents']
         cls.agent = agents[0]
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_list_agent(self):
         resp, body = self.admin_client.list_agents()
         self.assertEqual('200', resp['status'])
@@ -38,20 +41,20 @@
             agent.pop('heartbeat_timestamp', None)
         self.assertIn(self.agent, agents)
 
-    @attr(type=['smoke'])
+    @test.attr(type=['smoke'])
     def test_list_agents_non_admin(self):
         resp, body = self.client.list_agents()
         self.assertEqual('200', resp['status'])
         self.assertEqual(len(body["agents"]), 0)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_show_agent(self):
         resp, body = self.admin_client.show_agent(self.agent['id'])
         agent = body['agent']
         self.assertEqual('200', resp['status'])
         self.assertEqual(agent['id'], self.agent['id'])
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_update_agent_status(self):
         origin_status = self.agent['admin_state_up']
         # Try to update the 'admin_state_up' to the original
@@ -63,7 +66,7 @@
         self.assertEqual('200', resp['status'])
         self.assertEqual(origin_status, updated_status)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_update_agent_description(self):
         self.useFixture(fixtures.LockFixture('agent_description'))
         description = 'description for update agent.'
diff --git a/tempest/api/network/admin/test_dhcp_agent_scheduler.py b/tempest/api/network/admin/test_dhcp_agent_scheduler.py
index 13309cd..ecd992a 100644
--- a/tempest/api/network/admin/test_dhcp_agent_scheduler.py
+++ b/tempest/api/network/admin/test_dhcp_agent_scheduler.py
@@ -13,7 +13,7 @@
 #    under the License.
 
 from tempest.api.network import base
-from tempest.test import attr
+from tempest import test
 
 
 class DHCPAgentSchedulersTestJSON(base.BaseAdminNetworkTest):
@@ -22,6 +22,9 @@
     @classmethod
     def setUpClass(cls):
         super(DHCPAgentSchedulersTestJSON, cls).setUpClass()
+        if not test.is_extension_enabled('dhcp_agent_scheduler', 'network'):
+            msg = "dhcp_agent_scheduler extension not enabled."
+            raise cls.skipException(msg)
         # Create a network and make sure it will be hosted by a
         # dhcp agent.
         cls.network = cls.create_network()
@@ -29,13 +32,13 @@
         cls.cidr = cls.subnet['cidr']
         cls.port = cls.create_port(cls.network)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_list_dhcp_agent_hosting_network(self):
         resp, body = self.admin_client.list_dhcp_agent_hosting_network(
             self.network['id'])
         self.assertEqual(resp['status'], '200')
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_list_networks_hosted_by_one_dhcp(self):
         resp, body = self.admin_client.list_dhcp_agent_hosting_network(
             self.network['id'])
@@ -55,7 +58,7 @@
             network_ids.append(network['id'])
         return network_id in network_ids
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_remove_network_from_dhcp_agent(self):
         resp, body = self.admin_client.list_dhcp_agent_hosting_network(
             self.network['id'])
diff --git a/tempest/api/network/test_extensions.py b/tempest/api/network/test_extensions.py
index a177d65..529f8e9 100644
--- a/tempest/api/network/test_extensions.py
+++ b/tempest/api/network/test_extensions.py
@@ -44,6 +44,8 @@
                           'agent', 'dhcp_agent_scheduler', 'provider',
                           'router', 'extraroute', 'external-net',
                           'allowed-address-pairs', 'extra_dhcp_opt']
+        expected_alias = [ext for ext in expected_alias if
+                          test.is_extension_enabled(ext, 'network')]
         actual_alias = list()
         resp, extensions = self.client.list_extensions()
         self.assertEqual('200', resp['status'])
diff --git a/tempest/api/network/test_floating_ips.py b/tempest/api/network/test_floating_ips.py
index 69367ab..b31c090 100644
--- a/tempest/api/network/test_floating_ips.py
+++ b/tempest/api/network/test_floating_ips.py
@@ -16,7 +16,7 @@
 from tempest.api.network import base
 from tempest.common.utils import data_utils
 from tempest import config
-from tempest.test import attr
+from tempest import test
 
 CONF = config.CONF
 
@@ -46,6 +46,9 @@
     @classmethod
     def setUpClass(cls):
         super(FloatingIPTestJSON, cls).setUpClass()
+        if not test.is_extension_enabled('router', 'network'):
+            msg = "router extension not enabled."
+            raise cls.skipException(msg)
         cls.ext_net_id = CONF.network.public_network_id
 
         # Create network, subnet, router and add interface
@@ -59,7 +62,7 @@
         for i in range(2):
             cls.create_port(cls.network)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_create_list_show_update_delete_floating_ip(self):
         # Creates a floating IP
         created_floating_ip = self.create_floating_ip(
@@ -110,7 +113,7 @@
         self.assertIsNone(updated_floating_ip['fixed_ip_address'])
         self.assertIsNone(updated_floating_ip['router_id'])
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_floating_ip_delete_port(self):
         # Create a floating IP
         created_floating_ip = self.create_floating_ip(self.ext_net_id)
@@ -133,7 +136,7 @@
         self.assertIsNone(shown_floating_ip['fixed_ip_address'])
         self.assertIsNone(shown_floating_ip['router_id'])
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_floating_ip_update_different_router(self):
         # Associate a floating IP to a port on a router
         created_floating_ip = self.create_floating_ip(
diff --git a/tempest/api/network/test_quotas.py b/tempest/api/network/test_quotas.py
index a5be395..38784d8 100644
--- a/tempest/api/network/test_quotas.py
+++ b/tempest/api/network/test_quotas.py
@@ -17,7 +17,7 @@
 from tempest.api.network import base
 from tempest import clients
 from tempest.common.utils import data_utils
-from tempest.test import attr
+from tempest import test
 
 
 class QuotasTest(base.BaseNetworkTest):
@@ -46,11 +46,14 @@
     @classmethod
     def setUpClass(cls):
         super(QuotasTest, cls).setUpClass()
+        if not test.is_extension_enabled('quotas', 'network'):
+            msg = "quotas extension not enabled."
+            raise cls.skipException(msg)
         admin_manager = clients.AdminManager()
         cls.admin_client = admin_manager.network_client
         cls.identity_admin_client = admin_manager.identity_client
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_quotas(self):
         # Add a tenant to conduct the test
         test_tenant = data_utils.rand_name('test_tenant_')
diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py
index f3fac93..d552c70 100644
--- a/tempest/api/network/test_routers.py
+++ b/tempest/api/network/test_routers.py
@@ -29,6 +29,9 @@
     @classmethod
     def setUpClass(cls):
         super(RoutersTest, cls).setUpClass()
+        if not test.is_extension_enabled('router', 'network'):
+            msg = "router extension not enabled."
+            raise cls.skipException(msg)
 
     @test.attr(type='smoke')
     def test_create_show_list_update_delete_router(self):
diff --git a/tempest/api/network/test_routers_negative.py b/tempest/api/network/test_routers_negative.py
index 0d65b64..e6ad4de 100644
--- a/tempest/api/network/test_routers_negative.py
+++ b/tempest/api/network/test_routers_negative.py
@@ -16,7 +16,7 @@
 from tempest.api.network import base_routers as base
 from tempest.common.utils import data_utils
 from tempest import exceptions
-from tempest.test import attr
+from tempest import test
 
 
 class RoutersNegativeTest(base.BaseRouterTest):
@@ -25,11 +25,14 @@
     @classmethod
     def setUpClass(cls):
         super(RoutersNegativeTest, cls).setUpClass()
+        if not test.is_extension_enabled('router', 'network'):
+            msg = "router extension not enabled."
+            raise cls.skipException(msg)
         cls.router = cls.create_router(data_utils.rand_name('router-'))
         cls.network = cls.create_network()
         cls.subnet = cls.create_subnet(cls.network)
 
-    @attr(type=['negative', 'smoke'])
+    @test.attr(type=['negative', 'smoke'])
     def test_router_add_gateway_invalid_network_returns_404(self):
         self.assertRaises(exceptions.NotFound,
                           self.client.update_router,
@@ -37,7 +40,7 @@
                           external_gateway_info={
                               'network_id': self.router['id']})
 
-    @attr(type=['negative', 'smoke'])
+    @test.attr(type=['negative', 'smoke'])
     def test_router_add_gateway_net_not_external_returns_400(self):
         self.create_subnet(self.network)
         self.assertRaises(exceptions.BadRequest,
@@ -46,7 +49,7 @@
                           external_gateway_info={
                               'network_id': self.network['id']})
 
-    @attr(type=['negative', 'smoke'])
+    @test.attr(type=['negative', 'smoke'])
     def test_router_remove_interface_in_use_returns_409(self):
         self.client.add_router_interface_with_subnet_id(
             self.router['id'], self.subnet['id'])
diff --git a/tempest/api/network/test_security_groups.py b/tempest/api/network/test_security_groups.py
index b95182d..6eebf5b 100644
--- a/tempest/api/network/test_security_groups.py
+++ b/tempest/api/network/test_security_groups.py
@@ -14,13 +14,20 @@
 #    under the License.
 
 from tempest.api.network import base_security_groups as base
-from tempest.test import attr
+from tempest import test
 
 
 class SecGroupTest(base.BaseSecGroupTest):
     _interface = 'json'
 
-    @attr(type='smoke')
+    @classmethod
+    def setUpClass(cls):
+        super(SecGroupTest, cls).setUpClass()
+        if not test.is_extension_enabled('security-group', 'network'):
+            msg = "security-group extension not enabled."
+            raise cls.skipException(msg)
+
+    @test.attr(type='smoke')
     def test_list_security_groups(self):
         # Verify the that security group belonging to tenant exist in list
         resp, body = self.client.list_security_groups()
@@ -33,7 +40,7 @@
         msg = "Security-group list doesn't contain default security-group"
         self.assertIsNotNone(found, msg)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_create_show_delete_security_group(self):
         group_create_body, name = self._create_security_group()
 
@@ -51,7 +58,7 @@
             secgroup_list.append(secgroup['id'])
         self.assertIn(group_create_body['security_group']['id'], secgroup_list)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_create_show_delete_security_group_rule(self):
         group_create_body, _ = self._create_security_group()
 
@@ -80,7 +87,7 @@
                      for rule in rule_list_body['security_group_rules']]
         self.assertIn(rule_create_body['security_group_rule']['id'], rule_list)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_create_security_group_rule_with_additional_args(self):
         # Verify creating security group rule with the following
         # arguments works: "protocol": "tcp", "port_range_max": 77,
diff --git a/tempest/api/network/test_security_groups_negative.py b/tempest/api/network/test_security_groups_negative.py
index 98e109e..e1f4055 100644
--- a/tempest/api/network/test_security_groups_negative.py
+++ b/tempest/api/network/test_security_groups_negative.py
@@ -17,26 +17,33 @@
 
 from tempest.api.network import base_security_groups as base
 from tempest import exceptions
-from tempest.test import attr
+from tempest import test
 
 
 class NegativeSecGroupTest(base.BaseSecGroupTest):
     _interface = 'json'
 
-    @attr(type=['negative', 'gate'])
+    @classmethod
+    def setUpClass(cls):
+        super(NegativeSecGroupTest, cls).setUpClass()
+        if not test.is_extension_enabled('security-group', 'network'):
+            msg = "security-group extension not enabled."
+            raise cls.skipException(msg)
+
+    @test.attr(type=['negative', 'gate'])
     def test_show_non_existent_security_group(self):
         non_exist_id = str(uuid.uuid4())
         self.assertRaises(exceptions.NotFound, self.client.show_security_group,
                           non_exist_id)
 
-    @attr(type=['negative', 'gate'])
+    @test.attr(type=['negative', 'gate'])
     def test_show_non_existent_security_group_rule(self):
         non_exist_id = str(uuid.uuid4())
         self.assertRaises(exceptions.NotFound,
                           self.client.show_security_group_rule,
                           non_exist_id)
 
-    @attr(type=['negative', 'gate'])
+    @test.attr(type=['negative', 'gate'])
     def test_delete_non_existent_security_group(self):
         non_exist_id = str(uuid.uuid4())
         self.assertRaises(exceptions.NotFound,
@@ -44,7 +51,7 @@
                           non_exist_id
                           )
 
-    @attr(type=['negative', 'gate'])
+    @test.attr(type=['negative', 'gate'])
     def test_create_security_group_rule_with_bad_protocol(self):
         group_create_body, _ = self._create_security_group()
 
@@ -55,7 +62,7 @@
                           group_create_body['security_group']['id'],
                           protocol=pname)
 
-    @attr(type=['negative', 'gate'])
+    @test.attr(type=['negative', 'gate'])
     def test_create_security_group_rule_with_invalid_ports(self):
         group_create_body, _ = self._create_security_group()
 
@@ -73,7 +80,7 @@
                                    port_range_max=pmax)
             self.assertIn(msg, str(ex))
 
-    @attr(type=['negative', 'smoke'])
+    @test.attr(type=['negative', 'smoke'])
     def test_create_additional_default_security_group_fails(self):
         # Create security group named 'default', it should be failed.
         name = 'default'
@@ -81,7 +88,7 @@
                           self.client.create_security_group,
                           name)
 
-    @attr(type=['negative', 'smoke'])
+    @test.attr(type=['negative', 'smoke'])
     def test_create_security_group_rule_with_non_existent_security_group(self):
         # Create security group rules with not existing security group.
         non_existent_sg = str(uuid.uuid4())
diff --git a/tempest/cli/simple_read_only/test_neutron.py b/tempest/cli/simple_read_only/test_neutron.py
index ebf0dc4..cd81378 100644
--- a/tempest/cli/simple_read_only/test_neutron.py
+++ b/tempest/cli/simple_read_only/test_neutron.py
@@ -57,17 +57,20 @@
         self.assertTableStruct(ext, ['alias', 'name'])
 
     @test.attr(type='smoke')
+    @test.requires_ext(extension='dhcp_agent_scheduler', service='network')
     def test_neutron_dhcp_agent_list_hosting_net(self):
         self.neutron('dhcp-agent-list-hosting-net',
                      params=CONF.compute.fixed_network_name)
 
     @test.attr(type='smoke')
+    @test.requires_ext(extension='agent', service='network')
     def test_neutron_agent_list(self):
         agents = self.parser.listing(self.neutron('agent-list'))
         field_names = ['id', 'agent_type', 'host', 'alive', 'admin_state_up']
         self.assertTableStruct(agents, field_names)
 
     @test.attr(type='smoke')
+    @test.requires_ext(extension='router', service='network')
     def test_neutron_floatingip_list(self):
         self.neutron('floatingip-list')
 
@@ -83,6 +86,7 @@
     def test_neutron_meter_label_rule_list(self):
         self.neutron('meter-label-rule-list')
 
+    @test.requires_ext(extension='lbaas_agent_scheduler', service='network')
     def _test_neutron_lbaas_command(self, command):
         try:
             self.neutron(command)
@@ -107,6 +111,7 @@
         self._test_neutron_lbaas_command('lb-vip-list')
 
     @test.attr(type='smoke')
+    @test.requires_ext(extension='external-net', service='network')
     def test_neutron_net_external_list(self):
         self.neutron('net-external-list')
 
@@ -115,19 +120,23 @@
         self.neutron('port-list')
 
     @test.attr(type='smoke')
+    @test.requires_ext(extension='quotas', service='network')
     def test_neutron_quota_list(self):
         self.neutron('quota-list')
 
     @test.attr(type='smoke')
+    @test.requires_ext(extension='router', service='network')
     def test_neutron_router_list(self):
         self.neutron('router-list')
 
     @test.attr(type='smoke')
+    @test.requires_ext(extension='security-group', service='network')
     def test_neutron_security_group_list(self):
         security_grp = self.parser.listing(self.neutron('security-group-list'))
         self.assertTableStruct(security_grp, ['id', 'name', 'description'])
 
     @test.attr(type='smoke')
+    @test.requires_ext(extension='security-group', service='network')
     def test_neutron_security_group_rule_list(self):
         self.neutron('security-group-rule-list')
 
diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py
index 020a256..0c0234f 100644
--- a/tempest/scenario/test_network_basic_ops.py
+++ b/tempest/scenario/test_network_basic_ops.py
@@ -19,9 +19,7 @@
 from tempest import config
 from tempest.openstack.common import log as logging
 from tempest.scenario import manager
-
-from tempest.test import attr
-from tempest.test import services
+from tempest import test
 
 CONF = config.CONF
 LOG = logging.getLogger(__name__)
@@ -113,6 +111,10 @@
     @classmethod
     def setUpClass(cls):
         super(TestNetworkBasicOps, cls).setUpClass()
+        for ext in ['router', 'security-group']:
+            if not test.is_extension_enabled(ext, 'network'):
+                msg = "%s extension not enabled." % ext
+                raise cls.skipException(msg)
         cls.check_preconditions()
         # TODO(mnewby) Consider looking up entities as needed instead
         # of storing them as collections on the class.
@@ -235,8 +237,8 @@
             self._associate_floating_ip(floating_ip, server)
             self.floating_ips[floating_ip] = server
 
-    @attr(type='smoke')
-    @services('compute', 'network')
+    @test.attr(type='smoke')
+    @test.services('compute', 'network')
     def test_network_basic_ops(self):
         self._create_security_groups()
         self._create_networks()