2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2012-03-28 06:10:13 +00:00
|
|
|
'''
|
|
|
|
Set up the Salt integration test suite
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import, print_function
|
2012-02-20 12:18:13 +00:00
|
|
|
import os
|
2014-02-04 21:07:13 +00:00
|
|
|
import re
|
2012-04-21 23:27:59 +00:00
|
|
|
import sys
|
2014-06-12 23:59:55 +00:00
|
|
|
import copy
|
|
|
|
import json
|
2013-06-29 19:57:23 +00:00
|
|
|
import time
|
2016-05-08 18:39:57 +00:00
|
|
|
import stat
|
2016-05-10 13:05:32 +00:00
|
|
|
import errno
|
2014-10-30 06:45:52 +00:00
|
|
|
import signal
|
2012-03-28 06:10:13 +00:00
|
|
|
import shutil
|
2013-04-25 19:59:34 +00:00
|
|
|
import pprint
|
2014-11-26 00:41:02 +00:00
|
|
|
import atexit
|
2016-05-06 18:49:08 +00:00
|
|
|
import socket
|
2013-04-25 19:59:34 +00:00
|
|
|
import logging
|
2013-06-29 19:57:23 +00:00
|
|
|
import tempfile
|
2016-05-06 18:49:08 +00:00
|
|
|
import threading
|
2013-01-14 12:35:42 +00:00
|
|
|
import subprocess
|
2013-06-29 19:57:23 +00:00
|
|
|
import multiprocessing
|
2012-11-17 17:37:53 +00:00
|
|
|
from datetime import datetime, timedelta
|
2012-06-23 09:47:53 +00:00
|
|
|
try:
|
|
|
|
import pwd
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2017-02-26 14:20:41 +00:00
|
|
|
# Import salt tests support dirs
|
|
|
|
from tests.support.paths import * # pylint: disable=wildcard-import
|
|
|
|
from tests.support.processes import * # pylint: disable=wildcard-import
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase
|
|
|
|
from tests.support.case import ShellTestCase
|
|
|
|
from tests.support.parser import PNUM, print_header, SaltTestcaseParser
|
2017-02-27 15:59:04 +00:00
|
|
|
from tests.support.helpers import requires_sshd_server, RedirectStdStreams
|
2017-04-02 15:21:06 +00:00
|
|
|
from tests.support.paths import ScriptPathMixin
|
|
|
|
from tests.support.mixins import CheckShellBinaryNameAndVersionMixin, ShellCaseCommonTestsMixin
|
|
|
|
from tests.support.mixins import AdaptedConfigurationTestCaseMixin, SaltClientTestCaseMixin
|
|
|
|
from tests.support.mixins import SaltMinionEventAssertsMixin, SaltReturnAssertsMixin
|
|
|
|
from tests.support.runtests import RUNTIME_VARS
|
2012-03-28 06:10:13 +00:00
|
|
|
# Import Salt libs
|
2012-02-20 12:18:13 +00:00
|
|
|
import salt
|
|
|
|
import salt.config
|
|
|
|
import salt.minion
|
2012-05-28 03:00:10 +00:00
|
|
|
import salt.runner
|
2013-02-08 00:35:50 +00:00
|
|
|
import salt.output
|
2013-08-16 01:01:26 +00:00
|
|
|
import salt.version
|
2014-01-11 20:51:32 +00:00
|
|
|
import salt.utils
|
Add warnings to test suite when requisites are not installed
Since we have recently changed the test suite to use new-style
git_pillar, GitPython or Pygit2 is a hard dep for the test suite.
Additionally, when starting up the daemons, if no IPv4 addresses can be
detected (which can happen on docker containers which tend to have
minimal installs) then the suite will time out trying to detect whether
or not the minion/sub-minion has connected, which while it does not
prove fatal for the test suite, it does make the suite take several
minutes to start up and begin running tests. This is because the test
suite invokes the manage.joined runner, which in turn invokes
salt.utils.network.ip_addrs() to get the system's IP addresses to match
against those which are connected. If it can't get the IP addresses,
then the manage.joined runner returns an empty list, and the test suite
believes that no minions have connected, and the function that
periodically runs manage.joined will eventually time out.
This commit adds messages to the console when no suitable gitfs provider
is installed, and when salt.utils.network.ip_addrs() returns an empty
list, to hopefully prompt the user to install the missing requisites.
2017-02-25 22:06:52 +00:00
|
|
|
import salt.utils.network
|
2014-07-08 18:18:24 +00:00
|
|
|
import salt.utils.process
|
2015-08-03 12:20:08 +00:00
|
|
|
import salt.log.setup as salt_log_setup
|
2016-08-31 03:57:06 +00:00
|
|
|
from salt.ext import six
|
2012-03-09 07:47:34 +00:00
|
|
|
from salt.utils.verify import verify_env
|
2014-10-06 18:59:42 +00:00
|
|
|
from salt.utils.immutabletypes import freeze
|
2016-05-10 00:47:09 +00:00
|
|
|
from salt.utils.nb_popen import NonBlockingPopen
|
2015-04-04 22:20:52 +00:00
|
|
|
from salt.exceptions import SaltClientError
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2014-06-27 19:13:41 +00:00
|
|
|
try:
|
|
|
|
import salt.master
|
|
|
|
except ImportError:
|
2014-11-22 10:12:06 +00:00
|
|
|
# Not required for raet tests
|
2014-06-27 19:13:41 +00:00
|
|
|
pass
|
|
|
|
|
2013-08-30 17:24:15 +00:00
|
|
|
# Import 3rd-party libs
|
|
|
|
import yaml
|
2016-05-06 18:49:08 +00:00
|
|
|
import msgpack
|
2014-11-22 10:12:06 +00:00
|
|
|
import salt.ext.six as six
|
2016-09-01 15:20:18 +00:00
|
|
|
from salt.ext.six.moves import cStringIO
|
2016-07-19 17:04:24 +00:00
|
|
|
|
|
|
|
try:
|
2016-07-20 21:34:58 +00:00
|
|
|
import salt.ext.six.moves.socketserver as socketserver
|
2016-07-19 17:04:24 +00:00
|
|
|
except ImportError:
|
|
|
|
import socketserver
|
2016-06-29 20:30:18 +00:00
|
|
|
|
2016-05-06 18:49:08 +00:00
|
|
|
from tornado import gen
|
|
|
|
from tornado import ioloop
|
|
|
|
|
2017-02-26 14:20:41 +00:00
|
|
|
# Import salt tests support libs
|
|
|
|
from tests.support.processes import SaltMaster, SaltMinion, SaltSyndic
|
2016-11-24 13:19:56 +00:00
|
|
|
|
2013-04-25 19:59:34 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2016-05-10 12:19:43 +00:00
|
|
|
_RUNTESTS_PORTS = {}
|
2014-11-26 00:41:02 +00:00
|
|
|
|
2016-05-09 00:27:09 +00:00
|
|
|
|
2016-05-06 18:49:08 +00:00
|
|
|
def get_unused_localhost_port():
|
|
|
|
'''
|
|
|
|
Return a random unused port on localhost
|
|
|
|
'''
|
|
|
|
usock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
|
2016-05-10 12:19:43 +00:00
|
|
|
usock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
2016-05-06 18:49:08 +00:00
|
|
|
usock.bind(('127.0.0.1', 0))
|
|
|
|
port = usock.getsockname()[1]
|
2016-07-07 18:27:48 +00:00
|
|
|
if port in (54505, 54506, 64505, 64506, 64510, 64511, 64520, 64521):
|
2016-05-23 12:54:02 +00:00
|
|
|
# These ports are hardcoded in the test configuration
|
2016-05-23 15:33:29 +00:00
|
|
|
port = get_unused_localhost_port()
|
2016-05-23 12:54:02 +00:00
|
|
|
usock.close()
|
2016-05-23 15:33:29 +00:00
|
|
|
return port
|
2016-05-23 12:54:02 +00:00
|
|
|
|
2016-09-15 21:37:00 +00:00
|
|
|
DARWIN = True if sys.platform.startswith('darwin') else False
|
|
|
|
BSD = True if 'bsd' in sys.platform else False
|
|
|
|
|
|
|
|
if DARWIN and port in _RUNTESTS_PORTS:
|
2016-08-31 19:09:51 +00:00
|
|
|
port = get_unused_localhost_port()
|
|
|
|
usock.close()
|
|
|
|
return port
|
|
|
|
|
2016-05-10 12:19:43 +00:00
|
|
|
_RUNTESTS_PORTS[port] = usock
|
|
|
|
|
2016-09-15 21:37:00 +00:00
|
|
|
if DARWIN or BSD:
|
2016-08-31 19:09:51 +00:00
|
|
|
usock.close()
|
|
|
|
|
2016-05-06 18:49:08 +00:00
|
|
|
return port
|
|
|
|
|
|
|
|
|
2016-05-10 12:19:43 +00:00
|
|
|
def close_open_sockets(sockets_dict):
|
|
|
|
for port in list(sockets_dict):
|
|
|
|
sock = sockets_dict.pop(port)
|
|
|
|
sock.close()
|
|
|
|
|
|
|
|
|
|
|
|
atexit.register(close_open_sockets, _RUNTESTS_PORTS)
|
|
|
|
|
|
|
|
|
2016-05-06 18:49:08 +00:00
|
|
|
SALT_LOG_PORT = get_unused_localhost_port()
|
|
|
|
|
|
|
|
|
|
|
|
class ThreadingMixIn(socketserver.ThreadingMixIn):
|
|
|
|
daemon_threads = True
|
|
|
|
|
|
|
|
|
|
|
|
class ThreadedSocketServer(ThreadingMixIn, socketserver.TCPServer):
|
|
|
|
|
2016-05-10 12:19:43 +00:00
|
|
|
allow_reuse_address = True
|
|
|
|
|
2016-05-06 18:49:08 +00:00
|
|
|
def server_activate(self):
|
|
|
|
self.shutting_down = threading.Event()
|
|
|
|
socketserver.TCPServer.server_activate(self)
|
|
|
|
#super(ThreadedSocketServer, self).server_activate()
|
|
|
|
|
|
|
|
def server_close(self):
|
2016-05-10 12:19:43 +00:00
|
|
|
if hasattr(self, 'shutting_down'):
|
|
|
|
self.shutting_down.set()
|
2016-05-06 18:49:08 +00:00
|
|
|
socketserver.TCPServer.server_close(self)
|
|
|
|
#super(ThreadedSocketServer, self).server_close()
|
|
|
|
|
|
|
|
|
|
|
|
class SocketServerRequestHandler(socketserver.StreamRequestHandler):
|
|
|
|
def handle(self):
|
|
|
|
unpacker = msgpack.Unpacker(encoding='utf-8')
|
|
|
|
while not self.server.shutting_down.is_set():
|
|
|
|
try:
|
|
|
|
wire_bytes = self.request.recv(1024)
|
|
|
|
if not wire_bytes:
|
|
|
|
break
|
|
|
|
unpacker.feed(wire_bytes)
|
|
|
|
for record_dict in unpacker:
|
|
|
|
record = logging.makeLogRecord(record_dict)
|
|
|
|
logger = logging.getLogger(record.name)
|
|
|
|
logger.handle(record)
|
2017-04-07 11:27:37 +00:00
|
|
|
del record_dict
|
2016-05-06 18:49:08 +00:00
|
|
|
except (EOFError, KeyboardInterrupt, SystemExit):
|
|
|
|
break
|
2016-05-12 12:35:19 +00:00
|
|
|
except socket.error as exc:
|
|
|
|
try:
|
2016-05-12 12:38:22 +00:00
|
|
|
if exc.errno == errno.WSAECONNRESET:
|
2016-05-12 12:35:19 +00:00
|
|
|
# Connection reset on windows
|
|
|
|
break
|
|
|
|
except AttributeError:
|
|
|
|
# We're not on windows
|
|
|
|
pass
|
|
|
|
log.exception(exc)
|
2016-05-06 18:49:08 +00:00
|
|
|
except Exception as exc:
|
|
|
|
log.exception(exc)
|
|
|
|
|
|
|
|
|
2012-02-20 12:18:13 +00:00
|
|
|
class TestDaemon(object):
|
|
|
|
'''
|
|
|
|
Set up the master and minion daemons, and run related cases
|
|
|
|
'''
|
2012-12-04 13:02:56 +00:00
|
|
|
MINIONS_CONNECT_TIMEOUT = MINIONS_SYNC_TIMEOUT = 120
|
2012-07-20 06:16:14 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
def __init__(self, parser):
|
|
|
|
self.parser = parser
|
2016-07-12 19:13:57 +00:00
|
|
|
self.colors = salt.utils.get_colors(self.parser.options.no_colors is False)
|
2016-05-20 14:39:40 +00:00
|
|
|
if salt.utils.is_windows():
|
|
|
|
# There's no shell color support on windows...
|
|
|
|
for key in self.colors:
|
|
|
|
self.colors[key] = ''
|
2012-07-20 06:16:14 +00:00
|
|
|
|
2012-02-20 12:18:13 +00:00
|
|
|
def __enter__(self):
|
|
|
|
'''
|
|
|
|
Start a master and minion
|
|
|
|
'''
|
2015-08-03 12:20:08 +00:00
|
|
|
# Setup the multiprocessing logging queue listener
|
2015-12-19 19:31:19 +00:00
|
|
|
salt_log_setup.setup_multiprocessing_logging_listener(
|
2016-05-06 18:49:08 +00:00
|
|
|
self.master_opts
|
2015-12-19 19:31:19 +00:00
|
|
|
)
|
2015-08-03 12:20:08 +00:00
|
|
|
|
2012-07-26 16:14:00 +00:00
|
|
|
# Set up PATH to mockbin
|
|
|
|
self._enter_mockbin()
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2014-06-11 21:34:53 +00:00
|
|
|
if self.parser.options.transport == 'zeromq':
|
|
|
|
self.start_zeromq_daemons()
|
|
|
|
elif self.parser.options.transport == 'raet':
|
|
|
|
self.start_raet_daemons()
|
2015-07-20 22:52:48 +00:00
|
|
|
elif self.parser.options.transport == 'tcp':
|
|
|
|
self.start_tcp_daemons()
|
2012-03-29 04:14:31 +00:00
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
self.minion_targets = set(['minion', 'sub_minion'])
|
|
|
|
self.pre_setup_minions()
|
|
|
|
self.setup_minions()
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2014-06-04 12:43:59 +00:00
|
|
|
if getattr(self.parser.options, 'ssh', False):
|
2014-05-09 21:54:21 +00:00
|
|
|
self.prep_ssh()
|
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
if self.parser.options.sysinfo:
|
2014-01-14 15:16:30 +00:00
|
|
|
try:
|
|
|
|
print_header(
|
|
|
|
'~~~~~~~ Versions Report ', inline=True,
|
|
|
|
width=getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
print_header('~~~~~~~ Versions Report ', inline=True)
|
|
|
|
|
2013-08-16 01:01:26 +00:00
|
|
|
print('\n'.join(salt.version.versions_report()))
|
2012-11-06 18:11:26 +00:00
|
|
|
|
2014-01-14 15:16:30 +00:00
|
|
|
try:
|
|
|
|
print_header(
|
|
|
|
'~~~~~~~ Minion Grains Information ', inline=True,
|
|
|
|
width=getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
print_header('~~~~~~~ Minion Grains Information ', inline=True)
|
|
|
|
|
2013-11-08 19:39:12 +00:00
|
|
|
grains = self.client.cmd('minion', 'grains.items')
|
2013-11-08 19:50:38 +00:00
|
|
|
|
|
|
|
minion_opts = self.minion_opts.copy()
|
|
|
|
minion_opts['color'] = self.parser.options.no_colors is False
|
|
|
|
salt.output.display_output(grains, 'grains', minion_opts)
|
2013-02-08 00:35:50 +00:00
|
|
|
|
2014-01-14 15:16:30 +00:00
|
|
|
try:
|
|
|
|
print_header(
|
|
|
|
'=', sep='=', inline=True,
|
|
|
|
width=getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
print_header('', sep='=', inline=True)
|
2012-11-06 18:11:26 +00:00
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
try:
|
|
|
|
return self
|
|
|
|
finally:
|
|
|
|
self.post_setup_minions()
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2015-01-13 16:28:41 +00:00
|
|
|
def start_daemon(self, cls, opts, start_fun):
|
|
|
|
def start(cls, opts, start_fun):
|
2015-10-28 18:06:15 +00:00
|
|
|
salt.utils.appendproctitle('{0}-{1}'.format(self.__class__.__name__, cls.__name__))
|
2015-01-13 16:28:41 +00:00
|
|
|
daemon = cls(opts)
|
|
|
|
getattr(daemon, start_fun)()
|
|
|
|
process = multiprocessing.Process(target=start,
|
|
|
|
args=(cls, opts, start_fun))
|
|
|
|
process.start()
|
|
|
|
return process
|
|
|
|
|
2014-06-11 21:34:53 +00:00
|
|
|
def start_zeromq_daemons(self):
|
|
|
|
'''
|
|
|
|
Fire up the daemons used for zeromq tests
|
|
|
|
'''
|
Add warnings to test suite when requisites are not installed
Since we have recently changed the test suite to use new-style
git_pillar, GitPython or Pygit2 is a hard dep for the test suite.
Additionally, when starting up the daemons, if no IPv4 addresses can be
detected (which can happen on docker containers which tend to have
minimal installs) then the suite will time out trying to detect whether
or not the minion/sub-minion has connected, which while it does not
prove fatal for the test suite, it does make the suite take several
minutes to start up and begin running tests. This is because the test
suite invokes the manage.joined runner, which in turn invokes
salt.utils.network.ip_addrs() to get the system's IP addresses to match
against those which are connected. If it can't get the IP addresses,
then the manage.joined runner returns an empty list, and the test suite
believes that no minions have connected, and the function that
periodically runs manage.joined will eventually time out.
This commit adds messages to the console when no suitable gitfs provider
is installed, and when salt.utils.network.ip_addrs() returns an empty
list, to hopefully prompt the user to install the missing requisites.
2017-02-25 22:06:52 +00:00
|
|
|
if not salt.utils.network.ip_addrs():
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_RED}Unable to list IPv4 addresses. Test suite startup will be\n'
|
|
|
|
' slower. Install iproute/ifconfig to fix this.{ENDC}\n'.format(
|
|
|
|
**self.colors
|
|
|
|
)
|
|
|
|
)
|
2016-05-23 12:54:02 +00:00
|
|
|
self.log_server = ThreadedSocketServer(('localhost', SALT_LOG_PORT), SocketServerRequestHandler)
|
|
|
|
self.log_server_process = threading.Thread(target=self.log_server.serve_forever)
|
|
|
|
self.log_server_process.daemon = True
|
|
|
|
self.log_server_process.start()
|
2017-02-26 14:20:41 +00:00
|
|
|
try:
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_YELLOW}Starting salt-master ... {ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
self.master_process = start_daemon(
|
|
|
|
daemon_name='salt-master',
|
|
|
|
daemon_id=self.master_opts['id'],
|
|
|
|
daemon_log_prefix='salt-master/{}'.format(self.master_opts['id']),
|
|
|
|
daemon_cli_script_name='master',
|
|
|
|
daemon_config=self.master_opts,
|
2017-04-02 15:56:17 +00:00
|
|
|
daemon_config_dir=RUNTIME_VARS.TMP_CONF_DIR,
|
2017-02-26 14:20:41 +00:00
|
|
|
daemon_class=SaltMaster,
|
|
|
|
bin_dir_path=SCRIPT_DIR,
|
|
|
|
fail_hard=True,
|
|
|
|
start_timeout=30)
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_GREEN}Starting salt-master ... STARTED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
except (RuntimeWarning, RuntimeError):
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_RED}Starting salt-master ... FAILED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
2016-05-06 18:49:08 +00:00
|
|
|
|
2017-02-26 14:20:41 +00:00
|
|
|
try:
|
2016-05-06 23:30:07 +00:00
|
|
|
sys.stdout.write(
|
2017-02-26 14:20:41 +00:00
|
|
|
' * {LIGHT_YELLOW}Starting salt-minion ... {ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
self.minion_process = start_daemon(
|
|
|
|
daemon_name='salt-minion',
|
|
|
|
daemon_id=self.master_opts['id'],
|
|
|
|
daemon_log_prefix='salt-minion/{}'.format(self.minion_opts['id']),
|
|
|
|
daemon_cli_script_name='minion',
|
|
|
|
daemon_config=self.minion_opts,
|
2017-04-02 15:56:17 +00:00
|
|
|
daemon_config_dir=RUNTIME_VARS.TMP_CONF_DIR,
|
2017-02-26 14:20:41 +00:00
|
|
|
daemon_class=SaltMinion,
|
|
|
|
bin_dir_path=SCRIPT_DIR,
|
|
|
|
fail_hard=True,
|
|
|
|
start_timeout=30)
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
2016-05-06 23:30:07 +00:00
|
|
|
)
|
|
|
|
)
|
2017-02-26 14:20:41 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_GREEN}Starting salt-minion ... STARTED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
2016-05-06 23:30:07 +00:00
|
|
|
sys.stdout.flush()
|
2017-02-26 14:20:41 +00:00
|
|
|
except (RuntimeWarning, RuntimeError):
|
2016-05-06 23:30:07 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.write(
|
2017-02-26 14:20:41 +00:00
|
|
|
' * {LIGHT_RED}Starting salt-minion ... FAILED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
try:
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_YELLOW}Starting sub salt-minion ... {ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
self.sub_minion_process = start_daemon(
|
|
|
|
daemon_name='sub salt-minion',
|
|
|
|
daemon_id=self.master_opts['id'],
|
|
|
|
daemon_log_prefix='sub-salt-minion/{}'.format(self.sub_minion_opts['id']),
|
|
|
|
daemon_cli_script_name='minion',
|
|
|
|
daemon_config=self.sub_minion_opts,
|
2017-04-02 15:56:17 +00:00
|
|
|
daemon_config_dir=RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR,
|
2017-02-26 14:20:41 +00:00
|
|
|
daemon_class=SaltMinion,
|
|
|
|
bin_dir_path=SCRIPT_DIR,
|
|
|
|
fail_hard=True,
|
|
|
|
start_timeout=30)
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_GREEN}Starting sub salt-minion ... STARTED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
except (RuntimeWarning, RuntimeError):
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
2016-05-06 23:30:07 +00:00
|
|
|
)
|
|
|
|
)
|
2017-02-26 14:20:41 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_RED}Starting sub salt-minion ... FAILED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
try:
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_YELLOW}Starting syndic salt-master ... {ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
self.smaster_process = start_daemon(
|
|
|
|
daemon_name='salt-smaster',
|
|
|
|
daemon_id=self.syndic_master_opts['id'],
|
|
|
|
daemon_log_prefix='salt-smaster/{}'.format(self.syndic_master_opts['id']),
|
|
|
|
daemon_cli_script_name='master',
|
|
|
|
daemon_config=self.syndic_master_opts,
|
2017-04-02 15:56:17 +00:00
|
|
|
daemon_config_dir=RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR,
|
2017-02-26 14:20:41 +00:00
|
|
|
daemon_class=SaltMaster,
|
|
|
|
bin_dir_path=SCRIPT_DIR,
|
|
|
|
fail_hard=True,
|
|
|
|
start_timeout=30)
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_GREEN}Starting syndic salt-master ... STARTED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
except (RuntimeWarning, RuntimeError):
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_RED}Starting syndic salt-master ... FAILED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
try:
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_YELLOW}Starting salt-syndic ... {ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
self.syndic_process = start_daemon(
|
|
|
|
daemon_name='salt-syndic',
|
|
|
|
daemon_id=self.syndic_opts['id'],
|
|
|
|
daemon_log_prefix='salt-syndic/{}'.format(self.syndic_opts['id']),
|
|
|
|
daemon_cli_script_name='syndic',
|
|
|
|
daemon_config=self.syndic_opts,
|
2017-04-02 15:56:17 +00:00
|
|
|
daemon_config_dir=RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR,
|
2017-02-26 14:20:41 +00:00
|
|
|
daemon_class=SaltSyndic,
|
|
|
|
bin_dir_path=SCRIPT_DIR,
|
|
|
|
fail_hard=True,
|
|
|
|
start_timeout=30)
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_GREEN}Starting salt-syndic ... STARTED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
|
|
|
except (RuntimeWarning, RuntimeError):
|
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.write(
|
|
|
|
' * {LIGHT_RED}Starting salt-syndic ... FAILED!\n{ENDC}'.format(**self.colors)
|
|
|
|
)
|
2016-05-06 23:30:07 +00:00
|
|
|
sys.stdout.flush()
|
2014-06-11 21:34:53 +00:00
|
|
|
|
|
|
|
def start_raet_daemons(self):
|
|
|
|
'''
|
|
|
|
Fire up the raet daemons!
|
|
|
|
'''
|
|
|
|
import salt.daemons.flo
|
2015-01-13 16:28:41 +00:00
|
|
|
self.master_process = self.start_daemon(salt.daemons.flo.IofloMaster,
|
|
|
|
self.master_opts,
|
|
|
|
'start')
|
2014-06-11 21:34:53 +00:00
|
|
|
|
2015-01-13 16:28:41 +00:00
|
|
|
self.minion_process = self.start_daemon(salt.daemons.flo.IofloMinion,
|
|
|
|
self.minion_opts,
|
|
|
|
'tune_in')
|
2014-06-11 21:34:53 +00:00
|
|
|
|
2015-01-13 16:28:41 +00:00
|
|
|
self.sub_minion_process = self.start_daemon(salt.daemons.flo.IofloMinion,
|
|
|
|
self.sub_minion_opts,
|
|
|
|
'tune_in')
|
2014-06-11 21:34:53 +00:00
|
|
|
# Wait for the daemons to all spin up
|
|
|
|
time.sleep(5)
|
|
|
|
|
2015-04-27 16:28:53 +00:00
|
|
|
# self.smaster_process = self.start_daemon(salt.daemons.flo.IofloMaster,
|
2015-01-13 16:29:33 +00:00
|
|
|
# self.syndic_master_opts,
|
|
|
|
# 'start')
|
2014-06-11 21:34:53 +00:00
|
|
|
|
|
|
|
# no raet syndic daemon yet
|
|
|
|
|
2015-07-20 22:52:48 +00:00
|
|
|
start_tcp_daemons = start_zeromq_daemons
|
|
|
|
|
2014-05-09 22:00:36 +00:00
|
|
|
def prep_ssh(self):
|
2014-05-09 21:54:21 +00:00
|
|
|
'''
|
|
|
|
Generate keys and start an ssh daemon on an alternate port
|
|
|
|
'''
|
2016-08-31 12:34:38 +00:00
|
|
|
sys.stdout.write(
|
2016-08-31 12:41:05 +00:00
|
|
|
' * {LIGHT_GREEN}Starting {0} ... {ENDC}'.format(
|
2016-08-31 12:34:38 +00:00
|
|
|
'SSH server',
|
|
|
|
**self.colors
|
|
|
|
)
|
|
|
|
)
|
2014-05-09 21:54:21 +00:00
|
|
|
keygen = salt.utils.which('ssh-keygen')
|
|
|
|
sshd = salt.utils.which('sshd')
|
|
|
|
|
|
|
|
if not (keygen and sshd):
|
|
|
|
print('WARNING: Could not initialize SSH subsystem. Tests for salt-ssh may break!')
|
|
|
|
return
|
2017-04-02 15:56:17 +00:00
|
|
|
if not os.path.exists(RUNTIME_VARS.TMP_CONF_DIR):
|
|
|
|
os.makedirs(RUNTIME_VARS.TMP_CONF_DIR)
|
2014-05-09 22:00:36 +00:00
|
|
|
|
2014-05-23 20:10:08 +00:00
|
|
|
# Generate client key
|
2017-04-02 15:56:17 +00:00
|
|
|
pub_key_test_file = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'key_test.pub')
|
|
|
|
priv_key_test_file = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'key_test')
|
2014-05-12 22:38:16 +00:00
|
|
|
if os.path.exists(pub_key_test_file):
|
|
|
|
os.remove(pub_key_test_file)
|
|
|
|
if os.path.exists(priv_key_test_file):
|
|
|
|
os.remove(priv_key_test_file)
|
2014-05-09 21:54:21 +00:00
|
|
|
keygen_process = subprocess.Popen(
|
2014-05-12 22:38:16 +00:00
|
|
|
[keygen, '-t',
|
|
|
|
'ecdsa',
|
|
|
|
'-b',
|
|
|
|
'521',
|
|
|
|
'-C',
|
|
|
|
'"$(whoami)@$(hostname)-$(date -I)"',
|
|
|
|
'-f',
|
2014-05-23 20:10:08 +00:00
|
|
|
'key_test',
|
|
|
|
'-P',
|
2014-05-12 22:38:16 +00:00
|
|
|
''],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
close_fds=True,
|
2017-04-02 15:56:17 +00:00
|
|
|
cwd=RUNTIME_VARS.TMP_CONF_DIR
|
2014-05-09 21:54:21 +00:00
|
|
|
)
|
2014-05-12 22:38:16 +00:00
|
|
|
_, keygen_err = keygen_process.communicate()
|
|
|
|
if keygen_err:
|
2015-06-06 13:47:52 +00:00
|
|
|
print('ssh-keygen had errors: {0}'.format(salt.utils.to_str(keygen_err)))
|
2014-05-12 22:38:16 +00:00
|
|
|
sshd_config_path = os.path.join(FILES, 'conf/_ssh/sshd_config')
|
2017-04-02 15:56:17 +00:00
|
|
|
shutil.copy(sshd_config_path, RUNTIME_VARS.TMP_CONF_DIR)
|
|
|
|
auth_key_file = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'key_test.pub')
|
2014-05-23 20:10:08 +00:00
|
|
|
|
|
|
|
# Generate server key
|
2017-04-02 15:56:17 +00:00
|
|
|
server_key_dir = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'server')
|
2014-05-23 20:10:08 +00:00
|
|
|
if not os.path.exists(server_key_dir):
|
|
|
|
os.makedirs(server_key_dir)
|
|
|
|
server_dsa_priv_key_file = os.path.join(server_key_dir, 'ssh_host_dsa_key')
|
|
|
|
server_dsa_pub_key_file = os.path.join(server_key_dir, 'ssh_host_dsa_key.pub')
|
|
|
|
server_ecdsa_priv_key_file = os.path.join(server_key_dir, 'ssh_host_ecdsa_key')
|
|
|
|
server_ecdsa_pub_key_file = os.path.join(server_key_dir, 'ssh_host_ecdsa_key.pub')
|
|
|
|
server_ed25519_priv_key_file = os.path.join(server_key_dir, 'ssh_host_ed25519_key')
|
|
|
|
server_ed25519_pub_key_file = os.path.join(server_key_dir, 'ssh_host.ed25519_key.pub')
|
|
|
|
|
|
|
|
for server_key_file in (server_dsa_priv_key_file,
|
|
|
|
server_dsa_pub_key_file,
|
|
|
|
server_ecdsa_priv_key_file,
|
|
|
|
server_ecdsa_pub_key_file,
|
|
|
|
server_ed25519_priv_key_file,
|
|
|
|
server_ed25519_pub_key_file):
|
|
|
|
if os.path.exists(server_key_file):
|
|
|
|
os.remove(server_key_file)
|
|
|
|
|
|
|
|
keygen_process_dsa = subprocess.Popen(
|
|
|
|
[keygen, '-t',
|
|
|
|
'dsa',
|
|
|
|
'-b',
|
|
|
|
'1024',
|
|
|
|
'-C',
|
|
|
|
'"$(whoami)@$(hostname)-$(date -I)"',
|
|
|
|
'-f',
|
|
|
|
'ssh_host_dsa_key',
|
|
|
|
'-P',
|
|
|
|
''],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
close_fds=True,
|
|
|
|
cwd=server_key_dir
|
|
|
|
)
|
|
|
|
_, keygen_dsa_err = keygen_process_dsa.communicate()
|
|
|
|
if keygen_dsa_err:
|
2015-06-06 13:47:52 +00:00
|
|
|
print('ssh-keygen had errors: {0}'.format(salt.utils.to_str(keygen_dsa_err)))
|
2014-05-23 20:10:08 +00:00
|
|
|
|
|
|
|
keygen_process_ecdsa = subprocess.Popen(
|
|
|
|
[keygen, '-t',
|
|
|
|
'ecdsa',
|
|
|
|
'-b',
|
|
|
|
'521',
|
|
|
|
'-C',
|
|
|
|
'"$(whoami)@$(hostname)-$(date -I)"',
|
|
|
|
'-f',
|
|
|
|
'ssh_host_ecdsa_key',
|
|
|
|
'-P',
|
|
|
|
''],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
close_fds=True,
|
|
|
|
cwd=server_key_dir
|
|
|
|
)
|
|
|
|
_, keygen_escda_err = keygen_process_ecdsa.communicate()
|
|
|
|
if keygen_escda_err:
|
2015-06-06 13:47:52 +00:00
|
|
|
print('ssh-keygen had errors: {0}'.format(salt.utils.to_str(keygen_escda_err)))
|
2014-05-23 20:10:08 +00:00
|
|
|
|
|
|
|
keygen_process_ed25519 = subprocess.Popen(
|
|
|
|
[keygen, '-t',
|
|
|
|
'ed25519',
|
|
|
|
'-b',
|
|
|
|
'521',
|
|
|
|
'-C',
|
|
|
|
'"$(whoami)@$(hostname)-$(date -I)"',
|
|
|
|
'-f',
|
|
|
|
'ssh_host_ed25519_key',
|
|
|
|
'-P',
|
|
|
|
''],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
close_fds=True,
|
|
|
|
cwd=server_key_dir
|
|
|
|
)
|
|
|
|
_, keygen_ed25519_err = keygen_process_ed25519.communicate()
|
|
|
|
if keygen_ed25519_err:
|
2015-06-06 13:47:52 +00:00
|
|
|
print('ssh-keygen had errors: {0}'.format(salt.utils.to_str(keygen_ed25519_err)))
|
2014-05-23 20:10:08 +00:00
|
|
|
|
2017-04-02 15:56:17 +00:00
|
|
|
with salt.utils.fopen(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'sshd_config'), 'a') as ssh_config:
|
2014-05-09 21:54:21 +00:00
|
|
|
ssh_config.write('AuthorizedKeysFile {0}\n'.format(auth_key_file))
|
2015-02-04 23:16:41 +00:00
|
|
|
if not keygen_dsa_err:
|
|
|
|
ssh_config.write('HostKey {0}\n'.format(server_dsa_priv_key_file))
|
|
|
|
if not keygen_escda_err:
|
|
|
|
ssh_config.write('HostKey {0}\n'.format(server_ecdsa_priv_key_file))
|
|
|
|
if not keygen_ed25519_err:
|
|
|
|
ssh_config.write('HostKey {0}\n'.format(server_ed25519_priv_key_file))
|
2014-10-30 06:45:52 +00:00
|
|
|
|
2017-04-02 15:56:17 +00:00
|
|
|
self.sshd_pidfile = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'sshd.pid')
|
2014-05-12 22:38:16 +00:00
|
|
|
self.sshd_process = subprocess.Popen(
|
2014-10-30 06:45:52 +00:00
|
|
|
[sshd, '-f', 'sshd_config', '-oPidFile={0}'.format(self.sshd_pidfile)],
|
2014-05-12 22:38:16 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
close_fds=True,
|
2017-04-02 15:56:17 +00:00
|
|
|
cwd=RUNTIME_VARS.TMP_CONF_DIR
|
2014-05-09 21:54:21 +00:00
|
|
|
)
|
2014-05-12 22:38:16 +00:00
|
|
|
_, sshd_err = self.sshd_process.communicate()
|
|
|
|
if sshd_err:
|
2015-06-06 13:47:52 +00:00
|
|
|
print('sshd had errors on startup: {0}'.format(salt.utils.to_str(sshd_err)))
|
2014-12-13 00:11:41 +00:00
|
|
|
else:
|
|
|
|
os.environ['SSH_DAEMON_RUNNING'] = 'True'
|
2014-05-12 22:38:16 +00:00
|
|
|
roster_path = os.path.join(FILES, 'conf/_ssh/roster')
|
2017-04-02 15:56:17 +00:00
|
|
|
shutil.copy(roster_path, RUNTIME_VARS.TMP_CONF_DIR)
|
|
|
|
with salt.utils.fopen(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'roster'), 'a') as roster:
|
2017-04-02 15:21:06 +00:00
|
|
|
roster.write(' user: {0}\n'.format(RUNTIME_VARS.RUNNING_TESTS_USER))
|
2017-04-02 15:56:17 +00:00
|
|
|
roster.write(' priv: {0}/{1}'.format(RUNTIME_VARS.TMP_CONF_DIR, 'key_test'))
|
2016-08-31 12:41:05 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
' {LIGHT_GREEN}STARTED!\n{ENDC}'.format(
|
|
|
|
**self.colors
|
|
|
|
)
|
|
|
|
)
|
2014-05-09 21:54:21 +00:00
|
|
|
|
2015-03-13 22:15:23 +00:00
|
|
|
@classmethod
|
|
|
|
def config(cls, role):
|
|
|
|
'''
|
|
|
|
Return a configuration for a master/minion/syndic.
|
|
|
|
|
|
|
|
Currently these roles are:
|
|
|
|
* master
|
|
|
|
* minion
|
|
|
|
* syndic
|
|
|
|
* syndic_master
|
|
|
|
* sub_minion
|
|
|
|
'''
|
2017-04-02 15:56:17 +00:00
|
|
|
return RUNTIME_VARS.RUNTIME_CONFIGS[role]
|
2015-03-13 22:15:23 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def config_location(cls):
|
2017-04-02 15:56:17 +00:00
|
|
|
return RUNTIME_VARS.TMP_CONF_DIR
|
2015-03-13 22:15:23 +00:00
|
|
|
|
2013-01-11 16:21:04 +00:00
|
|
|
@property
|
|
|
|
def client(self):
|
|
|
|
'''
|
|
|
|
Return a local client which will be used for example to ping and sync
|
|
|
|
the test minions.
|
|
|
|
|
2014-04-30 19:06:27 +00:00
|
|
|
This client is defined as a class attribute because its creation needs
|
2013-01-11 16:21:04 +00:00
|
|
|
to be deferred to a latter stage. If created it on `__enter__` like it
|
|
|
|
previously was, it would not receive the master events.
|
|
|
|
'''
|
2017-04-02 15:56:17 +00:00
|
|
|
if 'runtime_client' not in RUNTIME_VARS.RUNTIME_CONFIGS:
|
|
|
|
RUNTIME_VARS.RUNTIME_CONFIGS['runtime_client'] = salt.client.get_local_client(
|
2014-10-07 13:02:25 +00:00
|
|
|
mopts=self.master_opts
|
|
|
|
)
|
2017-04-02 15:56:17 +00:00
|
|
|
return RUNTIME_VARS.RUNTIME_CONFIGS['runtime_client']
|
2013-01-11 16:21:04 +00:00
|
|
|
|
2014-06-12 23:59:55 +00:00
|
|
|
@classmethod
|
|
|
|
def transplant_configs(cls, transport='zeromq'):
|
2017-04-02 15:56:17 +00:00
|
|
|
if os.path.isdir(RUNTIME_VARS.TMP_CONF_DIR):
|
|
|
|
shutil.rmtree(RUNTIME_VARS.TMP_CONF_DIR)
|
|
|
|
os.makedirs(RUNTIME_VARS.TMP_CONF_DIR)
|
|
|
|
os.makedirs(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR)
|
|
|
|
os.makedirs(RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR)
|
|
|
|
os.makedirs(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR)
|
|
|
|
print(' * Transplanting configuration files to \'{0}\''.format(RUNTIME_VARS.TMP_CONF_DIR))
|
|
|
|
tests_known_hosts_file = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'salt_ssh_known_hosts')
|
2016-05-09 17:57:13 +00:00
|
|
|
with salt.utils.fopen(tests_known_hosts_file, 'w') as known_hosts:
|
2014-10-30 06:45:52 +00:00
|
|
|
known_hosts.write('')
|
2016-06-22 23:56:50 +00:00
|
|
|
|
2016-07-08 22:14:48 +00:00
|
|
|
# This master connects to syndic_master via a syndic
|
2017-04-02 15:56:17 +00:00
|
|
|
master_opts = salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'master'))
|
2016-05-09 17:57:13 +00:00
|
|
|
master_opts['known_hosts_file'] = tests_known_hosts_file
|
2016-06-28 16:08:45 +00:00
|
|
|
master_opts['cachedir'] = os.path.join(TMP, 'rootdir', 'cache')
|
2017-04-02 15:21:06 +00:00
|
|
|
master_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
|
2017-04-02 15:56:17 +00:00
|
|
|
master_opts['config_dir'] = RUNTIME_VARS.TMP_CONF_DIR
|
2016-07-07 18:27:48 +00:00
|
|
|
master_opts['root_dir'] = os.path.join(TMP, 'rootdir')
|
|
|
|
master_opts['pki_dir'] = os.path.join(TMP, 'rootdir', 'pki', 'master')
|
2014-06-12 23:59:55 +00:00
|
|
|
|
2016-07-08 22:14:48 +00:00
|
|
|
# This is the syndic for master
|
|
|
|
# Let's start with a copy of the syndic master configuration
|
|
|
|
syndic_opts = copy.deepcopy(master_opts)
|
|
|
|
# Let's update with the syndic configuration
|
2017-04-02 15:56:17 +00:00
|
|
|
syndic_opts.update(salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'syndic')))
|
2016-07-08 22:14:48 +00:00
|
|
|
syndic_opts['cachedir'] = os.path.join(TMP, 'rootdir', 'cache')
|
2017-04-02 15:56:17 +00:00
|
|
|
syndic_opts['config_dir'] = RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR
|
2016-07-08 22:14:48 +00:00
|
|
|
|
|
|
|
# This minion connects to master
|
2017-04-02 15:56:17 +00:00
|
|
|
minion_opts = salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'minion'))
|
2016-07-08 21:59:08 +00:00
|
|
|
minion_opts['cachedir'] = os.path.join(TMP, 'rootdir', 'cache')
|
2017-04-02 15:21:06 +00:00
|
|
|
minion_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
|
2017-04-02 15:56:17 +00:00
|
|
|
minion_opts['config_dir'] = RUNTIME_VARS.TMP_CONF_DIR
|
2016-07-07 18:27:48 +00:00
|
|
|
minion_opts['root_dir'] = os.path.join(TMP, 'rootdir')
|
2016-07-20 15:44:23 +00:00
|
|
|
minion_opts['pki_dir'] = os.path.join(TMP, 'rootdir', 'pki')
|
2016-07-26 22:00:07 +00:00
|
|
|
minion_opts['hosts.file'] = os.path.join(TMP, 'rootdir', 'hosts')
|
|
|
|
minion_opts['aliases.file'] = os.path.join(TMP, 'rootdir', 'aliases')
|
2014-06-12 23:59:55 +00:00
|
|
|
|
2016-07-08 22:14:48 +00:00
|
|
|
# This sub_minion also connects to master
|
2017-04-02 15:56:17 +00:00
|
|
|
sub_minion_opts = salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'sub_minion'))
|
2016-07-08 21:59:08 +00:00
|
|
|
sub_minion_opts['cachedir'] = os.path.join(TMP, 'rootdir-sub-minion', 'cache')
|
2017-04-02 15:21:06 +00:00
|
|
|
sub_minion_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
|
2017-04-02 15:56:17 +00:00
|
|
|
sub_minion_opts['config_dir'] = RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR
|
2016-05-20 13:45:09 +00:00
|
|
|
sub_minion_opts['root_dir'] = os.path.join(TMP, 'rootdir-sub-minion')
|
2016-07-07 18:27:48 +00:00
|
|
|
sub_minion_opts['pki_dir'] = os.path.join(TMP, 'rootdir-sub-minion', 'pki', 'minion')
|
2016-07-26 22:00:07 +00:00
|
|
|
sub_minion_opts['hosts.file'] = os.path.join(TMP, 'rootdir', 'hosts')
|
|
|
|
sub_minion_opts['aliases.file'] = os.path.join(TMP, 'rootdir', 'aliases')
|
2014-06-12 23:59:55 +00:00
|
|
|
|
2016-07-08 22:14:48 +00:00
|
|
|
# This is the master of masters
|
2017-04-02 15:56:17 +00:00
|
|
|
syndic_master_opts = salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'syndic_master'))
|
2016-07-07 18:27:48 +00:00
|
|
|
syndic_master_opts['cachedir'] = os.path.join(TMP, 'rootdir-syndic-master', 'cache')
|
2017-04-02 15:21:06 +00:00
|
|
|
syndic_master_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
|
2017-04-02 15:56:17 +00:00
|
|
|
syndic_master_opts['config_dir'] = RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR
|
2016-07-07 18:27:48 +00:00
|
|
|
syndic_master_opts['root_dir'] = os.path.join(TMP, 'rootdir-syndic-master')
|
|
|
|
syndic_master_opts['pki_dir'] = os.path.join(TMP, 'rootdir-syndic-master', 'pki', 'master')
|
2014-06-12 23:59:55 +00:00
|
|
|
|
2017-05-05 21:32:16 +00:00
|
|
|
# This proxy connects to master
|
2017-05-24 15:51:00 +00:00
|
|
|
# proxy_opts = salt.config._read_conf_file(os.path.join(CONF_DIR, 'proxy'))
|
|
|
|
# proxy_opts['cachedir'] = os.path.join(TMP, 'rootdir', 'cache')
|
|
|
|
# proxy_opts['user'] = running_tests_user
|
|
|
|
# proxy_opts['config_dir'] = TMP_CONF_DIR
|
|
|
|
# proxy_opts['root_dir'] = os.path.join(TMP, 'rootdir')
|
|
|
|
# proxy_opts['pki_dir'] = os.path.join(TMP, 'rootdir', 'pki')
|
|
|
|
# proxy_opts['hosts.file'] = os.path.join(TMP, 'rootdir', 'hosts')
|
|
|
|
# proxy_opts['aliases.file'] = os.path.join(TMP, 'rootdir', 'aliases')
|
2017-05-05 21:32:16 +00:00
|
|
|
|
2014-06-12 23:59:55 +00:00
|
|
|
if transport == 'raet':
|
|
|
|
master_opts['transport'] = 'raet'
|
|
|
|
master_opts['raet_port'] = 64506
|
|
|
|
minion_opts['transport'] = 'raet'
|
|
|
|
minion_opts['raet_port'] = 64510
|
|
|
|
sub_minion_opts['transport'] = 'raet'
|
|
|
|
sub_minion_opts['raet_port'] = 64520
|
2015-04-24 22:27:22 +00:00
|
|
|
# syndic_master_opts['transport'] = 'raet'
|
2014-06-12 23:59:55 +00:00
|
|
|
|
2015-07-20 22:52:48 +00:00
|
|
|
if transport == 'tcp':
|
|
|
|
master_opts['transport'] = 'tcp'
|
|
|
|
minion_opts['transport'] = 'tcp'
|
|
|
|
sub_minion_opts['transport'] = 'tcp'
|
2015-07-21 22:42:33 +00:00
|
|
|
syndic_master_opts['transport'] = 'tcp'
|
2015-07-20 22:52:48 +00:00
|
|
|
|
2014-06-12 23:59:55 +00:00
|
|
|
# Set up config options that require internal data
|
2016-05-20 13:15:13 +00:00
|
|
|
master_opts['pillar_roots'] = syndic_master_opts['pillar_roots'] = {
|
2014-06-12 23:59:55 +00:00
|
|
|
'base': [os.path.join(FILES, 'pillar', 'base')]
|
|
|
|
}
|
2016-05-20 13:15:13 +00:00
|
|
|
master_opts['file_roots'] = syndic_master_opts['file_roots'] = {
|
2014-06-12 23:59:55 +00:00
|
|
|
'base': [
|
|
|
|
os.path.join(FILES, 'file', 'base'),
|
|
|
|
# Let's support runtime created files that can be used like:
|
|
|
|
# salt://my-temp-file.txt
|
2017-04-02 15:56:17 +00:00
|
|
|
RUNTIME_VARS.TMP_STATE_TREE
|
2014-06-12 23:59:55 +00:00
|
|
|
],
|
|
|
|
# Alternate root to test __env__ choices
|
|
|
|
'prod': [
|
|
|
|
os.path.join(FILES, 'file', 'prod'),
|
2017-04-02 15:56:17 +00:00
|
|
|
RUNTIME_VARS.TMP_PRODENV_STATE_TREE
|
2014-06-12 23:59:55 +00:00
|
|
|
]
|
|
|
|
}
|
2017-02-10 17:49:01 +00:00
|
|
|
master_opts.setdefault('reactor', []).append(
|
|
|
|
{
|
|
|
|
'salt/minion/*/start': [
|
|
|
|
os.path.join(FILES, 'reactor-sync-minion.sls')
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2016-05-20 13:15:13 +00:00
|
|
|
for opts_dict in (master_opts, syndic_master_opts):
|
|
|
|
if 'ext_pillar' not in opts_dict:
|
|
|
|
opts_dict['ext_pillar'] = []
|
|
|
|
if salt.utils.is_windows():
|
|
|
|
opts_dict['ext_pillar'].append(
|
|
|
|
{'cmd_yaml': 'type {0}'.format(os.path.join(FILES, 'ext.yaml'))})
|
|
|
|
else:
|
|
|
|
opts_dict['ext_pillar'].append(
|
|
|
|
{'cmd_yaml': 'cat {0}'.format(os.path.join(FILES, 'ext.yaml'))})
|
2014-06-12 23:59:55 +00:00
|
|
|
|
2016-05-20 14:29:31 +00:00
|
|
|
for opts_dict in (master_opts, syndic_master_opts):
|
|
|
|
# We need to copy the extension modules into the new master root_dir or
|
|
|
|
# it will be prefixed by it
|
|
|
|
new_extension_modules_path = os.path.join(opts_dict['root_dir'], 'extension_modules')
|
|
|
|
if not os.path.exists(new_extension_modules_path):
|
|
|
|
shutil.copytree(
|
|
|
|
os.path.join(
|
|
|
|
INTEGRATION_TEST_DIR, 'files', 'extension_modules'
|
|
|
|
),
|
|
|
|
new_extension_modules_path
|
|
|
|
)
|
2016-05-20 14:33:40 +00:00
|
|
|
opts_dict['extension_modules'] = os.path.join(opts_dict['root_dir'], 'extension_modules')
|
2014-06-12 23:59:55 +00:00
|
|
|
|
|
|
|
# Point the config values to the correct temporary paths
|
|
|
|
for name in ('hosts', 'aliases'):
|
|
|
|
optname = '{0}.file'.format(name)
|
|
|
|
optname_path = os.path.join(TMP, name)
|
|
|
|
master_opts[optname] = optname_path
|
|
|
|
minion_opts[optname] = optname_path
|
|
|
|
sub_minion_opts[optname] = optname_path
|
2016-05-20 13:15:13 +00:00
|
|
|
syndic_opts[optname] = optname_path
|
|
|
|
syndic_master_opts[optname] = optname_path
|
2014-06-12 23:59:55 +00:00
|
|
|
|
2017-02-26 14:20:41 +00:00
|
|
|
master_opts['runtests_conn_check_port'] = get_unused_localhost_port()
|
|
|
|
minion_opts['runtests_conn_check_port'] = get_unused_localhost_port()
|
|
|
|
sub_minion_opts['runtests_conn_check_port'] = get_unused_localhost_port()
|
|
|
|
syndic_opts['runtests_conn_check_port'] = get_unused_localhost_port()
|
|
|
|
syndic_master_opts['runtests_conn_check_port'] = get_unused_localhost_port()
|
|
|
|
|
2016-05-06 18:49:08 +00:00
|
|
|
for conf in (master_opts, minion_opts, sub_minion_opts, syndic_opts, syndic_master_opts):
|
2017-02-26 14:20:41 +00:00
|
|
|
if 'engines' not in conf:
|
|
|
|
conf['engines'] = []
|
|
|
|
conf['engines'].append({'salt_runtests': {}})
|
|
|
|
|
|
|
|
if 'engines_dirs' not in conf:
|
|
|
|
conf['engines_dirs'] = []
|
|
|
|
|
|
|
|
conf['engines_dirs'].insert(0, ENGINES_DIR)
|
|
|
|
|
2016-05-23 12:54:02 +00:00
|
|
|
if 'log_handlers_dirs' not in conf:
|
|
|
|
conf['log_handlers_dirs'] = []
|
|
|
|
conf['log_handlers_dirs'].insert(0, LOG_HANDLERS_DIR)
|
|
|
|
conf['runtests_log_port'] = SALT_LOG_PORT
|
2016-05-06 18:49:08 +00:00
|
|
|
|
2014-06-12 23:59:55 +00:00
|
|
|
# ----- Transcribe Configuration ---------------------------------------------------------------------------->
|
2017-04-02 15:56:17 +00:00
|
|
|
for entry in os.listdir(RUNTIME_VARS.CONF_DIR):
|
2016-05-20 13:15:13 +00:00
|
|
|
if entry in ('master', 'minion', 'sub_minion', 'syndic', 'syndic_master'):
|
2014-06-12 23:59:55 +00:00
|
|
|
# These have runtime computed values and will be handled
|
|
|
|
# differently
|
|
|
|
continue
|
2017-04-02 15:56:17 +00:00
|
|
|
entry_path = os.path.join(RUNTIME_VARS.CONF_DIR, entry)
|
2014-06-12 23:59:55 +00:00
|
|
|
if os.path.isfile(entry_path):
|
|
|
|
shutil.copy(
|
|
|
|
entry_path,
|
2017-04-02 15:56:17 +00:00
|
|
|
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry)
|
2014-06-12 23:59:55 +00:00
|
|
|
)
|
|
|
|
elif os.path.isdir(entry_path):
|
|
|
|
shutil.copytree(
|
|
|
|
entry_path,
|
2017-04-02 15:56:17 +00:00
|
|
|
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry)
|
2014-06-12 23:59:55 +00:00
|
|
|
)
|
|
|
|
|
2017-05-24 15:51:00 +00:00
|
|
|
for entry in ('master', 'minion', 'sub_minion', 'syndic', 'syndic_master'):
|
2014-06-12 23:59:55 +00:00
|
|
|
computed_config = copy.deepcopy(locals()['{0}_opts'.format(entry)])
|
2017-04-02 15:56:17 +00:00
|
|
|
with salt.utils.fopen(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry), 'w') as fp_:
|
2016-08-11 16:45:24 +00:00
|
|
|
fp_.write(yaml.dump(computed_config, default_flow_style=False))
|
2016-05-06 18:49:08 +00:00
|
|
|
sub_minion_computed_config = copy.deepcopy(sub_minion_opts)
|
2017-04-04 11:11:37 +00:00
|
|
|
with salt.utils.fopen(os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'minion'), 'w') as wfh:
|
|
|
|
wfh.write(
|
|
|
|
yaml.dump(sub_minion_computed_config, default_flow_style=False)
|
|
|
|
)
|
2017-04-02 15:56:17 +00:00
|
|
|
shutil.copyfile(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'), os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'master'))
|
2016-05-20 13:15:13 +00:00
|
|
|
|
2016-05-06 18:49:08 +00:00
|
|
|
syndic_master_computed_config = copy.deepcopy(syndic_master_opts)
|
2017-04-04 11:11:37 +00:00
|
|
|
with salt.utils.fopen(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR, 'master'), 'w') as wfh:
|
|
|
|
wfh.write(
|
|
|
|
yaml.dump(syndic_master_computed_config, default_flow_style=False)
|
|
|
|
)
|
2016-05-20 13:15:13 +00:00
|
|
|
syndic_computed_config = copy.deepcopy(syndic_opts)
|
2017-04-04 11:11:37 +00:00
|
|
|
with salt.utils.fopen(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'minion'), 'w') as wfh:
|
|
|
|
wfh.write(
|
|
|
|
yaml.dump(syndic_computed_config, default_flow_style=False)
|
|
|
|
)
|
2017-04-02 15:56:17 +00:00
|
|
|
shutil.copyfile(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'), os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'master'))
|
2014-06-12 23:59:55 +00:00
|
|
|
# <---- Transcribe Configuration -----------------------------------------------------------------------------
|
|
|
|
|
2014-06-13 18:31:01 +00:00
|
|
|
# ----- Verify Environment ---------------------------------------------------------------------------------->
|
2017-04-02 15:56:17 +00:00
|
|
|
master_opts = salt.config.master_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'))
|
|
|
|
minion_opts = salt.config.minion_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'minion'))
|
2014-06-13 18:31:01 +00:00
|
|
|
syndic_opts = salt.config.syndic_config(
|
2017-04-02 15:56:17 +00:00
|
|
|
os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'master'),
|
|
|
|
os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'minion'),
|
2014-06-13 18:31:01 +00:00
|
|
|
)
|
2017-04-02 15:56:17 +00:00
|
|
|
sub_minion_opts = salt.config.minion_config(os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'minion'))
|
|
|
|
syndic_master_opts = salt.config.master_config(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR, 'master'))
|
2014-06-13 18:31:01 +00:00
|
|
|
|
2017-04-02 15:56:17 +00:00
|
|
|
RUNTIME_VARS.RUNTIME_CONFIGS['master'] = freeze(master_opts)
|
|
|
|
RUNTIME_VARS.RUNTIME_CONFIGS['minion'] = freeze(minion_opts)
|
|
|
|
RUNTIME_VARS.RUNTIME_CONFIGS['syndic'] = freeze(syndic_opts)
|
|
|
|
RUNTIME_VARS.RUNTIME_CONFIGS['sub_minion'] = freeze(sub_minion_opts)
|
|
|
|
RUNTIME_VARS.RUNTIME_CONFIGS['syndic_master'] = freeze(syndic_master_opts)
|
2014-11-07 20:39:49 +00:00
|
|
|
|
2014-06-13 18:31:01 +00:00
|
|
|
verify_env([os.path.join(master_opts['pki_dir'], 'minions'),
|
|
|
|
os.path.join(master_opts['pki_dir'], 'minions_pre'),
|
|
|
|
os.path.join(master_opts['pki_dir'], 'minions_rejected'),
|
2014-09-22 08:01:24 +00:00
|
|
|
os.path.join(master_opts['pki_dir'], 'minions_denied'),
|
2014-06-13 18:31:01 +00:00
|
|
|
os.path.join(master_opts['cachedir'], 'jobs'),
|
2014-07-07 21:56:16 +00:00
|
|
|
os.path.join(master_opts['cachedir'], 'raet'),
|
2014-10-07 11:19:58 +00:00
|
|
|
os.path.join(master_opts['root_dir'], 'cache', 'tokens'),
|
2014-06-13 18:31:01 +00:00
|
|
|
os.path.join(syndic_master_opts['pki_dir'], 'minions'),
|
|
|
|
os.path.join(syndic_master_opts['pki_dir'], 'minions_pre'),
|
|
|
|
os.path.join(syndic_master_opts['pki_dir'], 'minions_rejected'),
|
|
|
|
os.path.join(syndic_master_opts['cachedir'], 'jobs'),
|
2014-07-07 21:56:16 +00:00
|
|
|
os.path.join(syndic_master_opts['cachedir'], 'raet'),
|
2014-10-07 11:19:58 +00:00
|
|
|
os.path.join(syndic_master_opts['root_dir'], 'cache', 'tokens'),
|
2014-06-13 18:31:01 +00:00
|
|
|
os.path.join(master_opts['pki_dir'], 'accepted'),
|
|
|
|
os.path.join(master_opts['pki_dir'], 'rejected'),
|
|
|
|
os.path.join(master_opts['pki_dir'], 'pending'),
|
|
|
|
os.path.join(syndic_master_opts['pki_dir'], 'accepted'),
|
|
|
|
os.path.join(syndic_master_opts['pki_dir'], 'rejected'),
|
|
|
|
os.path.join(syndic_master_opts['pki_dir'], 'pending'),
|
2014-07-07 21:56:16 +00:00
|
|
|
os.path.join(syndic_master_opts['cachedir'], 'raet'),
|
2014-06-13 18:31:01 +00:00
|
|
|
|
|
|
|
os.path.join(minion_opts['pki_dir'], 'accepted'),
|
|
|
|
os.path.join(minion_opts['pki_dir'], 'rejected'),
|
|
|
|
os.path.join(minion_opts['pki_dir'], 'pending'),
|
2014-07-07 21:56:16 +00:00
|
|
|
os.path.join(minion_opts['cachedir'], 'raet'),
|
2014-06-13 18:31:01 +00:00
|
|
|
os.path.join(sub_minion_opts['pki_dir'], 'accepted'),
|
|
|
|
os.path.join(sub_minion_opts['pki_dir'], 'rejected'),
|
|
|
|
os.path.join(sub_minion_opts['pki_dir'], 'pending'),
|
2014-07-07 21:56:16 +00:00
|
|
|
os.path.join(sub_minion_opts['cachedir'], 'raet'),
|
2014-06-13 18:31:01 +00:00
|
|
|
os.path.dirname(master_opts['log_file']),
|
2014-06-13 18:32:59 +00:00
|
|
|
minion_opts['extension_modules'],
|
|
|
|
sub_minion_opts['extension_modules'],
|
2014-06-13 18:31:01 +00:00
|
|
|
sub_minion_opts['pki_dir'],
|
|
|
|
master_opts['sock_dir'],
|
|
|
|
syndic_master_opts['sock_dir'],
|
|
|
|
sub_minion_opts['sock_dir'],
|
|
|
|
minion_opts['sock_dir'],
|
2017-04-02 15:56:17 +00:00
|
|
|
RUNTIME_VARS.TMP_STATE_TREE,
|
|
|
|
RUNTIME_VARS.TMP_PRODENV_STATE_TREE,
|
2014-06-13 18:31:01 +00:00
|
|
|
TMP,
|
|
|
|
],
|
2017-04-02 15:21:06 +00:00
|
|
|
RUNTIME_VARS.RUNNING_TESTS_USER)
|
2014-06-13 23:22:03 +00:00
|
|
|
|
|
|
|
cls.master_opts = master_opts
|
|
|
|
cls.minion_opts = minion_opts
|
2017-05-24 15:51:00 +00:00
|
|
|
# cls.proxy_opts = proxy_opts
|
2014-06-13 23:22:03 +00:00
|
|
|
cls.sub_minion_opts = sub_minion_opts
|
|
|
|
cls.syndic_opts = syndic_opts
|
|
|
|
cls.syndic_master_opts = syndic_master_opts
|
2014-06-13 18:31:01 +00:00
|
|
|
# <---- Verify Environment -----------------------------------------------------------------------------------
|
|
|
|
|
2012-02-20 12:18:13 +00:00
|
|
|
def __exit__(self, type, value, traceback):
|
|
|
|
'''
|
|
|
|
Kill the minion and master processes
|
|
|
|
'''
|
2016-06-24 15:10:00 +00:00
|
|
|
self.sub_minion_process.terminate()
|
2016-05-06 18:49:08 +00:00
|
|
|
self.minion_process.terminate()
|
2017-05-24 15:51:00 +00:00
|
|
|
# if hasattr(self, 'proxy_process'):
|
|
|
|
# self.proxy_process.terminate()
|
2016-05-06 18:49:08 +00:00
|
|
|
self.master_process.terminate()
|
2014-06-12 18:33:56 +00:00
|
|
|
try:
|
2016-05-06 18:49:08 +00:00
|
|
|
self.syndic_process.terminate()
|
2014-06-12 18:33:56 +00:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
try:
|
2016-05-06 18:49:08 +00:00
|
|
|
self.smaster_process.terminate()
|
2014-06-12 18:33:56 +00:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
2016-05-06 18:49:08 +00:00
|
|
|
#salt.utils.process.clean_proc(self.sub_minion_process, wait_for_kill=50)
|
|
|
|
#self.sub_minion_process.join()
|
|
|
|
#salt.utils.process.clean_proc(self.minion_process, wait_for_kill=50)
|
|
|
|
#self.minion_process.join()
|
|
|
|
#salt.utils.process.clean_proc(self.master_process, wait_for_kill=50)
|
|
|
|
#self.master_process.join()
|
|
|
|
#try:
|
|
|
|
# salt.utils.process.clean_proc(self.syndic_process, wait_for_kill=50)
|
|
|
|
# self.syndic_process.join()
|
|
|
|
#except AttributeError:
|
|
|
|
# pass
|
|
|
|
#try:
|
|
|
|
# salt.utils.process.clean_proc(self.smaster_process, wait_for_kill=50)
|
|
|
|
# self.smaster_process.join()
|
|
|
|
#except AttributeError:
|
|
|
|
# pass
|
2016-05-23 12:54:02 +00:00
|
|
|
self.log_server.server_close()
|
|
|
|
self.log_server.shutdown()
|
2012-07-26 16:14:00 +00:00
|
|
|
self._exit_mockbin()
|
2014-05-12 22:38:16 +00:00
|
|
|
self._exit_ssh()
|
2016-05-23 12:54:02 +00:00
|
|
|
self.log_server_process.join()
|
2015-08-03 20:37:56 +00:00
|
|
|
# Shutdown the multiprocessing logging queue listener
|
2015-10-29 16:26:14 +00:00
|
|
|
salt_log_setup.shutdown_multiprocessing_logging()
|
2016-10-05 08:14:27 +00:00
|
|
|
salt_log_setup.shutdown_multiprocessing_logging_listener(daemonizing=True)
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
def pre_setup_minions(self):
|
2013-01-10 07:25:02 +00:00
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
Subclass this method for additional minion setups.
|
2013-01-10 07:25:02 +00:00
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
|
|
|
|
def setup_minions(self):
|
2016-05-09 00:27:09 +00:00
|
|
|
'''
|
|
|
|
Minions setup routines
|
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
|
|
|
|
def post_setup_minions(self):
|
2013-01-20 01:22:54 +00:00
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
Subclass this method to execute code after the minions have been setup
|
2013-01-20 01:22:54 +00:00
|
|
|
'''
|
2012-11-26 05:44:18 +00:00
|
|
|
|
2012-07-26 16:14:00 +00:00
|
|
|
def _enter_mockbin(self):
|
|
|
|
path = os.environ.get('PATH', '')
|
|
|
|
path_items = path.split(os.pathsep)
|
|
|
|
if MOCKBIN not in path_items:
|
|
|
|
path_items.insert(0, MOCKBIN)
|
|
|
|
os.environ['PATH'] = os.pathsep.join(path_items)
|
|
|
|
|
2014-05-12 22:38:16 +00:00
|
|
|
def _exit_ssh(self):
|
|
|
|
if hasattr(self, 'sshd_process'):
|
|
|
|
try:
|
|
|
|
self.sshd_process.kill()
|
2014-10-30 06:45:52 +00:00
|
|
|
except OSError as exc:
|
|
|
|
if exc.errno != 3:
|
|
|
|
raise
|
2014-11-26 23:38:34 +00:00
|
|
|
with salt.utils.fopen(self.sshd_pidfile) as fhr:
|
|
|
|
try:
|
|
|
|
os.kill(int(fhr.read()), signal.SIGKILL)
|
|
|
|
except OSError as exc:
|
|
|
|
if exc.errno != 3:
|
|
|
|
raise
|
2014-05-12 22:38:16 +00:00
|
|
|
|
2012-07-26 16:14:00 +00:00
|
|
|
def _exit_mockbin(self):
|
|
|
|
path = os.environ.get('PATH', '')
|
|
|
|
path_items = path.split(os.pathsep)
|
|
|
|
try:
|
|
|
|
path_items.remove(MOCKBIN)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
os.environ['PATH'] = os.pathsep.join(path_items)
|
|
|
|
|
2014-06-14 13:03:38 +00:00
|
|
|
@classmethod
|
|
|
|
def clean(cls):
|
2012-04-04 05:14:26 +00:00
|
|
|
'''
|
|
|
|
Clean out the tmp files
|
|
|
|
'''
|
2016-05-19 17:13:03 +00:00
|
|
|
def remove_readonly(func, path, excinfo):
|
2017-02-09 18:02:57 +00:00
|
|
|
# Give full permissions to owner
|
|
|
|
os.chmod(path, stat.S_IRWXU)
|
2016-05-19 17:13:03 +00:00
|
|
|
func(path)
|
|
|
|
|
2017-04-02 15:56:17 +00:00
|
|
|
for dirname in (TMP, RUNTIME_VARS.TMP_STATE_TREE, RUNTIME_VARS.TMP_PRODENV_STATE_TREE):
|
2013-11-02 22:40:09 +00:00
|
|
|
if os.path.isdir(dirname):
|
2016-05-19 17:13:03 +00:00
|
|
|
shutil.rmtree(dirname, onerror=remove_readonly)
|
2012-02-20 12:18:13 +00:00
|
|
|
|
2012-11-09 15:25:16 +00:00
|
|
|
def wait_for_jid(self, targets, jid, timeout=120):
|
2012-11-26 05:44:18 +00:00
|
|
|
time.sleep(1) # Allow some time for minions to accept jobs
|
2012-11-17 17:37:53 +00:00
|
|
|
now = datetime.now()
|
|
|
|
expire = now + timedelta(seconds=timeout)
|
2012-11-26 05:44:18 +00:00
|
|
|
job_finished = False
|
2012-11-17 17:37:53 +00:00
|
|
|
while now <= expire:
|
2012-11-09 15:25:16 +00:00
|
|
|
running = self.__client_job_running(targets, jid)
|
2014-01-14 15:16:30 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
if not running and job_finished is False:
|
|
|
|
# Let's not have false positives and wait one more seconds
|
|
|
|
job_finished = True
|
|
|
|
elif not running and job_finished is True:
|
2012-11-09 15:25:16 +00:00
|
|
|
return True
|
2012-11-26 05:44:18 +00:00
|
|
|
elif running and job_finished is True:
|
|
|
|
job_finished = False
|
|
|
|
|
|
|
|
if job_finished is False:
|
|
|
|
sys.stdout.write(
|
2014-12-25 07:06:29 +00:00
|
|
|
' * {LIGHT_YELLOW}[Quit in {0}]{ENDC} Waiting for {1}'.format(
|
2012-11-26 05:44:18 +00:00
|
|
|
'{0}'.format(expire - now).rsplit('.', 1)[0],
|
|
|
|
', '.join(running),
|
|
|
|
**self.colors
|
|
|
|
)
|
2012-11-09 15:25:16 +00:00
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.flush()
|
2012-11-09 15:25:16 +00:00
|
|
|
time.sleep(1)
|
2012-11-17 17:37:53 +00:00
|
|
|
now = datetime.now()
|
2013-11-27 13:07:24 +00:00
|
|
|
else: # pylint: disable=W0120
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.write(
|
2014-12-25 07:06:29 +00:00
|
|
|
'\n {LIGHT_RED}*{ENDC} ERROR: Failed to get information '
|
2012-11-26 05:44:18 +00:00
|
|
|
'back\n'.format(**self.colors)
|
|
|
|
)
|
2012-11-09 15:25:16 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __client_job_running(self, targets, jid):
|
|
|
|
running = self.client.cmd(
|
2016-12-01 22:21:49 +00:00
|
|
|
list(targets), 'saltutil.running', tgt_type='list'
|
2012-11-09 15:25:16 +00:00
|
|
|
)
|
|
|
|
return [
|
2014-11-21 19:41:22 +00:00
|
|
|
k for (k, v) in six.iteritems(running) if v and v[0]['jid'] == jid
|
2012-11-09 15:25:16 +00:00
|
|
|
]
|
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
def wait_for_minion_connections(self, targets, timeout):
|
2015-10-29 16:26:14 +00:00
|
|
|
salt.utils.appendproctitle('WaitForMinionConnections')
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
' {LIGHT_BLUE}*{ENDC} Waiting at most {0} for minions({1}) to '
|
|
|
|
'connect back\n'.format(
|
|
|
|
(timeout > 60 and
|
|
|
|
timedelta(seconds=timeout) or
|
|
|
|
'{0} secs'.format(timeout)),
|
|
|
|
', '.join(targets),
|
|
|
|
**self.colors
|
|
|
|
)
|
2012-11-06 11:20:06 +00:00
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.flush()
|
2012-11-06 11:20:06 +00:00
|
|
|
expected_connections = set(targets)
|
2012-11-26 05:44:18 +00:00
|
|
|
now = datetime.now()
|
|
|
|
expire = now + timedelta(seconds=timeout)
|
|
|
|
while now <= expire:
|
2014-01-14 15:16:30 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.write(
|
2014-12-25 07:06:29 +00:00
|
|
|
' * {LIGHT_YELLOW}[Quit in {0}]{ENDC} Waiting for {1}'.format(
|
2012-11-26 05:44:18 +00:00
|
|
|
'{0}'.format(expire - now).rsplit('.', 1)[0],
|
|
|
|
', '.join(expected_connections),
|
|
|
|
**self.colors
|
|
|
|
)
|
|
|
|
)
|
|
|
|
sys.stdout.flush()
|
2012-11-26 04:32:25 +00:00
|
|
|
|
2015-04-04 22:20:52 +00:00
|
|
|
try:
|
|
|
|
responses = self.client.cmd(
|
2016-12-01 22:21:49 +00:00
|
|
|
list(expected_connections), 'test.ping', tgt_type='list',
|
2015-04-04 22:20:52 +00:00
|
|
|
)
|
|
|
|
# we'll get this exception if the master process hasn't finished starting yet
|
|
|
|
except SaltClientError:
|
|
|
|
time.sleep(0.1)
|
2015-04-23 16:55:42 +00:00
|
|
|
now = datetime.now()
|
2015-04-04 22:20:52 +00:00
|
|
|
continue
|
2012-11-26 05:44:18 +00:00
|
|
|
for target in responses:
|
2012-11-06 11:20:06 +00:00
|
|
|
if target not in expected_connections:
|
|
|
|
# Someone(minion) else "listening"?
|
|
|
|
continue
|
|
|
|
expected_connections.remove(target)
|
2014-01-14 15:16:30 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
'\r{0}\r'.format(
|
|
|
|
' ' * getattr(self.parser.options, 'output_columns',
|
|
|
|
PNUM)
|
|
|
|
)
|
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.write(
|
|
|
|
' {LIGHT_GREEN}*{ENDC} {0} connected.\n'.format(
|
2012-11-26 04:32:25 +00:00
|
|
|
target, **self.colors
|
|
|
|
)
|
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
2012-11-06 11:20:06 +00:00
|
|
|
if not expected_connections:
|
2012-11-26 05:44:18 +00:00
|
|
|
return
|
|
|
|
|
2012-11-06 11:20:06 +00:00
|
|
|
time.sleep(1)
|
2012-11-26 05:44:18 +00:00
|
|
|
now = datetime.now()
|
2013-11-27 13:07:24 +00:00
|
|
|
else: # pylint: disable=W0120
|
2012-11-26 05:44:18 +00:00
|
|
|
print(
|
2014-12-25 07:06:29 +00:00
|
|
|
'\n {LIGHT_RED}*{ENDC} WARNING: Minions failed to connect '
|
2012-11-26 05:44:18 +00:00
|
|
|
'back. Tests requiring them WILL fail'.format(**self.colors)
|
|
|
|
)
|
2014-01-14 15:16:30 +00:00
|
|
|
try:
|
|
|
|
print_header(
|
|
|
|
'=', sep='=', inline=True,
|
|
|
|
width=getattr(self.parser.options, 'output_columns', PNUM)
|
|
|
|
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
print_header('=', sep='=', inline=True)
|
2012-11-26 05:44:18 +00:00
|
|
|
raise SystemExit()
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2014-01-28 12:40:03 +00:00
|
|
|
def sync_minion_modules_(self, modules_kind, targets, timeout=None):
|
|
|
|
if not timeout:
|
|
|
|
timeout = 120
|
2012-11-06 11:20:06 +00:00
|
|
|
# Let's sync all connected minions
|
2012-11-26 05:44:18 +00:00
|
|
|
print(
|
2014-01-28 12:40:03 +00:00
|
|
|
' {LIGHT_BLUE}*{ENDC} Syncing minion\'s {1} '
|
|
|
|
'(saltutil.sync_{1})'.format(
|
2012-11-26 05:44:18 +00:00
|
|
|
', '.join(targets),
|
2014-01-28 12:40:03 +00:00
|
|
|
modules_kind,
|
2012-11-26 05:44:18 +00:00
|
|
|
**self.colors
|
|
|
|
)
|
|
|
|
)
|
2012-11-06 11:20:06 +00:00
|
|
|
syncing = set(targets)
|
|
|
|
jid_info = self.client.run_job(
|
2014-01-28 12:40:03 +00:00
|
|
|
list(targets), 'saltutil.sync_{0}'.format(modules_kind),
|
2016-12-01 22:21:49 +00:00
|
|
|
tgt_type='list',
|
2014-11-20 15:46:13 +00:00
|
|
|
timeout=999999999999999,
|
2012-11-06 11:20:06 +00:00
|
|
|
)
|
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
if self.wait_for_jid(targets, jid_info['jid'], timeout) is False:
|
|
|
|
print(
|
2014-12-25 07:06:29 +00:00
|
|
|
' {LIGHT_RED}*{ENDC} WARNING: Minions failed to sync {0}. '
|
2014-01-28 12:40:03 +00:00
|
|
|
'Tests requiring these {0} WILL fail'.format(
|
|
|
|
modules_kind, **self.colors)
|
2012-11-26 05:44:18 +00:00
|
|
|
)
|
|
|
|
raise SystemExit()
|
2012-11-09 15:25:16 +00:00
|
|
|
|
2012-11-06 11:20:06 +00:00
|
|
|
while syncing:
|
2013-01-11 19:03:53 +00:00
|
|
|
rdata = self.client.get_full_returns(jid_info['jid'], syncing, 1)
|
2012-11-06 11:20:06 +00:00
|
|
|
if rdata:
|
2014-11-21 19:41:22 +00:00
|
|
|
for name, output in six.iteritems(rdata):
|
2013-01-11 19:03:53 +00:00
|
|
|
if not output['ret']:
|
|
|
|
# Already synced!?
|
|
|
|
syncing.remove(name)
|
|
|
|
continue
|
|
|
|
|
2014-11-21 19:41:22 +00:00
|
|
|
if isinstance(output['ret'], six.string_types):
|
2013-11-10 19:57:41 +00:00
|
|
|
# An errors has occurred
|
|
|
|
print(
|
2014-12-25 07:06:29 +00:00
|
|
|
' {LIGHT_RED}*{ENDC} {0} Failed to sync {2}: '
|
2014-01-28 12:40:03 +00:00
|
|
|
'{1}'.format(
|
|
|
|
name, output['ret'],
|
|
|
|
modules_kind,
|
|
|
|
**self.colors)
|
2013-11-10 19:57:41 +00:00
|
|
|
)
|
|
|
|
return False
|
|
|
|
|
2012-11-26 05:44:18 +00:00
|
|
|
print(
|
2014-01-28 12:40:03 +00:00
|
|
|
' {LIGHT_GREEN}*{ENDC} Synced {0} {2}: '
|
2013-01-11 19:03:53 +00:00
|
|
|
'{1}'.format(
|
2014-01-28 12:40:03 +00:00
|
|
|
name,
|
|
|
|
', '.join(output['ret']),
|
|
|
|
modules_kind, **self.colors
|
2013-01-11 19:03:53 +00:00
|
|
|
)
|
2012-11-26 05:44:18 +00:00
|
|
|
)
|
2012-11-06 11:20:06 +00:00
|
|
|
# Synced!
|
|
|
|
try:
|
|
|
|
syncing.remove(name)
|
|
|
|
except KeyError:
|
2012-11-26 05:44:18 +00:00
|
|
|
print(
|
2014-12-25 07:06:29 +00:00
|
|
|
' {LIGHT_RED}*{ENDC} {0} already synced??? '
|
2012-11-26 05:44:18 +00:00
|
|
|
'{1}'.format(name, output, **self.colors)
|
|
|
|
)
|
|
|
|
return True
|
2012-11-06 11:20:06 +00:00
|
|
|
|
2014-01-28 12:40:03 +00:00
|
|
|
def sync_minion_states(self, targets, timeout=None):
|
2015-10-29 16:26:14 +00:00
|
|
|
salt.utils.appendproctitle('SyncMinionStates')
|
2014-01-28 12:40:03 +00:00
|
|
|
self.sync_minion_modules_('states', targets, timeout=timeout)
|
|
|
|
|
|
|
|
def sync_minion_modules(self, targets, timeout=None):
|
2015-10-29 16:26:14 +00:00
|
|
|
salt.utils.appendproctitle('SyncMinionModules')
|
2014-01-28 12:40:03 +00:00
|
|
|
self.sync_minion_modules_('modules', targets, timeout=timeout)
|
|
|
|
|
2015-10-31 19:43:17 +00:00
|
|
|
def sync_minion_grains(self, targets, timeout=None):
|
2017-02-10 17:49:01 +00:00
|
|
|
salt.utils.appendproctitle('SyncMinionGrains')
|
2015-10-31 19:43:17 +00:00
|
|
|
self.sync_minion_modules_('grains', targets, timeout=timeout)
|