mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add tests for --strip/--strip-components
Also add a test for an unspecified archive_format, as this did not have a test case.
This commit is contained in:
parent
c502e68f12
commit
6442f8a7b5
1 changed files with 81 additions and 18 deletions
|
@ -4,10 +4,11 @@ Tests for the archive state
|
|||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import socket
|
||||
import shutil
|
||||
import threading
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
|
@ -21,15 +22,18 @@ ensure_in_syspath('../../')
|
|||
import integration
|
||||
import salt.utils
|
||||
|
||||
# Setup logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
STATE_DIR = os.path.join(integration.FILES, 'file', 'base')
|
||||
if salt.utils.is_windows():
|
||||
ARCHIVE_DIR = os.path.join("c:/", "tmp")
|
||||
else:
|
||||
ARCHIVE_DIR = '/tmp/archive/'
|
||||
ARCHIVE_DIR = '/tmp/archive'
|
||||
|
||||
PORT = 9999
|
||||
ARCHIVE_TAR_SOURCE = 'http://localhost:{0}/custom.tar.gz'.format(PORT)
|
||||
UNTAR_FILE = ARCHIVE_DIR + 'custom/README'
|
||||
UNTAR_FILE = os.path.join(ARCHIVE_DIR, 'custom/README')
|
||||
ARCHIVE_TAR_HASH = 'md5=7643861ac07c30fe7d2310e9f25ca514'
|
||||
STATE_DIR = os.path.join(integration.FILES, 'file', 'base')
|
||||
if '7' in platform.dist()[1]:
|
||||
|
@ -77,18 +81,26 @@ class ArchiveTest(integration.ModuleCase,
|
|||
tornado.ioloop.IOLoop.instance().stop()
|
||||
cls.server_thread.join()
|
||||
|
||||
def _check_ext_remove(self, dir, file):
|
||||
def setUp(self):
|
||||
self._clear_archive_dir()
|
||||
|
||||
def tearDown(self):
|
||||
self._clear_archive_dir()
|
||||
|
||||
@staticmethod
|
||||
def _clear_archive_dir():
|
||||
try:
|
||||
salt.utils.rm_rf(ARCHIVE_DIR)
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.ENOENT:
|
||||
raise
|
||||
|
||||
def _check_extracted(self, path):
|
||||
'''
|
||||
function to check if file was extracted
|
||||
and remove the directory.
|
||||
'''
|
||||
# check to see if it extracted
|
||||
check_dir = os.path.isfile(file)
|
||||
self.assertTrue(check_dir)
|
||||
|
||||
# wipe away dir. Can't do this in teardown
|
||||
# because it needs to be wiped before each test
|
||||
shutil.rmtree(dir)
|
||||
log.debug('Checking for extracted file: %s', path)
|
||||
self.assertTrue(os.path.isfile(path))
|
||||
|
||||
def test_archive_extracted_skip_verify(self):
|
||||
'''
|
||||
|
@ -97,11 +109,12 @@ class ArchiveTest(integration.ModuleCase,
|
|||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_TAR_SOURCE, archive_format='tar',
|
||||
skip_verify=True)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
self._check_ext_remove(ARCHIVE_DIR, UNTAR_FILE)
|
||||
self._check_extracted(UNTAR_FILE)
|
||||
|
||||
def test_archive_extracted_with_source_hash(self):
|
||||
'''
|
||||
|
@ -112,30 +125,80 @@ class ArchiveTest(integration.ModuleCase,
|
|||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_TAR_SOURCE, archive_format='tar',
|
||||
source_hash=ARCHIVE_TAR_HASH)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
self._check_ext_remove(ARCHIVE_DIR, UNTAR_FILE)
|
||||
self._check_extracted(UNTAR_FILE)
|
||||
|
||||
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
|
||||
def test_archive_extracted_with_root_user_and_group(self):
|
||||
'''
|
||||
test archive.extracted without skip_verify
|
||||
only external resources work to check to
|
||||
ensure source_hash is verified correctly
|
||||
test archive.extracted with user and group set to "root"
|
||||
'''
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_TAR_SOURCE, archive_format='tar',
|
||||
source_hash=ARCHIVE_TAR_HASH,
|
||||
user='root', group='root')
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
self._check_ext_remove(ARCHIVE_DIR, UNTAR_FILE)
|
||||
self._check_extracted(UNTAR_FILE)
|
||||
|
||||
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
|
||||
def test_archive_extracted_with_strip_in_options(self):
|
||||
'''
|
||||
test archive.extracted with --strip in options
|
||||
'''
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_TAR_SOURCE,
|
||||
source_hash=ARCHIVE_TAR_HASH,
|
||||
options='--strip=1',
|
||||
enforce_toplevel=False)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
self._check_extracted(os.path.join(ARCHIVE_DIR, 'README'))
|
||||
|
||||
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
|
||||
def test_archive_extracted_with_strip_components_in_options(self):
|
||||
'''
|
||||
test archive.extracted with --strip-components in options
|
||||
'''
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_TAR_SOURCE,
|
||||
source_hash=ARCHIVE_TAR_HASH,
|
||||
options='--strip-components=1',
|
||||
enforce_toplevel=False)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
self._check_extracted(os.path.join(ARCHIVE_DIR, 'README'))
|
||||
|
||||
def test_archive_extracted_without_archive_format(self):
|
||||
'''
|
||||
test archive.extracted with no archive_format option
|
||||
'''
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_TAR_SOURCE,
|
||||
source_hash=ARCHIVE_TAR_HASH)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
self._check_extracted(UNTAR_FILE)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Reference in a new issue