upgpkg: wordpress 6.2.1-1
[ArchLinux/community.git] / molecule-plugins / repos / community-any / molecule-plugins-23.4.1-molecule_internals.patch
blob0e6b47b04fca2856f066f7bd6d19509532d37c5a
1 From 6ee55c7b7a9e556fc18bbc14144b8ca1ee7be845 Mon Sep 17 00:00:00 2001
2 From: Arnaud Patard <apatard@hupstream.com>
3 Date: Thu, 27 Apr 2023 18:13:56 +0200
4 Subject: [PATCH] src/molecule_plugins/vagrant/modules/vagrant.py: Get rid of
5 molecule dependency
7 To avoid changes in molecule.util breaking the vagrant module, let's
8 get rid of the dependency by:
9 - embedded the recursive dict merge function
10 - replace template handling by our own code.
11 (and keep the autoescaping enabled)
13 Moreover, it will make it easier to use community.vagrant since molecule
14 is not needed anymore.
16 Signed-off-by: Arnaud Patard <apatard@hupstream.com>
17 ---
18 .../vagrant/modules/vagrant.py | 41 +++++++++++++++----
19 1 file changed, 33 insertions(+), 8 deletions(-)
21 diff --git a/src/molecule_plugins/vagrant/modules/vagrant.py b/src/molecule_plugins/vagrant/modules/vagrant.py
22 index 8232695..b8cb11f 100644
23 --- a/src/molecule_plugins/vagrant/modules/vagrant.py
24 +++ b/src/molecule_plugins/vagrant/modules/vagrant.py
25 @@ -22,16 +22,16 @@
28 import contextlib
29 +import copy
30 import datetime
31 import os
32 import subprocess
33 import sys
34 +from collections.abc import MutableMapping
36 +import jinja2
37 from ansible.module_utils.basic import AnsibleModule
39 -import molecule
40 -import molecule.util
42 try:
43 import vagrant
44 except ImportError:
45 @@ -199,6 +199,8 @@
46 {%- endfor -%}
47 {%- endmacro -%}
49 +# Ansible managed
51 Vagrant.configure('2') do |config|
52 if Vagrant.has_plugin?('vagrant-cachier')
53 {% if cachier is not none and cachier in [ "machine", "box" ] %}
54 @@ -335,6 +337,27 @@
55 """
58 +# Taken from molecule.util.
59 +def merge_dicts(a: MutableMapping, b: MutableMapping) -> MutableMapping:
60 + """Merge the values of b into a and returns a new dict.
62 + This function uses the same algorithm as Ansible's `combine(recursive=True)` filter.
64 + :param a: the target dictionary
65 + :param b: the dictionary to import
66 + :return: dict
67 + """
68 + result = copy.deepcopy(a)
70 + for k, v in b.items():
71 + if k in a and isinstance(a[k], dict) and isinstance(v, dict):
72 + result[k] = merge_dicts(a[k], v)
73 + else:
74 + result[k] = v
76 + return result
79 class VagrantClient:
80 def __init__(self, module) -> None:
81 self._module = module
82 @@ -548,13 +571,15 @@ def _get_config(self):
84 def _write_vagrantfile(self):
85 instances = self._get_vagrant_config_dict()
86 - template = molecule.util.render_template(
87 - VAGRANTFILE_TEMPLATE,
88 + j_env = jinja2.Environment(autoescape=True)
89 + t = j_env.from_string(VAGRANTFILE_TEMPLATE)
90 + template = t.render(
91 instances=instances,
92 cachier=self.cachier,
93 no_kvm=not os.path.exists("/dev/kvm"),
95 - molecule.util.write_file(self._vagrantfile, template)
96 + with open(self._vagrantfile, "w") as f:
97 + f.write(template)
99 def _write_configs(self):
100 self._write_vagrantfile()
101 @@ -628,7 +653,7 @@ def _get_instance_vagrant_config_dict(self, instance):
104 d["config_options"].update(
105 - molecule.util.merge_dicts(
106 + merge_dicts(
107 d["config_options"],
108 instance.get("config_options", {}),
110 @@ -640,7 +665,7 @@ def _get_instance_vagrant_config_dict(self, instance):
113 d["provider_options"].update(
114 - molecule.util.merge_dicts(
115 + merge_dicts(
116 d["provider_options"],
117 instance.get("provider_options", {}),