Check external network 97/47297/4
authorLinda Wang <wangwulin@huawei.com>
Thu, 16 Nov 2017 04:10:58 +0000 (04:10 +0000)
committerLinda Wang <wangwulin@huawei.com>
Fri, 17 Nov 2017 08:07:48 +0000 (08:07 +0000)
Change-Id: I1ff199fcad99aefccb92807c8f416d4f32ec91a6
Signed-off-by: Linda Wang <wangwulin@huawei.com>
functest/ci/check_deployment.py
functest/tests/unit/ci/test_check_deployment.py

index e593e17..e1ad137 100644 (file)
@@ -22,6 +22,8 @@ import pkg_resources
 import socket
 from urlparse import urlparse
 
+from functest.opnfv_tests.openstack.snaps import snaps_utils
+
 from snaps.openstack.utils import glance_utils
 from snaps.openstack.utils import keystone_utils
 from snaps.openstack.utils import neutron_utils
@@ -125,6 +127,14 @@ class CheckDeployment(object):
             LOGGER.error("Glance service ...FAILED")
             raise error
 
+    def check_ext_net(self):
+        """ checks if external network exists """
+        ext_net = snaps_utils.get_ext_net_name(self.os_creds)
+        if ext_net:
+            LOGGER.info("External network found: %s" % ext_net)
+        else:
+            raise Exception("ERROR: No external networks in the deployment.")
+
     def check_all(self):
         """
         Calls all the class functions and returns 0 if all of them succeed.
@@ -147,6 +157,7 @@ class CheckDeployment(object):
         self.check_nova()
         self.check_neutron()
         self.check_glance()
+        self.check_ext_net()
         return 0
 
 
index 1f44d07..24e3ce5 100644 (file)
@@ -170,6 +170,23 @@ class CheckDeploymentTesting(unittest.TestCase):
             self.assertRaises(Exception)
             self.assertTrue(m.called)
 
+    @mock.patch('functest.ci.check_deployment.LOGGER.info')
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+                'get_ext_net_name', return_value='ext-net')
+    def test_check_extnet(self, mock_getext, mock_loginfo):
+        self.deployment.check_ext_net()
+        self.assertTrue(mock_getext.called)
+        mock_loginfo.assert_called_once_with("External network found: ext-net")
+
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+                'get_ext_net_name', return_value='')
+    def test_check_extnet_None(self, mock_getext):
+        with self.assertRaises(Exception) as context:
+            self.deployment.check_ext_net()
+            self.assertTrue(mock_getext.called)
+            msg = 'ERROR: No external networks in the deployment.'
+            self.assertTrue(msg in context)
+
 
 if __name__ == "__main__":
     logging.disable(logging.CRITICAL)