← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~adam-collard/maas-ci/+git/system-tests:improve-ansible-performance into ~maas-committers/maas-ci/+git/system-tests:improve-ansible-performance

 

Adam Collard has proposed merging ~adam-collard/maas-ci/+git/system-tests:improve-ansible-performance into ~maas-committers/maas-ci/+git/system-tests:improve-ansible-performance.

Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~adam-collard/maas-ci/+git/system-tests/+merge/440858
-- 
Your team MAAS Committers is requested to review the proposed merge of ~adam-collard/maas-ci/+git/system-tests:improve-ansible-performance into ~maas-committers/maas-ci/+git/system-tests:improve-ansible-performance.
diff --git a/systemtests/ansible.py b/systemtests/ansible.py
index cebe838..37a5417 100644
--- a/systemtests/ansible.py
+++ b/systemtests/ansible.py
@@ -1,6 +1,5 @@
 from __future__ import annotations
 
-import inspect
 import re
 import warnings
 from collections import defaultdict
@@ -339,46 +338,16 @@ class AnsibleMain:
     def logger(self, logger: Logger) -> None:
         self.instance.logger = logger
 
-    def __climbstack__(self, _stackdepth_: int = 0) -> inspect.Traceback:
-        """Fetch the 'nth' parent frame as given by _stackdepth_"""
-        frame = _frame = inspect.currentframe()
-        while _frame and _stackdepth_ > 0:
-            frame, _frame, _stackdepth_ = _frame, _frame.f_back, _stackdepth_ - 1
-        return inspect.getframeinfo(frame)  # type: ignore
-
     def timed(
         self,
         function: Callable[..., Any],
         *args: Any,
-        _stackdepth_: int = 0,
         **kwargs: Any,
     ) -> float:
-        """Return the time to execute the provided function:\n
-        _stackdepth_: How far up the stack is the function name to log?
-        0 gives 'timed', 1 is the function that called timed(), and so on...
-        """
+        """Return the time to execute the provided function"""
         runtime = Timer(partial(function, *args, **kwargs)).timeit(number=1)
-        self.log_runtime(self.__climbstack__(_stackdepth_ + 1).function, runtime)
         return runtime
 
-    def log_runtime(self, function: str, runtime: float) -> None:
-        self.runtimes[function].append(runtime)
-
-    def show_runtimes(self) -> None:
-        def log_rt(func: str, runtime: float, width: int) -> None:
-            self.logger.info(f"| {func:<{width}}: {runtime:.2f}s")
-
-        if self.runtimes:
-            width = max([len(func) for func in self.runtimes.keys()]) + 3
-            self.logger.info("┌ Playbook execution time:")
-            for func, runtime in self.runtimes.items():
-                if len(runtime) == 1:
-                    log_rt(func, runtime[0], width)
-                    continue
-                for idx, rt in enumerate(runtime):
-                    log_rt(f"{func}-{idx}", rt, width)
-            self.logger.info("└ ✔")
-
     @cached_property
     def public_ssh_key(self) -> str:
         ssh_key = self.instance.files[self.ssh_key_file]
@@ -636,6 +605,5 @@ class AnsibleMain:
             self.instance.execute,
             command=cmd,
             environment=self._proxy_env,
-            _stackdepth_=2,
         )
-        self.logger.info(f"Playbook execution took {timedelta(seconds=runtime)}")
+        self.logger.info(f"Playbook execution took {runtime:.2f}s")
diff --git a/systemtests/ansible_tests/test_ansible.py b/systemtests/ansible_tests/test_ansible.py
index e02be0c..55c9fc8 100644
--- a/systemtests/ansible_tests/test_ansible.py
+++ b/systemtests/ansible_tests/test_ansible.py
@@ -67,7 +67,7 @@ class TestAnsibleMAAS:
                     "maas_version": DEFAULT_VERSION,
                 }
             )
-            ansible_main.run_playbook("site.yaml")
+            ansible_main.run_playbook()
             region = ansible_main.fetch_region(regionrack_host)
             assert region.read_version_information()["version"][:3] == DEFAULT_VERSION
         assert not ansible_main._inventory_
@@ -92,12 +92,12 @@ class TestAnsibleMAAS:
                     "maas_version": start_version,
                 }
             )
-            ansible_main.run_playbook("site.yaml")
+            ansible_main.run_playbook()
             region = ansible_main.fetch_region(host)
             assert region.read_version_information()["version"][:3] == start_version
 
             ansible_main.update_config({"maas_version": upgrade_version})
-            ansible_main.run_playbook("site.yaml")
+            ansible_main.run_playbook()
             region = ansible_main.fetch_region(host)
             region.refresh()
             assert region.read_version_information()["version"][:3] == upgrade_version
diff --git a/systemtests/fixtures.py b/systemtests/fixtures.py
index 27789e3..b5e5f8f 100644
--- a/systemtests/fixtures.py
+++ b/systemtests/fixtures.py
@@ -67,12 +67,13 @@ def ansible_main(config: dict[str, Any]) -> Optional[Iterator[AnsibleMain]]:
     yield main
     main.remove_hosts(main._inventory_)
     instance.delete()
-    main.show_runtimes()
 
 
 @pytest.fixture(scope="session")
 def maas_from_ansible(ansible_main: AnsibleMain) -> Iterator[AuthenticatedAPIClient]:
     """Deploy MAAS using Ansible."""
+    logger = getLogger(f"{LOG_NAME}.maas_from_ansible")
+    ansible_main.logger = logger
     host = ansible_main.add_host().add_region()
     with ansible_main.collect_inventory():
         ansible_main.update_config(
@@ -81,7 +82,7 @@ def maas_from_ansible(ansible_main: AnsibleMain) -> Iterator[AuthenticatedAPICli
                 "maas_url": f"http://{host.ip}:5240/MAAS";,
             }
         )
-        ansible_main.run_playbook("site.yaml")
+        ansible_main.run_playbook()
         yield ansible_main.fetch_region(host)
 
 

Follow ups