mirror of
https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git
synced 2024-12-18 08:33:08 +00:00
80 lines
2.2 KiB
Python
Executable File
80 lines
2.2 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import argparse
|
|
import sys
|
|
from datetime import date, datetime, timedelta
|
|
import requests
|
|
|
|
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:
|
|
_, value = line.split('=')
|
|
value = value.strip()
|
|
if value:
|
|
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 + timedelta(days=365)
|
|
log("Minimal SUPPORT_END calculated from system time =>", tomorrow)
|
|
support = get_file_support()
|
|
log("Real /etc/os-release SUPPORT_END =>", support)
|
|
|
|
# Test if the support end date is in the future.
|
|
result = False
|
|
if support >= tomorrow:
|
|
log("Real SUPPORT_END is one year in the future.")
|
|
log("Test passed.")
|
|
result = True
|
|
else:
|
|
log("Real SUPPORT_END is NOT one year in the future.")
|
|
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)
|