Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherrybomb] MTecknology's Masterless Contributions #56353

Merged
merged 35 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
44ab785
Cherry-pick from #50070
MTecknology Oct 16, 2018
a2eadd7
[cherry bomb] Move listen docs into correct section underneath watch.
MTecknology Oct 9, 2018
252a6c0
Move "require entire sls" underneath relevant section
MTecknology Oct 9, 2018
48c52df
Simplify laguage in Requisites summary
MTecknology Oct 9, 2018
0ecb6e8
Clean up explanation of <requisite>_in; merge multiple explanations
MTecknology Oct 9, 2018
c0732b1
Remove confusing table; Relocate sections
MTecknology Oct 10, 2018
b0cc185
Move more sections; Clean up headings
MTecknology Oct 10, 2018
17f8542
Move description of _any requisites into one section
MTecknology Oct 10, 2018
a9f205d
Clean up requisite definitions/examples
MTecknology Oct 16, 2018
0a7666e
Move onchanges above watch; help deprecate preference of watch
MTecknology Oct 16, 2018
2f82663
Fix typo & jinja mistake
MTecknology Oct 16, 2018
30cd8e8
Improve requisite short descriptions
MTecknology Oct 16, 2018
c3a7a6d
[refactor] modules.debian_ip._parse_settings_eth() (Fixes: #46388)
MTecknology Aug 30, 2018
f5f685e
Add new unit tests; fix existing tests.
MTecknology Aug 31, 2018
5abe823
[refactor] templates/debian_ip/debian_eth.jinja
MTecknology Aug 31, 2018
050e6da
Remove duplicate option from dictionary.
MTecknology Aug 31, 2018
1c5d08a
Add tests verifying -enable_ip{4,6}:False removes inet block.
MTecknology Aug 31, 2018
a5f89f5
Add many unit tests for debian_ip.get_interface().
MTecknology Sep 1, 2018
170dbe6
Add many unit tests for debian_ip._parse_interfaces().
MTecknology Sep 1, 2018
eebaf5c
Make remaining keys more flexible. Make debian_ip read all IPv6 optio…
MTecknology Sep 1, 2018
2679475
Fix more debian_ip bugs (and other improvements).
MTecknology Sep 1, 2018
883dca1
pylint typo
MTecknology Mar 10, 2020
b1fdfaf
Document behavior change in the debian_ip module.
MTecknology Oct 3, 2018
7e06e64
Improve explanation of changes in debian_ip module.
MTecknology Oct 4, 2018
fd5954d
Fix documentation for states.file.not_cached. (Fixes: #49203)
MTecknology Sep 2, 2018
632427e
Update states.user docs to prefer sha256 over md5. (Fixes: 48778)
MTecknology Sep 2, 2018
91c8095
Fix post-pick issues
MTecknology Mar 11, 2020
06fd4ad
Remove obsolete file; merge relevant information into new notes.
MTecknology Mar 12, 2020
a2f51db
Improve handling of input. Thanks waynew! #51343
MTecknology Mar 17, 2020
a7d0e89
Work through all the fun merge conflicts...
MTecknology Apr 17, 2020
657c510
Re-apply formatting changes that caused the conflicts
MTecknology Apr 17, 2020
e53c567
Re-apply further prettification changes
MTecknology Apr 17, 2020
bbaefb2
Modify source to fix failing test
MTecknology Apr 18, 2020
6b6beb4
Merge branch 'master' into master
waynew Apr 21, 2020
39af7c6
Merged salt/master
waynew Apr 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
871 changes: 374 additions & 497 deletions doc/ref/states/requisites.rst

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions doc/topics/releases/3000.rst
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,16 @@ Module Changes
fixed to remove file system entries other than files, directories
and symbolic links properly.

- The :py:func:`debian_ip <salt.modules.debian_ip>` module used by the
:py:func:`network.managed <salt.states.network.managed>` state has been
heavily refactored. The order that options appear in inet/inet6 blocks may
produce cosmetic changes. Many options without an 'ipvX' prefix will now be
shared between inet and inet6 blocks. The options ``enable_ipv4`` and
``enabled_ipv6`` will now fully remove relevant inet/inet6 blocks. Overriding
options by prefixing them with 'ipvX' will now work with most options (i.e.
``dns`` can be overriden by ``ipv4dns`` or ``ipv6dns``). The ``proto`` option
is now required.


Enhancements to Engines
=======================
Expand Down
259 changes: 100 additions & 159 deletions salt/modules/debian_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def __space_delimited_list(value):
#
"network": __anything, # i don't know what this is
"test": __anything, # TODO
"enable_ipv4": __anything, # TODO
"enable_ipv6": __anything, # TODO
}

Expand Down Expand Up @@ -503,6 +504,7 @@ def __space_delimited_list(value):
#
"vlan-raw-device": __anything,
"test": __anything, # TODO
"enable_ipv4": __anything, # TODO
"enable_ipv6": __anything, # TODO
}

Expand Down Expand Up @@ -700,10 +702,13 @@ def _parse_interfaces(interface_files=None):
adapters.pop(iface_name)
continue
for opt in ["ethtool", "bonding", "bridging"]:
if "inet" in adapters[iface_name]["data"]:
if opt in adapters[iface_name]["data"]["inet"]:
opt_keys = sorted(adapters[iface_name]["data"]["inet"][opt].keys())
adapters[iface_name]["data"]["inet"][opt + "_keys"] = opt_keys
for inet in ["inet", "inet6"]:
if inet in adapters[iface_name]["data"]:
if opt in adapters[iface_name]["data"][inet]:
opt_keys = sorted(
adapters[iface_name]["data"][inet][opt].keys()
)
adapters[iface_name]["data"][inet][opt + "_keys"] = opt_keys

return adapters

Expand Down Expand Up @@ -1254,148 +1259,92 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
if opts.get("hotplug", False):
adapters[iface]["hotplug"] = True

# Defaults assume IPv4 (inet) interfaces unless enable_ipv6=True
def_addrfam = "inet"
dual_stack = False

# If enable_ipv6=True, then expet either IPv6-only or dual stack.
if "enable_ipv6" in opts and opts["enable_ipv6"]:
iface_data["inet6"]["addrfam"] = "inet6"
iface_data["inet6"]["netmask"] = "64" # defaults to 64
def_addrfam = "inet6"
if opts.get("enable_ipv6", None) and opts.get("iface_type", "") == "vlan":
iface_data["inet6"]["vlan_raw_device"] = re.sub(r"\.\d*", "", iface)

if "iface_type" in opts and opts["iface_type"] == "vlan":
iface_data["inet6"]["vlan_raw_device"] = re.sub(r"\.\d*", "", iface)

if "ipaddr" in opts and "ipv6ipaddr" in opts:
# If both 'ipaddr' and 'ipv6ipaddr' are present; expect dual stack
for addrfam in ["inet", "inet6"]:
if iface_type not in ["bridge"]:
tmp_ethtool = _parse_ethtool_opts(opts, iface)
if tmp_ethtool:
ethtool = {}
for item in tmp_ethtool:
ethtool[_ETHTOOL_CONFIG_OPTS[item]] = tmp_ethtool[item]

iface_data[addrfam]["ethtool"] = ethtool
# return a list of sorted keys to ensure consistent order
iface_data[addrfam]["ethtool_keys"] = sorted(ethtool)

if iface_type == "bridge":
bridging = _parse_bridge_opts(opts, iface)
if bridging:
iface_data[addrfam]["bridging"] = bridging
iface_data[addrfam]["bridging_keys"] = sorted(bridging)
iface_data[addrfam]["addrfam"] = addrfam

elif iface_type == "bond":
bonding = _parse_settings_bond(opts, iface)
if bonding:
iface_data[addrfam]["bonding"] = bonding
iface_data[addrfam]["bonding"]["slaves"] = opts["slaves"]
iface_data[addrfam]["bonding_keys"] = sorted(bonding)
iface_data[addrfam]["addrfam"] = addrfam

elif iface_type == "slave":
adapters[iface]["master"] = opts["master"]

opts["proto"] = "manual"
iface_data[addrfam]["master"] = adapters[iface]["master"]
iface_data[addrfam]["addrfam"] = addrfam

elif iface_type == "vlan":
iface_data[addrfam]["vlan_raw_device"] = re.sub(r"\.\d*", "", iface)
iface_data[addrfam]["addrfam"] = addrfam

elif iface_type == "pppoe":
tmp_ethtool = _parse_ethtool_pppoe_opts(opts, iface)
if tmp_ethtool:
for item in tmp_ethtool:
adapters[iface]["data"][addrfam][
_DEB_CONFIG_PPPOE_OPTS[item]
] = tmp_ethtool[item]
iface_data[addrfam]["addrfam"] = addrfam

opts.pop("mode", None)

for opt, val in opts.items():
inet = None
if opt.startswith("ipv4"):
opt = opt[4:]
inet = "inet"
iface_data["inet"]["addrfam"] = "inet"
def_addrfam = "inet"
dual_stack = True

else:
# If enable_ipv6=False|None, IPv6 settings should not be set.
iface_data["inet"]["addrfam"] = "inet"

if iface_type not in ["bridge"]:
tmp_ethtool = _parse_ethtool_opts(opts, iface)
if tmp_ethtool:
ethtool = {}
for item in tmp_ethtool:
ethtool[_ETHTOOL_CONFIG_OPTS[item]] = tmp_ethtool[item]

iface_data[def_addrfam]["ethtool"] = ethtool
# return a list of sorted keys to ensure consistent order
iface_data[def_addrfam]["ethtool_keys"] = sorted(ethtool)

if iface_type == "bridge":
bridging = _parse_bridge_opts(opts, iface)
if bridging:
opts.pop("mode", None)
iface_data[def_addrfam]["bridging"] = bridging
iface_data[def_addrfam]["bridging_keys"] = sorted(bridging)
iface_data[def_addrfam]["addrfam"] = def_addrfam

elif iface_type == "bond":
bonding = _parse_settings_bond(opts, iface)
if bonding:
opts.pop("mode", None)
iface_data[def_addrfam]["bonding"] = bonding
iface_data[def_addrfam]["bonding"]["slaves"] = opts["slaves"]
iface_data[def_addrfam]["bonding_keys"] = sorted(bonding)
iface_data[def_addrfam]["addrfam"] = def_addrfam

elif iface_type == "slave":
adapters[iface]["master"] = opts["master"]

opts["proto"] = "manual"
iface_data[def_addrfam]["master"] = adapters[iface]["master"]
iface_data[def_addrfam]["addrfam"] = def_addrfam

elif iface_type == "vlan":
iface_data[def_addrfam]["vlan_raw_device"] = re.sub(r"\.\d*", "", iface)
iface_data[def_addrfam]["addrfam"] = def_addrfam

elif iface_type == "pppoe":
tmp_ethtool = _parse_ethtool_pppoe_opts(opts, iface)
if tmp_ethtool:
for item in tmp_ethtool:
adapters[iface]["data"][def_addrfam][
_DEB_CONFIG_PPPOE_OPTS[item]
] = tmp_ethtool[item]
iface_data[def_addrfam]["addrfam"] = def_addrfam

for opt in opts:
# trim leading "ipv6" from option
if opt.startswith("ipv6"):
optname = opt[4:] # trim off the ipv6
v6only = True
else:
optname = opt
v6only = False

_optname = SALT_ATTR_TO_DEBIAN_ATTR_MAP.get(optname, optname)
if _attrmaps_contain_attr(_optname):
valuestr = opts[opt]

# default to 'static' if proto is 'none'
if optname == "proto" and valuestr == "none":
valuestr = "static"

# If option is v6-only, don't validate against inet and always set value
if v6only:
(valid, value, errmsg) = _validate_interface_option(
_optname, valuestr, addrfam="inet6"
)

if not valid:
_raise_error_iface(
iface, "'{0}' '{1}'".format(opt, valuestr), [errmsg]
)

# replace dashes with underscores for jinja
_optname = _optname.replace("-", "_")
iface_data["inet6"][_optname] = value

# Else, if it's a dual stack, the option may belong in both; apply v4 opt as v6 default
elif dual_stack:
valid_once = False
errmsg = None
for addrfam in ["inet", "inet6"]:
(valid, value, errmsg) = _validate_interface_option(
_optname, valuestr, addrfam=addrfam
)

if valid:
valid_once = True
# replace dashes with underscores for jinja
_optname = _optname.replace("-", "_")
# if a v6-only version of this option was set; don't override
# otherwise, if dual stack, use the v4 version as a default value for v6
# allows overriding with =None
if addrfam == "inet" or _optname not in iface_data["inet6"]:
iface_data[addrfam][_optname] = value

if not valid_once:
_raise_error_iface(
iface, "'{0}' '{1}'".format(opt, valuestr), [errmsg]
)

# Else, it goes in the default(only) addrfam
# Not assuming v4 allows a v6 block to be created without lots of "ipv6" prefixes
else:
(valid, value, errmsg) = _validate_interface_option(
_optname, valuestr, addrfam=def_addrfam
)
elif opt.startswith("ipv6"):
iface_data["inet6"]["addrfam"] = "inet6"
opt = opt[4:]
inet = "inet6"
elif opt in [
"ipaddr",
"address",
"ipaddresses",
"addresses",
"gateway",
"proto",
]:
iface_data["inet"]["addrfam"] = "inet"
inet = "inet"

if not valid:
_raise_error_iface(
iface, "'{0}' '{1}'".format(opt, valuestr), [errmsg]
)
_opt = SALT_ATTR_TO_DEBIAN_ATTR_MAP.get(opt, opt)
_debopt = _opt.replace("-", "_")

# replace dashes with underscores for jinja
_optname = _optname.replace("-", "_")
iface_data[def_addrfam][_optname] = value
for addrfam in ["inet", "inet6"]:
(valid, value, errmsg) = _validate_interface_option(
_opt, val, addrfam=addrfam
)
if not valid:
continue
if inet is None and _debopt not in iface_data[addrfam]:
iface_data[addrfam][_debopt] = value
elif inet == addrfam:
iface_data[addrfam][_debopt] = value

for opt in [
"up_cmds",
Expand All @@ -1406,15 +1355,14 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
"post_down_cmds",
]:
if opt in opts:
iface_data[def_addrfam][opt] = opts[opt]
iface_data["inet"][opt] = opts[opt]
iface_data["inet6"][opt] = opts[opt]

for addrfam in ["inet", "inet6"]:
if (
"addrfam" in iface_data[addrfam]
and iface_data[addrfam]["addrfam"] == addrfam
):
pass
else:
# Remove incomplete/disabled inet blocks
for (addrfam, opt) in [("inet", "enable_ipv4"), ("inet6", "enable_ipv6")]:
if opts.get(opt, None) is False:
iface_data.pop(addrfam)
elif iface_data[addrfam].get("addrfam", "") != addrfam:
iface_data.pop(addrfam)

return adapters
Expand Down Expand Up @@ -1733,9 +1681,6 @@ def build_interface(iface, iface_type, enabled, **settings):
if iface_type not in _IFACE_TYPES:
_raise_error_iface(iface, iface_type, _IFACE_TYPES)

if "proto" not in settings:
settings["proto"] = "static"

if iface_type == "slave":
settings["slave"] = "yes"
if "master" not in settings:
Expand Down Expand Up @@ -1835,8 +1780,7 @@ def down(iface, iface_type):
# Slave devices are controlled by the master.
# Source 'interfaces' aren't brought down.
if iface_type not in ["slave", "source"]:
cmd = ["ip", "link", "set", iface, "down"]
return __salt__["cmd.run"](cmd, python_shell=False)
return __salt__["cmd.run"](["ifdown", iface])
return None


Expand Down Expand Up @@ -1897,8 +1841,7 @@ def up(iface, iface_type): # pylint: disable=C0103
# Slave devices are controlled by the master.
# Source 'interfaces' aren't brought up.
if iface_type not in ("slave", "source"):
cmd = ["ip", "link", "set", iface, "up"]
return __salt__["cmd.run"](cmd, python_shell=False)
return __salt__["cmd.run"](["ifup", iface])
return None


Expand Down Expand Up @@ -1929,11 +1872,9 @@ def get_network_settings():

hostname = _parse_hostname()
domainname = _parse_domainname()
searchdomain = _parse_searchdomain()

settings["hostname"] = hostname
settings["domainname"] = domainname
settings["searchdomain"] = searchdomain

else:
settings = _parse_current_network_settings()
Expand Down
Loading