Merge branch 'add_metaproxy_2019_2_1' of github.com:garethgreenaway/salt into add_metaproxy_2019_2_1

This commit is contained in:
Gareth J. Greenaway 2019-08-07 13:36:29 -07:00
commit 83534671eb
No known key found for this signature in database
GPG key ID: 10B62F8A7CAD7A41
5 changed files with 59 additions and 153 deletions

View file

@ -5,7 +5,10 @@ Integration tests for DigitalOcean APIv2
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import base64
import hashlib
import os
from Crypto.PublicKey import RSA
# Import Salt Testing Libs
from tests.support.case import ShellCase
@ -14,6 +17,8 @@ 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
@ -99,11 +104,16 @@ class DigitalOceanTest(ShellCase):
'''
Test key management
'''
pub = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example'
finger_print = '3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa'
do_key_name = INSTANCE_NAME + '-key'
# generate key and fingerprint
ssh_key = RSA.generate(4096)
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)])
try:
_key = self.run_cloud('-f create_key {0} name="MyPubKey" public_key="{1}"'.format(PROVIDER_NAME, pub))
_key = self.run_cloud('-f create_key {0} name="{1}" public_key="{2}"'.format(PROVIDER_NAME, do_key_name, pub))
# Upload public key
self.assertIn(
@ -120,8 +130,8 @@ class DigitalOceanTest(ShellCase):
)
# List key
show_keypair = self.run_cloud('-f show_keypair {0} keyname={1}'.format(PROVIDER_NAME, 'MyPubKey'))
show_keypair = self.run_cloud('-f show_keypair {0} keyname={1}'.format(PROVIDER_NAME,
do_key_name))
self.assertIn(
finger_print,
[i.strip() for i in show_keypair]

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,135 +150,6 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
]
self.assertTrue(True in ['returnTOmaster' in a for a in master_out])
@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()

View file

@ -1211,6 +1211,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
self.assertTrue(os.path.exists(good_file))
self.assertFalse(os.path.exists(wrong_file))
@skipIf(salt.utils.platform.is_darwin(), 'WAR ROOM TEMPORARY SKIP, Test is flaky on macosx')
@with_tempdir()
def test_directory_clean_require_with_name(self, name):
'''

View file

@ -653,7 +653,10 @@ class GitPillarHTTPTestBase(GitPillarTestBase, WebserverMixin):
for proc in (cls.case.nginx_proc, cls.case.uwsgi_proc):
if proc is not None:
try:
proc.send_signal(signal.SIGQUIT)
proc.send_signal(signal.SIGTERM)
time.sleep(1)
if proc.is_running():
proc.send_signal(signal.SIGKILL)
except psutil.NoSuchProcess:
pass
shutil.rmtree(cls.root_dir, ignore_errors=True)