Skip to content

Commit

Permalink
Simple handling of RPM lock file
Browse files Browse the repository at this point in the history
Differently as Zypper RPM does not write the process ID into the lock
file. Therefore RPM file lock has to be handled seperately.
  • Loading branch information
witekest committed Jul 11, 2022
1 parent 003a1c2 commit c17c8c9
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions salt/modules/zypperpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _is_error(self):
and self.exit_code not in self.WARNING_EXIT_CODES
)

def _is_lock(self):
def _is_zypper_lock(self):
"""
Is this is a lock error code?
Expand Down Expand Up @@ -281,7 +281,7 @@ def _check_result(self):
raise CommandExecutionError("No output result from Zypper?")

self.exit_code = self.__call_result["retcode"]
if self._is_lock():
if self._is_zypper_lock() or self._is_rpm_lock():
return False

if self._is_error():
Expand Down Expand Up @@ -346,15 +346,15 @@ def __call(self, *args, **kwargs):
cmd.extend(self.__cmd)
log.debug("Calling Zypper: %s", " ".join(cmd))
self.__call_result = __salt__["cmd.run_all"](cmd, **kwargs)
if self._check_result() and not self._is_rpm_lock():
if self._check_result():
break

# Zypper lock
if self._is_lock():
self._handle_lock_file(self.ZYPPER_LOCK, "Zypper")
if self._is_zypper_lock():
self._handle_zypper_lock_file()
# RPM lock
if self._is_rpm_lock():
self._handle_lock_file(self.RPM_LOCK, "RPM")
self._handle_rpm_lock_file()
was_blocked = True

if was_blocked:
Expand All @@ -378,10 +378,10 @@ def __call(self, *args, **kwargs):
or self.__call_result["stdout"]
)

def _handle_lock_file(self, lock_file, tool):
if os.path.exists(lock_file):
def _handle_zypper_lock_file(self):
if os.path.exists(self.ZYPPER_LOCK):
try:
with salt.utils.files.fopen(lock_file) as rfh:
with salt.utils.files.fopen(self.ZYPPER_LOCK) as rfh:
data = __salt__["ps.proc_info"](
int(rfh.readline()),
attrs=["pid", "name", "cmdline", "create_time"],
Expand All @@ -405,8 +405,7 @@ def _handle_lock_file(self, lock_file, tool):
}
else:
data = {
"info": "{} is locked, but no {} lock has been "
"found.".format(tool, tool),
"info": "Zypper is locked, but no Zypper lock has been found.",
"success": False,
}
if not data["success"]:
Expand All @@ -415,12 +414,22 @@ def _handle_lock_file(self, lock_file, tool):
log.debug("Collected data about blocking process.")
__salt__["event.fire_master"](data, self.TAG_BLOCKED)
log.debug(
"Fired a %s blocked event to the master with the data: "
"%s", tool, data
"Fired a Zypper blocked event to the master with the data: %s", data
)
log.debug("Waiting 5 seconds for Zypper gets released...")
time.sleep(5)

def _handle_rpm_lock_file(self):
data = {
"info": "RPM is temporarily locked.",
"success": True
}
__salt__["event.fire_master"](data, self.TAG_BLOCKED)
log.debug("Fired an RPM blocked event to the master with the data: "
"%s", data)
log.debug("Waiting 5 seconds for RPM to get released...")
time.sleep(5)


__zypper__ = _Zypper()

Expand Down

0 comments on commit c17c8c9

Please sign in to comment.