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

Commit

Permalink
Reinstated Vagrant driver
Browse files Browse the repository at this point in the history
- Added Zuul-CI config
- Code to install vagrant
- Made prepare playbook embedded
- Made box optional (defaults to Alpine for size)
- Added min-requirement molecule>=3.0.2

Related: hashicorp/vagrant#11070
  • Loading branch information
ssbarnea committed Feb 25, 2020
1 parent 5e6d51b commit 78582f9
Show file tree
Hide file tree
Showing 36 changed files with 1,075 additions and 349 deletions.
73 changes: 53 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
---
default_language_version:
python: python3
minimum_pre_commit_version: "1.14.0"
repos:
- repo: https://github.com/PyCQA/doc8.git
rev: 0.8.1rc1
hooks:
- id: doc8
- repo: https://github.com/python/black.git
rev: 19.3b0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v2.2.3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand All @@ -19,21 +13,27 @@ repos:
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: debug-statements
- id: check-yaml
files: .*\.(yaml|yml)$
# https://github.com/pre-commit/pre-commit-hooks/issues/273
args: ["--unsafe"]
- repo: https://github.com/PyCQA/doc8.git
rev: 0.8.1rc3
hooks:
- id: doc8
- repo: https://github.com/python/black.git
rev: 19.10b0
hooks:
- id: black
language_version: python3
- repo: https://gitlab.com/pycqa/flake8.git
rev: 3.7.8
rev: 3.7.9
hooks:
- id: flake8
additional_dependencies:
- flake8-black
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.16.0
hooks:
- id: yamllint
files: \.(yaml|yml)$
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/codespell-project/codespell.git
rev: v1.15.0
rev: v1.16.0
hooks:
- id: codespell
name: codespell
Expand All @@ -44,3 +44,36 @@ repos:
args: []
require_serial: false
additional_dependencies: []
- repo: https://github.com/PyCQA/flake8.git
rev: 3.7.9
hooks:
- id: flake8
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.20.0
hooks:
- id: yamllint
files: \.(yaml|yml)$
types: [file, yaml]
entry: yamllint --strict -f parsable
- repo: https://github.com/openstack-dev/bashate.git
rev: 1.0.0
hooks:
- id: bashate
entry: bashate --error . --ignore=E006,E040
# Run bashate check for all bash scripts
# Ignores the following rules:
# E006: Line longer than 79 columns (as many scripts use jinja
# templating, this is very difficult)
# E040: Syntax error determined using `bash -n` (as many scripts
# use jinja templating, this will often fail and the syntax
# error will be discovered in execution anyway)
- repo: https://github.com/ansible/ansible-lint.git
rev: v4.2.0
hooks:
- id: ansible-lint
always_run: true
pass_filenames: false
# do not add file filters here as ansible-lint does not give reliable
# results when called with individual files.
# https://github.com/ansible/ansible-lint/issues/611
entry: env ANSIBLE_LIBRARY=molecule_vagrant/modules ansible-lint --force-color -p -v
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ Molecule Vagrant Plugin
:target: https://badge.fury.io/py/molecule-vagrant
:alt: PyPI Package

.. image:: https://img.shields.io/travis/com/pycontribs/molecule-vagrant/master.svg?label=Linux%20builds%20%40%20Travis%20CI
:target: https://travis-ci.com/pycontribs/molecule-vagrant
.. image:: https://zuul-ci.org/gated.svg
:target: https://dashboard.zuul.ansible.com/t/ansible/builds?project=ansible-community/molecule-vagrant

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/python/black
:alt: Python Black Code Style

.. image:: https://img.shields.io/badge/Code%20of%20Conduct-Ansible-silver.svg
.. image:: https://img.shields.io/badge/Code%20of%20Conduct-silver.svg
:target: https://docs.ansible.com/ansible/latest/community/code_of_conduct.html
:alt: Ansible Code of Conduct

.. image:: https://img.shields.io/badge/Mailing%20lists-Ansible-orange.svg
.. image:: https://img.shields.io/badge/Mailing%20lists-silver.svg
:target: https://docs.ansible.com/ansible/latest/community/communication.html#mailing-list-information
:alt: Ansible mailing lists

Expand Down
33 changes: 33 additions & 0 deletions bindep.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is a cross-platform list tracking distribution packages needed by tests;
# see https://docs.openstack.org/infra/bindep/ for additional information.

build-dep [platform:dpkg]
dnsmasq-base [platform:dpkg]
ebtables [platform:dpkg]
gcc [test platform:rpm]
gcc-c++ [test platform:rpm]
libselinux-python [platform:centos-7]
libvirt [platform:rpm]
libvirt-clients [platform:dpkg]
libvirt-daemon [platform:dpkg]
libvirt-daemon-kvm [platform:rpm]
libvirt-daemon-system [platform:dpkg]
libvirt-dev [platform:dpkg]
libvirt-devel [platform:rpm]
libxml2-dev [platform:dpkg]
libxslt-dev [platform:dpkg]
make [platform:centos-7]
pkg-config [platform:dpkg]
python3 [test platform:rpm !platform:centos-7]
python3-devel [test platform:rpm !platform:centos-7]
python3-libselinux [test platform:rpm !platform:centos-7]
python3-libvirt [test platform:rpm !platform:centos-7 platform:dpkg]
python3-netifaces [test !platform:centos-7 platform:rpm]
python36 [test !platform:centos-7 !platform:fedora-28]
qemu [platform:dpkg]
qemu-kvm [platform:rpm]
ruby-dev [platform:dpkg]
ruby-devel [platform:rpm]
ruby-libvirt [platform:dpkg]
vagrant [platform:dpkg]
zlib1g-dev [platform:dpkg]
1 change: 1 addition & 0 deletions molecule
3 changes: 3 additions & 0 deletions molecule_vagrant/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Plugin exports."""

__name__ = __name__.split("_")[-1]
5 changes: 5 additions & 0 deletions molecule_vagrant/cookiecutter/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"molecule_directory": "molecule",
"role_name": "OVERRIDDEN",
"scenario_name": "OVERRIDDEN"
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*******
*********************************
Vagrant driver installation guide
*******
*********************************

Requirements
============
Expand All @@ -20,4 +20,4 @@ widely recommended `'--user' flag`_ when invoking ``pip``.

.. code-block:: bash
$ pip install 'molecule[vagrant]'
$ pip install 'molecule_vagrant'
55 changes: 28 additions & 27 deletions molecule_vagrant/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Vagrant(Driver):
.. important::
This driver is alpha quality software. Do not perform any additonal
This driver is alpha quality software. Do not perform any additional
tasks inside the ``create`` playbook. Molecule does not know about the
Vagrant instances' configuration until the ``converge`` playbook is
executed.
Expand Down Expand Up @@ -86,7 +86,7 @@ class Vagrant(Driver):
.. code-block:: bash
$ pip install molecule[vagrant]
$ pip install molecule-vagrant
Change the provider passed to Vagrant.
Expand Down Expand Up @@ -126,7 +126,7 @@ class Vagrant(Driver):

def __init__(self, config=None):
super(Vagrant, self).__init__(config)
self._name = 'vagrant'
self._name = "vagrant"

@property
def name(self):
Expand All @@ -139,20 +139,20 @@ def name(self, value):
@property
def testinfra_options(self):
return {
'connection': 'ansible',
'ansible-inventory': self._config.provisioner.inventory_file,
"connection": "ansible",
"ansible-inventory": self._config.provisioner.inventory_file,
}

@property
def login_cmd_template(self):
connection_options = ' '.join(self.ssh_connection_options)
connection_options = " ".join(self.ssh_connection_options)

return (
'ssh {{address}} '
'-l {{user}} '
'-p {{port}} '
'-i {{identity_file}} '
'{}'
"ssh {{address}} "
"-l {{user}} "
"-p {{port}} "
"-i {{identity_file}} "
"{}"
).format(connection_options)

@property
Expand All @@ -161,17 +161,17 @@ def default_safe_files(self):
self.vagrantfile,
self.vagrantfile_config,
self.instance_config,
os.path.join(self._config.scenario.ephemeral_directory, '.vagrant'),
os.path.join(self._config.scenario.ephemeral_directory, 'vagrant-*.out'),
os.path.join(self._config.scenario.ephemeral_directory, 'vagrant-*.err'),
os.path.join(self._config.scenario.ephemeral_directory, ".vagrant"),
os.path.join(self._config.scenario.ephemeral_directory, "vagrant-*.out"),
os.path.join(self._config.scenario.ephemeral_directory, "vagrant-*.err"),
]

@property
def default_ssh_connection_options(self):
return self._get_ssh_connection_options()

def login_options(self, instance_name):
d = {'instance': instance_name}
d = {"instance": instance_name}

return util.merge_dicts(d, self._get_instance_config(instance_name))

Expand All @@ -180,12 +180,12 @@ def ansible_connection_options(self, instance_name):
d = self._get_instance_config(instance_name)

return {
'ansible_user': d['user'],
'ansible_host': d['address'],
'ansible_port': d['port'],
'ansible_private_key_file': d['identity_file'],
'connection': 'ssh',
'ansible_ssh_common_args': ' '.join(self.ssh_connection_options),
"ansible_user": d["user"],
"ansible_host": d["address"],
"ansible_port": d["port"],
"ansible_private_key_file": d["identity_file"],
"connection": "ssh",
"ansible_ssh_common_args": " ".join(self.ssh_connection_options),
}
except StopIteration:
return {}
Expand All @@ -196,17 +196,17 @@ def ansible_connection_options(self, instance_name):

@property
def vagrantfile(self):
return os.path.join(self._config.scenario.ephemeral_directory, 'Vagrantfile')
return os.path.join(self._config.scenario.ephemeral_directory, "Vagrantfile")

@property
def vagrantfile_config(self):
return os.path.join(self._config.scenario.ephemeral_directory, 'vagrant.yml')
return os.path.join(self._config.scenario.ephemeral_directory, "vagrant.yml")

def _get_instance_config(self, instance_name):
instance_config_dict = util.safe_load_file(self._config.driver.instance_config)

return next(
item for item in instance_config_dict if item['instance'] == instance_name
item for item in instance_config_dict if item["instance"] == instance_name
)

def sanity_checks(self):
Expand All @@ -217,6 +217,7 @@ def template_dir(self):
""" Return path to its own cookiecutterm templates. It is used by init
command in order to figure out where to load the templates from.
"""
return os.path.join(
os.path.dirname(__file__), "cookiecutter/scenario/driver/vagrant"
)
return os.path.join(os.path.dirname(__file__), "cookiecutter")

def modules_dir(self):
return os.path.join(os.path.dirname(__file__), "modules")
Empty file.
Loading

0 comments on commit 78582f9

Please sign in to comment.