Fix LP #1006198 - Network tests should be skipped if no Quantum

* Adds base network test case class that handles
  skipping if network client returns no endpoint
  found for network (Quantum)

Change-Id: I602f84a2b5c686ddd28fe1522baddbc3d33fbc46
diff --git a/tempest/tests/network/base.py b/tempest/tests/network/base.py
new file mode 100644
index 0000000..1046cd6
--- /dev/null
+++ b/tempest/tests/network/base.py
@@ -0,0 +1,59 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 OpenStack, LLC
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    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 nose
+import unittest2 as unittest
+
+from tempest import exceptions
+from tempest import openstack
+from tempest.common.utils.data_utils import rand_name
+
+
+class BaseNetworkTest(unittest.TestCase):
+
+    os = openstack.Manager()
+    client = os.network_client
+    config = os.config
+    networks = []
+    enabled = True
+
+    # Validate that there is even an endpoint configured
+    # for networks, and mark the attr for skipping if not
+    try:
+        client.list_networks()
+    except exceptions.EndpointNotFound:
+        enabled = False
+        skip_msg = "No network endpoint"
+
+    @classmethod
+    def setUpClass(cls):
+        if not cls.enabled:
+            raise nose.SkipTest(cls.skip_msg)
+
+    @classmethod
+    def tearDownClass(cls):
+        for network in cls.networks:
+            cls.client.delete_network(network['id'])
+
+    def create_network(self, network_name=None):
+        """Wrapper utility that returns a test network"""
+        network_name = network_name or rand_name('test-network')
+
+        resp, body = self.client.create_network(network_name)
+        network = body['network']
+        self.networks.append(network)
+        return network
diff --git a/tempest/tests/network/test_networks.py b/tempest/tests/network/test_networks.py
index 6adbb6b..5476551 100644
--- a/tempest/tests/network/test_networks.py
+++ b/tempest/tests/network/test_networks.py
@@ -1,23 +1,33 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 OpenStack, LLC
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
 from nose.plugins.attrib import attr
-from tempest import openstack
+
 from tempest.common.utils.data_utils import rand_name
-import unittest2 as unittest
+from tempest.tests.network import base
 
 
-class NetworksTest(unittest.TestCase):
+class NetworksTest(base.BaseNetworkTest):
 
     @classmethod
     def setUpClass(cls):
-        cls.os = openstack.Manager()
-        cls.client = cls.os.network_client
-        cls.config = cls.os.config
-        cls.name = rand_name('network')
-        resp, body = cls.client.create_network(cls.name)
-        cls.network = body['network']
-
-    @classmethod
-    def tearDownClass(cls):
-        cls.client.delete_network(cls.network['id'])
+        super(NetworksTest, cls).setUpClass()
+        cls.network = cls.create_network()
+        cls.name = cls.network['name']
 
     @attr(type='positive')
     def test_create_delete_network(self):