test_koji.sh: refactor the test case and de-duplicate some code
Refactor the test case implementation to make it easier to reuse existing code when adding a new testing scenario. The common pieces were moved under a new `SutInfo` class, which provides information and convenience methods related to the system on which the test is running. This change will make it easier to later add a new scenario testing upload to the cloud.
This commit is contained in:
parent
0a026a6573
commit
ed6b01bb97
1 changed files with 79 additions and 60 deletions
|
|
@ -10,19 +10,6 @@ import string
|
|||
import subprocess
|
||||
|
||||
|
||||
REPOS = {
|
||||
"fedora": [
|
||||
{"url": "http://download.fedoraproject.org/pub/fedora/linux/releases/$release/Everything/$arch/os"}
|
||||
],
|
||||
"rhel": [
|
||||
{"url": "http://download.devel.redhat.com/released/RHEL-8/$release/BaseOS/x86_64/os/",
|
||||
"package_sets": "blueprint; build; packages"},
|
||||
{"url": "http://download.devel.redhat.com/released/RHEL-8/$release/AppStream/x86_64/os/",
|
||||
"package_sets": "blueprint; build; packages"},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def koji_command(*args, _input=None, _globals=None, **kwargs):
|
||||
args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()]
|
||||
if _globals:
|
||||
|
|
@ -37,18 +24,71 @@ def koji_command(*args, _input=None, _globals=None, **kwargs):
|
|||
check=False)
|
||||
|
||||
|
||||
def parse_os_release():
|
||||
info = {}
|
||||
with open("/etc/os-release", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
if line[0] == "#":
|
||||
continue
|
||||
k, v = line.split("=", 1)
|
||||
info[k] = v.strip('"')
|
||||
return info
|
||||
class SutInfo:
|
||||
"""Class representing information about the system under test"""
|
||||
|
||||
REPOS = {
|
||||
"fedora": [
|
||||
{"url": "http://download.fedoraproject.org/pub/fedora/linux/releases/$release/Everything/$arch/os"}
|
||||
],
|
||||
"rhel": [
|
||||
{"url": "http://download.devel.redhat.com/released/RHEL-8/$release/BaseOS/$arch/os/",
|
||||
"package_sets": "blueprint; build; packages"},
|
||||
{"url": "http://download.devel.redhat.com/released/RHEL-8/$release/AppStream/$arch/os/",
|
||||
"package_sets": "blueprint; build; packages"},
|
||||
]
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
info = SutInfo.parse_os_release()
|
||||
|
||||
self.os_name = info["ID"] # 'fedora' or 'rhel'
|
||||
self.os_version = info["VERSION_ID"] # <major> or <major>.<minor>
|
||||
|
||||
comps = self.os_version.split(".")
|
||||
self.os_version_major = comps[0]
|
||||
self.os_version_minor = comps[1] if len(comps) > 1 else ""
|
||||
|
||||
self.composer_distro_name = f"{self.os_name}-{self.os_version_major}{self.os_version_minor}"
|
||||
self.koji_tag = f"{self.os_name}{self.os_version_major}-candidate" # fedora<major> or rhel<major>
|
||||
self.os_arch = platform.machine()
|
||||
|
||||
@staticmethod
|
||||
def parse_os_release():
|
||||
info = {}
|
||||
with open("/etc/os-release", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
if line[0] == "#":
|
||||
continue
|
||||
k, v = line.split("=", 1)
|
||||
info[k] = v.strip('"')
|
||||
return info
|
||||
|
||||
def testing_repos(self):
|
||||
"""
|
||||
Returns a list of repositories to be used by the test.
|
||||
|
||||
All variables in the URLs are replaced by proper values.
|
||||
"""
|
||||
release = self.os_version
|
||||
if self.os_name.lower() == "rhel":
|
||||
release += ".0"
|
||||
|
||||
repos = []
|
||||
for repo in self.REPOS[self.os_name]:
|
||||
repo_copy = dict(repo)
|
||||
tpl = string.Template(repo_copy["url"])
|
||||
url = tpl.safe_substitute({
|
||||
"release": release,
|
||||
"arch": self.os_arch,
|
||||
})
|
||||
repo_copy["url"] = url
|
||||
repos.append(repo_copy)
|
||||
|
||||
return repos
|
||||
|
||||
|
||||
class TestIntegration(unittest.TestCase):
|
||||
|
|
@ -81,40 +121,23 @@ class TestIntegration(unittest.TestCase):
|
|||
"""Successful compose"""
|
||||
# Simple test of a successful compose of RHEL
|
||||
|
||||
info = parse_os_release()
|
||||
|
||||
name = info["ID"] # 'fedora' or 'rhel'
|
||||
version = info["VERSION_ID"] # <major> or <major>.<minor>
|
||||
|
||||
comps = version.split(".")
|
||||
major = comps[0]
|
||||
minor = comps[1] if len(comps) > 1 else ""
|
||||
|
||||
distro = f"{name}-{major}{minor}"
|
||||
tag = f"{name}{major}-candidate" # fedora<major> or rhel<major>
|
||||
arch = platform.machine()
|
||||
|
||||
release = version
|
||||
if name.lower() == "rhel":
|
||||
release += ".0"
|
||||
sut_info = SutInfo()
|
||||
|
||||
repos = []
|
||||
for repo in REPOS[name]:
|
||||
baseurl = repo["url"]
|
||||
for repo in sut_info.testing_repos():
|
||||
url = repo["url"]
|
||||
package_sets = repo.get("package_sets")
|
||||
tpl = string.Template(baseurl)
|
||||
url = tpl.safe_substitute({"release": release})
|
||||
repos += ["--repo", url]
|
||||
if package_sets:
|
||||
repos += ["--repo-package-sets", package_sets]
|
||||
|
||||
package = f"{name.lower()}-guest"
|
||||
package = f"{sut_info.os_name.lower()}-guest"
|
||||
|
||||
res = self.koji(package,
|
||||
major,
|
||||
distro,
|
||||
tag,
|
||||
arch,
|
||||
sut_info.os_version_major,
|
||||
sut_info.composer_distro_name,
|
||||
sut_info.koji_tag,
|
||||
sut_info.os_arch,
|
||||
"--wait",
|
||||
*repos)
|
||||
self.check_res(res)
|
||||
|
|
@ -123,16 +146,12 @@ class TestIntegration(unittest.TestCase):
|
|||
"""Unknown Tag check"""
|
||||
# Check building an unknown tag fails
|
||||
|
||||
info = parse_os_release()
|
||||
sut_info = SutInfo()
|
||||
package = f"{sut_info.os_name.lower()}-guest"
|
||||
|
||||
name = info["ID"] # 'fedora' or 'rhel'
|
||||
version = info["VERSION_ID"] # <major> or <major>.<minor>
|
||||
major = version.split(".")[0]
|
||||
distro = f"{name}-{major}"
|
||||
|
||||
res = self.koji("fedora-guest",
|
||||
major,
|
||||
distro,
|
||||
res = self.koji(package,
|
||||
sut_info.os_version_major,
|
||||
sut_info.composer_distro_name,
|
||||
"UNKNOWNTAG",
|
||||
platform.machine())
|
||||
sut_info.os_arch)
|
||||
self.check_fail(res)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue