Merge branch '2017.7' into bp-43018

This commit is contained in:
Justin Bradfield 2017-08-29 16:50:01 -05:00 committed by GitHub
commit 25419a56db
2 changed files with 29 additions and 16 deletions

View file

@ -2835,7 +2835,8 @@ def _findOptionValueInSeceditFile(option):
_reader = codecs.open(_tfile, 'r', encoding='utf-16')
_secdata = _reader.readlines()
_reader.close()
_ret = __salt__['file.remove'](_tfile)
if __salt__['file.file_exists'](_tfile):
_ret = __salt__['file.remove'](_tfile)
for _line in _secdata:
if _line.startswith(option):
return True, _line.split('=')[1].strip()
@ -2856,16 +2857,20 @@ def _importSeceditConfig(infdata):
_tInfFile = '{0}\\{1}'.format(__salt__['config.get']('cachedir'),
'salt-secedit-config-{0}.inf'.format(_d))
# make sure our temp files don't already exist
_ret = __salt__['file.remove'](_tSdbfile)
_ret = __salt__['file.remove'](_tInfFile)
if __salt__['file.file_exists'](_tSdbfile):
_ret = __salt__['file.remove'](_tSdbfile)
if __salt__['file.file_exists'](_tInfFile):
_ret = __salt__['file.remove'](_tInfFile)
# add the inf data to the file, win_file sure could use the write() function
_ret = __salt__['file.touch'](_tInfFile)
_ret = __salt__['file.append'](_tInfFile, infdata)
# run secedit to make the change
_ret = __salt__['cmd.run']('secedit /configure /db {0} /cfg {1}'.format(_tSdbfile, _tInfFile))
# cleanup our temp files
_ret = __salt__['file.remove'](_tSdbfile)
_ret = __salt__['file.remove'](_tInfFile)
if __salt__['file.file_exists'](_tSdbfile):
_ret = __salt__['file.remove'](_tSdbfile)
if __salt__['file.file_exists'](_tInfFile):
_ret = __salt__['file.remove'](_tInfFile)
return True
except Exception as e:
log.debug('error occurred while trying to import secedit data')
@ -4174,8 +4179,6 @@ def _writeAdminTemplateRegPolFile(admtemplate_data,
existing_data = ''
base_policy_settings = {}
policy_data = _policy_info()
#//{0}:policy[@displayName = "{1}" and (@class = "Both" or @class = "{2}") ]
#policySearchXpath = etree.XPath('//*[@ns1:id = $id or @ns1:name = $id]')
policySearchXpath = '//ns1:*[@id = "{0}" or @name = "{0}"]'
try:
if admx_policy_definitions is None or adml_policy_resources is None:
@ -4206,8 +4209,7 @@ def _writeAdminTemplateRegPolFile(admtemplate_data,
this_valuename = None
if str(base_policy_settings[adm_namespace][admPolicy]).lower() == 'disabled':
log.debug('time to disable {0}'.format(admPolicy))
#this_policy = policySearchXpath(admx_policy_definitions, id=admPolicy, namespaces={'ns1': adm_namespace})
this_policy = admx_policy_definitions.xpath(policySearchXpath.format('ns1', admPolicy), namespaces={'ns1': adm_namespace})
this_policy = admx_policy_definitions.xpath(policySearchXpath.format(admPolicy), namespaces={'ns1': adm_namespace})
if this_policy:
this_policy = this_policy[0]
if 'class' in this_policy.attrib:
@ -4318,7 +4320,6 @@ def _writeAdminTemplateRegPolFile(admtemplate_data,
log.error(msg.format(this_policy.attrib))
else:
log.debug('time to enable and set the policy "{0}"'.format(admPolicy))
#this_policy = policySearchXpath(admx_policy_definitions, id=admPolicy, namespaces={'ns1': adm_namespace})
this_policy = admx_policy_definitions.xpath(policySearchXpath.format(admPolicy), namespaces={'ns1': adm_namespace})
log.debug('found this_policy == {0}'.format(this_policy))
if this_policy:

View file

@ -9,8 +9,12 @@ import os
import shutil
import tempfile
import textwrap
import pwd
import logging
import stat
try:
import pwd
except ImportError:
pass
# Import 3rd-party libs
import yaml
@ -189,7 +193,6 @@ class GitFSTest(TestCase, LoaderModuleMockMixin):
self.integration_base_files = os.path.join(FILES, 'file', 'base')
# Create the dir if it doesn't already exist
try:
shutil.copytree(self.integration_base_files, self.tmp_repo_dir + '/')
except OSError:
@ -203,7 +206,12 @@ class GitFSTest(TestCase, LoaderModuleMockMixin):
if 'USERNAME' not in os.environ:
try:
os.environ['USERNAME'] = pwd.getpwuid(os.geteuid()).pw_name
import salt.utils
if salt.utils.is_windows():
import salt.utils.win_functions
os.environ['USERNAME'] = salt.utils.win_functions.get_current_user()
else:
os.environ['USERNAME'] = pwd.getpwuid(os.geteuid()).pw_name
except AttributeError:
log.error('Unable to get effective username, falling back to '
'\'root\'.')
@ -219,14 +227,18 @@ class GitFSTest(TestCase, LoaderModuleMockMixin):
Remove the temporary git repository and gitfs cache directory to ensure
a clean environment for each test.
'''
shutil.rmtree(self.tmp_repo_dir)
shutil.rmtree(self.tmp_cachedir)
shutil.rmtree(self.tmp_sock_dir)
shutil.rmtree(self.tmp_repo_dir, onerror=self._rmtree_error)
shutil.rmtree(self.tmp_cachedir, onerror=self._rmtree_error)
shutil.rmtree(self.tmp_sock_dir, onerror=self._rmtree_error)
del self.tmp_repo_dir
del self.tmp_cachedir
del self.tmp_sock_dir
del self.integration_base_files
def _rmtree_error(self, func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)
def test_file_list(self):
ret = gitfs.file_list(LOAD)
self.assertIn('testfile', ret)