This repository has been archived by the owner on May 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgpkg: molecule-plugins 23.4.1-3: Rebuild to fix issues with vagrant…
… plugin. Apply an upstream (not merged) fix to make the vagrant plugin work again: ansible-community/molecule-plugins#142 https://bugs.archlinux.org/task/78447 git-svn-id: file:///srv/repos/svn-community/svn@1459743 9fca08f4-af9d-4005-b8df-a31f2cc04f65
- Loading branch information
Showing
2 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
molecule-plugins/trunk/molecule-plugins-23.4.1-molecule_internals.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
From 6ee55c7b7a9e556fc18bbc14144b8ca1ee7be845 Mon Sep 17 00:00:00 2001 | ||
From: Arnaud Patard <apatard@hupstream.com> | ||
Date: Thu, 27 Apr 2023 18:13:56 +0200 | ||
Subject: [PATCH] src/molecule_plugins/vagrant/modules/vagrant.py: Get rid of | ||
molecule dependency | ||
|
||
To avoid changes in molecule.util breaking the vagrant module, let's | ||
get rid of the dependency by: | ||
- embedded the recursive dict merge function | ||
- replace template handling by our own code. | ||
(and keep the autoescaping enabled) | ||
|
||
Moreover, it will make it easier to use community.vagrant since molecule | ||
is not needed anymore. | ||
|
||
Signed-off-by: Arnaud Patard <apatard@hupstream.com> | ||
--- | ||
.../vagrant/modules/vagrant.py | 41 +++++++++++++++---- | ||
1 file changed, 33 insertions(+), 8 deletions(-) | ||
|
||
diff --git a/src/molecule_plugins/vagrant/modules/vagrant.py b/src/molecule_plugins/vagrant/modules/vagrant.py | ||
index 8232695..b8cb11f 100644 | ||
--- a/src/molecule_plugins/vagrant/modules/vagrant.py | ||
+++ b/src/molecule_plugins/vagrant/modules/vagrant.py | ||
@@ -22,16 +22,16 @@ | ||
|
||
|
||
import contextlib | ||
+import copy | ||
import datetime | ||
import os | ||
import subprocess | ||
import sys | ||
+from collections.abc import MutableMapping | ||
|
||
+import jinja2 | ||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
-import molecule | ||
-import molecule.util | ||
- | ||
try: | ||
import vagrant | ||
except ImportError: | ||
@@ -199,6 +199,8 @@ | ||
{%- endfor -%} | ||
{%- endmacro -%} | ||
|
||
+# Ansible managed | ||
+ | ||
Vagrant.configure('2') do |config| | ||
if Vagrant.has_plugin?('vagrant-cachier') | ||
{% if cachier is not none and cachier in [ "machine", "box" ] %} | ||
@@ -335,6 +337,27 @@ | ||
""" | ||
|
||
|
||
+# Taken from molecule.util. | ||
+def merge_dicts(a: MutableMapping, b: MutableMapping) -> MutableMapping: | ||
+ """Merge the values of b into a and returns a new dict. | ||
+ | ||
+ This function uses the same algorithm as Ansible's `combine(recursive=True)` filter. | ||
+ | ||
+ :param a: the target dictionary | ||
+ :param b: the dictionary to import | ||
+ :return: dict | ||
+ """ | ||
+ result = copy.deepcopy(a) | ||
+ | ||
+ for k, v in b.items(): | ||
+ if k in a and isinstance(a[k], dict) and isinstance(v, dict): | ||
+ result[k] = merge_dicts(a[k], v) | ||
+ else: | ||
+ result[k] = v | ||
+ | ||
+ return result | ||
+ | ||
+ | ||
class VagrantClient: | ||
def __init__(self, module) -> None: | ||
self._module = module | ||
@@ -548,13 +571,15 @@ def _get_config(self): | ||
|
||
def _write_vagrantfile(self): | ||
instances = self._get_vagrant_config_dict() | ||
- template = molecule.util.render_template( | ||
- VAGRANTFILE_TEMPLATE, | ||
+ j_env = jinja2.Environment(autoescape=True) | ||
+ t = j_env.from_string(VAGRANTFILE_TEMPLATE) | ||
+ template = t.render( | ||
instances=instances, | ||
cachier=self.cachier, | ||
no_kvm=not os.path.exists("/dev/kvm"), | ||
) | ||
- molecule.util.write_file(self._vagrantfile, template) | ||
+ with open(self._vagrantfile, "w") as f: | ||
+ f.write(template) | ||
|
||
def _write_configs(self): | ||
self._write_vagrantfile() | ||
@@ -628,7 +653,7 @@ def _get_instance_vagrant_config_dict(self, instance): | ||
} | ||
|
||
d["config_options"].update( | ||
- molecule.util.merge_dicts( | ||
+ merge_dicts( | ||
d["config_options"], | ||
instance.get("config_options", {}), | ||
), | ||
@@ -640,7 +665,7 @@ def _get_instance_vagrant_config_dict(self, instance): | ||
) | ||
|
||
d["provider_options"].update( | ||
- molecule.util.merge_dicts( | ||
+ merge_dicts( | ||
d["provider_options"], | ||
instance.get("provider_options", {}), | ||
), |