diff --git a/.travis.yml b/.travis.yml index fbd8b5d..dbdda31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,11 @@ +dist: xenial sudo: false services: - docker language: python -cache: pip services: - docker -before_install: -- pyenv versions -- pyenv version-name -- env - install: - pip install tox @@ -19,21 +14,28 @@ python: - '3.4' - '3.5' - '3.6' -- '3.7-dev' +- '3.7' +- '3.8-dev' env: -- SALT=-v2018.3 BACKEND=-cherrypy CODECOV=py -- SALT=-v2018.3 BACKEND=-tornado CODECOV=py -- SALT=-v2019.2 BACKEND=-cherrypy CODECOV=py -- SALT=-v2019.2 BACKEND=-tornado CODECOV=py +- SALT=v2018.3 BACKEND=cherrypy +- SALT=v2018.3 BACKEND=tornado +- SALT=v2019.2 BACKEND=cherrypy +- SALT=v2019.2 BACKEND=tornado +- SALT=develop BACKEND=cherrypy +- SALT=develop BACKEND=tornado matrix: - env: + allow_failures: + - python: '3.8-dev' + - env: SALT=develop BACKEND=tornado + - env: SALT=develop BACKEND=cherrypy script: -- PYTHON="${TRAVIS_PYTHON_VERSION%-dev}" -- docker run -v $PWD:/pepper -ti --rm gtmanfred/pepper:latest tox -c /pepper/tox.ini -e "${TRAVIS_PYTHON_VERSION%%.*}flake8,${CODECOV}${PYTHON//./}${BACKEND}${SALT}" +- PYTHON="${TRAVIS_PYTHON_VERSION/-dev/-rc}" +- TOX_VERSION="py${PYTHON//./}" +- docker run -v $PWD:/pepper -ti --rm "python:$PYTHON" make -C /pepper test PYVERSION="${TOX_VERSION%-rc}" SALT="${SALT}" BACKEND="${BACKEND}" after_success: - sudo chown $USER .tox/ -- if [[ $CODECOV == "py" ]]; then tox -e codecov; fi +- tox -e codecov diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1c69fd3 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +PYVERSION?=py37 +SALT?=v2019.2 +BACKEND?=cherrypy +DEBIAN_FRONTEND=noninteractive + +install: + apt update && apt install -y libc6-dev libffi-dev gcc git openssh-server libzmq3-dev + pip install tox + +test: install + tox -e flake8,$(PYVERSION)-$(BACKEND)-$(SALT) diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..87d32eb --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,60 @@ +trigger: +- develop + +variables: + python: '["py2.7", "py3.4", "py3.5", "py3.6", "py3.7", "py3.8"]' + salt: '["v2018.3", "v2019.2", "develop"]' + backends: '["cherrypy", "tornado"]' + +jobs: +- job: build_matrix + pool: + vmImage: 'Ubuntu-16.04' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.7' + architecture: x64 + + - task: PythonScript@0 + name: matrix + inputs: + scriptSource: Inline + script: | + import json + matrix = {} + for pyver in $(python): + for saltver in $(salt): + for backend in $(backends): + matrix['{0}-{1}-{2}'.format(pyver, backend, saltver)] = { + 'python.version': pyver[2:], + 'version': pyver.replace('.', ''), + 'salt': saltver, + 'backend': backend, + } + print('##vso[task.setvariable variable=matrix;isOutput=true]{0}'.format(json.dumps(matrix))) + +- job: test_pepper + dependsOn: build_matrix + pool: + vmImage: 'Ubuntu-16.04' + strategy: + matrix: $[ dependencies.build_matrix.outputs['matrix.matrix'] ] + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' + architecture: x64 + + - script: | + pip install tox + displayName: Install dependencies + - script: | + docker run -v $PWD:/pepper --rm "python:$(python.version)" make -C /pepper test PYTHON_VERSION=$(version) SALT=$(salt) BACKEND=$(backend) + displayName: pytest + - script: | + sudo chown $USER .tox/ + tox -e codecov + displayName: codecov + env: + CODECOV_TOKEN: '16c2a232-4329-438c-b163-ccbfeeab47aa' diff --git a/pepper/cli.py b/pepper/cli.py index 8473c88..0a6a02a 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -411,7 +411,9 @@ def get_login_details(self): else: if self.options.username is not None: results['SALTAPI_USER'] = self.options.username - if self.options.password is None and results['SALTAPI_PASS'] is None: + if self.options.password is None and \ + results['SALTAPI_PASS'] is None and \ + results['SALTAPI_EAUTH'] != 'kerberos': if self.options.interactive: results['SALTAPI_PASS'] = getpass.getpass(prompt='Password: ') else: diff --git a/pepper/libpepper.py b/pepper/libpepper.py index 60c03db..46880c3 100644 --- a/pepper/libpepper.py +++ b/pepper/libpepper.py @@ -267,8 +267,8 @@ def req_requests(self, path, data=None): ''' import requests - from requests_kerberos import HTTPKerberosAuth, OPTIONAL - auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL) + from requests_gssapi import HTTPSPNEGOAuth, OPTIONAL + auth = HTTPSPNEGOAuth(mutual_authentication=OPTIONAL) headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', diff --git a/setup.py b/setup.py index c013a12..c6d645b 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,9 @@ 'packages': [ 'pepper', ], + 'extras_require': { + 'kerberos': ["requests-gssapi>=1.1.0"], + }, 'scripts': [ 'scripts/pepper', ] diff --git a/tests/Dockerfile b/tests/Dockerfile deleted file mode 100644 index 0b4f43c..0000000 --- a/tests/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM centos - -ENV PYENV_ROOT /usr/local/pyenv/ -ENV PATH /usr/local/pyenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - -RUN mkdir /usr/local/pyenv && \ - yum install -y git openssh-server gcc readline-devel bzip2-devel zlib-devel openssl-devel sqlite-devel make libffi-devel && \ - yum clean all && \ - git clone git://github.com/yyuu/pyenv.git /usr/local/pyenv && \ - git clone git://github.com/yyuu/pyenv-virtualenv.git /usr/local/pyenv/plugins/pyenv-virtualenv && \ - ln -vs /usr/local/pyenv/bin/* /usr/local/pyenv/plugins/*/bin/* /usr/local/bin - -RUN pyenv install 2.7.15 && \ - pyenv install 3.4.9 && \ - pyenv install 3.5.6 && \ - pyenv install 3.6.7 && \ - pyenv install 3.7.1 && \ - pyenv global 3.7.1 3.6.7 3.5.6 3.4.9 2.7.15 && \ - pip install tox diff --git a/tests/conftest.py b/tests/conftest.py index 23a88c8..81d2662 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals, print_function # Import python libraries +import distutils.spawn import logging import os.path import shutil @@ -10,6 +11,8 @@ import textwrap # Import Salt Libraries +import salt.client +import salt.config import salt.utils.yaml as yaml # Import pytest libraries @@ -26,6 +29,16 @@ log = logging.getLogger(__name__) +@pytest.fixture(scope='session') +def install_sshd_server(): + if distutils.spawn.find_executable('sshd'): + return + __opts__ = salt.config.minion_config('tests/minion.conf') + __opts__['file_client'] = 'local' + caller = salt.client.Caller(mopts=__opts__) + caller.cmd('pkg.install', 'openssh-server') + + class SaltApi(SaltDaemonScriptBase): ''' Class which runs the salt-api daemon @@ -76,7 +89,6 @@ def pepperconfig(salt_api_port): SALTAPI_EAUTH=sharedsecret [noopts] SALTAPI_URL=http://localhost:{0}/ - SALTAPI_EAUTH=kerberos '''.format(salt_api_port)) with open('tests/.pepperrc', 'w') as pepper_file: print(config, file=pepper_file) @@ -109,7 +121,7 @@ def output_file(): @pytest.fixture(params=['/run', '/login']) -def pepper_cli(request, session_salt_api, salt_api_port, output_file, session_sshd_server): +def pepper_cli(request, session_salt_api, salt_api_port, output_file, install_sshd_server, session_sshd_server): ''' Wrapper to invoke Pepper with common params and inside an empty env ''' diff --git a/tests/integration/test_clients.py b/tests/integration/test_clients.py index dba7ceb..6012c8e 100644 --- a/tests/integration/test_clients.py +++ b/tests/integration/test_clients.py @@ -35,10 +35,7 @@ def test_runner_client(pepper_cli): ) def test_wheel_client_arg(pepper_cli, session_minion_id): ret = pepper_cli('--client=wheel', 'minions.connected') - # note - this seems not to work in returning session_minion_id with current runner, returning [] - # the test originally was asserting the success atr but that isn't returned anymore - # further debugging needed with pytest-salt - assert ret == [] + assert ret == ['pytest-session-salt-minion-0'] @pytest.mark.xfail( diff --git a/tox.ini b/tox.ini index 24c72be..ece2b3c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{27,34,35,36}-{cherrypy,tornado}-{v2018.3,v2019.2},coverage,flake8 +envlist = py{27,34,35,36,37,38}-{cherrypy,tornado}-{v2018.3,v2019.2,develop},coverage,flake8 skip_missing_interpreters = true skipsdist = false @@ -13,18 +13,10 @@ deps = -r{toxinidir}/tests/requirements.txt changedir = {toxinidir} setenv = COVERAGE_FILE = {toxworkdir}/.coverage.{envname} commands = - cherrypy: pytest --cov=pepper/ --cov-config=tox.ini --cov-report= {posargs} --salt-api-backend=rest_cherrypy - tornado: pytest --cov=pepper/ --cov-config=tox.ini --cov-report= {posargs} --salt-api-backend=rest_tornado + cherrypy: pytest -v --cov=pepper/ --cov-config=tox.ini --cov-report= {posargs} --salt-api-backend=rest_cherrypy + tornado: pytest -v --cov=pepper/ --cov-config=tox.ini --cov-report= {posargs} --salt-api-backend=rest_tornado -[testenv:2flake8] -basepython = python2 -deps = - -r {toxinidir}/tests/requirements.txt - flake8 -commands = flake8 tests/ pepper/ scripts/pepper setup.py - -[testenv:3flake8] -basepython = python3 +[testenv:flake8] deps = -r {toxinidir}/tests/requirements.txt flake8 @@ -57,7 +49,7 @@ changedir = {toxinidir}/htmlcov commands = python -m http.server [pytest] -addopts = --showlocals --log-file /tmp/pepper-runtests.log --no-print-logs -ra -sv +addopts = --showlocals --log-file /tmp/pepper-runtests.log --no-print-logs -ra testpaths = tests norecursedirs = .git .tox usefixtures = pepperconfig