]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/dashboard: fix test_list_enabled_module failure
authorNizamudeen A <nia@redhat.com>
Wed, 30 Oct 2024 14:01:10 +0000 (19:31 +0530)
committerNizamudeen A <nia@redhat.com>
Thu, 13 Mar 2025 06:01:05 +0000 (11:31 +0530)
Check the ports availability and go for a new port if the current one is
not available

Fixes: https://tracker.ceph.com/issues/62972
Signed-off-by: Nizamudeen A <nia@redhat.com>
(cherry picked from commit a2a4a3415c0e5ceef2cb01d3bcdf5eb1fff23803)

qa/tasks/mgr/dashboard/helper.py
qa/tasks/mgr/dashboard/test_mgr_module.py
qa/tasks/mgr/mgr_test_case.py
src/pybind/mgr/dashboard/run-backend-api-tests.sh

index 10ce9218fd5a36cc73b08517c6e741f44766c9b1..55355048a360e38c330735abe427b0dad6039a21 100644 (file)
@@ -221,7 +221,7 @@ class DashboardTestCase(MgrTestCase):
             # To avoid any issues with e.g. unlink bugs, we destroy and recreate
             # the filesystem rather than just doing a rm -rf of files
             cls.mds_cluster.delete_all_filesystems()
-            cls.mds_cluster.mds_restart() # to reset any run-time configs, etc.
+            cls.mds_cluster.mds_restart()  # to reset any run-time configs, etc.
             cls.fs = None  # is now invalid!
 
             cls.fs = cls.mds_cluster.newfs(create=True)
index aa12a5a1c4dd9668bc189f2c7705b5f349968fcc..5866a63ee7bfdee95d3b45ddf365dc109307eef1 100644 (file)
@@ -4,6 +4,7 @@ from __future__ import absolute_import
 import logging
 
 import requests
+from urllib3.exceptions import MaxRetryError
 
 from .helper import (DashboardTestCase, JLeaf, JList, JObj,
                      module_options_object_schema, module_options_schema,
@@ -24,10 +25,11 @@ class MgrModuleTestCase(DashboardTestCase):
         def _check_connection():
             try:
                 # Try reaching an API endpoint successfully.
+                logger.info('Trying to reach the REST API endpoint')
                 self._get('/api/mgr/module')
                 if self._resp.status_code == 200:
                     return True
-            except requests.ConnectionError:
+            except (MaxRetryError, requests.ConnectionError):
                 pass
             return False
 
index aa5bc6e56a9fac8ffa48178af422d43a4b5704ee..6a41b5e7ad33fff556c41c19474222de8bc0d83b 100644 (file)
@@ -1,5 +1,6 @@
 import json
 import logging
+import socket
 
 from unittest import SkipTest
 
@@ -209,15 +210,22 @@ class MgrTestCase(CephTestCase):
         """
         # Start handing out ports well above Ceph's range.
         assign_port = min_port
+        ip_addr = cls.mgr_cluster.get_mgr_map()['active_addr'].split(':')[0]
 
         for mgr_id in cls.mgr_cluster.mgr_ids:
             cls.mgr_cluster.mgr_stop(mgr_id)
             cls.mgr_cluster.mgr_fail(mgr_id)
 
+
         for mgr_id in cls.mgr_cluster.mgr_ids:
-            log.debug("Using port {0} for {1} on mgr.{2}".format(
-                assign_port, module_name, mgr_id
-            ))
+            # Find a port that isn't in use
+            while True:
+                if not cls.is_port_in_use(ip_addr, assign_port):
+                    break
+                log.debug(f"Port {assign_port} in use, trying next")
+                assign_port += 1
+
+            log.debug(f"Using port {assign_port} for {module_name} on mgr.{mgr_id}")
             cls.mgr_cluster.set_module_localized_conf(module_name, mgr_id,
                                                       config_name,
                                                       str(assign_port),
@@ -235,3 +243,8 @@ class MgrTestCase(CephTestCase):
                     mgr_map['active_name'], mgr_map['active_gid']))
             return done
         cls.wait_until_true(is_available, timeout=30)
+
+    @classmethod
+    def is_port_in_use(cls, ip_addr: str, port: int) -> bool:
+        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
+            return s.connect_ex((ip_addr, port)) == 0
index bdd38cbe8c5110d9873152f169ad9e9f3dc0d17f..69005ef2c612b2f12be2181e66f816aa04d2cfef 100755 (executable)
@@ -134,7 +134,7 @@ run_teuthology_tests() {
     export CEPH_OUT_CLIENT_DIR=${LOCAL_BUILD_DIR}/out/client
     find . -iname "*${COVERAGE_FILE}*" -type f -delete
 
-    python ../qa/tasks/vstart_runner.py --ignore-missing-binaries --no-verbose $OPTIONS $(echo $TEST_CASES) ||
+    python ../qa/tasks/vstart_runner.py --ignore-missing-binaries --no-verbose --debug $OPTIONS $(echo $TEST_CASES) ||
       on_tests_error
 
     deactivate