mirror of
https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git
synced 2024-12-18 00:23:11 +00:00
Add Python checking script.
This commit is contained in:
parent
df9766b051
commit
a6e4913a46
79
check-release.py
Executable file
79
check-release.py
Executable file
@ -0,0 +1,79 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import requests
|
||||||
|
import sys
|
||||||
|
from datetime import date, datetime
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
|
verbose = False
|
||||||
|
|
||||||
|
def cli_parser():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Fedora '/etc/os-release' support date validator."
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--test", "-t",
|
||||||
|
type=str,
|
||||||
|
required=True,
|
||||||
|
help="Test to perform [future, compare]"
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--verbose", "-v",
|
||||||
|
action="store_true",
|
||||||
|
help="Prints detailed info on the screen."
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
def log(*args, **kwargs):
|
||||||
|
print(*args, **kwargs) if verbose else None
|
||||||
|
|
||||||
|
def get_file_support() -> date:
|
||||||
|
""" Returns the support date from the os-release file. """
|
||||||
|
with open('/etc/os-release', 'r') as release:
|
||||||
|
lines = release.readlines()
|
||||||
|
log("File content read.")
|
||||||
|
|
||||||
|
support_day = datetime.fromtimestamp(0)
|
||||||
|
for line in lines:
|
||||||
|
if "SUPPORT_END" in line:
|
||||||
|
key, value = line.split('=')
|
||||||
|
value = value.strip()
|
||||||
|
support_day = date.fromisoformat(value)
|
||||||
|
return support_day
|
||||||
|
|
||||||
|
def support_date_in_future() -> bool:
|
||||||
|
""" This function checks the support date from the os-release
|
||||||
|
file, compares it with the current system date and tests if
|
||||||
|
the os-release support date lies at least 12 months in the future. """
|
||||||
|
|
||||||
|
# Get the necessary values from the operating system.
|
||||||
|
today = datetime.today().date()
|
||||||
|
log("Current date on tested system =>", today)
|
||||||
|
tomorrow = today + relativedelta(years=1)
|
||||||
|
log(f"Minimal future EOL =>", tomorrow)
|
||||||
|
support = get_file_support()
|
||||||
|
log(f"/etc/os-release SUPPORT_END =>", support)
|
||||||
|
|
||||||
|
# Test if the support end date is in the future.
|
||||||
|
result = False
|
||||||
|
if support >= tomorrow:
|
||||||
|
log("SUPPORT_END is in the future.")
|
||||||
|
log("Test passed.")
|
||||||
|
result = True
|
||||||
|
else:
|
||||||
|
log("Test failed.")
|
||||||
|
result = False
|
||||||
|
return result
|
||||||
|
|
||||||
|
args = cli_parser()
|
||||||
|
verbose = args.verbose
|
||||||
|
result = support_date_in_future()
|
||||||
|
if result:
|
||||||
|
sys.exit(12)
|
||||||
|
else:
|
||||||
|
sys.exit(25)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user