Skip to content

Commit

Permalink
Merge branch 'main' into add_tag_support
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitthakur2590 authored Aug 21, 2023
2 parents 84d68cc + f2bec23 commit c15dcad
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 74 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# molecule
# Remove the following once tox-ansible is molecule aware
# molecule/
# !molecule/default/
# !molecule/resources/
# !molecule/.env.yml

# sanity artifacts
tests/output/

Expand Down
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ repos:
additional_dependencies:
- ansible-core
- pytest
- tox
- git+https://github.com/ansible-network/pytest-ansible-network-integration.git
- pytest-ansible

- repo: https://github.com/pre-commit/mirrors-mypy.git
rev: v1.3.0
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"python.linting.mypyEnabled": true,
"prettier.enable": true,
"python.testing.pytestArgs": [
"--capture=fd",
"tests"
],
"python.testing.unittestEnabled": false,
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The Ansible SCM (ansible.scm) Collection Release Notes
.. contents:: Topics


v1.1.1
======

v1.1.0
======

Expand Down
2 changes: 1 addition & 1 deletion changelogs/.plugin-cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ plugins:
shell: {}
strategy: {}
vars: {}
version: 1.1.0
version: 1.1.1
3 changes: 3 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
ancestor:
releases:
1.1.1:
changes: {}
release_date: "2023-08-01"
1.1.0:
changes:
minor_changes:
Expand Down
39 changes: 39 additions & 0 deletions extensions/molecule/default/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
- name: Default create playbook
hosts: localhost
gather_facts: false
vars_files:
- ../resources/vars/vars.yml
tasks:
- name: Find integration test targets
ansible.builtin.find:
file_type: directory
paths: "{{ integration_tests_path }}"
recurse: false
register: _targets

- name: Create directories
ansible.builtin.file:
path: "{{ directory }}"
state: directory
mode: "0700"
loop: "{{ _targets.files }}"
loop_control:
loop_var: target
label: "{{ directory }}"
vars:
directory: "../integration_{{ target.path | basename }}"

- name: Copy the template vars_files
ansible.builtin.template:
src: "{{ source }}"
dest: "{{ destination }}"
mode: "0600"
loop: "{{ _targets.files | product(files) | list }}"
loop_control:
loop_var: product
label: "{{ destination }}"
vars:
source: "{{ product[1] }}"
destination: "../integration_{{ product[0].path | basename }}/{{ product[1] | basename }}"
files:
- ../resources/templates/molecule.yml
16 changes: 16 additions & 0 deletions extensions/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
platforms:
- name: na

provisioner:
name: ansible
playbooks:
destroy: ../resources/playbooks/noop.yml
prepare: ../resources/playbooks/noop.yml

scenario:
create_sequence:
- create
test_sequence:
- prepare
destroy_sequence:
- destroy
19 changes: 19 additions & 0 deletions extensions/molecule/integration_failure/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
platforms:
- name: na

provisioner:
name: ansible
playbooks:
cleanup: ../resources/playbooks/noop.yml
converge: ../resources/playbooks/converge.yml
destroy: ../resources/playbooks/noop.yml
prepare: ../resources/playbooks/noop.yml
config_options:
defaults:
collections_path: ${ANSIBLE_COLLECTIONS_PATH}
scenario:
test_sequence:
- prepare
- converge
destroy_sequence:
- destroy
19 changes: 19 additions & 0 deletions extensions/molecule/integration_key_checking/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
platforms:
- name: na

provisioner:
name: ansible
playbooks:
cleanup: ../resources/playbooks/noop.yml
converge: ../resources/playbooks/converge.yml
destroy: ../resources/playbooks/noop.yml
prepare: ../resources/playbooks/noop.yml
config_options:
defaults:
collections_path: ${ANSIBLE_COLLECTIONS_PATH}
scenario:
test_sequence:
- prepare
- converge
destroy_sequence:
- destroy
19 changes: 19 additions & 0 deletions extensions/molecule/integration_success/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
platforms:
- name: na

provisioner:
name: ansible
playbooks:
cleanup: ../resources/playbooks/noop.yml
converge: ../resources/playbooks/converge.yml
destroy: ../resources/playbooks/noop.yml
prepare: ../resources/playbooks/noop.yml
config_options:
defaults:
collections_path: ${ANSIBLE_COLLECTIONS_PATH}
scenario:
test_sequence:
- prepare
- converge
destroy_sequence:
- destroy
19 changes: 19 additions & 0 deletions extensions/molecule/integration_user_dir/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
platforms:
- name: na

provisioner:
name: ansible
playbooks:
cleanup: ../resources/playbooks/noop.yml
converge: ../resources/playbooks/converge.yml
destroy: ../resources/playbooks/noop.yml
prepare: ../resources/playbooks/noop.yml
config_options:
defaults:
collections_path: ${ANSIBLE_COLLECTIONS_PATH}
scenario:
test_sequence:
- prepare
- converge
destroy_sequence:
- destroy
16 changes: 16 additions & 0 deletions extensions/molecule/resources/playbooks/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Shared integration test runner
hosts: localhost
gather_facts: false

tasks:
- name: Load the vars
ansible.builtin.include_vars:
file: ../../resources/vars/vars.yml

- name: "Integration test: {{ test_name }}"
ansible.builtin.include_role:
name: "{{ test_path }}"
vars:
test_path: "{{ integration_tests_path }}{{ test_name }}"
test_name: "{{ molecule_scenario_name.replace('integration_', '') }}"
4 changes: 4 additions & 0 deletions extensions/molecule/resources/playbooks/noop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: noop
hosts: localhost
gather_facts: false
tasks:
19 changes: 19 additions & 0 deletions extensions/molecule/resources/templates/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
platforms:
- name: na

provisioner:
name: ansible
playbooks:
cleanup: ../resources/playbooks/noop.yml
converge: ../resources/playbooks/converge.yml
destroy: ../resources/playbooks/noop.yml
prepare: ../resources/playbooks/noop.yml
config_options:
defaults:
collections_path: ${ANSIBLE_COLLECTIONS_PATH}
scenario:
test_sequence:
- prepare
- converge
destroy_sequence:
- destroy
3 changes: 3 additions & 0 deletions extensions/molecule/resources/vars/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collection_root: "{{ lookup( 'pipe', 'git rev-parse --show-toplevel') }}"
integration_tests_path: "{{ collection_root }}/tests/integration/targets/"
molecule_scenario_name: "{{ molecule_scenario_directory | basename }}"
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tags:
- storage
- tools
- windows
version: 1.1.0
version: 1.1.1
build_ignore:
- .github
- .gitignore
Expand Down
4 changes: 2 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ ignore_missing_imports = true
# No type hints as of version 2.6.1
ignore_missing_imports = true

[mypy-pytest_ansible_network_integration]
# No type hints as of 6/8/2022
[mypy-pytest_ansible.*]
# No type hints as of 8/7/2023
ignore_missing_imports = true

[mypy-ansible_collections.*]
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ enable = [

]

# Run with xdist 1 until molecule has shared scenario state
[tool.pytest.ini_options]
addopts = [
"--integration-tests-path=tests/integration/targets",
"-vvv",
"-n",
"2",
"1",
"--log-level",
"WARNING",
"--color",
Expand Down Expand Up @@ -69,8 +68,9 @@ target-version = "py38"
# S603, subprocess ok
"plugins/plugin_utils/git_base.py" = ["S603"]
#
# S101 allow assert in tests
# T201 allow print in tests
"tests/**" = ["T201"]
"tests/**" = ["S101", "T201"]
#
# UP001 until __metaclass__ is not required
# UP010 until from __future__ is gone
Expand Down
3 changes: 2 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
black
git+https://github.com/ansible-network/pytest-ansible-network-integration.git
molecule ; python_version < '3.9'
molecule==v6.0.0b0 ; python_version > '3.8'
mypy
pre-commit
pylint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
register: repository
ignore_errors: true

- name: Confirm the timeout return code and message
- name: Confirm the return code and message
ansible.builtin.assert:
that:
- repository["output"][0]["return_code"] == 62
- repository["msg"].startswith("Timeout:")
- repository["output"][0]["return_code"] != 0
67 changes: 7 additions & 60 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,13 @@
"""Run the integration tests."""
"""Tests for molecule scenarios."""
from __future__ import absolute_import, division, print_function

import subprocess
from pytest_ansible.molecule import MoleculeScenario

from typing import Dict

import pytest
def test_integration(molecule_scenario: MoleculeScenario) -> None:
"""Run molecule for each scenario.
from pytest_ansible_network_integration import AnsibleProject


# pylint: disable=invalid-name
__metaclass__ = type
# pylint: enable=invalid-name


def run(localhost_project: AnsibleProject, environment: Dict[str, str]) -> None:
"""Run the integration tests.
:param localhost_project: The localhost project.
:param environment: The environment.
"""
__tracebackhide__ = True # pylint: disable=unused-variable
args = [
"ansible-navigator",
"run",
str(localhost_project.playbook),
"--ee",
"false",
"--mode",
"stdout",
"--pas",
str(localhost_project.playbook_artifact),
"--ll",
"debug",
"--lf",
str(localhost_project.log_file),
"--cdcp",
str(localhost_project.collection_doc_cache),
"-vvvv",
]
process = subprocess.run(
args=args,
env=environment,
capture_output=True,
check=False,
shell=False,
)
if process.returncode:
print(process.stdout.decode("utf-8"))
print(process.stderr.decode("utf-8"))

pytest.fail(msg=f"Integration test failed: {localhost_project.role}")


def test_integration(
localhost_project: AnsibleProject,
environment: Dict[str, str],
) -> None:
"""Run the integration tests.
:param localhost_project: The localhost project.
:param environment: The environment.
:param molecule_scenario: The molecule scenario object
"""
run(localhost_project, environment)
proc = molecule_scenario.test()
assert proc.returncode == 0
1 change: 1 addition & 0 deletions tox-ansible.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

skip =
py3.7
2.9 # molecule is >= 2.12

0 comments on commit c15dcad

Please sign in to comment.