Skip to content

Commit aee16f3

Browse files
authored
Merge branch 'main' into vagrant_validate
2 parents c0b8a81 + 4fa9e93 commit aee16f3

File tree

11 files changed

+97
-19
lines changed

11 files changed

+97
-19
lines changed

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# We are limited to 4 usernames, if we ever exceed this limit we will rethink it
2+
github: [ssbarnea, konstruktoid]

.github/workflows/tox.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
- macos-10.15
2626
unit: ["true"]
2727
include:
28+
- tox_env: lint
29+
os: ubuntu-20.04
30+
python-version: "3.10"
31+
unit: false
32+
skip_vagrant: true
2833
- tox_env: packaging
2934
os: ubuntu-20.04
3035
python-version: 3.8
@@ -82,16 +87,14 @@ jobs:
8287
- name: "tox -e ${{ matrix.tox_env }}"
8388
run: python3 -m tox
8489

85-
- name: Combine coverage data
86-
if: ${{ matrix.unit }}
87-
# produce a single .coverage file at repo root
88-
run: coverage combine .tox/.coverage.*
89-
9090
- name: Upload coverage data
91-
if: ${{ matrix.unit }}
92-
uses: codecov/codecov-action@v1
91+
uses: codecov/codecov-action@v2
9392
with:
93+
directory: .tox
94+
files: "coverage-*.xml"
9495
name: ${{ matrix.tox_env }}
96+
verbose: true # optional (default = false)
97+
if: ${{ startsWith(matrix.tox_env, 'py') }}
9598

9699
- name: Archive logs
97100
uses: actions/upload-artifact@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Vagrantfile
1616
/dist/
1717
/python_vagrant.egg-info/
1818
*.egg-info/
19+
*.box

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ backwards-compatible features or bug fixes are added.
3535

3636
## Requirements
3737

38-
- Vagrant 1.4 or greater (currently tested with 1.7.2). Using the latest
39-
version of Vagrant is strongly recommended.
38+
- Vagrant 2.2 or greater. Using the latest version of Vagrant is strongly
39+
recommended.
4040
- Vagrant requires VirtualBox, VMWare, or another supported provider.
41-
- Python 2.7 (the only version this package has been tested with.) or Python
42-
3.3 or higher.
41+
- Python 3.8 or newer.
4342
- The Sahara gem for Vagrant is optional. It will allow you to use
4443
`SandboxVagrant`.
4544

@@ -56,7 +55,7 @@ Download and install python-vagrant:
5655
Clone and install python-vagrant
5756

5857
cd ~
59-
git clone git@github.com:todddeluca/python-vagrant.git
58+
git clone git@github.com:pycontribs/python-vagrant.git
6059
cd python-vagrant
6160
python setup.py install
6261

codecov.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
codecov:
3+
require_ci_to_pass: true
4+
comment: false
5+
coverage:
6+
status:
7+
patch: false
8+
project:
9+
default:
10+
threshold: 0.5%

pytest.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[pytest]
2+
# do not add options here as this will likely break either console runs or IDE
3+
# integration like vscode or pycharm
4+
addopts =
5+
# https://code.visualstudio.com/docs/python/testing
6+
# coverage is re-enabled in `tox.ini`. That approach is safer than
7+
# `--no-cov` which prevents activation from tox.ini and which also fails
8+
# when plugin is effectively missing.
9+
-p no:pytest_cov

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ python_requires = >=3.8
3939

4040
[options.extras_require]
4141
test =
42+
coverage>=6.3
43+
pytest-cov>=3.0.0
4244
pytest>=7.0.0
4345

4446
[options.package_data]

tests/test_vagrant.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
TEST_BOX_URL = "generic/alpine315"
5252
TEST_BOX_NAME = TEST_BOX_URL
5353
TEST_PROVIDER = "virtualbox"
54+
TEST_DUMMY_BOX_URL = os.path.join(
55+
os.path.dirname(os.path.abspath(__file__)), "tools", f"dummy-{TEST_PROVIDER}.box"
56+
)
5457
# temp dir for testing.
5558

5659

@@ -77,7 +80,11 @@ def fixture_test_dir() -> Generator[str, None, None]:
7780
# Removes the directory created initially, runs once after the last test
7881
sys.stderr.write("module teardown()\n")
7982
if my_dir is not None:
80-
subprocess.check_call("vagrant destroy -f", cwd=my_dir, shell=True)
83+
try:
84+
subprocess.check_call("vagrant destroy -f", cwd=my_dir, shell=True)
85+
except subprocess.CalledProcessError:
86+
pass
87+
8188
shutil.rmtree(my_dir)
8289

8390

@@ -459,7 +466,7 @@ def test_boxesvm(test_dir):
459466
b.name for b in v.box_list()
460467
], "There should be no dummy box before it's added."
461468
# Add a box
462-
v.box_add(box_name, TEST_BOX_URL)
469+
v.box_add(box_name, TEST_DUMMY_BOX_URL)
463470

464471
# Test that there is a dummy box listed
465472
box_listing = v.box_list()
@@ -600,7 +607,7 @@ def test_streaming_output(vm_dir):
600607
"""
601608
Test streaming output of up or reload.
602609
"""
603-
test_string = "Waiting for machine to boot."
610+
test_string = "Machine already provisioned"
604611
v = vagrant.Vagrant(vm_dir)
605612

606613
with pytest.raises(subprocess.CalledProcessError):

tests/tools/create_dummy_box.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5+
6+
if [ $# -ne 1 ]; then
7+
echo "Missing provider" >&2
8+
exit 1
9+
fi
10+
11+
if [ -f "$DIR/dummy.box" ]; then
12+
echo "Box already created"
13+
exit 0
14+
fi
15+
16+
PROVIDER="$1"
17+
TMPDIR=`mktemp -d`
18+
cd "$TMPDIR"
19+
echo "{ \"provider\": \"$PROVIDER\"}" > metadata.json
20+
tar czf "$DIR/dummy-$PROVIDER.box" .
21+
cd "$DIR"
22+
rm -rf "$TMPDIR"

tox.ini

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
11
[tox]
22
envlist =
3+
lint
34
packaging
45
py
56
# needed by PEP-517 projects:
67
isolated_build = True
78
minversion = 3.24.5
9+
requires =
10+
# fail build if git reports dirty after test run
11+
tox-extra
812

913
[testenv]
1014
deps =
11-
.[test]
15+
--editable .[test]
16+
commands_pre =
17+
{toxinidir}/tests/tools/create_dummy_box.sh virtualbox
18+
{toxinidir}/tests/tools/create_dummy_box.sh libvirt
1219
commands =
13-
pytest {posargs}
20+
pytest {posargs:\
21+
-p pytest_cov \
22+
--cov vagrant \
23+
--cov "{envsitepackagesdir}/vagrant" \
24+
--cov-report term-missing:skip-covered \
25+
--cov-report=xml:{toxworkdir}/coverage-{envname}.xml \
26+
--no-cov-on-fail \
27+
}
1428
passenv =
1529
# Pass HOME to the test environment as it is required by
1630
# vagrant. Otherwise error happens due to missing HOME env variable.
1731
HOME
32+
setenv =
33+
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
1834
allowlist_externals =
1935
sh
2036

2137
[testenv:dev]
2238
commands = {posargs}
2339

40+
[testenv:lint]
41+
description = Run all linters
42+
deps =
43+
pre-commit>=2.6.0
44+
skip_install = true
45+
commands =
46+
{envpython} -m pre_commit run --all-files --show-diff-on-failure {posargs:}
47+
2448
[testenv:packaging]
2549
description =
2650
Build package, verify metadata, install package and assert behavior when ansible is missing.

0 commit comments

Comments
 (0)