Skip to content

Commit

Permalink
Merge pull request #55479 from s0undt3ch/features/pytest-staged-14
Browse files Browse the repository at this point in the history
[PyTest #14] Prefer `RUNTIME_VARS` usage
  • Loading branch information
dwoz authored Dec 4, 2019
2 parents 69e52f5 + cb4c28f commit c232896
Show file tree
Hide file tree
Showing 112 changed files with 851 additions and 818 deletions.
8 changes: 4 additions & 4 deletions tests/integration/cloud/clouds/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import salt.utils.yaml

# Import Salt Testing Libs
from tests.support.paths import FILES
from tests.support.runtests import RUNTIME_VARS
from tests.support.helpers import expensiveTest
from tests.support.unit import skipIf
from tests.support import win_installer
Expand All @@ -38,14 +38,14 @@ class EC2Test(CloudTest):
def __fetch_installer():
# Determine the downloaded installer name by searching the files
# directory for the first file that looks like an installer.
for path, dirs, files in os.walk(FILES):
for path, dirs, files in os.walk(RUNTIME_VARS.FILES):
for file in files:
if file.startswith(win_installer.PREFIX):
return file

# If the installer wasn't found in the previous steps, download the latest Windows installer executable
name = win_installer.latest_installer_name()
path = os.path.join(FILES, name)
path = os.path.join(RUNTIME_VARS.FILES, name)
with salt.utils.files.fopen(path, 'wb') as fp:
win_installer.download_and_verify(fp, name)
return name
Expand Down Expand Up @@ -87,7 +87,7 @@ def copy_file(self, name):
configuration directory. The path to the file which is created will be
returned.
'''
src = os.path.join(FILES, name)
src = os.path.join(RUNTIME_VARS.FILES, name)
dst = os.path.join(self.config_dir, name)
with salt.utils.files.fopen(src, 'rb') as sfp:
with salt.utils.files.fopen(dst, 'wb') as dfp:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cloud/helpers/virtualbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import tests.integration.cloud.helpers
from tests.support.case import ShellCase
from tests.support.unit import TestCase, skipIf
from tests.support.paths import FILES
from tests.support.runtests import RUNTIME_VARS

# Import Salt libs
from salt.ext import six
Expand Down Expand Up @@ -57,7 +57,7 @@ def run_cloud(self, arg_str, catch_stderr=False, timeout=None):
@return:
@rtype: dict
"""
config_path = os.path.join(FILES, 'conf')
config_path = os.path.join(RUNTIME_VARS.FILES, 'conf')
arg_str = '--out=json -c {0} {1}'.format(config_path, arg_str)
# arg_str = "{0} --log-level=error".format(arg_str)
log.debug("running salt-cloud with %s", arg_str)
Expand Down
37 changes: 21 additions & 16 deletions tests/integration/daemons/test_masterapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -tests/integration/daemons/test_masterapi.py:71*- coding: utf-8 -*-

# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
Expand All @@ -7,31 +7,33 @@
import stat

# Import Salt Testing libs
from tests.support.runtests import RUNTIME_VARS
from tests.support.case import ShellCase
from tests.support.paths import TMP, INTEGRATION_TEST_DIR

# Import 3rd-party libs

# Import Salt libs
import salt.utils.files
import salt.utils.stringutils

# all read, only owner write
autosign_file_permissions = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR
autosign_file_path = os.path.join(TMP, 'rootdir', 'autosign_file')


class AutosignGrainsTest(ShellCase):
'''
Test autosigning minions based on grain values.
'''

def setUp(self):
# all read, only owner write
self.autosign_file_permissions = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR
if RUNTIME_VARS.PYTEST_SESSION:
self.autosign_file_path = os.path.join(RUNTIME_VARS.TMP, 'autosign_file')
else:
self.autosign_file_path = os.path.join(RUNTIME_VARS.TMP, 'rootdir', 'autosign_file')
shutil.copyfile(
os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_grains', 'autosign_file'),
autosign_file_path
os.path.join(RUNTIME_VARS.FILES, 'autosign_grains', 'autosign_file'),
self.autosign_file_path
)
os.chmod(autosign_file_path, autosign_file_permissions)
os.chmod(self.autosign_file_path, self.autosign_file_permissions)

self.run_key('-d minion -y')
self.run_call('test.ping -l quiet') # get minon to try to authenticate itself again
Expand All @@ -49,21 +51,24 @@ def setUp(self):

def tearDown(self):
shutil.copyfile(
os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_file'),
autosign_file_path
os.path.join(RUNTIME_VARS.FILES, 'autosign_file'),
self.autosign_file_path
)
os.chmod(autosign_file_path, autosign_file_permissions)
os.chmod(self.autosign_file_path, self.autosign_file_permissions)

self.run_call('test.ping -l quiet') # get minon to authenticate itself again

if os.path.isdir(self.autosign_grains_dir):
shutil.rmtree(self.autosign_grains_dir)
try:
if os.path.isdir(self.autosign_grains_dir):
shutil.rmtree(self.autosign_grains_dir)
except AttributeError:
pass

def test_autosign_grains_accept(self):
grain_file_path = os.path.join(self.autosign_grains_dir, 'test_grain')
with salt.utils.files.fopen(grain_file_path, 'w') as f:
f.write(salt.utils.stringutils.to_str('#invalid_value\ncheese'))
os.chmod(grain_file_path, autosign_file_permissions)
os.chmod(grain_file_path, self.autosign_file_permissions)

self.run_call('test.ping -l quiet') # get minon to try to authenticate itself again
self.assertIn('minion', self.run_key('-l acc'))
Expand All @@ -72,7 +77,7 @@ def test_autosign_grains_fail(self):
grain_file_path = os.path.join(self.autosign_grains_dir, 'test_grain')
with salt.utils.files.fopen(grain_file_path, 'w') as f:
f.write(salt.utils.stringutils.to_str('#cheese\ninvalid_value'))
os.chmod(grain_file_path, autosign_file_permissions)
os.chmod(grain_file_path, self.autosign_file_permissions)

self.run_call('test.ping -l quiet') # get minon to try to authenticate itself again
self.assertNotIn('minion', self.run_key('-l acc'))
Expand Down
133 changes: 70 additions & 63 deletions tests/integration/doc/test_man.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,84 @@
import salt.utils.platform

# Import Salt Testing libs
from tests.support.runtests import RUNTIME_VARS
from tests.support.case import ModuleCase
from tests.support.paths import TMP
from tests.support.unit import skipIf


@skipIf(salt.utils.platform.is_windows(), 'minion is windows')
class ManTest(ModuleCase):
# Map filenames to search strings which should be in the manpage
manpages = {
'salt-cp.1': [
'salt-cp Documentation',
'copies files from the master',
],
'salt-cloud.1': [
'Salt Cloud Command',
'Provision virtual machines in the cloud',
],
'salt-call.1': [
'salt-call Documentation',
'run module functions locally',
],
'salt-api.1': [
'salt-api Command',
'Start interfaces used to remotely connect',
],
'salt-unity.1': [
'salt-unity Command',
'unified invocation wrapper',
],
'salt-syndic.1': [
'salt-syndic Documentation',
'Salt syndic daemon',
],
'salt-ssh.1': [
'salt-ssh Documentation',
'executed using only SSH',
],
'salt-run.1': [
'salt-run Documentation',
'frontend command for executing',
],
'salt-proxy.1': [
'salt-proxy Documentation',
'proxies these commands',
],
'salt-minion.1': [
'salt-minion Documentation',
'Salt minion daemon',
],
'salt-master.1': [
'salt-master Documentation',
'Salt master daemon',
],
'salt-key.1': [
'salt-key Documentation',
'management of Salt server public keys',
],
'salt.1': [
'allows for commands to be executed',
],
'salt.7': [
'Salt Documentation',
],
'spm.1': [
'Salt Package Manager Command',
'command for managing Salt packages',
],
}

@classmethod
def setUpClass(cls):
cls.rootdir = os.path.join(RUNTIME_VARS.TMP, 'mantest')
# Map filenames to search strings which should be in the manpage
cls.manpages = {
'salt-cp.1': [
'salt-cp Documentation',
'copies files from the master',
],
'salt-cloud.1': [
'Salt Cloud Command',
'Provision virtual machines in the cloud',
],
'salt-call.1': [
'salt-call Documentation',
'run module functions locally',
],
'salt-api.1': [
'salt-api Command',
'Start interfaces used to remotely connect',
],
'salt-unity.1': [
'salt-unity Command',
'unified invocation wrapper',
],
'salt-syndic.1': [
'salt-syndic Documentation',
'Salt syndic daemon',
],
'salt-ssh.1': [
'salt-ssh Documentation',
'executed using only SSH',
],
'salt-run.1': [
'salt-run Documentation',
'frontend command for executing',
],
'salt-proxy.1': [
'salt-proxy Documentation',
'proxies these commands',
],
'salt-minion.1': [
'salt-minion Documentation',
'Salt minion daemon',
],
'salt-master.1': [
'salt-master Documentation',
'Salt master daemon',
],
'salt-key.1': [
'salt-key Documentation',
'management of Salt server public keys',
],
'salt.1': [
'allows for commands to be executed',
],
'salt.7': [
'Salt Documentation',
],
'spm.1': [
'Salt Package Manager Command',
'command for managing Salt packages',
],
}

@classmethod
def tearDownClass(cls):
cls.manpages = None

def setUp(self):
self.rootdir = os.path.join(TMP, 'mantest')
self.addCleanup(shutil.rmtree, self.rootdir, ignore_errors=True)
if not os.path.exists(self.rootdir):
ret = self.run_function('mantest.install', [self.rootdir])
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/files/file/base/_modules/mantest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from salt.exceptions import CommandExecutionError

# Import Salt Tesing libs
from tests.support.paths import CODE_DIR
from tests.support.runtests import RUNTIME_VARS

log = logging.getLogger(__name__)

Expand All @@ -26,7 +26,7 @@ def install(rootdir):
return __salt__['cmd.run_all'](
[
sys.executable,
os.path.join(CODE_DIR, 'setup.py'),
os.path.join(RUNTIME_VARS.CODE_DIR, 'setup.py'),
'install', '--root={0}'.format(rootdir)
],
redirect_stderr=True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

# Import Salt libs
import salt.utils.decorators
from tests.support.paths import BASE_FILES
from tests.support.runtests import RUNTIME_VARS

EXIT_CODE_SH = os.path.join(BASE_FILES, 'exit_code.sh')
EXIT_CODE_CMD = os.path.join(BASE_FILES, 'exit_code.cmd')
EXIT_CODE_SH = os.path.join(RUNTIME_VARS.BASE_FILES, 'exit_code.sh')
EXIT_CODE_CMD = os.path.join(RUNTIME_VARS.BASE_FILES, 'exit_code.cmd')


def _exit_code(code):
Expand Down
32 changes: 20 additions & 12 deletions tests/integration/files/file/base/_modules/runtests_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

# Import python libs
from __future__ import absolute_import
import fnmatch
import os
import re
import sys
Expand All @@ -22,26 +21,35 @@
# Import 3rd-party libs
from salt.ext import six

SYS_TMP_DIR = os.path.realpath(
# Avoid ${TMPDIR} and gettempdir() on MacOS as they yield a base path too long
# for unix sockets: ``error: AF_UNIX path too long``
# Gentoo Portage prefers ebuild tests are rooted in ${TMPDIR}
os.environ.get('TMPDIR', tempfile.gettempdir()) if not salt.utils.platform.is_darwin() else '/tmp'
)
# This tempdir path is defined on tests.integration.__init__
TMP = os.path.join(SYS_TMP_DIR, 'salt-tests-tmpdir')
# Import tests libs
try:
from tests.support.runtests import RUNTIME_VARS
except ImportError:
# Salt SSH Tests
SYS_TMP_DIR = os.path.realpath(
# Avoid ${TMPDIR} and gettempdir() on MacOS as they yield a base path too long
# for unix sockets: ``error: AF_UNIX path too long``
# Gentoo Portage prefers ebuild tests are rooted in ${TMPDIR}
os.environ.get('TMPDIR', tempfile.gettempdir()) if not salt.utils.platform.is_darwin() else '/tmp'
)
# This tempdir path is defined on tests.integration.__init__
TMP = os.path.join(SYS_TMP_DIR, 'salt-tests-tmpdir')

class RUNTIME_VARS(object):
TMP = TMP
SYS_TMP_DIR = SYS_TMP_DIR


def get_salt_temp_dir():
return TMP
return RUNTIME_VARS.TMP


def get_salt_temp_dir_for_path(*path):
return os.path.join(TMP, *path)
return os.path.join(RUNTIME_VARS.TMP, *path)


def get_sys_temp_dir_for_path(*path):
return os.path.join(SYS_TMP_DIR, *path)
return os.path.join(RUNTIME_VARS.SYS_TMP_DIR, *path)


def get_invalid_docs():
Expand Down
8 changes: 1 addition & 7 deletions tests/integration/files/file/base/file-pillardefaultget.sls
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{% if grains['kernel'] == 'Windows' %}
{% set TMP = "C:\\Windows\\Temp\\" %}
{% else %}
{% set TMP = "/tmp/" %}
{% endif %}

{% set file = salt['pillar.get']('pillardoesnotexist', 'defaultvalue') %}

create_file:
file.managed:
- name: {{ TMP }}filepillar-{{ file }}
- name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('filepillar-' + file) }}
Loading

0 comments on commit c232896

Please sign in to comment.