mirror of
https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git
synced 2024-12-18 08:33:08 +00:00
Compare commits
No commits in common. "f82958b9355b8fdeedf75632580824b78e501fd2" and "df9766b051af1ed63dd65b54d2383ac94237f898" have entirely different histories.
f82958b935
...
df9766b051
@ -1,79 +0,0 @@
|
||||
#!/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)
|
Loading…
Reference in New Issue
Block a user