From 07389f04f77836926d1b12a78f87a379343cd2f4 Mon Sep 17 00:00:00 2001 From: Wong Hoi Sing Edison Date: Thu, 18 May 2023 16:44:03 +0800 Subject: [PATCH] alvistack/v23.4.1 git clean -xdf tar zcvf ../python-molecule-plugins_23.4.1.orig.tar.gz --exclude=.git . debuild -uc -us cp python-molecule-plugins.spec ../python-molecule-plugins_23.4.1-1.spec mv ../python*-molecule-plugins*23.4.1*.{gz,xz,spec,dsc} /osc/home\:alvistack/ansible-community-molecule-plugins-23.4.1 rm -rf ../python*-molecule-plugins*23.4.1*.* See https://github.com/ansible-community/molecule-plugins/pull/142 See https://github.com/ansible-community/molecule-plugins/pull/155 Signed-off-by: Wong Hoi Sing Edison --- .gitignore | 4 +- MANIFEST.in | 9 ++ debian/.gitignore | 6 + debian/changelog | 5 + debian/control | 40 ++++++ debian/copyright | 21 +++ debian/python3-molecule-plugins.install | 1 + ...python3-molecule-plugins.lintian-overrides | 4 + debian/rules | 15 ++ debian/source/format | 1 + debian/source/lintian-overrides | 5 + pyproject.toml | 7 +- python-molecule-plugins.spec | 136 ++++++++++++++++++ setup.cfg | 4 + setup.py | 34 +++++ src/molecule_plugins/_version.py | 4 + .../vagrant/modules/vagrant.py | 45 ++++-- 17 files changed, 324 insertions(+), 17 deletions(-) create mode 100644 MANIFEST.in create mode 100644 debian/.gitignore create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/python3-molecule-plugins.install create mode 100644 debian/python3-molecule-plugins.lintian-overrides create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100644 debian/source/lintian-overrides create mode 100644 python-molecule-plugins.spec create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 src/molecule_plugins/_version.py diff --git a/.gitignore b/.gitignore index ed1acdbc..1c445a69 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,6 @@ MANIFEST # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest -*.spec # Installer logs pip-log.txt @@ -127,4 +126,5 @@ dmypy.json # Pyre type checker .pyre/ -src/molecule_plugins/_version.py + +.pybuild/ diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..27c0ce67 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,9 @@ +include LICENSE +include README.md + +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] + +recursive-include src/molecule_plugins/*/cookiecutter **/* +recursive-include src/molecule_plugins/*/modules **/* +recursive-include src/molecule_plugins/*/playbooks **/* diff --git a/debian/.gitignore b/debian/.gitignore new file mode 100644 index 00000000..4a569ac5 --- /dev/null +++ b/debian/.gitignore @@ -0,0 +1,6 @@ +*.substvars +*debhelper* +.debhelper +files +python3-molecule-plugins +tmp diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 00000000..1a06fad4 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +python-molecule-plugins (100:23.4.1-1) UNRELEASED; urgency=medium + + * https://github.com/ansible-community/molecule-plugins/releases/tag/v23.4.1 + + -- Wong Hoi Sing Edison Sat, 29 Apr 2023 15:15:08 +0800 diff --git a/debian/control b/debian/control new file mode 100644 index 00000000..301ceb96 --- /dev/null +++ b/debian/control @@ -0,0 +1,40 @@ +Source: python-molecule-plugins +Section: python +Priority: optional +Standards-Version: 4.5.0 +Maintainer: Wong Hoi Sing Edison +Homepage: https://github.com/ansible-community/molecule-plugins/tags +Vcs-Browser: https://github.com/alvistack/ansible-community-molecule-plugins +Vcs-Git: https://github.com/alvistack/ansible-community-molecule-plugins.git +Build-Depends: + debhelper, + debhelper-compat (= 10), + dh-python, + fdupes, + python3-dev, + python3-setuptools, + +Package: python3-molecule-plugins +Architecture: all +Description: Molecule Plugins + Molecule Plugins. +Depends: + ${misc:Depends}, + ${shlibs:Depends}, + ${python3:Depends}, + python3, + python3-docker (>= 4.3.1), + python3-jinja2 (>= 2.11.3), + python3-molecule (>= 5.0), + python3-requests, + python3-selinux, + python3-vagrant (>= 1.0.0), + python3-yaml (>= 5.1), +Conflicts: + python3-molecule-docker, + python3-molecule-podman, + python3-molecule-vagrant, +Replaces: + python3-molecule-docker, + python3-molecule-podman, + python3-molecule-vagrant, diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 00000000..dcb9a244 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,21 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ + +Files: debian/* +Copyright: 2023 Wong Hoi Sing Edison +License: Apache-2.0 + +License: Apache-2.0 + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + . + The complete text of the Apache version 2.0 license + can be found in "/usr/share/common-licenses/Apache-2.0". diff --git a/debian/python3-molecule-plugins.install b/debian/python3-molecule-plugins.install new file mode 100644 index 00000000..e3da3e75 --- /dev/null +++ b/debian/python3-molecule-plugins.install @@ -0,0 +1 @@ +usr/lib/python*/*-packages/* diff --git a/debian/python3-molecule-plugins.lintian-overrides b/debian/python3-molecule-plugins.lintian-overrides new file mode 100644 index 00000000..35a863a2 --- /dev/null +++ b/debian/python3-molecule-plugins.lintian-overrides @@ -0,0 +1,4 @@ +python3-molecule-plugins: copyright-without-copyright-notice +python3-molecule-plugins: initial-upload-closes-no-bugs +python3-molecule-plugins: no-manual-page +python3-molecule-plugins: zero-byte-file-in-doc-directory diff --git a/debian/rules b/debian/rules new file mode 100755 index 00000000..fcaa45ef --- /dev/null +++ b/debian/rules @@ -0,0 +1,15 @@ +#!/usr/bin/make -f + +SHELL := /bin/bash + +override_dh_auto_install: + dh_auto_install --destdir=debian/tmp + find debian/tmp/usr/lib/python*/*-packages -type f -name '*.pyc' -exec rm -rf {} \; + fdupes -qnrps debian/tmp/usr/lib/python*/*-packages + +override_dh_auto_test: + +override_dh_auto_clean: + +%: + dh $@ --buildsystem=pybuild --with python3 diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 00000000..163aaf8d --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/source/lintian-overrides b/debian/source/lintian-overrides new file mode 100644 index 00000000..699b4c4d --- /dev/null +++ b/debian/source/lintian-overrides @@ -0,0 +1,5 @@ +python-molecule-plugins source: file-without-copyright-information +python-molecule-plugins source: no-debian-changes +python-molecule-plugins source: source-contains-prebuilt-windows-binary +python-molecule-plugins source: source-is-missing +python-molecule-plugins source: source-package-encodes-python-version diff --git a/pyproject.toml b/pyproject.toml index cac83571..5ebf9b4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,6 @@ [build-system] requires = [ "setuptools >= 64.0.0", # required by pyproject+setuptools_scm integration - "setuptools_scm[toml] >= 7.0.5", # required for "no-local-version" scheme ] build-backend = "setuptools.build_meta" @@ -9,7 +8,7 @@ build-backend = "setuptools.build_meta" [project] # https://peps.python.org/pep-0621/#readme requires-python = ">=3.9" -dynamic = ["version"] +version = "23.4.1" name = "molecule-plugins" description = "Molecule Plugins" readme = "README.md" @@ -128,7 +127,3 @@ ec2 = "molecule_plugins.ec2.driver:EC2" gce = "molecule_plugins.gce.driver:GCE" podman = "molecule_plugins.podman.driver:Podman" vagrant = "molecule_plugins.vagrant.driver:Vagrant" - -[tool.setuptools_scm] -local_scheme = "no-local-version" -write_to = "src/molecule_plugins/_version.py" diff --git a/python-molecule-plugins.spec b/python-molecule-plugins.spec new file mode 100644 index 00000000..6397b9c6 --- /dev/null +++ b/python-molecule-plugins.spec @@ -0,0 +1,136 @@ +# Copyright 2023 Wong Hoi Sing Edison +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +%global debug_package %{nil} + +Name: python-molecule-plugins +Epoch: 100 +Version: 23.4.1 +Release: 1%{?dist} +BuildArch: noarch +Summary: Molecule Plugins +License: BSD-3-Clause +URL: https://github.com/ansible-community/molecule-plugins/tags +Source0: %{name}_%{version}.orig.tar.gz +BuildRequires: fdupes +BuildRequires: python-rpm-macros +BuildRequires: python3-devel +BuildRequires: python3-setuptools + +%description +Molecule Plugins. + +%prep +%autosetup -T -c -n %{name}_%{version}-%{release} +tar -zx -f %{S:0} --strip-components=1 -C . + +%build +%py3_build + +%install +%py3_install +find %{buildroot}%{python3_sitelib} -type f -name '*.pyc' -exec rm -rf {} \; +fdupes -qnrps %{buildroot}%{python3_sitelib} + +%check + +%if 0%{?suse_version} > 1500 +%package -n python%{python3_version_nodots}-molecule-plugins +Summary: Molecule Plugins +Requires: python3 +Requires: python3-Jinja2 >= 2.11.3 +Requires: python3-PyYAML >= 5.1 +Requires: python3-docker >= 4.3.1 +Requires: python3-molecule >= 5.0 +Requires: python3-requests +Requires: python3-selinux +Requires: python3-vagrant >= 1.0.0 +Provides: python3-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python3dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Provides: python%{python3_version}-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python%{python3_version}dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Provides: python%{python3_version_nodots}-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python%{python3_version_nodots}dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Conflicts: python3-molecule-docker +Conflicts: python3-molecule-podman +Conflicts: python3-molecule-vagrant + +%description -n python%{python3_version_nodots}-molecule-plugins +Molecule Plugins. + +%files -n python%{python3_version_nodots}-molecule-plugins +%license LICENSE +%{python3_sitelib}/* +%endif + +%if 0%{?sle_version} > 150000 +%package -n python3-molecule-plugins +Summary: Molecule Plugins +Requires: python3 +Requires: python3-Jinja2 >= 2.11.3 +Requires: python3-PyYAML >= 5.1 +Requires: python3-docker >= 4.3.1 +Requires: python3-molecule >= 5.0 +Requires: python3-requests +Requires: python3-selinux +Requires: python3-vagrant >= 1.0.0 +Provides: python3-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python3dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Provides: python%{python3_version}-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python%{python3_version}dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Provides: python%{python3_version_nodots}-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python%{python3_version_nodots}dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Conflicts: python3-molecule-docker +Conflicts: python3-molecule-podman +Conflicts: python3-molecule-vagrant + +%description -n python3-molecule-plugins +Molecule Plugins. + +%files -n python3-molecule-plugins +%license LICENSE +%{python3_sitelib}/* +%endif + +%if !(0%{?suse_version} > 1500) && !(0%{?sle_version} > 150000) +%package -n python3-molecule-plugins +Summary: Molecule Plugins +Requires: python3 +Requires: python3-docker >= 4.3.1 +Requires: python3-jinja2 >= 2.11.3 +Requires: python3-libselinux +Requires: python3-molecule >= 5.0 +Requires: python3-pyyaml >= 5.1 +Requires: python3-requests +Requires: python3-selinux +Requires: python3-vagrant >= 1.0.0 +Provides: python3-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python3dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Provides: python%{python3_version}-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python%{python3_version}dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Provides: python%{python3_version_nodots}-molecule-plugins = %{epoch}:%{version}-%{release} +Provides: python%{python3_version_nodots}dist(molecule-plugins) = %{epoch}:%{version}-%{release} +Conflicts: python3-molecule-docker +Conflicts: python3-molecule-podman +Conflicts: python3-molecule-vagrant + +%description -n python3-molecule-plugins +Molecule Plugins. + +%files -n python3-molecule-plugins +%license LICENSE +%{python3_sitelib}/* +%endif + +%changelog diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..8bfd5a12 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[egg_info] +tag_build = +tag_date = 0 + diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..734ae90b --- /dev/null +++ b/setup.py @@ -0,0 +1,34 @@ +#! /usr/bin/env python +# Copyright (c) 2019 Red Hat, Inc. +# Copyright (c) 2015-2018 Cisco Systems, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +"""Molecule distribution package setuptools installer.""" + +import site +import sys + +import setuptools + +# See https://github.com/pypa/pip/issues/7953 +site.ENABLE_USER_SITE = "--user" in sys.argv[1:] + + +if __name__ == "__main__": + setuptools.setup() diff --git a/src/molecule_plugins/_version.py b/src/molecule_plugins/_version.py new file mode 100644 index 00000000..a9dc1d64 --- /dev/null +++ b/src/molecule_plugins/_version.py @@ -0,0 +1,4 @@ +# file generated by setuptools_scm +# don't change, don't track in version control +__version__ = version = '23.4.1' +__version_tuple__ = version_tuple = (23, 4, 1) diff --git a/src/molecule_plugins/vagrant/modules/vagrant.py b/src/molecule_plugins/vagrant/modules/vagrant.py index ad97007e..a489a208 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,9 +337,31 @@ """ +# 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 + self.provider = self._module.params["provider_name"] self.provision = self._module.params["provision"] self.cachier = self._module.params["cachier"] @@ -425,9 +449,10 @@ def up(self): changed = False if self._running() != len(self.instances): changed = True + provider = self.provider provision = self.provision with contextlib.suppress(Exception): - self._vagrant.up(provision=provision) + self._vagrant.up(provider=provider, provision=provision) # NOTE(retr0h): Ansible wants only one module return `fail_json` # or `exit_json`. @@ -548,13 +573,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 +655,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 +667,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", {}), ),