Updated to use grains/core.py get_machine_id for machine identifier

This commit is contained in:
David Murphy 2024-03-07 16:24:54 -07:00 committed by Daniel Wozniak
parent c982cbdb3e
commit 695353ee91
4 changed files with 24 additions and 16 deletions

View file

@ -907,14 +907,14 @@ def get_encoding(path):
## TBD DGM just parking here till final machine identifier work is done
def get_machine_identifier():
"""
Provide the machine-identifier for machine/virtualization combination
"""
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 fopen(existing_locations[0]) as machineid:
return machineid.read().strip()
## def get_machine_identifier():
## """
## Provide the machine-identifier for machine/virtualization combination
## """
## 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 fopen(existing_locations[0]) as machineid:
## return machineid.read().strip()

View file

@ -39,6 +39,7 @@ import salt.utils.versions
from salt.config import DEFAULT_HASH_TYPE
from salt.config import DEFAULT_MASTER_OPTS as _DEFAULT_MASTER_OPTS
from salt.exceptions import FileserverConfigError, GitLockError, get_error_message
from salt.grains.core import get_machine_id
from salt.utils.event import tagify
from salt.utils.odict import OrderedDict
from salt.utils.process import os_is_running as pid_exists
@ -250,7 +251,8 @@ class GitProvider:
# DGM try getting machine_identifier
# get machine_identifier
self.mach_id = salt.utils.files.get_machine_identifier()
## self.mach_id = salt.utils.files.get_machine_identifier()
self.mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
log.debug("DGM machine_id for lock file, machine_id %s", self.mach_id)
self.global_saltenv = salt.utils.data.repack_dictlist(

View file

@ -30,6 +30,7 @@ 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__)
@ -1075,7 +1076,8 @@ class SignalHandlingProcess(Process):
msg += ". Exiting"
log.debug(msg)
mach_id = salt.utils.files.get_machine_identifier()
## mach_id = salt.utils.files.get_machine_identifier()
mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
dbg_msg = (
f"exiting for process id '{os.getpid()}' and machine identifer '{mach_id}'"
)

View file

@ -20,6 +20,7 @@ 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
@ -404,7 +405,8 @@ def test_git_provider_mp_gen_lock(main_class, caplog):
"""
# DGM try getting machine_identifier
# get machine_identifier
mach_id = salt.utils.files.get_machine_identifier()
## mach_id = salt.utils.files.get_machine_identifier()
mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
cur_pid = os.getpid()
test_msg1 = (
@ -437,7 +439,8 @@ def test_git_provider_mp_lock_dead_pid(main_class, caplog):
"""
# DGM try getting machine_identifier
# get machine_identifier
mach_id = salt.utils.files.get_machine_identifier()
## mach_id = salt.utils.files.get_machine_identifier()
mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
cur_pid = os.getpid()
test_msg1 = (
@ -508,7 +511,8 @@ def test_git_provider_mp_lock_bad_machine(main_class, caplog):
"""
# DGM try getting machine_identifier
# get machine_identifier
mach_id = salt.utils.files.get_machine_identifier()
## mach_id = salt.utils.files.get_machine_identifier()
mach_id = get_machine_id().get("machine_id", "no_machine_id_available")
cur_pid = os.getpid()
provider = main_class.remotes[0]