Merge ~maas-committers/maas-ci/+git/system-tests:ansible-systemtests-performance into ~maas-committers/maas-ci/+git/system-tests:master

Proposed by Jack Lloyd-Walters
Status: Merged
Approved by: Jack Lloyd-Walters
Approved revision: 9a068d2853b632d7b538328357246466f8d6a74d
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~maas-committers/maas-ci/+git/system-tests:ansible-systemtests-performance
Merge into: ~maas-committers/maas-ci/+git/system-tests:master
Diff against target: 177 lines (+39/-24)
3 files modified
systemtests/ansible.py (+27/-16)
systemtests/ansible_tests/test_ansible.py (+10/-7)
systemtests/fixtures.py (+2/-1)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
MAAS Committers Pending
Review via email: mp+439191@code.launchpad.net

Commit message

Implement performance and log-file changes in ansible system-tests

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b ansible-systemtests-performance lp:~maas-committers/maas-ci/+git/system-tests into -b master lp:~maas-committers/maas-ci/+git/system-tests

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/system-tests-tester/452/consoleText
COMMIT: a665d7c58c3d51ede8e7c6f647a007e14c002ffa

review: Needs Fixing
1ad3786... by Jack Lloyd-Walters

linter happier?

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b ansible-systemtests-performance lp:~maas-committers/maas-ci/+git/system-tests into -b master lp:~maas-committers/maas-ci/+git/system-tests

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/system-tests-tester/453/consoleText
COMMIT: 1ad3786350b4039db249bd27183338fe9b21ccc3

review: Needs Fixing
9a068d2... by Jack Lloyd-Walters

remove trailing space

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b ansible-systemtests-performance lp:~maas-committers/maas-ci/+git/system-tests into -b master lp:~maas-committers/maas-ci/+git/system-tests

STATUS: SUCCESS
COMMIT: 9a068d2853b632d7b538328357246466f8d6a74d

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/systemtests/ansible.py b/systemtests/ansible.py
2index 8db10f9..7c671c8 100644
3--- a/systemtests/ansible.py
4+++ b/systemtests/ansible.py
5@@ -17,7 +17,7 @@ from .lxd import Instance
6 if TYPE_CHECKING:
7 from logging import Logger
8
9- from .lxd import CLILXD, _FileWrapper
10+ from .lxd import CLILXD
11 NAME = "systemtests.ansible"
12 LOG = getLogger(NAME)
13
14@@ -284,6 +284,7 @@ class AnsibleMain:
15 playbooks_repo: str,
16 playbooks_branch: str,
17 proxy_env: Optional[dict[str, str]],
18+ debug: str = "",
19 ) -> None:
20 self._lxd = lxd
21 self.instance = instance
22@@ -297,6 +298,7 @@ class AnsibleMain:
23 self._inventory_: set[AnsibleHost] = set()
24
25 self.ansible_repo_path = "/home/ubuntu/ansible_repo"
26+ self.default_debug = debug or ""
27
28 def setup(self) -> None:
29 self.logger.info("Installing python3-pip")
30@@ -465,6 +467,7 @@ class AnsibleMain:
31 ["maas", "apikey", "--username", user]
32 ).stdout.rstrip("\n")
33 _, authd_client = maas_client.log_in("admin", api_key)
34+ authd_client.refresh()
35 return authd_client
36 raise HostWithoutRegion()
37
38@@ -504,33 +507,41 @@ class AnsibleMain:
39 ]
40 )
41 file_content = "\n".join(inv)
42- LOG.info(f"Ansible hosts file generated:\n{file_content}")
43+ if self.default_debug:
44+ self.logger.info("Ansible hosts file generated:")
45+ for line in file_content:
46+ self.logger.info(line)
47 self._hosts_file.write(file_content)
48
49 def create_config_file(self) -> None:
50- def append_if_not_found(
51- content: str, file_: _FileWrapper, loose_check: bool = True
52- ) -> None:
53- search = content if not loose_check else content.split()[0]
54- if search not in file_.read():
55- file_.append(content)
56+ cfg_dict = {
57+ "host_key_checking": "False",
58+ "remote_user": "ubuntu",
59+ "deprecation_warnings": "False",
60+ "callback_result_format": "yaml",
61+ "timeout": "60",
62+ "display_skipped_hosts": "False",
63+ "display_ok_hosts": "False",
64+ }
65
66 path = f"{self.ansible_repo_path}/ansible.cfg"
67 ansible_cfg = self.instance.files[path]
68 if not ansible_cfg.exists():
69 ansible_cfg.write("[defaults]\ninventory = hosts\n")
70- append_if_not_found("host_key_checking = False", ansible_cfg)
71- append_if_not_found("remote_user = ubuntu", ansible_cfg)
72- append_if_not_found("deprecation_warnings = False", ansible_cfg)
73+ ansible_cfg_content = ansible_cfg.read().split("\n")
74+
75 if self.use_timeout:
76- append_if_not_found(
77- f"task_timeout = {int(self.timeout.total_seconds())}", ansible_cfg
78- )
79+ cfg_dict["task_timeout"] = f"{int(self.timeout.total_seconds())}"
80+ for k, v in cfg_dict.items():
81+ if k not in ansible_cfg_content:
82+ ansible_cfg_content.append(f"{k} = {v}")
83+
84+ ansible_cfg.write("\n".join(ansible_cfg_content))
85 self.instance.execute(["mkdir", "-p", "/etc/ansible"])
86 etc_ansible_cfg = self.instance.files["/etc/ansible/ansible.cfg"]
87 etc_ansible_cfg.write(ansible_cfg.read())
88
89- def run_playbook(self, playbook: str = "site.yaml", debug: str = "-v") -> None:
90+ def run_playbook(self, playbook: str = "site.yaml", debug: str = "") -> None:
91 self.create_hosts_file()
92 cmd: list[str] = [
93 "eatmydata",
94@@ -541,6 +552,6 @@ class AnsibleMain:
95 "--private-key",
96 self.ssh_key_file[:-4],
97 ]
98- if _debug := re.match(r"-(v)+", debug):
99+ if _debug := re.match(r"-(v)+", debug or self.default_debug or ""):
100 cmd.append(str(_debug.group()))
101 self.instance.execute(cmd, environment=self._proxy_env)
102diff --git a/systemtests/ansible_tests/test_ansible.py b/systemtests/ansible_tests/test_ansible.py
103index 0b89249..e02be0c 100644
104--- a/systemtests/ansible_tests/test_ansible.py
105+++ b/systemtests/ansible_tests/test_ansible.py
106@@ -9,6 +9,8 @@ from systemtests.ansible import AnsibleMain, pip_package_exists
107 if TYPE_CHECKING:
108 from logging import Logger
109
110+DEFAULT_VERSION = "3.3"
111+
112
113 @pytest.mark.skip_if_ansible_playbooks_unconfigured(
114 "Needs Ansible playbook configuration"
115@@ -62,12 +64,12 @@ class TestAnsibleMAAS:
116 "maas_installation_type": installation_type,
117 "maas_postgres_password": "sekret",
118 "maas_url": f"http://{regionrack_host.ip}:5240/MAAS",
119- "maas_version": "3.3",
120+ "maas_version": DEFAULT_VERSION,
121 }
122 )
123- ansible_main.run_playbook("site.yaml", "-vv")
124+ ansible_main.run_playbook("site.yaml")
125 region = ansible_main.fetch_region(regionrack_host)
126- assert region.read_version_information()["version"][:3] == "3.3"
127+ assert region.read_version_information()["version"][:3] == DEFAULT_VERSION
128 assert not ansible_main._inventory_
129 assert not regionrack_host.instance.exists()
130 assert not database.instance.exists()
131@@ -77,9 +79,9 @@ class TestAnsibleMAAS:
132 ) -> None:
133 ansible_main.logger = testlog
134 start_version = "3.1"
135- upgrade_version = "3.3"
136+ upgrade_version = DEFAULT_VERSION
137 database = ansible_main.add_host().add_postgres_primary()
138- host = ansible_main.add_host().add_region_rack()
139+ host = ansible_main.add_host(image="ubuntu:22.04").add_region_rack()
140
141 with ansible_main.collect_inventory():
142 ansible_main.update_config(
143@@ -90,12 +92,13 @@ class TestAnsibleMAAS:
144 "maas_version": start_version,
145 }
146 )
147- ansible_main.run_playbook("site.yaml", "-vvv")
148+ ansible_main.run_playbook("site.yaml")
149 region = ansible_main.fetch_region(host)
150 assert region.read_version_information()["version"][:3] == start_version
151
152 ansible_main.update_config({"maas_version": upgrade_version})
153- ansible_main.run_playbook("site.yaml", "-vvv")
154+ ansible_main.run_playbook("site.yaml")
155+ region = ansible_main.fetch_region(host)
156 region.refresh()
157 assert region.read_version_information()["version"][:3] == upgrade_version
158 assert not ansible_main._inventory_
159diff --git a/systemtests/fixtures.py b/systemtests/fixtures.py
160index f035b4e..ce4c5cd 100644
161--- a/systemtests/fixtures.py
162+++ b/systemtests/fixtures.py
163@@ -61,6 +61,7 @@ def ansible_main(config: dict[str, Any]) -> Optional[Iterator[AnsibleMain]]:
164 playbooks_repo=playbooks_repo,
165 playbooks_branch=playbooks_branch,
166 proxy_env=proxy_env,
167+ debug=playbooks_config.get("verbosity", ""),
168 )
169 main.setup()
170 yield main
171@@ -79,7 +80,7 @@ def maas_from_ansible(ansible_main: AnsibleMain) -> Iterator[AuthenticatedAPICli
172 "maas_url": f"http://{host.ip}:5240/MAAS",
173 }
174 )
175- ansible_main.run_playbook("site.yaml", "-vv")
176+ ansible_main.run_playbook("site.yaml")
177 yield ansible_main.fetch_region(host)
178
179

Subscribers

People subscribed via source and target branches

to all changes: