Implement connection_check via shade too 61/58961/4
authorCédric Ollivier <cedric.ollivier@orange.com>
Mon, 25 Jun 2018 04:07:26 +0000 (06:07 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Mon, 25 Jun 2018 05:46:18 +0000 (07:46 +0200)
SNAPS connection_check tests are merged into api_check.
It would ease debugging deployment as well [1]

[1] https://build.opnfv.org/ci/view/functest/job/functest-apex-baremetal-daily-master/127/console

Change-Id: I30254a46c3dc6874881d687e36903c6b7878d63d
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
docker/healthcheck/testcases.yaml
functest/ci/testcases.yaml
functest/opnfv_tests/openstack/api/__init__.py [new file with mode: 0644]
functest/opnfv_tests/openstack/api/connection_check.py [new file with mode: 0644]
functest/opnfv_tests/openstack/snaps/api_check.py
functest/opnfv_tests/openstack/snaps/connection_check.py [deleted file]
functest/tests/unit/openstack/snaps/test_snaps.py

index 12dc7d2..9e9b68b 100644 (file)
@@ -16,15 +16,13 @@ tiers:
                 description: >-
                     This test case verifies the retrieval of OpenStack clients:
                     Keystone, Glance, Neutron and Nova and may perform some
-                    simple queries. When the config value of
-                    snaps.use_keystone is True, functest must have access to
-                    the cloud's private network.
+                    simple queries.
                 dependencies:
                     installer: ''
                     scenario: ''
                 run:
                     module:
-                        'functest.opnfv_tests.openstack.snaps.connection_check'
+                        'functest.opnfv_tests.openstack.api.connection_check'
                     class: 'ConnectionCheck'
 
             -
index a441553..68d1a36 100644 (file)
@@ -16,15 +16,13 @@ tiers:
                 description: >-
                     This test case verifies the retrieval of OpenStack clients:
                     Keystone, Glance, Neutron and Nova and may perform some
-                    simple queries. When the config value of
-                    snaps.use_keystone is True, functest must have access to
-                    the cloud's private network.
+                    simple queries.
                 dependencies:
                     installer: ''
                     scenario: ''
                 run:
                     module:
-                        'functest.opnfv_tests.openstack.snaps.connection_check'
+                        'functest.opnfv_tests.openstack.api.connection_check'
                     class: 'ConnectionCheck'
 
             -
diff --git a/functest/opnfv_tests/openstack/api/__init__.py b/functest/opnfv_tests/openstack/api/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/functest/opnfv_tests/openstack/api/connection_check.py b/functest/opnfv_tests/openstack/api/connection_check.py
new file mode 100644 (file)
index 0000000..663119a
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2018 Orange and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""Verify the connection to OpenStack Services"""
+
+import logging
+import time
+
+import os_client_config
+import shade
+from xtesting.core import testcase
+
+
+class ConnectionCheck(testcase.TestCase):
+    """Perform simplest queries"""
+    __logger = logging.getLogger(__name__)
+
+    def __init__(self, **kwargs):
+        if "case_name" not in kwargs:
+            kwargs["case_name"] = 'connection_check'
+        super(ConnectionCheck, self).__init__(**kwargs)
+        try:
+            cloud_config = os_client_config.get_config()
+            self.cloud = shade.OpenStackCloud(cloud_config=cloud_config)
+        except Exception:  # pylint: disable=broad-except
+            self.cloud = None
+
+    def run(self, **kwargs):
+        """Run all read operations to check connections"""
+        status = testcase.TestCase.EX_RUN_ERROR
+        try:
+            assert self.cloud
+            self.start_time = time.time()
+            for func in ["list_aggregates", "list_domains", "list_endpoints",
+                         "list_floating_ip_pools", "list_floating_ips",
+                         "list_hypervisors", "list_keypairs", "list_networks",
+                         "list_ports", "list_role_assignments", "list_roles",
+                         "list_routers", "list_servers", "list_services",
+                         "list_subnets", "list_zones"]:
+                self.__logger.debug(
+                    "%s: %s", func, getattr(self.cloud, func)())
+            self.result = 100
+            status = testcase.TestCase.EX_OK
+        except Exception:  # pylint: disable=broad-except
+            self.__logger.exception('Cannot run %s', self.case_name)
+        finally:
+            self.stop_time = time.time()
+        return status
index b8cd4fd..d4204bf 100644 (file)
@@ -36,6 +36,11 @@ class ApiCheck(SnapsTestRunner):
         :param kwargs: the arguments to pass on
         :return:
         """
+        snaps_suite_builder.add_openstack_client_tests(
+            suite=self.suite,
+            os_creds=self.os_creds,
+            ext_net_name=self.ext_net_name,
+            use_keystone=self.use_keystone)
         snaps_suite_builder.add_openstack_api_tests(
             suite=self.suite,
             os_creds=self.os_creds,
diff --git a/functest/opnfv_tests/openstack/snaps/connection_check.py b/functest/opnfv_tests/openstack/snaps/connection_check.py
deleted file mode 100644 (file)
index f8bf885..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
-#
-# This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-
-# pylint: disable=missing-docstring
-
-import unittest
-
-from functest.opnfv_tests.openstack.snaps import snaps_suite_builder
-from functest.opnfv_tests.openstack.snaps.snaps_test_runner import \
-    SnapsTestRunner
-
-
-class ConnectionCheck(SnapsTestRunner):
-    """
-    This test executes the Python Tests included with the SNAPS libraries
-    that simply obtain the different OpenStack clients and may perform
-    simple queries
-    """
-    def __init__(self, **kwargs):
-        if "case_name" not in kwargs:
-            kwargs["case_name"] = "connection_check"
-        super(ConnectionCheck, self).__init__(**kwargs)
-
-        self.suite = unittest.TestSuite()
-
-    def run(self, **kwargs):
-        """
-        Builds the test suite then calls super.run()
-        :param kwargs: the arguments to pass on
-        :return:
-        """
-        snaps_suite_builder.add_openstack_client_tests(
-            suite=self.suite,
-            os_creds=self.os_creds,
-            ext_net_name=self.ext_net_name,
-            use_keystone=self.use_keystone)
-        return super(ConnectionCheck, self).run()
index 9da4f2a..a376044 100644 (file)
@@ -15,73 +15,9 @@ import mock
 from snaps.openstack.os_credentials import OSCreds
 from xtesting.core import testcase
 
-from functest.opnfv_tests.openstack.snaps import (
-    connection_check, api_check, health_check, smoke)
-
-
-class ConnectionCheckTesting(unittest.TestCase):
-    """
-    Ensures the VPingUserdata class can run in Functest. This test does not
-    actually connect with an OpenStack pod.
-    """
-
-    def setUp(self):
-        self.os_creds = OSCreds(
-            username='user', password='pass',
-            auth_url='http://foo.com:5000/v3', project_name='bar')
-
-        self.connection_check = connection_check.ConnectionCheck(
-            os_creds=self.os_creds, ext_net_name='foo')
-
-    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
-                'add_openstack_client_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
-    def test_run_success(self, *args):
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = []
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.connection_check.run())
-        self.assertEquals(
-            testcase.TestCase.EX_OK, self.connection_check.is_successful())
-        args[0].assert_called_with(mock.ANY)
-        args[1].assert_called_with(
-            ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
-            use_keystone=True)
-
-    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
-                'add_openstack_client_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
-    def test_run_1_of_100_ko(self, *args):
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = ['foo']
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.connection_check.run())
-        self.assertEquals(
-            testcase.TestCase.EX_TESTCASE_FAILED,
-            self.connection_check.is_successful())
-        args[0].assert_called_with(mock.ANY)
-        args[1].assert_called_with(
-            ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
-            use_keystone=True)
-
-    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
-                'add_openstack_client_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
-    def test_run_1_of_100_ko_criteria(self, *args):
-        self.connection_check.criteria = 90
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = ['foo']
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.connection_check.run())
-        self.assertEquals(
-            testcase.TestCase.EX_OK, self.connection_check.is_successful())
-        args[0].assert_called_with(mock.ANY)
-        args[1].assert_called_with(
-            ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
-            use_keystone=True)
+from functest.opnfv_tests.openstack.snaps import api_check
+from functest.opnfv_tests.openstack.snaps import health_check
+from functest.opnfv_tests.openstack.snaps import smoke
 
 
 class APICheckTesting(unittest.TestCase):
@@ -98,6 +34,8 @@ class APICheckTesting(unittest.TestCase):
         self.api_check = api_check.ApiCheck(
             os_creds=self.os_creds, ext_net_name='foo')
 
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
+                'add_openstack_client_tests')
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_api_tests')
     @mock.patch('unittest.TextTestRunner.run',
@@ -114,6 +52,8 @@ class APICheckTesting(unittest.TestCase):
             ext_net_name='foo', image_metadata=mock.ANY,
             os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
 
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
+                'add_openstack_client_tests')
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_api_tests')
     @mock.patch('unittest.TextTestRunner.run',
@@ -131,6 +71,8 @@ class APICheckTesting(unittest.TestCase):
             ext_net_name='foo', image_metadata=mock.ANY,
             os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
 
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
+                'add_openstack_client_tests')
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_api_tests')
     @mock.patch('unittest.TextTestRunner.run',