Merge branch '2019.2.1' into fix_win_service_2019.2.1

This commit is contained in:
Charles McMarrow 2019-07-29 16:14:02 -06:00 committed by GitHub
commit 0e2a2b8a84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 150 deletions

View file

@ -18,6 +18,7 @@ from tests.support.helpers import expensiveTest, generate_random_name
# Import Salt Libs
from salt.config import cloud_providers_config
from salt.ext.six.moves import range
import salt.utils.stringutils
# Create the cloud instance name to be used throughout the tests
@ -107,7 +108,7 @@ class DigitalOceanTest(ShellCase):
# generate key and fingerprint
ssh_key = RSA.generate(4096)
pub = ssh_key.publickey().exportKey("OpenSSH")
pub = salt.utils.stringutils.to_str(ssh_key.publickey().exportKey("OpenSSH"))
key_hex = hashlib.md5(base64.b64decode(pub.strip().split()[1].encode())).hexdigest()
finger_print = ':'.join([key_hex[x:x+2] for x in range(0, len(key_hex), 2)])

View file

@ -7,6 +7,7 @@ import logging
import os
import signal
import subprocess
import time
import textwrap
# Import Salt Testing libs
@ -369,9 +370,15 @@ class WinSystemModuleTest(ModuleCase):
'''
Validate the date/time functions in the win_system module
'''
@classmethod
def setUpClass(cls):
if subprocess.call('net stop w32time', shell=True) != 0:
log.error('Failed to stop w32time service')
@classmethod
def tearDownClass(cls):
if subprocess.call('net start w32time', shell=True) != 0:
log.error('Failed to start w32time service')
if subprocess.call('w32tm /resync', shell=True) != 0:
log.error("Re-syncing time failed")
@ -402,13 +409,29 @@ class WinSystemModuleTest(ModuleCase):
finally:
self.run_function('system.set_computer_desc', [current_desc])
@skipIf(True, 'WAR ROOM 7/29/2019, unit test?')
def test_get_system_time(self):
'''
Test getting the system time
'''
ret = self.run_function('system.get_system_time')
now = datetime.datetime.now()
self.assertEqual(now.strftime("%I:%M"), ret.rsplit(':', 1)[0])
time_now = datetime.datetime.now()
# We have to do some datetime fu to account for the possibility that the
# system time will be obtained just before the minutes increment
ret = self.run_function('system.get_system_time', timeout=300)
# Split out time and AM/PM
sys_time, meridian = ret.split(' ')
h, m, s = sys_time.split(':')
# Get the current time
# Use the system time to generate a datetime object for the system time
# with the same date
time_sys = time_now.replace(hour=int(h), minute=int(m), second=int(s))
# get_system_time returns a non 24 hour time
# Lets make it 24 hour time
if meridian == 'PM':
time_sys = time_sys + datetime.timedelta(hours=12)
diff = time_sys - time_now
# Timeouts are set to 300 seconds. We're adding a 30 second buffer
self.assertTrue(diff.seconds < 330)
@skipIf(True, 'WAR ROOM 7/18/2019, unit test?')
@destructiveTest
@ -421,23 +444,22 @@ class WinSystemModuleTest(ModuleCase):
In order for this test to pass, time sync must be disabled for the
VM in the hypervisor
'''
self.run_function('service.stop', ['w32time'])
test_time = '10:55'
current_time = self.run_function('system.get_system_time')
try:
current_time = datetime.datetime.now().strftime('%H:%M:%S')
test_time = '10:55'
self.run_function('system.set_system_time', [test_time + ' AM'])
get_time = self.run_function('system.get_system_time').rsplit(':', 1)[0]
self.assertEqual(get_time, test_time)
time.sleep(.25)
new_time = datetime.datetime.now().strftime('%H:%M')
self.assertEqual(new_time, test_time)
finally:
self.run_function('system.set_system_time', [current_time])
self.run_function('service.start', ['w32time'])
def test_get_system_date(self):
'''
Test getting system date
'''
ret = self.run_function('system.get_system_date')
date = datetime.datetime.now().date().strftime("%m/%d/%Y")
date = datetime.datetime.now().strftime("%m/%d/%Y")
self.assertEqual(date, ret)
@skipIf(True, 'WAR ROOM 7/18/2019, unit test?')
@ -451,12 +473,12 @@ class WinSystemModuleTest(ModuleCase):
In order for this test to pass, time sync must be disabled for the
VM in the hypervisor
'''
self.run_function('service.stop', ['w32time'])
current_date = self.run_function('system.get_system_date')
try:
# If the test still fails, the hypervisor may be maintaining time
# sync
current_date = datetime.datetime.now().strftime('%Y/%m/%d')
self.run_function('system.set_system_date', ['03/25/2018'])
ret = self.run_function('system.get_system_date')
self.assertEqual(ret, '03/25/2018')
new_date = datetime.datetime.now().strftime('%Y/%m/%d')
self.assertEqual(new_date, '2018/03/25')
finally:
self.run_function('system.set_system_date', [current_date])
self.run_function('service.start', ['w32time'])

View file

@ -9,12 +9,11 @@
# Import python libs
from __future__ import absolute_import
import logging
import os
import sys
import re
import shutil
from datetime import datetime
import logging
import sys
# Import Salt Testing libs
from tests.support.case import ShellCase
@ -151,137 +150,6 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
]
self.assertTrue(True in ['returnTOmaster' in a for a in master_out])
# This test was skipped because it is consistantly failing on centos 7 tcp builds (2019.2.1)
@skipIf(True, 'WAR ROOM TEMPORARY SKIP 7/24/2019')
@skipIf(sys.platform.startswith('win'), 'This test does not apply on Win')
@flaky
def test_issue_2731_masterless(self):
root_dir = os.path.join(TMP, 'issue-2731')
config_dir = os.path.join(root_dir, 'conf')
minion_config_file = os.path.join(config_dir, 'minion')
logfile = os.path.join(root_dir, 'minion_test_issue_2731')
if not os.path.isdir(config_dir):
os.makedirs(config_dir)
with salt.utils.files.fopen(self.get_config_file_path('master')) as fhr:
master_config = salt.utils.yaml.safe_load(fhr)
master_root_dir = master_config['root_dir']
this_minion_key = os.path.join(
master_root_dir, 'pki', 'master', 'minions', 'minion_test_issue_2731'
)
minion_config = {
'id': 'minion_test_issue_2731',
'master': 'localhost',
'master_port': 64506,
'root_dir': master_root_dir,
'pki_dir': 'pki',
'cachedir': 'cachedir',
'sock_dir': 'minion_sock',
'open_mode': True,
'log_file': logfile,
'log_level': 'quiet',
'log_level_logfile': 'info',
'transport': self.master_opts['transport'],
}
try:
# Remove existing logfile
if os.path.isfile(logfile):
os.unlink(logfile)
start = datetime.now()
# Let's first test with a master running
with salt.utils.files.fopen(minion_config_file, 'w') as fh_:
salt.utils.yaml.safe_dump(minion_config, fh_, default_flow_style=False)
ret = self.run_script(
'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format(
config_dir
)
)
try:
self.assertIn('local:', ret)
except AssertionError:
if os.path.isfile(minion_config_file):
os.unlink(minion_config_file)
# Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
raise
# Calculate the required timeout, since next will fail.
# I needed this because after many attempts, I was unable to catch:
# WARNING: Master hostname: salt not found. Retrying in 30 seconds
ellapsed = datetime.now() - start
timeout = ellapsed.seconds + 3
# Now let's remove the master configuration
minion_config.pop('master')
minion_config.pop('master_port')
with salt.utils.files.fopen(minion_config_file, 'w') as fh_:
salt.utils.yaml.safe_dump(minion_config, fh_, default_flow_style=False)
_, timed_out = self.run_script(
'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format(
config_dir
),
timeout=timeout,
catch_timeout=True,
)
try:
self.assertTrue(timed_out)
except AssertionError:
if os.path.isfile(minion_config_file):
os.unlink(minion_config_file)
# Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
raise
# Should work with --local
ret = self.run_script(
'salt-call',
'--config-dir {0} --local cmd.run "echo foo"'.format(
config_dir
),
timeout=60
)
try:
self.assertIn('local:', ret)
except AssertionError:
if os.path.isfile(minion_config_file):
os.unlink(minion_config_file)
# Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
raise
# Should work with local file client
minion_config['file_client'] = 'local'
with salt.utils.files.fopen(minion_config_file, 'w') as fh_:
salt.utils.yaml.safe_dump(minion_config, fh_, default_flow_style=False)
ret = self.run_script(
'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format(
config_dir
),
timeout=60
)
self.assertIn('local:', ret)
finally:
if os.path.isfile(minion_config_file):
os.unlink(minion_config_file)
# Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
@skipIf(salt.utils.platform.is_windows(), 'Skip on Windows')
def test_issue_7754(self):
old_cwd = os.getcwd()