Merge pull request #34404 from rallytime/merge-2016.3

[2016.3] Merge forward from 2015.8 to 2016.3
This commit is contained in:
Nicole Thomas 2016-07-01 11:02:09 -04:00 committed by GitHub
commit d1cd36ab2b
9 changed files with 304 additions and 23 deletions

View File

@ -59,6 +59,15 @@ QuickStart
The :ref:`Salt Cloud Quickstart <salt-cloud-qs>` walks you through defining
a provider, a VM profile, and shows you how to create virtual machines using Salt Cloud.
Note that if you installed Salt via `Salt Bootstrap`_, it may not have
automatically installed salt-cloud for you. Use your distribution's package
manager to install the ``salt-cloud`` package from the same repo that you
used to install Salt. These repos will automatically be setup by Salt Bootstrap.
If there is no salt-cloud package, install with ``pip install salt-cloud``.
.. _`Salt Bootstrap`: https://github.com/saltstack/salt-bootstrap
Using Salt Cloud
================
.. toctree::

View File

@ -5,8 +5,16 @@ Salt Cloud Quickstart
=====================
Salt Cloud is built-in to Salt, and the easiest way to run Salt Cloud is
directly from your Salt Master. On most platforms you can install the
``salt-cloud`` package from the same repo that you used to install Salt.
directly from your Salt Master.
Note that if you installed Salt via `Salt Bootstrap`_, it may not have
automatically installed salt-cloud for you. Use your distribution's package
manager to install the ``salt-cloud`` package from the same repo that you
used to install Salt. These repos will automatically be setup by Salt Bootstrap.
If there is no salt-cloud package, install with ``pip install salt-cloud``.
.. _`Salt Bootstrap`: https://github.com/saltstack/salt-bootstrap
This quickstart walks you through the basic steps of setting up a cloud host
and defining some virtual machines to create.

View File

@ -1021,6 +1021,10 @@ def installed(
pkg.installed:
- only_upgrade: True
.. note::
If this parameter is set to True and the package is not already
installed, the state will fail.
:return:
A dictionary containing the state of the software installation
:rtype dict:
@ -1557,6 +1561,9 @@ def latest(
pkg.latest:
- only_upgrade: True
.. note::
If this parameter is set to True and the package is not already
installed, the state will fail.
'''
rtag = __gen_rtag()
refresh = bool(

View File

@ -0,0 +1,6 @@
dummy0:
network.managed:
- enabled: True
- type: eth
- ipaddr: 10.1.0.1
- netmask: 255.255.255.0

View File

@ -0,0 +1,8 @@
routes:
network.routes:
- name: dummy0
- routes:
- name: secure_network
ipaddr: 10.2.0.0
netmask: 255.255.255.0
gateway: 10.1.0.3

View File

@ -0,0 +1,6 @@
system:
network.system:
- enabled: True
- hostname: server1.example.com
- gateway: 10.1.0.1
- gatewaydev: dummy0

View File

@ -1,3 +0,0 @@
nova_packages:
pkg.latest:
- name: bash-completion

View File

@ -0,0 +1,89 @@
# -*- encoding: utf-8 -*-
'''
:codeauthor: :email: `Justin Anderson <janderson@saltstack.com>`
tests.integration.states.network
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'''
# Python libs
from __future__ import absolute_import
# Salt libs
import integration
import salt.utils
# Salttesting libs
from salttesting import skipIf
from salttesting.helpers import destructiveTest, ensure_in_syspath
ensure_in_syspath('../../')
def _check_arch_linux():
with salt.utils.fopen('/etc/os-release', 'r') as f:
release = f.readline()
r = release.split('=')[1].strip().strip('"')
return r
@destructiveTest
@skipIf(_check_arch_linux() == 'Arch Linux', 'Network state not supported on Arch')
class NetworkTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
'''
Validate network state module
'''
def setUp(self):
self.run_function('cmd.run', ['ip link add name dummy0 type dummy'])
def tearDown(self):
self.run_function('cmd.run', ['ip link delete dev dummy0'])
def test_managed(self):
'''
network.managed
'''
if_name = 'dummy0'
ipaddr = '10.1.0.1'
netmask = '255.255.255.0'
broadcast = '10.1.0.255'
expected_if_ret = [{
"broadcast": broadcast,
"netmask": netmask,
"label": if_name,
"address": ipaddr
}]
ret = self.run_function('state.sls', mods='network.managed')
self.assertSaltTrueReturn(ret)
interface = self.run_function('network.interface', [if_name])
self.assertEqual(interface, expected_if_ret)
def test_routes(self):
'''
network.routes
'''
state_key = 'network_|-routes_|-dummy0_|-routes'
expected_changes = {'network_routes': 'Added interface dummy0 routes.'}
ret = self.run_function('state.sls', mods='network.routes')
self.assertSaltTrueReturn(ret)
self.assertEqual(ret[state_key]['changes'], expected_changes)
def test_system(self):
'''
network.system
'''
state_key = 'network_|-system_|-system_|-system'
ret = self.run_function('state.sls', mods='network.system')
self.assertSaltTrueReturn(ret)
self.assertIn('network_settings', ret[state_key]['changes'])
if __name__ == '__main__':
from integration import run_tests
run_tests(NetworkTest)

View File

@ -5,6 +5,7 @@ tests for pkg state
'''
# Import python libs
from __future__ import absolute_import
import logging
import os
import time
@ -25,6 +26,10 @@ import salt.utils
# Import 3rd-party libs
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
log = logging.getLogger(__name__)
__testcontext__ = {}
_PKG_TARGETS = {
'Arch': ['python2-django', 'libpng'],
'Debian': ['python-plist', 'apg'],
@ -110,6 +115,32 @@ def pkgmgr_avail(run_function, grains):
return True
def latest_version(run_function, *names):
'''
Helper function which ensures that we don't make any unnecessary calls to
pkg.latest_version to figure out what version we need to install. This
won't stop pkg.latest_version from being run in a pkg.latest state, but it
will reduce the amount of times we check the latest version here in the
test suite.
'''
key = 'latest_version'
if key not in __testcontext__:
__testcontext__[key] = {}
targets = [x for x in names if x not in __testcontext__[key]]
if targets:
result = run_function('pkg.latest_version', targets, refresh=False)
try:
__testcontext__[key].update(result)
except ValueError:
# Only a single target, pkg.latest_version returned a string
__testcontext__[key][targets[0]] = result
ret = dict([(x, __testcontext__[key][x]) for x in names])
if len(names) == 1:
return ret[names[0]]
return ret
@destructiveTest
@requires_salt_modules('pkg.version', 'pkg.latest_version')
class PkgTest(integration.ModuleCase,
@ -117,6 +148,15 @@ class PkgTest(integration.ModuleCase,
'''
pkg.installed state tests
'''
def setUp(self):
'''
Ensure that we only refresh the first time we run a test
'''
super(PkgTest, self).setUp()
if 'refresh' not in __testcontext__:
self.run_function('pkg.refresh_db')
__testcontext__['refresh'] = True
@skipIf(salt.utils.is_windows(), 'minion is windows')
@requires_system_grains
def test_pkg_001_installed(self, grains=None):
@ -143,7 +183,7 @@ class PkgTest(integration.ModuleCase,
# needs to not be installed before we run the states below
self.assertFalse(version)
ret = self.run_state('pkg.installed', name=target)
ret = self.run_state('pkg.installed', name=target, refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=target)
self.assertSaltTrueReturn(ret)
@ -181,14 +221,17 @@ class PkgTest(integration.ModuleCase,
time.sleep(5)
target = pkg_targets[0]
version = self.run_function('pkg.latest_version', [target])
version = latest_version(self.run_function, target)
# If this assert fails, we need to find new targets, this test needs to
# be able to test successful installation of packages, so this package
# needs to not be installed before we run the states below
self.assertTrue(version)
ret = self.run_state('pkg.installed', name=target, version=version)
ret = self.run_state('pkg.installed',
name=target,
version=version,
refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=target)
self.assertSaltTrueReturn(ret)
@ -217,7 +260,10 @@ class PkgTest(integration.ModuleCase,
# packages need to not be installed before we run the states below
self.assertFalse(any(version.values()))
ret = self.run_state('pkg.installed', name=None, pkgs=pkg_targets)
ret = self.run_state('pkg.installed',
name=None,
pkgs=pkg_targets,
refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=None, pkgs=pkg_targets)
self.assertSaltTrueReturn(ret)
@ -254,7 +300,7 @@ class PkgTest(integration.ModuleCase,
break
time.sleep(5)
version = self.run_function('pkg.latest_version', [pkg_targets[0]])
version = latest_version(self.run_function, pkg_targets[0])
# If this assert fails, we need to find new targets, this test needs to
# be able to test successful installation of packages, so these
@ -263,7 +309,10 @@ class PkgTest(integration.ModuleCase,
pkgs = [{pkg_targets[0]: version}, pkg_targets[1]]
ret = self.run_state('pkg.installed', name=None, pkgs=pkgs)
ret = self.run_state('pkg.installed',
name=None,
pkgs=pkgs,
refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=None, pkgs=pkg_targets)
self.assertSaltTrueReturn(ret)
@ -298,7 +347,9 @@ class PkgTest(integration.ModuleCase,
# below
self.assertFalse(bool(version))
ret = self.run_state('pkg.installed', name=target)
ret = self.run_state('pkg.installed',
name=target,
refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=target)
self.assertSaltTrueReturn(ret)
@ -334,7 +385,7 @@ class PkgTest(integration.ModuleCase,
and grains['osrelease'].startswith('5.'):
target = target.replace('.i686', '.i386')
version = self.run_function('pkg.latest_version', [target])
version = latest_version(self.run_function, target)
# If this assert fails, we need to find a new target. This test
# needs to be able to test successful installation of the package, so
@ -342,7 +393,10 @@ class PkgTest(integration.ModuleCase,
# below
self.assertTrue(bool(version))
ret = self.run_state('pkg.installed', name=target, version=version)
ret = self.run_state('pkg.installed',
name=target,
version=version,
refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=target)
self.assertSaltTrueReturn(ret)
@ -364,20 +418,20 @@ class PkgTest(integration.ModuleCase,
os_version = grains.get('osmajorrelease', [''])[0]
target = _PKG_TARGETS_DOT.get(os_family, {}).get(os_version)
if target:
version = self.run_function('pkg.latest_version', [target])
version = latest_version(self.run_function, target)
# If this assert fails, we need to find a new target. This test
# needs to be able to test successful installation of the package, so
# the target needs to not be installed before we run the
# pkg.installed state below
self.assertTrue(bool(version))
ret = self.run_state('pkg.installed', name=target)
ret = self.run_state('pkg.installed', name=target, refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=target)
self.assertSaltTrueReturn(ret)
@skipIf(salt.utils.is_windows(), 'minion is windows')
@requires_system_grains
def test_pkg_with_epoch_in_version(self, grains=None):
def test_pkg_008_epoch_in_version(self, grains=None):
'''
This tests for the regression found in the following issue:
https://github.com/saltstack/salt/issues/8614
@ -392,20 +446,22 @@ class PkgTest(integration.ModuleCase,
os_version = grains.get('osmajorrelease', [''])[0]
target = _PKG_TARGETS_EPOCH.get(os_family, {}).get(os_version)
if target:
version = self.run_function('pkg.latest_version', [target])
version = latest_version(self.run_function, target)
# If this assert fails, we need to find a new target. This test
# needs to be able to test successful installation of the package, so
# the target needs to not be installed before we run the
# pkg.installed state below
self.assertTrue(bool(version))
ret = self.run_state('pkg.installed', name=target, version=version)
ret = self.run_state('pkg.installed',
name=target,
version=version,
refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=target)
self.assertSaltTrueReturn(ret)
@destructiveTest
@skipIf(salt.utils.is_windows(), 'minion is windows')
def test_pkg_008_latest_with_epoch(self):
def test_pkg_009_latest_with_epoch(self):
'''
This tests for the following issue:
https://github.com/saltstack/salt/issues/31014
@ -416,11 +472,14 @@ class PkgTest(integration.ModuleCase,
if not pkgmgr_avail(self.run_function, self.run_function('grains.items')):
self.skipTest('Package manager is not available')
ret = self.run_function('state.sls', mods='pkg_latest_epoch')
ret = self.run_state('pkg.installed',
name='bash-completion',
refresh=False)
self.assertSaltTrueReturn(ret)
@skipIf(salt.utils.is_windows(), 'minion is windows')
@requires_salt_modules('pkg.info_installed')
def test_pkg_009_latest_with_epoch_and_info_installed(self):
def test_pkg_010_latest_with_epoch_and_info_installed(self):
'''
Need to check to ensure the package has been
installed after the pkg_latest_epoch sls
@ -438,6 +497,98 @@ class PkgTest(integration.ModuleCase,
ret = self.run_function('pkg.info_installed', [package])
self.assertTrue(pkgquery in str(ret))
@skipIf(salt.utils.is_windows(), 'minion is windows')
@requires_system_grains
def test_pkg_011_latest(self, grains=None):
'''
This tests pkg.latest with a package that has no epoch (or a zero
epoch).
'''
# Skip test if package manager not available
if not pkgmgr_avail(self.run_function, self.run_function('grains.items')):
self.skipTest('Package manager is not available')
os_family = grains.get('os_family', '')
pkg_targets = _PKG_TARGETS.get(os_family, [])
# Make sure that we have targets that match the os_family. If this
# fails then the _PKG_TARGETS dict above needs to have an entry added,
# with two packages that are not installed before these tests are run
self.assertTrue(pkg_targets)
target = pkg_targets[0]
version = latest_version(self.run_function, target)
# If this assert fails, we need to find new targets, this test needs to
# be able to test successful installation of packages, so this package
# needs to not be installed before we run the states below
self.assertTrue(version)
ret = self.run_state('pkg.latest', name=target, refresh=False)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pkg.removed', name=target)
self.assertSaltTrueReturn(ret)
@skipIf(salt.utils.is_windows(), 'minion is windows')
@requires_system_grains
def test_pkg_012_latest_only_upgrade(self, grains=None):
'''
WARNING: This test will pick a package with an available upgrade (if
there is one) and upgrade it to the latest version.
'''
os_family = grains.get('os_family', '')
if os_family != 'Debian':
self.skipTest('Minion is not Debian/Ubuntu')
# Skip test if package manager not available
if not pkgmgr_avail(self.run_function, self.run_function('grains.items')):
self.skipTest('Package manager is not available')
pkg_targets = _PKG_TARGETS.get(os_family, [])
# Make sure that we have targets that match the os_family. If this
# fails then the _PKG_TARGETS dict above needs to have an entry added,
# with two packages that are not installed before these tests are run
self.assertTrue(pkg_targets)
target = pkg_targets[0]
version = latest_version(self.run_function, target)
# If this assert fails, we need to find new targets, this test needs to
# be able to test that the state fails when you try to run the state
# with only_upgrade=True on a package which is not already installed,
# so the targeted package needs to not be installed before we run the
# state below.
self.assertTrue(version)
ret = self.run_state('pkg.latest', name=target, refresh=False,
only_upgrade=True)
self.assertSaltFalseReturn(ret)
# Now look for updates and try to run the state on a package which is
# already up-to-date.
updates = self.run_function('pkg.list_upgrades', refresh=False)
try:
target = next(iter(updates))
except StopIteration:
log.warning(
'No available upgrades, skipping only_upgrade=True test with '
'already-installed package. For best results run this test '
'on a machine with upgrades available.'
)
else:
ret = self.run_state('pkg.latest', name=target, refresh=False,
only_upgrade=True)
self.assertSaltTrueReturn(ret)
new_version = self.run_function('pkg.version', [target])
self.assertEqual(new_version, updates[target])
ret = self.run_state('pkg.latest', name=target, refresh=False,
only_upgrade=True)
self.assertEqual(
ret['pkg_|-{0}_|-{0}_|-latest'.format(target)]['comment'],
'Package {0} is already up-to-date'.format(target)
)
if __name__ == '__main__':
from integration import run_tests
run_tests(PkgTest)