Merge pull request #48394 from rallytime/merge-2018.3

[2018.3] Merge forward from 2017.7 to 2018.3
This commit is contained in:
Mike Place 2018-06-30 22:13:02 -06:00 committed by GitHub
commit 3b53e2d206
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 524 additions and 332 deletions

View file

@ -5,6 +5,14 @@ pipeline {
PATH = "$PYENV_ROOT/bin:$PATH"
}
stages {
stage('github-pending') {
steps {
githubNotify credentialsId: 'test-jenkins-credentials',
description: 'Testing docs...',
status: 'PENDING',
context: "jenkins/pr/docs"
}
}
stage('setup') {
steps {
sh 'eval "$(pyenv init -)"; pyenv install 2.7.14 || echo "We already have this python."; pyenv local 2.7.14; pyenv shell 2.7.14'
@ -14,16 +22,25 @@ pipeline {
stage('build') {
steps {
sh 'eval "$(pyenv init -)"; make -C doc clean html'
archiveArtifacts artifacts: 'doc/_build/html'
archiveArtifacts artifacts: 'doc/_build/html/'
}
}
}
post {
always {
cleanWs()
}
success {
githubNotify description: "The docs job has passed, artifacts have been saved", status: "SUCCESS"
githubNotify credentialsId: 'test-jenkins-credentials',
description: 'The docs job has passed',
status: 'SUCCESS',
context: "jenkins/pr/docs"
}
failure {
githubNotify description: "The docs job has failed", status: "FAILURE"
githubNotify credentialsId: 'test-jenkins-credentials',
description: 'The docs job has failed',
status: 'FAILURE',
context: "jenkins/pr/docs"
}
}
}

View file

@ -9,6 +9,14 @@ pipeline {
TEST_PLATFORM = "centos-7"
}
stages {
stage('github-pending') {
steps {
githubNotify credentialsId: 'test-jenkins-credentials',
description: "running ${TEST_SUITE}-${TEST_PLATFORM}...",
status: 'PENDING',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
}
stage('setup') {
steps {
sh 'bundle install --with ec2 windows --without opennebula docker'
@ -29,7 +37,7 @@ pipeline {
always {
script { withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sshagent(credentials: ['jenkins-testing-ssh-key']) {
sh 'ssh-add ~/.ssh/jenkins/jenkins-testing.pem'
sh 'ssh-add ~/.ssh/jenkins-testing.pem'
sh 'bundle exec kitchen destroy $TEST_SUITE-$TEST_PLATFORM'
}
}}
@ -38,11 +46,20 @@ pipeline {
}
}
post {
always {
cleanWs()
}
success {
githubNotify description: "The centos7-py2 job has passed", status: "SUCCESS"
githubNotify credentialsId: 'test-jenkins-credentials',
description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has passed",
status: 'SUCCESS',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
failure {
githubNotify description: "The centos7-py2 job has failed", status: "FAILURE"
githubNotify credentialsId: 'test-jenkins-credentials',
description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has failed",
status: 'FAILURE',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
}
}

View file

@ -9,6 +9,14 @@ pipeline {
TEST_PLATFORM = "centos-7"
}
stages {
stage('github-pending') {
steps {
githubNotify credentialsId: 'test-jenkins-credentials',
description: "running ${TEST_SUITE}-${TEST_PLATFORM}...",
status: 'PENDING',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
}
stage('setup') {
steps {
sh 'bundle install --with ec2 windows --without opennebula docker'
@ -29,7 +37,7 @@ pipeline {
always {
script { withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sshagent(credentials: ['jenkins-testing-ssh-key']) {
sh 'ssh-add ~/.ssh/jenkins/jenkins-testing.pem'
sh 'ssh-add ~/.ssh/jenkins-testing.pem'
sh 'bundle exec kitchen destroy $TEST_SUITE-$TEST_PLATFORM'
}
}}
@ -38,11 +46,20 @@ pipeline {
}
}
post {
always {
cleanWs()
}
success {
githubNotify description: "The centos7-py3 job has passed", status: "SUCCESS"
githubNotify credentialsId: 'test-jenkins-credentials',
description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has passed",
status: 'SUCCESS',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
failure {
githubNotify description: "The centos7-py3 job has failed", status: "FAILURE"
githubNotify credentialsId: 'test-jenkins-credentials',
description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has failed",
status: 'FAILURE',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
}
}

View file

@ -9,6 +9,14 @@ pipeline {
TEST_PLATFORM = "ubuntu-1604"
}
stages {
stage('github-pending') {
steps {
githubNotify credentialsId: 'test-jenkins-credentials',
description: "running ${TEST_SUITE}-${TEST_PLATFORM}...",
status: 'PENDING',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
}
stage('setup') {
steps {
sh 'bundle install --with ec2 windows --without opennebula docker'
@ -29,7 +37,7 @@ pipeline {
always {
script { withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sshagent(credentials: ['jenkins-testing-ssh-key']) {
sh 'ssh-add ~/.ssh/jenkins/jenkins-testing.pem'
sh 'ssh-add ~/.ssh/jenkins-testing.pem'
sh 'bundle exec kitchen destroy $TEST_SUITE-$TEST_PLATFORM'
}
}}
@ -38,11 +46,20 @@ pipeline {
}
}
post {
always {
cleanWs()
}
success {
githubNotify description: "The ubuntu-1604-py2 job has passed", status: "SUCCESS"
githubNotify credentialsId: 'test-jenkins-credentials',
description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has passed",
status: 'SUCCESS',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
failure {
githubNotify description: "The ubuntu-1604-py2 job has failed", status: "FAILURE"
githubNotify credentialsId: 'test-jenkins-credentials',
description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has failed",
status: 'FAILURE',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
}
}

View file

@ -9,6 +9,14 @@ pipeline {
TEST_PLATFORM = "ubuntu-1604"
}
stages {
stage('github-pending') {
steps {
githubNotify credentialsId: 'test-jenkins-credentials',
description: "running ${TEST_SUITE}-${TEST_PLATFORM}...",
status: 'PENDING',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
}
stage('setup') {
steps {
sh 'bundle install --with ec2 windows --without opennebula docker'
@ -29,7 +37,7 @@ pipeline {
always {
script { withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sshagent(credentials: ['jenkins-testing-ssh-key']) {
sh 'ssh-add ~/.ssh/jenkins/jenkins-testing.pem'
sh 'ssh-add ~/.ssh/jenkins-testing.pem'
sh 'bundle exec kitchen destroy $TEST_SUITE-$TEST_PLATFORM'
}
}}
@ -38,11 +46,20 @@ pipeline {
}
}
post {
always {
cleanWs()
}
success {
githubNotify description: "The ubuntu-1604-py3 job has passed", status: "SUCCESS"
githubNotify credentialsId: 'test-jenkins-credentials',
description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has passed",
status: 'SUCCESS',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
failure {
githubNotify description: "The ubuntu-1604-py3 job has failed", status: "FAILURE"
githubNotify credentialsId: 'test-jenkins-credentials',
description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has failed",
status: 'FAILURE',
context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
}
}
}

View file

@ -5,6 +5,14 @@ pipeline {
PATH = "$PYENV_ROOT/bin:$PATH"
}
stages {
stage('github-pending') {
steps {
githubNotify credentialsId: 'test-jenkins-credentials',
description: 'Testing lint...',
status: 'PENDING',
context: "jenkins/pr/lint"
}
}
stage('setup') {
steps {
sh 'eval "$(pyenv init -)"; pyenv install 2.7.14 || echo "We already have this python."; pyenv local 2.7.14; pyenv shell 2.7.14'
@ -31,11 +39,28 @@ pipeline {
}
}
post {
always {
step([$class: 'WarningsPublisher',
parserConfigurations: [[
parserName: 'PyLint',
pattern: 'pylint-report*.xml'
]],
unstableTotalAll: '999',
usePreviousBuildAsReference: true
])
cleanWs()
}
success {
githubNotify description: "The lint job has passed", status: "SUCCESS"
githubNotify credentialsId: 'test-jenkins-credentials',
description: 'The lint job has passed',
status: 'SUCCESS',
context: "jenkins/pr/lint"
}
failure {
githubNotify description: "The lint job has failed", status: "FAILURE"
githubNotify credentialsId: 'test-jenkins-credentials',
description: 'The lint job has failed',
status: 'FAILURE',
context: "jenkins/pr/lint"
}
}
}

1
.github/CODEOWNERS vendored
View file

@ -48,6 +48,7 @@ salt/spm/* @saltstack/team-spm
# Team SSH
salt/cli/ssh.py @saltstack/team-ssh
salt/client/ssh/* @saltstack/team-ssh
salt/roster/* @saltstack/team-ssh
salt/runners/ssh.py @saltstack/team-ssh
salt/**/thin.py @saltstack/team-ssh

View file

@ -25,13 +25,13 @@ def __virtual__():
'''
if salt.utils.platform.is_darwin() or salt.utils.platform.is_windows():
return True
return (False, 'Module proxy: module only works on Windows or MacOS systems')
return False, 'Module proxy: module only works on Windows or MacOS systems'
def _get_proxy_osx(function, network_service):
def _get_proxy_osx(cmd_function, network_service):
ret = {}
out = __salt__['cmd.run']('networksetup -{0} {1}'.format(function, network_service))
out = __salt__['cmd.run']('networksetup -{0} {1}'.format(cmd_function, network_service))
match = re.match('Enabled: (.*)\nServer: (.*)\nPort: (.*)\n', out)
if match is not None:
g = match.groups()
@ -41,8 +41,8 @@ def _get_proxy_osx(function, network_service):
return ret
def _set_proxy_osx(function, server, port, user, password, network_service):
cmd = 'networksetup -{0} {1} {2} {3}'.format(function, network_service, server, port)
def _set_proxy_osx(cmd_function, server, port, user, password, network_service):
cmd = 'networksetup -{0} {1} {2} {3}'.format(cmd_function, network_service, server, port)
if user is not None and password is not None:
cmd = cmd + ' On {0} {1}'.format(user, password)
@ -58,12 +58,12 @@ def _get_proxy_windows(types=None):
if types is None:
types = ['http', 'https', 'ftp']
reg_val = __salt__['reg.read_value']('HKEY_CURRENT_USER',
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
'ProxyServer')
servers = reg_val['vdata']
servers = __salt__['reg.read_value'](
hive='HKEY_CURRENT_USER',
key=r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
vname='ProxyServer')['vdata']
if "=" in servers:
if servers and "=" in servers:
split = servers.split(";")
for s in split:
if len(s) == 0:
@ -87,16 +87,19 @@ def _get_proxy_windows(types=None):
del ret[key]
# Return enabled info
reg_val = __salt__['reg.read_value']('HKEY_CURRENT_USER',
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
'ProxyEnable')
enabled = reg_val.get('vdata', 0)
ret['enabled'] = True if enabled == 1 else False
ret['enabled'] = __salt__['reg.read_value'](
hive='HKEY_CURRENT_USER',
key=r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
vname='ProxyEnable')['vdata'] == 1
return ret
def _set_proxy_windows(server, port, types=None, bypass_hosts=None, import_winhttp=True):
def _set_proxy_windows(server,
port,
types=None,
bypass_hosts=None,
import_winhttp=True):
if types is None:
types = ['http', 'https', 'ftp']
@ -104,17 +107,27 @@ def _set_proxy_windows(server, port, types=None, bypass_hosts=None, import_winht
for t in types:
server_str += '{0}={1}:{2};'.format(t, server, port)
__salt__['reg.set_value']('HKEY_CURRENT_USER', r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
'ProxyServer', server_str)
__salt__['reg.set_value'](
hive='HKEY_CURRENT_USER',
key=r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
vname='ProxyServer',
vdata=server_str)
__salt__['reg.set_value']('HKEY_CURRENT_USER', r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
'ProxyEnable', 1, vtype='REG_DWORD')
__salt__['reg.set_value'](
hive='HKEY_CURRENT_USER',
key=r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
vname='ProxyEnable',
vdata=1,
vtype='REG_DWORD')
if bypass_hosts is not None:
bypass_hosts_str = '<local>;{0}'.format(';'.join(bypass_hosts))
__salt__['reg.set_value']('HKEY_CURRENT_USER', r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
'ProxyOverride', bypass_hosts_str)
__salt__['reg.set_value'](
hive='HKEY_CURRENT_USER',
key=r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
vname='ProxyOverride',
vdata=bypass_hosts_str)
if import_winhttp:
cmd = 'netsh winhttp import proxy source=ie'
@ -138,15 +151,22 @@ def get_http_proxy(network_service="Ethernet"):
salt '*' proxy.get_http_proxy Ethernet
'''
if __grains__['os'] == 'Windows':
return _get_proxy_windows(['http'])
return _get_proxy_windows(types=['http'])
return _get_proxy_osx("getwebproxy", network_service)
return _get_proxy_osx(cmd_function="getwebproxy",
network_service=network_service)
def set_http_proxy(server, port, user=None, password=None, network_service="Ethernet", bypass_hosts=None):
def set_http_proxy(server,
port,
user=None,
password=None,
network_service="Ethernet",
bypass_hosts=None):
'''
Sets the http proxy settings. Note: On Windows this will override any other proxy settings you have,
the preferred method of updating proxies on windows is using set_proxy.
Sets the http proxy settings. Note: On Windows this will override any other
proxy settings you have, the preferred method of updating proxies on windows
is using set_proxy.
server
The proxy server to use
@ -165,8 +185,8 @@ def set_http_proxy(server, port, user=None, password=None, network_service="Ethe
macOS
bypass_hosts
The hosts that are allowed to by pass the proxy. Only used on Windows for other OS's use
set_proxy_bypass to edit the bypass hosts.
The hosts that are allowed to by pass the proxy. Only used on Windows
for other OS's use set_proxy_bypass to edit the bypass hosts.
CLI Example:
@ -175,9 +195,17 @@ def set_http_proxy(server, port, user=None, password=None, network_service="Ethe
salt '*' proxy.set_http_proxy example.com 1080 user=proxy_user password=proxy_pass network_service=Ethernet
'''
if __grains__['os'] == 'Windows':
return _set_proxy_windows(server, port, ['http'], bypass_hosts)
return _set_proxy_windows(server=server,
port=port,
types=['http'],
bypass_hosts=bypass_hosts)
return _set_proxy_osx("setwebproxy", server, port, user, password, network_service)
return _set_proxy_osx(cmd_function="setwebproxy",
server=server,
port=port,
user=user,
password=password,
network_service=network_service)
def get_https_proxy(network_service="Ethernet"):
@ -195,15 +223,22 @@ def get_https_proxy(network_service="Ethernet"):
salt '*' proxy.get_https_proxy Ethernet
'''
if __grains__['os'] == 'Windows':
return _get_proxy_windows(['https'])
return _get_proxy_windows(types=['https'])
return _get_proxy_osx("getsecurewebproxy", network_service)
return _get_proxy_osx(cmd_function="getsecurewebproxy",
network_service=network_service)
def set_https_proxy(server, port, user=None, password=None, network_service="Ethernet", bypass_hosts=None):
def set_https_proxy(server,
port,
user=None,
password=None,
network_service="Ethernet",
bypass_hosts=None):
'''
Sets the https proxy settings. Note: On Windows this will override any other proxy settings you have,
the preferred method of updating proxies on windows is using set_proxy.
Sets the https proxy settings. Note: On Windows this will override any other
proxy settings you have, the preferred method of updating proxies on windows
is using set_proxy.
server
The proxy server to use
@ -222,8 +257,8 @@ def set_https_proxy(server, port, user=None, password=None, network_service="Eth
macOS
bypass_hosts
The hosts that are allowed to by pass the proxy. Only used on Windows for other OS's use
set_proxy_bypass to edit the bypass hosts.
The hosts that are allowed to by pass the proxy. Only used on Windows
for other OS's use set_proxy_bypass to edit the bypass hosts.
CLI Example:
@ -232,9 +267,17 @@ def set_https_proxy(server, port, user=None, password=None, network_service="Eth
salt '*' proxy.set_https_proxy example.com 1080 user=proxy_user password=proxy_pass network_service=Ethernet
'''
if __grains__['os'] == 'Windows':
return _set_proxy_windows(server, port, ['https'], bypass_hosts)
return _set_proxy_windows(server=server,
port=port,
types=['https'],
bypass_hosts=bypass_hosts)
return _set_proxy_osx("setsecurewebproxy", server, port, user, password, network_service)
return _set_proxy_osx(cmd_function="setsecurewebproxy",
server=server,
port=port,
user=user,
password=password,
network_service=network_service)
def get_ftp_proxy(network_service="Ethernet"):
@ -252,12 +295,18 @@ def get_ftp_proxy(network_service="Ethernet"):
salt '*' proxy.get_ftp_proxy Ethernet
'''
if __grains__['os'] == 'Windows':
return _get_proxy_windows(['ftp'])
return _get_proxy_windows(types=['ftp'])
return _get_proxy_osx("getftpproxy", network_service)
return _get_proxy_osx(cmd_function="getftpproxy",
network_service=network_service)
def set_ftp_proxy(server, port, user=None, password=None, network_service="Ethernet", bypass_hosts=None):
def set_ftp_proxy(server,
port,
user=None,
password=None,
network_service="Ethernet",
bypass_hosts=None):
'''
Sets the ftp proxy settings
@ -278,8 +327,8 @@ def set_ftp_proxy(server, port, user=None, password=None, network_service="Ether
macOS
bypass_hosts
The hosts that are allowed to by pass the proxy. Only used on Windows for other OS's use
set_proxy_bypass to edit the bypass hosts.
The hosts that are allowed to by pass the proxy. Only used on Windows
for other OS's use set_proxy_bypass to edit the bypass hosts.
CLI Example:
@ -288,9 +337,17 @@ def set_ftp_proxy(server, port, user=None, password=None, network_service="Ether
salt '*' proxy.set_ftp_proxy example.com 1080 user=proxy_user password=proxy_pass network_service=Ethernet
'''
if __grains__['os'] == 'Windows':
return _set_proxy_windows(server, port, ['ftp'], bypass_hosts)
return _set_proxy_windows(server=server,
port=port,
types=['ftp'],
bypass_hosts=bypass_hosts)
return _set_proxy_osx("setftpproxy", server, port, user, password, network_service)
return _set_proxy_osx(cmd_function="setftpproxy",
server=server,
port=port,
user=user,
password=password,
network_service=network_service)
def get_proxy_bypass(network_service="Ethernet"):
@ -309,12 +366,16 @@ def get_proxy_bypass(network_service="Ethernet"):
'''
if __grains__['os'] == 'Windows':
reg_val = __salt__['reg.read_value']('HKEY_CURRENT_USER',
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
'ProxyOverride')
bypass_servers = reg_val['vdata'].replace("<local>", "").split(";")
reg_val = __salt__['reg.read_value'](
hive='HKEY_CURRENT_USER',
key=r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
vname='ProxyOverride')['vdata']
return bypass_servers
# `reg.read_value` returns None if the key doesn't exist
if reg_val is None:
return []
return reg_val.replace('<local>', '').split(';')
out = __salt__['cmd.run']('networksetup -getproxybypassdomains {0}'.format(network_service))
@ -357,7 +418,12 @@ def set_proxy_win(server, port, types=None, bypass_hosts=None):
The password to use if required by the server
types
The types of proxy connections should be setup with this server. Valid types are http and https.
The types of proxy connections should be setup with this server. Valid
types are:
- ``http``
- ``https``
- ``ftp``
bypass_hosts
The hosts that are allowed to by pass the proxy.
@ -369,7 +435,10 @@ def set_proxy_win(server, port, types=None, bypass_hosts=None):
salt '*' proxy.set_http_proxy example.com 1080 types="['http', 'https']"
'''
if __grains__['os'] == 'Windows':
return _set_proxy_windows(server, port, types, bypass_hosts)
return _set_proxy_windows(server=server,
port=port,
types=types,
bypass_hosts=bypass_hosts)
def get_proxy_win():

View file

@ -225,6 +225,7 @@ def list_users(runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'list_users', '-q'],
reset_system_locale=False,
runas=runas,
python_shell=False)
@ -248,6 +249,7 @@ def list_vhosts(runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'list_vhosts', '-q'],
reset_system_locale=False,
runas=runas,
python_shell=False)
_check_response(res)
@ -322,6 +324,7 @@ def add_user(name, password=None, runas=None):
res = __salt__['cmd.run_all'](
cmd,
reset_system_locale=False,
output_loglevel='quiet',
runas=runas,
python_shell=python_shell)
@ -354,6 +357,7 @@ def delete_user(name, runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'delete_user', name],
reset_system_locale=False,
python_shell=False,
runas=runas)
msg = 'Deleted'
@ -389,6 +393,7 @@ def change_password(name, password, runas=None):
cmd = [RABBITMQCTL, 'change_password', name, password]
res = __salt__['cmd.run_all'](
cmd,
reset_system_locale=False,
runas=runas,
output_loglevel='quiet',
python_shell=python_shell)
@ -411,6 +416,7 @@ def clear_password(name, runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'clear_password', name],
reset_system_locale=False,
runas=runas,
python_shell=False)
msg = 'Password Cleared'
@ -436,7 +442,7 @@ def check_password(name, password, runas=None):
runas = salt.utils.user.get_user()
try:
res = __salt__['cmd.run']([RABBITMQCTL, 'status'], runas=runas, python_shell=False)
res = __salt__['cmd.run']([RABBITMQCTL, 'status'], reset_system_locale=False, runas=runas, python_shell=False)
server_version = re.search(r'\{rabbit,"RabbitMQ","(.+)"\}', res)
if server_version is None:
@ -468,6 +474,7 @@ def check_password(name, password, runas=None):
res = __salt__['cmd.run_all'](
cmd,
reset_system_locale=False,
runas=runas,
output_loglevel='quiet',
python_shell=python_shell)
@ -483,6 +490,7 @@ def check_password(name, password, runas=None):
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'eval', cmd],
reset_system_locale=False,
runas=runas,
output_loglevel='quiet',
python_shell=False)
@ -511,6 +519,7 @@ def add_vhost(vhost, runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'add_vhost', vhost],
reset_system_locale=False,
runas=runas,
python_shell=False)
@ -532,6 +541,7 @@ def delete_vhost(vhost, runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'delete_vhost', vhost],
reset_system_locale=False,
runas=runas,
python_shell=False)
msg = 'Deleted'
@ -553,6 +563,7 @@ def set_permissions(vhost, user, conf='.*', write='.*', read='.*', runas=None):
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'set_permissions', '-p',
vhost, user, conf, write, read],
reset_system_locale=False,
runas=runas,
python_shell=False)
msg = 'Permissions Set'
@ -573,6 +584,7 @@ def list_permissions(vhost, runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'list_permissions', '-q', '-p', vhost],
reset_system_locale=False,
runas=runas,
python_shell=False)
@ -593,6 +605,7 @@ def list_user_permissions(name, runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'list_user_permissions', name, '-q'],
reset_system_locale=False,
runas=runas,
python_shell=False)
@ -616,6 +629,7 @@ def set_user_tags(name, tags, runas=None):
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'set_user_tags', name] + list(tags),
reset_system_locale=False,
runas=runas,
python_shell=False)
msg = "Tag(s) set"
@ -636,6 +650,7 @@ def status(runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'status'],
reset_system_locale=False,
runas=runas,
python_shell=False)
_check_response(res)
@ -656,6 +671,7 @@ def cluster_status(runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'cluster_status'],
reset_system_locale=False,
runas=runas,
python_shell=False)
_check_response(res)
@ -680,7 +696,7 @@ def join_cluster(host, user='rabbit', ram_node=None, runas=None):
if runas is None and not salt.utils.platform.is_windows():
runas = salt.utils.user.get_user()
stop_app(runas)
res = __salt__['cmd.run_all'](cmd, runas=runas, python_shell=False)
res = __salt__['cmd.run_all'](cmd, reset_system_locale=False, runas=runas, python_shell=False)
start_app(runas)
return _format_response(res, 'Join')
@ -700,6 +716,7 @@ def stop_app(runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'stop_app'],
reset_system_locale=False,
runas=runas,
python_shell=False)
_check_response(res)
@ -720,6 +737,7 @@ def start_app(runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'start_app'],
reset_system_locale=False,
runas=runas,
python_shell=False)
_check_response(res)
@ -740,6 +758,7 @@ def reset(runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'reset'],
reset_system_locale=False,
runas=runas,
python_shell=False)
_check_response(res)
@ -760,6 +779,7 @@ def force_reset(runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'force_reset'],
reset_system_locale=False,
runas=runas,
python_shell=False)
_check_response(res)
@ -780,7 +800,7 @@ def list_queues(runas=None, *args):
runas = salt.utils.user.get_user()
cmd = [RABBITMQCTL, 'list_queues', '-q']
cmd.extend(args)
res = __salt__['cmd.run_all'](cmd, runas=runas, python_shell=False)
res = __salt__['cmd.run_all'](cmd, reset_system_locale=False, runas=runas, python_shell=False)
_check_response(res)
return _output_to_dict(res['stdout'])
@ -802,7 +822,7 @@ def list_queues_vhost(vhost, runas=None, *args):
runas = salt.utils.user.get_user()
cmd = [RABBITMQCTL, 'list_queues', '-q', '-p', vhost]
cmd.extend(args)
res = __salt__['cmd.run_all'](cmd, runas=runas, python_shell=False)
res = __salt__['cmd.run_all'](cmd, reset_system_locale=False, runas=runas, python_shell=False)
_check_response(res)
return _output_to_dict(res['stdout'])
@ -825,6 +845,7 @@ def list_policies(vhost="/", runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'list_policies', '-q', '-p', vhost],
reset_system_locale=False,
runas=runas,
python_shell=False)
_check_response(res)
@ -902,7 +923,7 @@ def set_policy(vhost,
if apply_to:
cmd.extend(['--apply-to', apply_to])
cmd.extend([name, pattern, definition])
res = __salt__['cmd.run_all'](cmd, runas=runas, python_shell=False)
res = __salt__['cmd.run_all'](cmd, reset_system_locale=False, runas=runas, python_shell=False)
log.debug('Set policy: %s', res['stdout'])
return _format_response(res, 'Set')
@ -923,6 +944,7 @@ def delete_policy(vhost, name, runas=None):
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'clear_policy', '-p', vhost, name],
reset_system_locale=False,
runas=runas,
python_shell=False)
log.debug('Delete policy: %s', res['stdout'])
@ -960,7 +982,7 @@ def list_available_plugins(runas=None):
if runas is None and not salt.utils.platform.is_windows():
runas = salt.utils.user.get_user()
cmd = [_get_rabbitmq_plugin(), 'list', '-m']
ret = __salt__['cmd.run_all'](cmd, python_shell=False, runas=runas)
ret = __salt__['cmd.run_all'](cmd, reset_system_locale=False, python_shell=False, runas=runas)
_check_response(ret)
return _output_to_list(ret['stdout'])
@ -978,7 +1000,7 @@ def list_enabled_plugins(runas=None):
if runas is None and not salt.utils.platform.is_windows():
runas = salt.utils.user.get_user()
cmd = [_get_rabbitmq_plugin(), 'list', '-m', '-e']
ret = __salt__['cmd.run_all'](cmd, python_shell=False, runas=runas)
ret = __salt__['cmd.run_all'](cmd, reset_system_locale=False, python_shell=False, runas=runas)
_check_response(ret)
return _output_to_list(ret['stdout'])
@ -1011,7 +1033,7 @@ def enable_plugin(name, runas=None):
if runas is None and not salt.utils.platform.is_windows():
runas = salt.utils.user.get_user()
cmd = [_get_rabbitmq_plugin(), 'enable', name]
ret = __salt__['cmd.run_all'](cmd, runas=runas, python_shell=False)
ret = __salt__['cmd.run_all'](cmd, reset_system_locale=False, runas=runas, python_shell=False)
return _format_response(ret, 'Enabled')
@ -1028,5 +1050,5 @@ def disable_plugin(name, runas=None):
if runas is None and not salt.utils.platform.is_windows():
runas = salt.utils.user.get_user()
cmd = [_get_rabbitmq_plugin(), 'disable', name]
ret = __salt__['cmd.run_all'](cmd, runas=runas, python_shell=False)
ret = __salt__['cmd.run_all'](cmd, reset_system_locale=False, runas=runas, python_shell=False)
return _format_response(ret, 'Disabled')

View file

@ -37,6 +37,7 @@ def __virtual__():
'Devuan',
'Arch',
'Arch ARM',
'Manjaro',
'ALT',
'SUSE Enterprise Server',
'SUSE',

View file

@ -933,9 +933,11 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
# Generate jid before triggering a job to subscribe all returns from minions
chunk['jid'] = salt.utils.jid.gen_jid(self.application.opts)
# Subscribe returns from minions before firing a job
minions = set(self.ckminions.check_minions(chunk['tgt'], chunk.get('tgt_type', 'glob')))
future_minion_map = self.subscribe_minion_returns(chunk['jid'], minions)
# start listening for the event before we fire the job to avoid races
events = [
self.application.event_listener.get_event(self, tag='salt/job/'+chunk['jid']),
self.application.event_listener.get_event(self, tag='syndic/job/'+chunk['jid']),
]
f_call = self._format_call_run_job_async(chunk)
# fire a job off
@ -944,88 +946,92 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
# if the job didn't publish, lets not wait around for nothing
# TODO: set header??
if 'jid' not in pub_data:
for future in future_minion_map:
for future in events:
try:
future.set_result(None)
except Exception:
pass
raise tornado.gen.Return('No minions matched the target. No command was sent, no jid was assigned.')
# Map of minion_id -> returned for all minions we think we need to wait on
minions = {m: False for m in pub_data['minions']}
# minimum time required for return to complete. By default no waiting, if
# we are a syndic then we must wait syndic_wait at a minimum
min_wait_time = Future()
min_wait_time.set_result(True)
# wait syndic a while to avoid missing published events
if self.application.opts['order_masters']:
yield tornado.gen.sleep(self.application.opts['syndic_wait'])
min_wait_time = tornado.gen.sleep(self.application.opts['syndic_wait'])
# To ensure job_not_running and all_return are terminated by each other, communicate using a future
is_finished = Future()
is_finished = tornado.gen.sleep(self.application.opts['gather_job_timeout'])
job_not_running_future = self.job_not_running(pub_data['jid'],
# ping until the job is not running, while doing so, if we see new minions returning
# that they are running the job, add them to the list
tornado.ioloop.IOLoop.current().spawn_callback(self.job_not_running, pub_data['jid'],
chunk['tgt'],
f_call['kwargs']['tgt_type'],
minions,
is_finished)
minion_returns_future = self.sanitize_minion_returns(future_minion_map, pub_data['minions'], is_finished)
yield job_not_running_future
raise tornado.gen.Return((yield minion_returns_future))
def subscribe_minion_returns(self, jid, minions):
# Subscribe each minion event
future_minion_map = {}
for minion in minions:
tag = tagify([jid, 'ret', minion], 'job')
minion_future = self.application.event_listener.get_event(self,
tag=tag,
matcher=EventListener.exact_matcher)
future_minion_map[minion_future] = minion
return future_minion_map
@tornado.gen.coroutine
def sanitize_minion_returns(self, future_minion_map, minions, is_finished):
'''
Return a future which will complete once all returns are completed
(according to minions), or one of the passed in "finish_chunk_ret_future" completes
'''
if minions is None:
minions = []
# Remove redundant minions
redundant_minion_futures = [future for future in future_minion_map.keys() if future_minion_map[future] not in minions]
for redundant_minion_future in redundant_minion_futures:
try:
redundant_minion_future.set_result(None)
except Exception:
pass
del future_minion_map[redundant_minion_future]
def more_todo():
'''Check if there are any more minions we are waiting on returns from
'''
return any(x is False for x in six.itervalues(minions))
# here we want to follow the behavior of LocalClient.get_iter_returns
# namely we want to wait at least syndic_wait (assuming we are a syndic)
# and that there are no more jobs running on minions. We are allowed to exit
# early if gather_job_timeout has been exceeded
chunk_ret = {}
while True:
f = yield Any(list(future_minion_map.keys()) + [is_finished])
to_wait = events+[is_finished]
if not min_wait_time.done():
to_wait += [min_wait_time]
def cancel_inflight_futures():
for event in to_wait:
if not event.done():
event.set_result(None)
f = yield Any(to_wait)
try:
# When finished entire routine, cleanup other futures and return result
if f is is_finished:
for event in future_minion_map.keys():
if not event.done():
event.set_result(None)
cancel_inflight_futures()
raise tornado.gen.Return(chunk_ret)
elif f is min_wait_time:
if not more_todo():
cancel_inflight_futures()
raise tornado.gen.Return(chunk_ret)
continue
f_result = f.result()
chunk_ret[f_result['data']['id']] = f_result['data']['return']
# if this is a start, then we need to add it to the pile
if f_result['tag'].endswith('/new'):
for minion_id in f_result['data']['minions']:
if minion_id not in minions:
minions[minion_id] = False
else:
chunk_ret[f_result['data']['id']] = f_result['data']['return']
# clear finished event future
minions[f_result['data']['id']] = True
# if there are no more minions to wait for, then we are done
if not more_todo() and min_wait_time.done():
cancel_inflight_futures()
raise tornado.gen.Return(chunk_ret)
except TimeoutException:
pass
# clear finished event future
try:
minions.remove(future_minion_map[f])
del future_minion_map[f]
except ValueError:
pass
if not minions:
if not is_finished.done():
is_finished.set_result(True)
raise tornado.gen.Return(chunk_ret)
if f == events[0]:
events[0] = self.application.event_listener.get_event(self, tag='salt/job/'+chunk['jid'])
else:
events[1] = self.application.event_listener.get_event(self, tag='syndic/job/'+chunk['jid'])
@tornado.gen.coroutine
def job_not_running(self, jid, tgt, tgt_type, is_finished):
def job_not_running(self, jid, tgt, tgt_type, minions, is_finished):
'''
Return a future which will complete once jid (passed in) is no longer
running on tgt
@ -1051,8 +1057,6 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
event = f.result()
except TimeoutException:
if not minion_running:
if not is_finished.done():
is_finished.set_result(True)
raise tornado.gen.Return(True)
else:
ping_pub_data = yield self.saltclients['local'](tgt,
@ -1066,6 +1070,8 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
# Minions can return, we want to see if the job is running...
if event['data'].get('return', {}) == {}:
continue
if event['data']['id'] not in minions:
minions[event['data']['id']] = False
minion_running = True
@tornado.gen.coroutine

View file

@ -255,7 +255,12 @@ def _disable(name, started, result=True, **kwargs):
return ret
# Service can be disabled
before_toggle_disable_status = __salt__['service.disabled'](name)
if salt.utils.platform.is_windows():
# service.disabled in Windows returns True for services that are set to
# Manual start, so we need to check specifically for Disabled
before_toggle_disable_status = __salt__['service.info'](name)['StartType'] in ['Disabled']
else:
before_toggle_disable_status = __salt__['service.disabled'](name)
if before_toggle_disable_status:
# Service is disabled
if started is True:
@ -556,7 +561,12 @@ def dead(name,
# command, so it is just an indicator but can not be fully trusted
before_toggle_status = __salt__['service.status'](name, sig)
if 'service.enabled' in __salt__:
before_toggle_enable_status = __salt__['service.enabled'](name)
if salt.utils.platform.is_windows():
# service.enabled in Windows returns True for services that are set
# to Auto start, but services set to Manual can also be disabled
before_toggle_enable_status = __salt__['service.info'](name)['StartType'] in ['Auto', 'Manual']
else:
before_toggle_enable_status = __salt__['service.enabled'](name)
else:
before_toggle_enable_status = True

View file

@ -142,7 +142,7 @@ def accept_dict(match, include_rejected=False, include_denied=False):
.. code-block:: python
>>> wheel.cmd('accept_dict',
>>> wheel.cmd('key.accept_dict',
{
'minions_pre': [
'jerry',

View file

@ -264,6 +264,10 @@ class TestSaltAPIHandler(_SaltnadoIntegrationTestCase):
'tgt': '*',
'fun': 'test.ping',
}
self.application.opts['order_masters'] = True
self.application.opts['syndic_wait'] = 5
response = self.fetch('/',
method='POST',
body=salt.utils.json.dumps(low),

View file

@ -126,65 +126,56 @@ class ProxyTestCase(TestCase, LoaderModuleMockMixin):
def test_get_http_proxy_windows(self):
'''
Test to make sure that we correctly get the current proxy info
on Windows
Test to make sure that we correctly get the current proxy info on
Windows
'''
result = {'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'}
mock = MagicMock(return_value=result)
expected = {'server': '192.168.0.1',
'port': '3128'}
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
result = {
'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'
}
mock = MagicMock(return_value=result)
expected = {
'server': '192.168.0.1',
'port': '3128'
}
with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
out = proxy.get_http_proxy()
mock.assert_called_once_with('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer')
mock.assert_called_once_with(
hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer')
self.assertEqual(expected, out)
def test_get_https_proxy_windows(self):
'''
Test to make sure that we correctly get the current proxy info
on Windows
Test to make sure that we correctly get the current proxy info on
Windows
'''
result = {'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'}
mock = MagicMock(return_value=result)
expected = {'server': '192.168.0.2',
'port': '3128'}
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
result = {
'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'
}
mock = MagicMock(return_value=result)
expected = {
'server': '192.168.0.2',
'port': '3128'
}
with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
out = proxy.get_https_proxy()
mock.assert_called_once_with('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer')
mock.assert_called_once_with(
hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer')
self.assertEqual(expected, out)
def test_get_ftp_proxy_windows(self):
'''
Test to make sure that we correctly get the current proxy info
on Windows
Test to make sure that we correctly get the current proxy info on
Windows
'''
result = {'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'}
mock = MagicMock(return_value=result)
expected = {'server': '192.168.0.3',
'port': '3128'}
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
result = {
'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'
}
mock = MagicMock(return_value=result)
expected = {
'server': '192.168.0.3',
'port': '3128'
}
with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
out = proxy.get_ftp_proxy()
mock.assert_called_once_with('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer')
mock.assert_called_once_with(
hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer')
self.assertEqual(expected, out)
def test_get_all_proxies_macos_fails(self):
@ -196,201 +187,179 @@ class ProxyTestCase(TestCase, LoaderModuleMockMixin):
def test_get_all_proxies_windows(self):
'''
Test to make sure that we correctly get the current proxy info
on Windows
Test to make sure that we correctly get the current proxy info on
Windows
'''
results = [{'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'},
{'vdata': 1}]
mock = MagicMock(side_effect=results)
expected = {'enabled': True,
'http': {'server': '192.168.0.1',
'port': '3128'},
'https': {'server': '192.168.0.2',
'port': '3128'},
'ftp': {'server': '192.168.0.3',
'port': '3128'}}
calls = [
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyEnable')]
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
results = [
{
'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'
},
{
'vdata': 1
}
]
mock = MagicMock(side_effect=results)
expected = {
'enabled': True,
'http': {
'server': '192.168.0.1',
'port': '3128'
},
'https': {
'server': '192.168.0.2',
'port': '3128'
},
'ftp': {
'server': '192.168.0.3',
'port': '3128'
}
}
with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
out = proxy.get_proxy_win()
calls = [
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyEnable'),
]
mock.assert_has_calls(calls)
self.assertEqual(expected, out)
def test_set_http_proxy_windows(self):
'''
Test to make sure that we correctly set the proxy info
on Windows
Test to make sure that we correctly set the proxy info on Windows
'''
calls = [
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer',
vdata='http=192.168.0.1:3128;'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyEnable',
vdata=1,
vtype='REG_DWORD'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyOverride',
vdata='<local>;.moo.com;.salt.com')]
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}):
out = proxy.set_http_proxy('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com'])
calls = [
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer',
'http=192.168.0.1:3128;'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyEnable',
1,
vtype='REG_DWORD'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyOverride',
'<local>;.moo.com;.salt.com')
]
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg,
'cmd.run': mock_cmd}):
out = proxy.set_http_proxy(server='192.168.0.1',
port=3128,
bypass_hosts=['.moo.com', '.salt.com'])
mock_reg.assert_has_calls(calls)
mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie')
self.assertTrue(out)
def test_set_https_proxy_windows(self):
'''
Test to make sure that we correctly set the proxy info
on Windows
Test to make sure that we correctly set the proxy info on Windows
'''
calls = [
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer',
vdata='https=192.168.0.1:3128;'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyEnable',
vdata=1,
vtype='REG_DWORD'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyOverride',
vdata='<local>;.moo.com;.salt.com')]
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}):
out = proxy.set_https_proxy('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com'])
calls = [
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer',
'https=192.168.0.1:3128;'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyEnable',
1,
vtype='REG_DWORD'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyOverride',
'<local>;.moo.com;.salt.com')
]
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg,
'cmd.run': mock_cmd}):
out = proxy.set_https_proxy(server='192.168.0.1',
port=3128,
bypass_hosts=['.moo.com', '.salt.com'])
mock_reg.assert_has_calls(calls)
mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie')
self.assertTrue(out)
def test_set_ftp_proxy_windows(self):
'''
Test to make sure that we correctly set the proxy info
on Windows
Test to make sure that we correctly set the proxy info on Windows
'''
calls = [
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer',
vdata='ftp=192.168.0.1:3128;'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyEnable',
vdata=1,
vtype='REG_DWORD'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyOverride',
vdata='<local>;.moo.com;.salt.com')]
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}):
out = proxy.set_ftp_proxy('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com'])
calls = [
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer',
'ftp=192.168.0.1:3128;'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyEnable',
1,
vtype='REG_DWORD'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyOverride',
'<local>;.moo.com;.salt.com')
]
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg,
'cmd.run': mock_cmd}):
out = proxy.set_ftp_proxy(server='192.168.0.1',
port=3128,
bypass_hosts=['.moo.com', '.salt.com'])
mock_reg.assert_has_calls(calls)
mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie')
self.assertTrue(out)
def test_set_proxy_windows(self):
'''
Test to make sure that we correctly set the proxy info
on Windows
Test to make sure that we correctly set the proxy info on Windows
'''
calls = [
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer',
vdata='http=192.168.0.1:3128;https=192.168.0.1:3128;ftp=192.168.0.1:3128;'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyEnable',
vdata=1,
vtype='REG_DWORD'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyOverride',
vdata='<local>;.moo.com;.salt.com')]
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}):
out = proxy.set_proxy_win('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com'])
calls = [
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer',
'http=192.168.0.1:3128;https=192.168.0.1:3128;ftp=192.168.0.1:3128;'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyEnable',
1,
vtype='REG_DWORD'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyOverride',
'<local>;.moo.com;.salt.com')
]
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg,
'cmd.run': mock_cmd}):
out = proxy.set_proxy_win(server='192.168.0.1',
port=3128,
bypass_hosts=['.moo.com', '.salt.com'])
mock_reg.assert_has_calls(calls)
mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie')
self.assertTrue(out)
def test_set_proxy_windows_no_ftp(self):
'''
Test to make sure that we correctly set the proxy info
on Windows
Test to make sure that we correctly set the proxy info on Windows
'''
calls = [
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyServer',
vdata='http=192.168.0.1:3128;https=192.168.0.1:3128;'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyEnable',
vdata=1,
vtype='REG_DWORD'),
call(hive='HKEY_CURRENT_USER',
key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
vname='ProxyOverride',
vdata='<local>;.moo.com;.salt.com')]
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__grains__, {'os': 'Windows'}):
mock_reg = MagicMock()
mock_cmd = MagicMock()
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}):
out = proxy.set_proxy_win('192.168.0.1', 3128, types=['http', 'https'],
with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg,
'cmd.run': mock_cmd}):
out = proxy.set_proxy_win(server='192.168.0.1',
port=3128,
types=['http', 'https'],
bypass_hosts=['.moo.com', '.salt.com'])
calls = [
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyServer',
'http=192.168.0.1:3128;https=192.168.0.1:3128;'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyEnable',
1,
vtype='REG_DWORD'),
call('HKEY_CURRENT_USER',
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
'ProxyOverride',
'<local>;.moo.com;.salt.com')
]
mock_reg.assert_has_calls(calls)
mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie')
self.assertTrue(out)