Skip to content

Commit

Permalink
Merge pull request #5585 from freedomofpress/updates_pytest_pluggy_te…
Browse files Browse the repository at this point in the history
…stinfra_molecule_and_the_universe

Updates pytest pluggy testinfra molecule and the universe
  • Loading branch information
emkll authored Oct 28, 2020
2 parents bb80bfc + a11647a commit 6117fcc
Show file tree
Hide file tree
Showing 64 changed files with 387 additions and 213 deletions.
8 changes: 4 additions & 4 deletions admin/requirements-testinfra.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest==3.2.0
testinfra==3.2.0
pytest-xdist==1.18.2
paramiko==2.6.0
pytest==6.1.1
testinfra==5.3.1
pytest-xdist==2.1.0
paramiko==2.7.2
67 changes: 52 additions & 15 deletions admin/requirements-testinfra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ apipkg==1.5 \
--hash=sha256:37228cda29411948b422fae072f57e31d3396d2ee1c9783775980ee9c9990af6 \
--hash=sha256:58587dd4dc3daefad0487f6d9ae32b4542b185e1c36db6993290e7c41ca2b47c \
# via execnet
attrs==20.2.0 \
--hash=sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594 \
--hash=sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc \
# via pytest
bcrypt==3.2.0 \
--hash=sha256:5b93c1726e50a93a033c36e5ca7fdcd29a5c7395af50a6892f5d9e7c6cfbfb29 \
--hash=sha256:63d4e3ff96188e5898779b6057878fecf3f11cfe6ec3b313ea09955d587ec7a7 \
Expand Down Expand Up @@ -86,6 +90,14 @@ execnet==1.7.1 \
--hash=sha256:cacb9df31c9680ec5f95553976c4da484d407e85e41c83cb812aa014f0eddc50 \
--hash=sha256:d4efd397930c46415f62f8a31388d6be4f27a91d7550eb79bc64a756e0056547 \
# via pytest-xdist
importlib-metadata==2.0.0 \
--hash=sha256:77a540690e24b0305878c37ffd421785a6f7e53c8b5720d211b211de8d0e95da \
--hash=sha256:cefa1a2f919b866c5beb7c9f7b0ebb4061f30a8a9bf16d609b000e2dfaceb9c3 \
# via pluggy, pytest
iniconfig==1.1.1 \
--hash=sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3 \
--hash=sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32 \
# via pytest
jinja2==2.11.2 \
--hash=sha256:89aab215427ef59c34ad58735269eb58b1a5808103067f7bb9d5836c651b3bb0 \
--hash=sha256:f0a4641d3cf955324a89c04f3d94663aa4d638abe8f733ecd3582848e1c37035 \
Expand Down Expand Up @@ -129,10 +141,18 @@ netaddr==0.8.0 \
--hash=sha256:9666d0232c32d2656e5e5f8d735f58fd6c7457ce52fc21c98d45f2af78f990ac \
--hash=sha256:d6cc57c7a07b1d9d2e917aa8b36ae8ce61c35ba3fcd1b83ca31c5a0ee2b5a243 \
# via -r requirements-ansible.in
paramiko==2.6.0 \
--hash=sha256:99f0179bdc176281d21961a003ffdb2ec369daac1a1007241f53374e376576cf \
--hash=sha256:f4b2edfa0d226b70bd4ca31ea7e389325990283da23465d572ed1f70a7583041 \
packaging==20.4 \
--hash=sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8 \
--hash=sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181 \
# via pytest
paramiko==2.7.2 \
--hash=sha256:4f3e316fef2ac628b05097a637af35685183111d4bc1b5979bd397c2ab7b5898 \
--hash=sha256:7f36f4ba2c0d81d219f4595e35f70d56cc94f9ac40a6acdf51d6ca210ce65035 \
# via -r requirements-testinfra.in
pluggy==0.13.1 \
--hash=sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0 \
--hash=sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d \
# via pytest
prompt_toolkit==2.0.9 \
--hash=sha256:11adf3389a996a6d45cc277580d0d53e8a5afd281d0c9ec71b28e6f121463780 \
--hash=sha256:2519ad1d8038fd5fc8e770362237ad0364d16a7650fb5724af6997ed5515e3c1 \
Expand All @@ -141,7 +161,7 @@ prompt_toolkit==2.0.9 \
py==1.9.0 \
--hash=sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2 \
--hash=sha256:9ca6883ce56b4e8da7e79ac18787889fa5206c79dcc67fb065376cd2fe03f342 \
# via pytest
# via pytest, pytest-forked
pycparser==2.20 \
--hash=sha256:2d475327684562c3a96cc71adf7dc8c4f0565175cf86b6d7a404ff4c771f15f0 \
--hash=sha256:7582ad22678f0fcd81102833f60ef8d0e57288b6b5fb00323d101be910e35705 \
Expand All @@ -166,13 +186,22 @@ pynacl==1.4.0 \
--hash=sha256:ea6841bc3a76fa4942ce00f3bda7d436fda21e2d91602b9e21b7ca9ecab8f3ff \
--hash=sha256:f8851ab9041756003119368c1e6cd0b9c631f46d686b3904b18c0139f4419f80 \
# via paramiko
pytest-xdist==1.18.2 \
--hash=sha256:10468377901b80255cf192c4603a94ffe8b1f071f5c912868da5f5cb91170dae \
pyparsing==2.4.7 \
--hash=sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1 \
--hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \
# via packaging
pytest-forked==1.3.0 \
--hash=sha256:6aa9ac7e00ad1a539c41bec6d21011332de671e938c7637378ec9710204e37ca \
--hash=sha256:dc4147784048e70ef5d437951728825a131b81714b398d5d52f17c7c144d8815 \
# via pytest-xdist
pytest-xdist==2.1.0 \
--hash=sha256:7c629016b3bb006b88ac68e2b31551e7becf173c76b977768848e2bbed594d90 \
--hash=sha256:82d938f1a24186520e2d9d3a64ef7d9ac7ecdf1a0659e095d18e596b8cbd0672 \
# via -r requirements-testinfra.in
pytest==3.2.0 \
--hash=sha256:0225cf10b9e173f84729d5f4648211458a222c6e53a77a85e104bc5f31c244ee \
--hash=sha256:d994b4f28c6d449a467ad3d336544945a0dcf350e3b7b301219547ef5aa8125e \
# via -r requirements-testinfra.in, pytest-xdist, testinfra
pytest==6.1.1 \
--hash=sha256:7a8190790c17d79a11f847fba0b004ee9a8122582ebff4729a082c109e81a4c9 \
--hash=sha256:8f593023c1a0f916110285b6efd7f99db07d59546e3d8c36fc60e2ab05d3be92 \
# via -r requirements-testinfra.in, pytest-forked, pytest-xdist, testinfra
pyyaml==5.3.1 \
--hash=sha256:06a0d7ba600ce0b2d2fe2e78453a470b5a6e000a985dd4a4e54e436cc36b0e97 \
--hash=sha256:240097ff019d7c70a4922b6869d8a86407758333f02203e0fc6ff79c5dcede76 \
Expand All @@ -189,18 +218,26 @@ pyyaml==5.3.1 \
six==1.15.0 \
--hash=sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259 \
--hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \
# via -r requirements.in, bcrypt, cryptography, prompt-toolkit, pynacl, testinfra
testinfra==3.2.0 \
--hash=sha256:16201d64659ec0c2d25f65d6ce1f5367668b7b4eb102450efd4f8983a399d7d0 \
--hash=sha256:5cebf61fee13c2e83b5e177431e751e243fc779293377c5e0c3b43910bb7e870 \
# via -r requirements.in, bcrypt, cryptography, packaging, prompt-toolkit, pynacl
testinfra==5.3.1 \
--hash=sha256:9d3a01fb787253df76ac4ab46d18a84d4b01be877ed1b5812e590dcf480a627e \
--hash=sha256:baf1d809ea2dc22c0cb5b9441bf4e17c1eb653e1ccc02cc63137d0ab467fa1de \
# via -r requirements-testinfra.in
toml==0.10.1 \
--hash=sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f \
--hash=sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88 \
# via pytest
wcwidth==0.2.5 \
--hash=sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784 \
--hash=sha256:c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83 \
# via prompt-toolkit
zipp==3.4.0 \
--hash=sha256:102c24ef8f171fd729d46599845e95c7ab894a4cf45f5de11a44cc7444fb1108 \
--hash=sha256:ed5eee1974372595f9e416cc7bbeeb12335201d8081ca8a0743c954d4446e5cb \
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
setuptools==50.3.0 \
--hash=sha256:39060a59d91cf5cf403fa3bacbb52df4205a8c3585e0b9ba4b30e0e19d4c4b18 \
--hash=sha256:c77b3920663a435c9450d9d971c48f5a7478fca8881b2cd2564e59f970f03536 \
# via -r requirements.in, pytest
# via -r requirements.in
12 changes: 6 additions & 6 deletions molecule/ansible-config/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ driver:
login_cmd_template: 'docker exec -ti {instance} bash'
ansible_connection_options:
connection: local
lint:
name: yamllint
lint: |
yamllint
platforms:
- name: localhost
provisioner:
name: ansible
playbooks:
prepare: ''
create: ''
lint:
name: ansible-lint
lint: |
ansible-lint
config_options:
defaults:
callback_whitelist: "profile_tasks, timer"
Expand All @@ -33,5 +33,5 @@ scenario:
- verify
verifier:
name: testinfra
lint:
name: flake8
lint: |
flake8
12 changes: 6 additions & 6 deletions molecule/builder-focal/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
driver:
name: docker
lint:
name: yamllint
lint: |
yamllint
platforms:
- name: focal-sd-app
groups:
Expand Down Expand Up @@ -50,8 +50,8 @@ provisioner:
ANSIBLE_CALLBACK_WHITELIST: skippy
ANSIBLE_STDOUT_CALLBACK: skippy
ANSIBLE_GATHER_TIMEOUT: "120"
lint:
name: ansible-lint
lint: |
ansible-lint
playbooks:
converge: playbook.yml
scenario:
Expand All @@ -77,5 +77,5 @@ verifier:
SECUREDROP_PYTHON_VERSION: "3.8"
# Reuse the same test suite for all packages
directory: ../builder-xenial/tests/
lint:
name: flake8
lint: |
flake8
12 changes: 6 additions & 6 deletions molecule/builder-xenial/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
driver:
name: docker
lint:
name: yamllint
lint: |
yamllint
platforms:
- name: xenial-sd-app
groups:
Expand Down Expand Up @@ -48,8 +48,8 @@ provisioner:
ANSIBLE_CALLBACK_WHITELIST: skippy
ANSIBLE_STDOUT_CALLBACK: skippy
ANSIBLE_GATHER_TIMEOUT: "120"
lint:
name: ansible-lint
lint: |
ansible-lint
playbooks:
converge: playbook.yml
scenario:
Expand All @@ -74,5 +74,5 @@ verifier:
SECUREDROP_TARGET_PLATFORM: xenial
SECUREDROP_PYTHON_VERSION: "3.5"
directory: tests/
lint:
name: flake8
lint: |
flake8
23 changes: 10 additions & 13 deletions molecule/builder-xenial/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
"""
Import variables from vars.yml and inject into pytest namespace
Import variables from vars.yml and inject into testutils namespace
"""

import os
import io
import yaml
import testutils


def pytest_namespace():
""" Return dict of vars imported as 'securedrop_test_vars' into pytest
global namespace
"""
filepath = os.path.join(os.path.dirname(__file__), "vars.yml")
with io.open(filepath, 'r') as f:
securedrop_test_vars = yaml.safe_load(f)
filepath = os.path.join(os.path.dirname(__file__), "vars.yml")
with io.open(filepath, 'r') as f:
securedrop_test_vars = yaml.safe_load(f)

# Tack on target OS for use in tests
securedrop_target_platform = os.environ.get("SECUREDROP_TARGET_PLATFORM")
securedrop_test_vars["securedrop_target_platform"] = securedrop_target_platform
# Wrapping the return value to accommodate for pytest namespacing
return dict(securedrop_test_vars=securedrop_test_vars)
# Tack on target OS for use in tests
securedrop_target_platform = os.environ.get("SECUREDROP_TARGET_PLATFORM")
securedrop_test_vars["securedrop_target_platform"] = securedrop_target_platform

testutils.securedrop_test_vars = testutils.inject_vars(securedrop_test_vars)
3 changes: 2 additions & 1 deletion molecule/builder-xenial/tests/test_securedrop_deb_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import os
import re
import tempfile
import testutils


SECUREDROP_TARGET_PLATFORM = os.environ.get("SECUREDROP_TARGET_PLATFORM")
testinfra_hosts = [
"docker://{}-sd-dpkg-verification".format(SECUREDROP_TARGET_PLATFORM)
]
securedrop_test_vars = pytest.securedrop_test_vars
securedrop_test_vars = testutils.securedrop_test_vars


def extract_package_name_from_filepath(filepath):
Expand Down
13 changes: 13 additions & 0 deletions molecule/builder-xenial/tests/testutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Myvalues:
def __init__(self):
pass


securedrop_test_vars = Myvalues()


def inject_vars(value):
res = Myvalues()
for key, value in value.items():
setattr(res, key, value)
return res
12 changes: 6 additions & 6 deletions molecule/fetch-tor-packages/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
lint: |
yamllint
platforms:
- name: tor-package-fetcher-xenial
image: "quay.io/freedomofpress/sd-docker-builder-xenial"
Expand All @@ -16,8 +16,8 @@ platforms:

provisioner:
name: ansible
lint:
name: ansible-lint
lint: |
ansible-lint
config_options:
defaults:
interpreter_python: auto
Expand All @@ -34,5 +34,5 @@ verifier:
name: testinfra
options:
connection: docker
lint:
name: flake8
lint: |
flake8
2 changes: 1 addition & 1 deletion molecule/libvirt-staging-focal/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
tasks:

- name: Create molecule instance(s)
molecule_vagrant:
vagrant:
instance_name: "{{ item.name }}"
instance_interfaces: "{{ item.interfaces | default(omit) }}"
instance_raw_config_args: "{{ item.instance_raw_config_args | default(omit) }}"
Expand Down
2 changes: 1 addition & 1 deletion molecule/libvirt-staging-focal/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}"
tasks:
- name: Destroy molecule instance(s)
molecule_vagrant:
vagrant:
instance_name: "{{ item.name }}"
platform_box: "{{ item.box }}"
provider_name: "{{ molecule_yml.driver.provider.name }}"
Expand Down
14 changes: 7 additions & 7 deletions molecule/libvirt-staging-focal/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ driver:
name: vagrant
provider:
name: libvirt
lint:
name: yamllint
lint: |
yamllint
platforms:
- name: app-staging
Expand Down Expand Up @@ -41,8 +41,8 @@ platforms:

provisioner:
name: ansible
lint:
name: ansible-lint
lint: |
ansible-lint
config_options:
defaults:
interpreter_python: auto
Expand All @@ -65,9 +65,9 @@ scenario:
- verify
verifier:
name: testinfra
lint:
name: flake8
directory: ../testinfra/
lint: |
flake8
directory: ../testinfra
options:
n: auto
v: 2
Expand Down
2 changes: 1 addition & 1 deletion molecule/libvirt-staging-xenial/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
tasks:

- name: Create molecule instance(s)
molecule_vagrant:
vagrant:
instance_name: "{{ item.name }}"
instance_interfaces: "{{ item.interfaces | default(omit) }}"
instance_raw_config_args: "{{ item.instance_raw_config_args | default(omit) }}"
Expand Down
2 changes: 1 addition & 1 deletion molecule/libvirt-staging-xenial/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}"
tasks:
- name: Destroy molecule instance(s)
molecule_vagrant:
vagrant:
instance_name: "{{ item.name }}"
platform_box: "{{ item.box }}"
provider_name: "{{ molecule_yml.driver.provider.name }}"
Expand Down
Loading

0 comments on commit 6117fcc

Please sign in to comment.