sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #06690
Re: [Merge] ~maas-committers/maas-ci/+git/system-tests:improve-ansible-performance into ~maas-committers/maas-ci/+git/system-tests:master
Diff comments:
> diff --git a/systemtests/ansible.py b/systemtests/ansible.py
> index 7c671c8..b69b96b 100644
> --- a/systemtests/ansible.py
> +++ b/systemtests/ansible.py
> @@ -515,28 +543,54 @@ class AnsibleMain:
>
> def create_config_file(self) -> None:
> cfg_dict = {
> - "host_key_checking": "False",
> - "remote_user": "ubuntu",
> - "deprecation_warnings": "False",
> - "callback_result_format": "yaml",
> - "timeout": "60",
> - "display_skipped_hosts": "False",
> - "display_ok_hosts": "False",
> + "defaults": {
> + "callback_result_format": "yaml",
> + "deprecation_warnings": "False",
> + "display_ok_hosts": "False",
> + "display_skipped_hosts": "False",
> + "host_key_checking": "False",
> + "pipelining": "True",
> + "remote_user": "ubuntu",
> + "timeout": "60",
> + },
> + "ssh_connection": {
> + "ssh_args": "-o ControlMaster=auto -o ControlPersist=60s"
> + },
> }
> + if self.use_timeout:
> + cfg_dict["defaults"][
> + "task_timeout"
> + ] = f"{int(self.timeout.total_seconds())}"
>
> path = f"{self.ansible_repo_path}/ansible.cfg"
> ansible_cfg = self.instance.files[path]
> - if not ansible_cfg.exists():
> - ansible_cfg.write("[defaults]\ninventory = hosts\n")
> - ansible_cfg_content = ansible_cfg.read().split("\n")
> -
> - if self.use_timeout:
> - cfg_dict["task_timeout"] = f"{int(self.timeout.total_seconds())}"
> - for k, v in cfg_dict.items():
> - if k not in ansible_cfg_content:
> - ansible_cfg_content.append(f"{k} = {v}")
> -
> - ansible_cfg.write("\n".join(ansible_cfg_content))
> + _found_cfg_dict = {"defaults": {"inventory": "hosts"}}
> + if ansible_cfg.exists():
> + ansible_cfg_content = ansible_cfg.read()
> + # find all sections denoted by "[<title>]"
> + if cfg_heads := re.findall(MATCH_HEADERS, ansible_cfg_content):
> + head_pos = [ansible_cfg_content.find(heading) for heading in cfg_heads] + [-1]
I think i can do that if i change findall() to finditer()
> + # fetch all of the key, values under each column
> + for key, start, end in zip(cfg_heads, head_pos[:-1], head_pos[1:]):
> + if key not in _found_cfg_dict.keys():
> + _found_cfg_dict[key] = {}
> + for entries in ansible_cfg_content[start:end].split("\n")[1:]:
> + k, v = entries.split("=")
> + _found_cfg_dict[key][k.strip()] = v.strip()
> + for key in cfg_dict.keys():
> + if key in _found_cfg_dict:
> + _found_cfg_dict[key].update(cfg_dict[key])
> + else:
> + _found_cfg_dict[key] = cfg_dict[key]
> +
> + # reconstruct the file format from the dictionary
> + new_cfg_content = []
> + for new_head, new_entries in _found_cfg_dict.items():
> + new_cfg_content.append(f"[{new_head}]")
> + new_cfg_content.extend([f"{new_key} = {new_value}" for new_key, new_value in new_entries.items()])
> +
> + # and write back to the cfg file
> + ansible_cfg.write("\n".join(new_cfg_content))
> self.instance.execute(["mkdir", "-p", "/etc/ansible"])
> etc_ansible_cfg = self.instance.files["/etc/ansible/ansible.cfg"]
> etc_ansible_cfg.write(ansible_cfg.read())
--
https://code.launchpad.net/~maas-committers/maas-ci/+git/system-tests/+merge/440179
Your team MAAS Committers is requested to review the proposed merge of ~maas-committers/maas-ci/+git/system-tests:improve-ansible-performance into ~maas-committers/maas-ci/+git/system-tests:master.