Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit ada8770

Browse files
authored
Merge pull request #2 from pycontribs/fix/validate-docker
Adds docker and selinux validation
2 parents a6a88b5 + b635712 commit ada8770

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

pytest_molecule.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import print_function
3+
import logging
34
import os
45
import pytest
56
import subprocess
7+
import sys
8+
9+
10+
def pytest_configure(config):
11+
12+
import docker
13+
14+
# validate docker conectivity
15+
c = docker.from_env(timeout=5, version="auto")
16+
if not c.ping():
17+
raise Exception("Failed to ping docker server.")
18+
19+
# validate selinux availability
20+
if sys.platform == 'linux':
21+
try:
22+
import selinux # noqa
23+
except Exception as e:
24+
logging.error(
25+
"It appears that you are trying to use "
26+
"molecule with a Python interpreter that does not have the "
27+
"libselinux python bindings installed. These can only be "
28+
"installed using your distro package manager and are specific "
29+
"to each python version. Common package names: "
30+
"libselinux-python python2-libselinux python3-libselinux")
31+
raise e
632

733

834
def pytest_collect_file(parent, path):

tox.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ envlist = lint,py27,py35,py36,py37
44

55
[testenv]
66
deps =
7-
docker
8-
paramiko
7+
docker>=4.0.1
8+
paramiko>=2.5.0
99
pytest>=3.0
10-
pytest-html
10+
pytest-html>=1.21.0
11+
selinux>=0.1.5rc1
1112
commands =
1213
pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {posargs:tests}
1314
setenv =

0 commit comments

Comments
 (0)