mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #34529 from Ch3LL/add_skip_verify_archive
Add skip_verify for archive.extracted
This commit is contained in:
commit
40081176af
3 changed files with 119 additions and 0 deletions
|
@ -95,6 +95,7 @@ def extracted(name,
|
|||
if_missing=None,
|
||||
keep=False,
|
||||
trim_output=False,
|
||||
skip_verify=False,
|
||||
source_hash_update=None):
|
||||
'''
|
||||
.. versionadded:: 2014.1.0
|
||||
|
@ -174,6 +175,13 @@ def extracted(name,
|
|||
|
||||
.. versionadded:: 2016.3.0
|
||||
|
||||
skip_verify:False
|
||||
If ``True``, hash verification of remote file sources (``http://``,
|
||||
``https://``, ``ftp://``) will be skipped, and the ``source_hash``
|
||||
argument will be ignored.
|
||||
|
||||
.. versionadded:: 2016.3.4
|
||||
|
||||
archive_format
|
||||
``tar``, ``zip`` or ``rar``
|
||||
|
||||
|
@ -324,6 +332,7 @@ def extracted(name,
|
|||
source=source,
|
||||
source_hash=source_hash,
|
||||
makedirs=True,
|
||||
skip_verify=skip_verify,
|
||||
saltenv=__env__)
|
||||
log.debug('file.managed: {0}'.format(file_result))
|
||||
# get value of first key
|
||||
|
|
BIN
tests/integration/files/file/base/custom.tar.gz
Normal file
BIN
tests/integration/files/file/base/custom.tar.gz
Normal file
Binary file not shown.
110
tests/integration/states/archive.py
Normal file
110
tests/integration/states/archive.py
Normal file
|
@ -0,0 +1,110 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Tests for the archive state
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import shutil
|
||||
import threading
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting import TestCase
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import salt libs
|
||||
import integration
|
||||
import salt.utils
|
||||
|
||||
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/'
|
||||
|
||||
PORT = 9999
|
||||
ARCHIVE_TAR_SOURCE = 'http://localhost:{0}/custom.tar.gz'.format(PORT)
|
||||
UNTAR_FILE = ARCHIVE_DIR + 'custom/README'
|
||||
ARCHIVE_TAR_HASH = 'md5=7643861ac07c30fe7d2310e9f25ca514'
|
||||
STATE_DIR = os.path.join(integration.FILES, 'file', 'base')
|
||||
|
||||
|
||||
class SetupWebServer(TestCase):
|
||||
'''
|
||||
Setup and Teardown of Web Server
|
||||
Only need to set this up once not
|
||||
before all tests
|
||||
'''
|
||||
@classmethod
|
||||
def webserver(cls):
|
||||
'''
|
||||
method to start tornado
|
||||
static web app
|
||||
'''
|
||||
application = tornado.web.Application([(r"/(.*)", tornado.web.StaticFileHandler,
|
||||
{"path": STATE_DIR})])
|
||||
application.listen(PORT)
|
||||
tornado.ioloop.IOLoop.instance().start()
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.server_thread = threading.Thread(target=cls.webserver)
|
||||
cls.server_thread.daemon = True
|
||||
cls.server_thread.start()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
tornado.ioloop.IOLoop.instance().stop()
|
||||
cls.server_thread.join()
|
||||
|
||||
|
||||
class ArchiveTest(SetupWebServer,
|
||||
integration.ModuleCase,
|
||||
integration.SaltReturnAssertsMixIn):
|
||||
'''
|
||||
Validate the archive state
|
||||
'''
|
||||
def _check_ext_remove(self, dir, file):
|
||||
'''
|
||||
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)
|
||||
|
||||
def test_archive_extracted_skip_verify(self):
|
||||
'''
|
||||
test archive.extracted with skip_verify
|
||||
'''
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_TAR_SOURCE, archive_format='tar',
|
||||
skip_verify=True)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
self._check_ext_remove(ARCHIVE_DIR, UNTAR_FILE)
|
||||
|
||||
def test_archive_extracted_with_source_hash(self):
|
||||
'''
|
||||
test archive.extracted without skip_verify
|
||||
only external resources work to check to
|
||||
ensure source_hash is verified correctly
|
||||
'''
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_TAR_SOURCE, archive_format='tar',
|
||||
source_hash=ARCHIVE_TAR_HASH)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
self._check_ext_remove(ARCHIVE_DIR, UNTAR_FILE)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(ArchiveTest)
|
Loading…
Add table
Reference in a new issue