Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 23, 2023
1 parent d5fcc61 commit d68b7c2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
16 changes: 10 additions & 6 deletions scripts/conversion_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,30 @@ def to_dict(self):
"report_json": self.report_json,
}


def _check_ini_file_modified():
rpm_va_output, ini_file_not_modified = run_subprocess(["/usr/bin/rpm", "-Va", "convert2rhel"])
rpm_va_output, ini_file_not_modified = run_subprocess(
["/usr/bin/rpm", "-Va", "convert2rhel"]
)

# No modifications at all
if not ini_file_not_modified:
return False


lines = rpm_va_output.strip().split('\n')
lines = rpm_va_output.strip().split("\n")
for line in lines:
line = line.strip().split()
status = line[0].replace(".", "").replace("?", "")
path = line[-1]

default_ini_modified = path == '/etc/convert2rhel.ini'
md5_hash_mismatch = '5' in status
default_ini_modified = path == "/etc/convert2rhel.ini"
md5_hash_mismatch = "5" in status

if default_ini_modified and md5_hash_mismatch:
return True
return False


def check_convert2rhel_inhibitors_before_run():
"""
Conditions that must be True in order to run convert2rhel command.
Expand All @@ -121,7 +124,8 @@ def check_convert2rhel_inhibitors_before_run():

if _check_ini_file_modified():
raise ProcessError(
message="According to 'rpm -Va' command %s was modified." % default_ini_path,
message="According to 'rpm -Va' command %s was modified."
% default_ini_path,
report=ini_report % (default_ini_path, default_ini_path),
)

Expand Down
15 changes: 9 additions & 6 deletions scripts/preconversion_assessment_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,28 @@ def to_dict(self):


def _check_ini_file_modified():
rpm_va_output, ini_file_not_modified = run_subprocess(["/usr/bin/rpm", "-Va", "convert2rhel"])
rpm_va_output, ini_file_not_modified = run_subprocess(
["/usr/bin/rpm", "-Va", "convert2rhel"]
)

# No modifications at all
if not ini_file_not_modified:
return False


lines = rpm_va_output.strip().split('\n')
lines = rpm_va_output.strip().split("\n")
for line in lines:
line = line.strip().split()
status = line[0].replace(".", "").replace("?", "")
path = line[-1]

default_ini_modified = path == '/etc/convert2rhel.ini'
md5_hash_mismatch = '5' in status
default_ini_modified = path == "/etc/convert2rhel.ini"
md5_hash_mismatch = "5" in status

if default_ini_modified and md5_hash_mismatch:
return True
return False


def check_convert2rhel_inhibitors_before_run():
"""
Conditions that must be True in order to run convert2rhel command.
Expand All @@ -121,7 +123,8 @@ def check_convert2rhel_inhibitors_before_run():

if _check_ini_file_modified():
raise ProcessError(
message="According to 'rpm -Va' command %s was modified." % default_ini_path,
message="According to 'rpm -Va' command %s was modified."
% default_ini_path,
report=ini_report % (default_ini_path, default_ini_path),
)

Expand Down
12 changes: 9 additions & 3 deletions tests/conversion_script/test_check_ini_file_modified.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
from scripts.conversion_script import _check_ini_file_modified


@patch('scripts.conversion_script.run_subprocess', return_value=("S.5....T c /etc/convert2rhel.ini\n", True))
@patch(
"scripts.conversion_script.run_subprocess",
return_value=("S.5....T c /etc/convert2rhel.ini\n", True),
)
def test_check_ini_file_modified(mock_rpm_va):
result = _check_ini_file_modified()
assert result
mock_rpm_va.assert_called_once()


@patch('scripts.conversion_script.run_subprocess', return_value=("S.5....T c /foo/bar\n", True))
@patch(
"scripts.conversion_script.run_subprocess",
return_value=("S.5....T c /foo/bar\n", True),
)
def test_check_ini_file_not_modified(mock_rpm_va):
result = _check_ini_file_modified()
assert not result
mock_rpm_va.assert_called_once()


@patch('scripts.conversion_script.run_subprocess', return_value=("", False))
@patch("scripts.conversion_script.run_subprocess", return_value=("", False))
def test_check_ini_file_no_changes(mock_rpm_va):
result = _check_ini_file_modified()
assert not result
Expand Down
14 changes: 11 additions & 3 deletions tests/preconversion_assessment/test_check_ini_file_modified.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@
from scripts.preconversion_assessment_script import _check_ini_file_modified


@patch('scripts.preconversion_assessment_script.run_subprocess', return_value=("S.5....T c /etc/convert2rhel.ini\n", True))
@patch(
"scripts.preconversion_assessment_script.run_subprocess",
return_value=("S.5....T c /etc/convert2rhel.ini\n", True),
)
def test_check_ini_file_modified(mock_rpm_va):
result = _check_ini_file_modified()
assert result
mock_rpm_va.assert_called_once()


@patch('scripts.preconversion_assessment_script.run_subprocess', return_value=("S.5....T c /foo/bar\n", True))
@patch(
"scripts.preconversion_assessment_script.run_subprocess",
return_value=("S.5....T c /foo/bar\n", True),
)
def test_check_ini_file_not_modified(mock_rpm_va):
result = _check_ini_file_modified()
assert not result
mock_rpm_va.assert_called_once()


@patch('scripts.preconversion_assessment_script.run_subprocess', return_value=("", False))
@patch(
"scripts.preconversion_assessment_script.run_subprocess", return_value=("", False)
)
def test_check_ini_file_no_changes(mock_rpm_va):
result = _check_ini_file_modified()
assert not result
Expand Down

0 comments on commit d68b7c2

Please sign in to comment.