mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Moved location for finding machine_id to salt utils files, and had grains import from there
This commit is contained in:
parent
37164221e5
commit
f98b7073cd
4 changed files with 28 additions and 13 deletions
|
@ -3048,13 +3048,7 @@ def get_machine_id():
|
|||
if platform.system() == "AIX":
|
||||
return _aix_get_machine_id()
|
||||
|
||||
locations = ["/etc/machine-id", "/var/lib/dbus/machine-id"]
|
||||
existing_locations = [loc for loc in locations if os.path.exists(loc)]
|
||||
if not existing_locations:
|
||||
return {}
|
||||
else:
|
||||
with salt.utils.files.fopen(existing_locations[0]) as machineid:
|
||||
return {"machine_id": machineid.read().strip()}
|
||||
return salt.utils.files.local_get_machine_id()
|
||||
|
||||
|
||||
def cwd():
|
||||
|
|
|
@ -904,3 +904,18 @@ def get_encoding(path):
|
|||
return "ASCII"
|
||||
|
||||
raise CommandExecutionError("Could not detect file encoding")
|
||||
|
||||
|
||||
def local_get_machine_id():
|
||||
"""
|
||||
Provide the machine-id for machine/virtualization combination
|
||||
"""
|
||||
# Provides:
|
||||
# machine-id
|
||||
locations = ["/etc/machine-id", "/var/lib/dbus/machine-id"]
|
||||
existing_locations = [loc for loc in locations if os.path.exists(loc)]
|
||||
if not existing_locations:
|
||||
return {}
|
||||
else:
|
||||
with salt.utils.files.fopen(existing_locations[0]) as machineid:
|
||||
return {"machine_id": machineid.read().strip()}
|
||||
|
|
|
@ -30,7 +30,6 @@ import salt.utils.path
|
|||
import salt.utils.platform
|
||||
import salt.utils.versions
|
||||
from salt.ext.tornado import gen
|
||||
from salt.grains.core import get_machine_id
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -1076,7 +1075,9 @@ class SignalHandlingProcess(Process):
|
|||
msg += ". Exiting"
|
||||
log.debug(msg)
|
||||
|
||||
mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
|
||||
mach_id = salt.utils.files.local_get_machine_id().get(
|
||||
"machine_id", "no_machine_id_available"
|
||||
)
|
||||
log.debug(
|
||||
"exiting for process id %s and machine identifer %s", os.getpid(), mach_id
|
||||
)
|
||||
|
|
|
@ -19,7 +19,6 @@ import salt.utils.gitfs
|
|||
import salt.utils.path
|
||||
import salt.utils.platform
|
||||
import salt.utils.process
|
||||
from salt.grains.core import get_machine_id
|
||||
from salt.utils.immutabletypes import freeze
|
||||
from salt.utils.verify import verify_env
|
||||
|
||||
|
@ -378,7 +377,9 @@ def test_git_provider_mp_gen_lock(main_class, caplog):
|
|||
Check that gen_lock is obtains lock, and then releases, provider.lock()
|
||||
"""
|
||||
# get machine_identifier
|
||||
mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
|
||||
mach_id = salt.utils.files.local_get_machine_id().get(
|
||||
"machine_id", "no_machine_id_available"
|
||||
)
|
||||
cur_pid = os.getpid()
|
||||
|
||||
test_msg1 = (
|
||||
|
@ -412,7 +413,9 @@ def test_git_provider_mp_lock_dead_pid(main_class, caplog):
|
|||
Check that lock obtains lock, if previous pid in lock file doesn't exist for same machine id
|
||||
"""
|
||||
# get machine_identifier
|
||||
mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
|
||||
mach_id = salt.utils.files.local_get_machine_id().get(
|
||||
"machine_id", "no_machine_id_available"
|
||||
)
|
||||
cur_pid = os.getpid()
|
||||
|
||||
test_msg1 = (
|
||||
|
@ -484,7 +487,9 @@ def test_git_provider_mp_lock_bad_machine(main_class, caplog):
|
|||
Check that lock obtains lock, if previous pid in lock file doesn't exist for same machine id
|
||||
"""
|
||||
# get machine_identifier
|
||||
mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
|
||||
mach_id = salt.utils.files.local_get_machine_id().get(
|
||||
"machine_id", "no_machine_id_available"
|
||||
)
|
||||
cur_pid = os.getpid()
|
||||
|
||||
provider = main_class.remotes[0]
|
||||
|
|
Loading…
Add table
Reference in a new issue