Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
witekest committed Aug 17, 2022
1 parent e59c680 commit f618ed9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
16 changes: 4 additions & 12 deletions salt/modules/zypperpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ def _handle_zypper_lock_file(self):
data = {
"info": (
"Unable to retrieve information about "
"blocking process: {}".format(
err
)
"blocking process: {}".format(err)
),
"success": False,
}
Expand All @@ -414,20 +412,14 @@ def _handle_zypper_lock_file(self):
else:
log.debug("Collected data about blocking process.")
__salt__["event.fire_master"](data, self.TAG_BLOCKED)
log.debug(
"Fired a Zypper blocked event to the master with the data: %s", data
)
log.debug("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
}
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("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)

Expand Down
25 changes: 13 additions & 12 deletions tests/unit/modules/test_zypperpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import salt.utils.pkg
from salt.exceptions import CommandExecutionError
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, Mock, call, patch, mock_open
from tests.support.mock import MagicMock, Mock, call, mock_open, patch
from tests.support.unit import TestCase


Expand Down Expand Up @@ -195,8 +195,9 @@ def __call__(self, *args, **kwargs):
' type="error">Booya!</message></stream>'
)
sniffer = RunSniffer(stdout=stdout_xml_snippet, retcode=1)
with patch.dict("salt.modules.zypperpkg.__salt__", {"cmd.run_all": sniffer}), \
patch.object(zypper.__zypper__, "_is_rpm_lock", return_value=False):
with patch.dict(
"salt.modules.zypperpkg.__salt__", {"cmd.run_all": sniffer}
), patch.object(zypper.__zypper__, "_is_rpm_lock", return_value=False):
with self.assertRaisesRegex(
CommandExecutionError, "^Zypper command failure: Booya!$"
):
Expand Down Expand Up @@ -2073,29 +2074,29 @@ def test_is_rpm_lock_no_error(self):
def test_rpm_lock_does_not_exist(self):
if salt.utils.files.is_fcntl_available():
zypper.__zypper__.exit_code = 1
with patch.object(os.path, "exists", return_value=False) as \
mock_path_exists:
with patch.object(
os.path, "exists", return_value=False
) as mock_path_exists:
self.assertFalse(zypper.__zypper__._is_rpm_lock())
mock_path_exists.assert_called_with(zypper.__zypper__.RPM_LOCK)
zypper.__zypper__._reset()

def test_rpm_lock_acquirable(self):
if salt.utils.files.is_fcntl_available():
zypper.__zypper__.exit_code = 1
with patch.object(os.path, "exists", return_value=True), \
patch("fcntl.lockf", side_effect=OSError(errno.EAGAIN,
"")) as lockf_mock, \
patch("salt.utils.files.fopen", mock_open()):
with patch.object(os.path, "exists", return_value=True), patch(
"fcntl.lockf", side_effect=OSError(errno.EAGAIN, "")
) as lockf_mock, patch("salt.utils.files.fopen", mock_open()):
self.assertTrue(zypper.__zypper__._is_rpm_lock())
lockf_mock.assert_called()
zypper.__zypper__._reset()

def test_rpm_lock_not_acquirable(self):
if salt.utils.files.is_fcntl_available():
zypper.__zypper__.exit_code = 1
with patch.object(os.path, "exists", return_value=True), \
patch("fcntl.lockf") as lockf_mock, patch(
"salt.utils.files.fopen", mock_open()):
with patch.object(os.path, "exists", return_value=True), patch(
"fcntl.lockf"
) as lockf_mock, patch("salt.utils.files.fopen", mock_open()):
self.assertFalse(zypper.__zypper__._is_rpm_lock())
self.assertEqual(lockf_mock.call_count, 2)
zypper.__zypper__._reset()

0 comments on commit f618ed9

Please sign in to comment.