Removed circular dependency on salt.utils.files.fopen

This commit is contained in:
David Murphy 2024-05-09 16:36:58 -06:00 committed by Daniel Wozniak
parent 5910c162d7
commit 56f3cbeff8

View file

@ -12,7 +12,8 @@ import sys
import distro import distro
from salt.utils.decorators import memoize as real_memoize from salt.utils.decorators import memoize as real_memoize
from salt.utils.files import fopen as _fopen
## from salt.utils.files import fopen as _fopen
def linux_distribution(full_distribution_name=True): def linux_distribution(full_distribution_name=True):
@ -246,6 +247,7 @@ def get_machine_identifier():
""" """
Provide the machine-id for machine/virtualization combination Provide the machine-id for machine/virtualization combination
""" """
# pylint: disable=resource-leakage
# Provides: # Provides:
# machine-id # machine-id
locations = ["/etc/machine-id", "/var/lib/dbus/machine-id"] locations = ["/etc/machine-id", "/var/lib/dbus/machine-id"]
@ -253,5 +255,9 @@ def get_machine_identifier():
if not existing_locations: if not existing_locations:
return {} return {}
else: else:
with _fopen(existing_locations[0]) as machineid: ## with _fopen(existing_locations[0]) as machineid:
# cannot use salt.utils.files.fopen due to circular dependency
with open(
existing_locations[0], encoding=__salt_system_encoding__
) as machineid:
return {"machine_id": machineid.read().strip()} return {"machine_id": machineid.read().strip()}