salt/feat-add-grain-for-all-fqdns.patch
Mihai Dincă bbe3fe8f72 Accepting request 586784 from systemsmanagement:saltstack:testing
- Update patches
- Modified:
  * run-salt-master-as-dedicated-salt-user.patch
  * run-salt-api-as-user-salt-bsc-1064520.patch
  * fix-openscap-push.patch
  * fix-cp.push-empty-file.patch
  * avoid-excessive-syslogging-by-watchdog-cronjob-58.patch
  * feat-add-grain-for-all-fqdns.patch
  * fix-bsc-1065792.patch
  * move-log_file-option-to-changeable-defaults.patch
  * activate-all-beacons-sources-config-pillar-grains.patch
  * remove-obsolete-unicode-handling-in-pkg.info_install.patch
  
- Removed:
  * salt-ssh-fix-json-load-of-return-data-when-it-contai.patch
  
-------------------------------------------------------------------                                                                                                     
                                                                                    
- Update cp.push patch
- Modified:
  * fix-cp.push-empty-file.patch
  * salt-ssh-fix-json-load-of-return-data-when-it-contai.patch

- force re-generate a new thin.tgz when an update gets installed

- fix salt-ssh with a different patch
- remove: dumps-should-return-unicode-also-with-py2-to-prevent.patch
- added: salt-ssh-fix-json-load-of-return-data-when-it-contai.patch
- Added:

OBS-URL: https://build.opensuse.org/request/show/586784
OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=115
2018-03-19 08:54:13 +00:00

89 lines
2.7 KiB
Diff

From 067b63ccbc6942a0399eb43d7fdf314b5c9b417f Mon Sep 17 00:00:00 2001
From: Michele Bologna <michele.bologna@suse.com>
Date: Thu, 14 Dec 2017 18:20:02 +0100
Subject: [PATCH] Feat: add grain for all FQDNs
This PR adds a grain named fqdns to the grains.
fqdns represents all the FQDNs known for the system on all available interfaces (excluding lo).
Note: hostname != FQDN
hostname is the UNIX name of the machine. A machine can have one and only one hostname.
FQDN is host.domain that resolves to an IP address that the machines is answering to.
A machine can have 1+ FQDNs.
Upstream PR:
https://github.com/saltstack/salt/pull/45060
---
salt/grains/core.py | 27 +++++++++++++++++++++++++++
tests/integration/modules/test_grains.py | 1 +
tests/unit/grains/test_core.py | 1 +
3 files changed, 29 insertions(+)
diff --git a/salt/grains/core.py b/salt/grains/core.py
index 9352987abd..f8e36a895e 100644
--- a/salt/grains/core.py
+++ b/salt/grains/core.py
@@ -1890,6 +1890,33 @@ def append_domain():
return grain
+def fqdns():
+ '''
+ Return all known FQDNs for the system by enumerating all interfaces and
+ then trying to reverse resolve them (excluding 'lo' interface).
+ '''
+ # Provides:
+ # fqdns
+
+ grains = {}
+ fqdns = set()
+
+ addresses = salt.utils.network.ip_addrs(include_loopback=False,
+ interface_data=_INTERFACES)
+ addresses.extend(salt.utils.network.ip_addrs6(include_loopback=False,
+ interface_data=_INTERFACES))
+
+ for ip in addresses:
+ try:
+ fqdns.add(socket.gethostbyaddr(ip)[0])
+ except (socket.error, socket.herror,
+ socket.gaierror, socket.timeout) as e:
+ log.error("Exception during resolving address: " + str(e))
+
+ grains['fqdns'] = list(fqdns)
+ return grains
+
+
def ip_fqdn():
'''
Return ip address and FQDN grains
diff --git a/tests/integration/modules/test_grains.py b/tests/integration/modules/test_grains.py
index 709f882b45..aa7bd44202 100644
--- a/tests/integration/modules/test_grains.py
+++ b/tests/integration/modules/test_grains.py
@@ -51,6 +51,7 @@ class TestModulesGrains(ModuleCase):
'cpuarch',
'domain',
'fqdn',
+ 'fqdns',
'gid',
'groupname',
'host',
diff --git a/tests/unit/grains/test_core.py b/tests/unit/grains/test_core.py
index e781fadefe..dba8d082c5 100644
--- a/tests/unit/grains/test_core.py
+++ b/tests/unit/grains/test_core.py
@@ -7,6 +7,7 @@
from __future__ import absolute_import, print_function, unicode_literals
import logging
import os
+import socket
# Import Salt Testing Libs
try:
--
2.16.2