Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2018.3' into merge-forward/201…
Browse files Browse the repository at this point in the history
…8.3-to-2019.2

Conflicts:
* tests/unit/modules/test_win_file.py
  • Loading branch information
s0undt3ch committed Apr 25, 2019
2 parents 102deb9 + 9cfc681 commit bc25a89
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 24 deletions.
12 changes: 12 additions & 0 deletions .ci/kitchen-centos7-py2
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
properties([
[
$class: 'ScannerJobProperty', doNotScan: false
],
[
$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false
],
parameters([
booleanParam(defaultValue: false, description: 'Run full test suite', name: 'runFull')
])
])
timeout(time: 8, unit: 'HOURS') {
node('kitchen-slave') {
timestamps {
Expand All @@ -16,6 +27,7 @@ timeout(time: 8, unit: 'HOURS') {
'TEST_SUITE=py2',
'TEST_PLATFORM=centos-7',
'PY_COLORS=1',
"FORCE_FULL=${params.runFull}",
]) {
stage('checkout-scm') {
cleanWs notFailBuild: true
Expand Down
12 changes: 12 additions & 0 deletions .ci/kitchen-centos7-py3
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
properties([
[
$class: 'ScannerJobProperty', doNotScan: false
],
[
$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false
],
parameters([
booleanParam(defaultValue: false, description: 'Run full test suite', name: 'runFull')
])
])
timeout(time: 6, unit: 'HOURS') {
node('kitchen-slave') {
timestamps {
Expand All @@ -16,6 +27,7 @@ timeout(time: 6, unit: 'HOURS') {
'TEST_SUITE=py3',
'TEST_PLATFORM=centos-7',
'PY_COLORS=1',
"FORCE_FULL=${params.runFull}",
]) {
stage('checkout-scm') {
cleanWs notFailBuild: true
Expand Down
12 changes: 12 additions & 0 deletions .ci/kitchen-ubuntu1604-py2
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
properties([
[
$class: 'ScannerJobProperty', doNotScan: false
],
[
$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false
],
parameters([
booleanParam(defaultValue: false, description: 'Run full test suite', name: 'runFull')
])
])
timeout(time: 6, unit: 'HOURS') {
node('kitchen-slave') {
timestamps {
Expand All @@ -16,6 +27,7 @@ timeout(time: 6, unit: 'HOURS') {
'TEST_SUITE=py2',
'TEST_PLATFORM=ubuntu-1604',
'PY_COLORS=1',
"FORCE_FULL=${params.runFull}",
]) {
stage('checkout-scm') {
cleanWs notFailBuild: true
Expand Down
12 changes: 12 additions & 0 deletions .ci/kitchen-ubuntu1604-py3
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
properties([
[
$class: 'ScannerJobProperty', doNotScan: false
],
[
$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false
],
parameters([
booleanParam(defaultValue: false, description: 'Run full test suite', name: 'runFull')
])
])
timeout(time: 6, unit: 'HOURS') {
node('kitchen-slave') {
timestamps {
Expand All @@ -16,6 +27,7 @@ timeout(time: 6, unit: 'HOURS') {
'TEST_SUITE=py3',
'TEST_PLATFORM=ubuntu-1604',
'PY_COLORS=1',
"FORCE_FULL=${params.runFull}",
]) {
stage('checkout-scm') {
cleanWs notFailBuild: true
Expand Down
12 changes: 12 additions & 0 deletions .ci/kitchen-windows2016-py2
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
properties([
[
$class: 'ScannerJobProperty', doNotScan: false
],
[
$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false
],
parameters([
booleanParam(defaultValue: false, description: 'Run full test suite', name: 'runFull')
])
])
timeout(time: 6, unit: 'HOURS') {
node('kitchen-slave') {
timestamps {
Expand All @@ -15,6 +26,7 @@ timeout(time: 6, unit: 'HOURS') {
'TEST_SUITE=py2',
'TEST_PLATFORM=windows-2016',
'PY_COLORS=1',
"FORCE_FULL=${params.runFull}",
]) {
stage('checkout-scm') {
cleanWs notFailBuild: true
Expand Down
12 changes: 12 additions & 0 deletions .ci/kitchen-windows2016-py3
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
properties([
[
$class: 'ScannerJobProperty', doNotScan: false
],
[
$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false
],
parameters([
booleanParam(defaultValue: false, description: 'Run full test suite', name: 'runFull')
])
])
timeout(time: 6, unit: 'HOURS') {
node('kitchen-slave') {
timestamps {
Expand All @@ -15,6 +26,7 @@ timeout(time: 6, unit: 'HOURS') {
'TEST_SUITE=py3',
'TEST_PLATFORM=windows-2016',
'PY_COLORS=1',
"FORCE_FULL=${params.runFull}",
]) {
stage('checkout-scm') {
cleanWs notFailBuild: true
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source 'https://rubygems.org'

# Point this back at the test-kitchen package after 1.23.3 is relased
gem 'test-kitchen', '~>1.23.3'
gem 'kitchen-salt', :git => 'https://github.com/s0undt3ch/kitchen-salt.git', :branch => 'features/nox', :ref => '7a8854f'
gem 'kitchen-salt', :git => 'https://github.com/s0undt3ch/kitchen-salt.git', :branch => 'features/nox'
gem 'kitchen-sync'
gem 'git'

Expand Down
9 changes: 9 additions & 0 deletions salt/grains/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ def _virtual(osdata):
with salt.utils.files.fopen('/proc/1/cgroup', 'r') as fhr:
fhr_contents = fhr.read()
if ':/lxc/' in fhr_contents:
grains['virtual'] = 'container'
grains['virtual_subtype'] = 'LXC'
elif ':/kubepods/' in fhr_contents:
grains['virtual_subtype'] = 'kubernetes'
Expand All @@ -953,6 +954,7 @@ def _virtual(osdata):
if any(x in fhr_contents
for x in (':/system.slice/docker', ':/docker/',
':/docker-ce/')):
grains['virtual'] = 'container'
grains['virtual_subtype'] = 'Docker'
except IOError:
pass
Expand Down Expand Up @@ -1055,6 +1057,11 @@ def _virtual(osdata):
if os.path.isfile('/var/run/xenconsoled.pid'):
grains['virtual_subtype'] = 'Xen Dom0'

# If we have a virtual_subtype, we're virtual, but maybe we couldn't
# figure out what specific virtual type we were?
if grains.get('virtual_subtype') and grains['virtual'] == 'physical':
grains['virtual'] = 'virtual'

for command in failed_commands:
log.info(
"Although '%s' was found in path, the current user "
Expand Down Expand Up @@ -1341,6 +1348,8 @@ def _windows_platform_data():
grains['virtual_subtype'] = 'HVM domU'
elif 'OpenStack' in systeminfo.Model:
grains['virtual'] = 'OpenStack'
elif 'AMAZON' in biosinfo.Version:
grains['virtual'] = 'EC2'

return grains

Expand Down
58 changes: 56 additions & 2 deletions tests/unit/grains/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ def test_bsd_memdata(self):
@skipIf(salt.utils.platform.is_windows(), 'System is Windows')
def test_docker_virtual(self):
'''
Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
Test if virtual grains are parsed correctly in Docker.
'''
with patch.object(os.path, 'isdir', MagicMock(return_value=False)):
with patch.object(os.path,
Expand All @@ -834,10 +834,37 @@ def test_docker_virtual(self):
'Testing Docker cgroup substring \'%s\'', cgroup_substr)
with patch('salt.utils.files.fopen', mock_open(read_data=cgroup_data)):
with patch.dict(core.__salt__, {'cmd.run_all': MagicMock()}):
grains = core._virtual({'kernel': 'Linux'})
self.assertEqual(
core._virtual({'kernel': 'Linux'}).get('virtual_subtype'),
grains.get('virtual_subtype'),
'Docker'
)
self.assertEqual(
grains.get('virtual'),
'container',
)

@skipIf(salt.utils.platform.is_windows(), 'System is Windows')
def test_lxc_virtual(self):
'''
Test if virtual grains are parsed correctly in LXC.
'''
with patch.object(os.path, 'isdir', MagicMock(return_value=False)):
with patch.object(os.path,
'isfile',
MagicMock(side_effect=lambda x: True if x == '/proc/1/cgroup' else False)):
cgroup_data = '10:memory:/lxc/a_long_sha256sum'
with patch('salt.utils.files.fopen', mock_open(read_data=cgroup_data)):
with patch.dict(core.__salt__, {'cmd.run_all': MagicMock()}):
grains = core._virtual({'kernel': 'Linux'})
self.assertEqual(
grains.get('virtual_subtype'),
'LXC'
)
self.assertEqual(
grains.get('virtual'),
'container',
)

@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
def test_xen_virtual(self):
Expand All @@ -854,6 +881,33 @@ def test_xen_virtual(self):
'Xen PV DomU'
)

def test_if_virtual_subtype_exists_virtual_should_fallback_to_virtual(self):
def mockstat(path):
if path == '/':
return 'fnord'
elif path == '/proc/1/root/.':
return 'roscivs'
return None
with patch.dict(
core.__salt__,
{
'cmd.run': MagicMock(return_value=''),
'cmd.run_all': MagicMock(return_value={'retcode': 0, 'stdout': ''}),
}
):
with patch.multiple(
os.path,
isfile=MagicMock(return_value=False),
isdir=MagicMock(side_effect=lambda x: x == '/proc'),
):
with patch.multiple(
os,
stat=MagicMock(side_effect=mockstat),
):
grains = core._virtual({'kernel': 'Linux'})
assert grains.get('virtual_subtype') is not None
assert grains.get('virtual') == 'virtual'

def _check_ipaddress(self, value, ip_v):
'''
check if ip address in a list is valid
Expand Down
43 changes: 22 additions & 21 deletions tests/unit/modules/test_win_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
# Import Salt Libs
import salt.modules.temp as temp
import salt.modules.win_file as win_file
import salt.utils.win_dacl as win_dacl
import salt.utils.platform
import salt.utils.win_dacl
import salt.utils.win_functions
from salt.exceptions import CommandExecutionError


Expand Down Expand Up @@ -101,9 +101,6 @@ def setup_loader_modules(self):
self.current_user = salt.utils.win_functions.get_current_user(False)
return {
win_file: {
'__utils__': {'dacl.check_perms': win_dacl.check_perms}
},
win_dacl: {
'__opts__': {'test': False},
}
}
Expand All @@ -130,7 +127,7 @@ def test_check_perms_set_owner_test_true(self):
'changes': {'owner': 'Administrators'},
'name': self.temp_file.name,
'result': None}
with patch.dict(win_dacl.__opts__, {'test': True}):
with patch.dict(win_file.__opts__, {'test': True}):
ret = win_file.check_perms(path=self.temp_file.name,
owner='Administrators',
inheritance=None)
Expand All @@ -154,10 +151,10 @@ def test_check_perms_deny_test_true(self):
Test setting deny perms on a file with test=True
'''
expected = {'comment': '',
'changes': {'perms': {'Users': {'deny': 'read_execute'}}},
'changes': {'deny_perms': {'Users': {'perms': 'read_execute'}}},
'name': self.temp_file.name,
'result': None}
with patch.dict(win_dacl.__opts__, {'test': True}):
with patch.dict(win_file.__opts__, {'test': True}):
ret = win_file.check_perms(
path=self.temp_file.name,
deny_perms={'Users': {'perms': 'read_execute'}},
Expand All @@ -169,7 +166,8 @@ def test_check_perms_deny(self):
Test setting deny perms on a file
'''
expected = {'comment': '',
'changes': {'perms': {'Users': {'deny': 'read_execute'}}},
'changes': {
'deny_perms': {'Users': {'perms': 'read_execute'}}},
'name': self.temp_file.name,
'result': True}
ret = win_file.check_perms(
Expand All @@ -183,10 +181,10 @@ def test_check_perms_grant_test_true(self):
Test setting grant perms on a file with test=True
'''
expected = {'comment': '',
'changes': {'perms': {'Users': {'grant': 'read_execute'}}},
'changes': {'grant_perms': {'Users': {'perms': 'read_execute'}}},
'name': self.temp_file.name,
'result': None}
with patch.dict(win_dacl.__opts__, {'test': True}):
with patch.dict(win_file.__opts__, {'test': True}):
ret = win_file.check_perms(
path=self.temp_file.name,
grant_perms={'Users': {'perms': 'read_execute'}},
Expand All @@ -198,7 +196,8 @@ def test_check_perms_grant(self):
Test setting grant perms on a file
'''
expected = {'comment': '',
'changes': {'perms': {'Users': {'grant': 'read_execute'}}},
'changes': {
'grant_perms': {'Users': {'perms': 'read_execute'}}},
'name': self.temp_file.name,
'result': True}
ret = win_file.check_perms(
Expand All @@ -215,7 +214,7 @@ def test_check_perms_inheritance_false_test_true(self):
'changes': {'inheritance': False},
'name': self.temp_file.name,
'result': None}
with patch.dict(win_dacl.__opts__, {'test': True}):
with patch.dict(win_file.__opts__, {'test': True}):
ret = win_file.check_perms(path=self.temp_file.name,
inheritance=False)
self.assertDictEqual(expected, ret)
Expand Down Expand Up @@ -258,16 +257,17 @@ def test_check_perms_reset_test_true(self):
permissions='full_control')
expected = {'comment': '',
'changes': {
'perms': {
'Administrators': {'grant': 'full_control'},
'Users': {'grant': 'read_execute'}},
'grant_perms': {
'Administrators': {'perms': 'full_control'},
'Users': {'perms': 'read_execute'}},
'remove_perms': {
'Administrator': {
'grant': {'applies to': 'Not Inherited (file)',
'permissions': 'Full control'}}}},
'inherited': False,
'permissions': ['Full control']}}}},
'name': self.temp_file.name,
'result': None}
with patch.dict(win_dacl.__opts__, {'test': True}):
with patch.dict(win_file.__opts__, {'test': True}):
ret = win_file.check_perms(
path=self.temp_file.name,
grant_perms={'Users': {'perms': 'read_execute'},
Expand All @@ -290,13 +290,14 @@ def test_check_perms_reset(self):
permissions='full_control')
expected = {'comment': '',
'changes': {
'perms': {
'Administrators': {'grant': 'full_control'},
'Users': {'grant': 'read_execute'}},
'grant_perms': {
'Administrators': {'perms': 'full_control'},
'Users': {'perms': 'read_execute'}},
'remove_perms': {
'Administrator': {
'grant': {'applies to': 'Not Inherited (file)',
'permissions': 'Full control'}}}},
'inherited': False,
'permissions': ['Full control']}}}},
'name': self.temp_file.name,
'result': True}
ret = win_file.check_perms(
Expand Down

0 comments on commit bc25a89

Please sign in to comment.