Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
upgpkg: molecule-plugins 23.4.1-3: Rebuild to fix issues with vagrant…
Browse files Browse the repository at this point in the history
… 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
dvzrv committed May 10, 2023
1 parent 479abd4 commit d060ed9
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 4 deletions.
20 changes: 16 additions & 4 deletions molecule-plugins/trunk/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pkgname=molecule-plugins
pkgver=23.4.1
pkgrel=2
pkgrel=3
pkgdesc="Collection of molecule plugins"
arch=(any)
url="https://github.com/ansible-community/molecule-plugins"
Expand Down Expand Up @@ -54,9 +54,21 @@ replaces=(
molecule-podman
molecule-vagrant
)
source=(https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz)
sha512sums=('5c158e278318402006f9f86f4143dac27d0cf6e95912963414e9c06720f9b5572240a6b6ddaccbd2872bb594144215a4a5ec434f4414e692fb72a3d97de175d3')
b2sums=('e0261d189e55b0705ff2e967620146dd6ef0bc4182a6e87d5ffdaf8e1298dc0bc9e9bb188669300b63cf692f822ad6b0d4c8038fc1cff6afbf7f79b61dfbc184')
source=(
https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz
$pkgname-23.4.1-molecule_internals.patch
)
sha512sums=('5c158e278318402006f9f86f4143dac27d0cf6e95912963414e9c06720f9b5572240a6b6ddaccbd2872bb594144215a4a5ec434f4414e692fb72a3d97de175d3'
'11822fbd65ba7ccc796e454c015fe765a811e82bd89dc0727201cd45495907df3f808be967d73f45473c073816f9db5c072f32dbcab807229d7c7cf82de9101c')
b2sums=('e0261d189e55b0705ff2e967620146dd6ef0bc4182a6e87d5ffdaf8e1298dc0bc9e9bb188669300b63cf692f822ad6b0d4c8038fc1cff6afbf7f79b61dfbc184'
'62bb11057e5c429229a033ca8911b836817c456270077469decf608c9c9927c425e1c647a54f5370b4cabb644cfb0a1e44e0166b6a4f21912ce4e430f6b56a8f')

prepare() {
# fix issues with vagrant plugin using molecule internals that are now gone:
# https://github.com/ansible-community/molecule-plugins/pull/142
# https://bugs.archlinux.org/task/78447
patch -Np1 -d $pkgname-$pkgver -i ../$pkgname-23.4.1-molecule_internals.patch
}

build() {
cd $pkgname-$pkgver
Expand Down
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", {}),
),

0 comments on commit d060ed9

Please sign in to comment.