test/cases: add test-cases to verify customizations

Add one test-case per distro that tries to cover all the customizations
we support.

For now omit firewall customizations, as there are open questions about
how to support that on all image types.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-06-26 13:44:09 +02:00 committed by Ondřej Budai
parent 8c7d8a442b
commit b32f0feeae
4 changed files with 31685 additions and 16 deletions

View file

@ -73,6 +73,25 @@ class TestCaseGenerator:
return self.test_case
def generate_test_case(test_type, distro, arch, output_format, test_case_request, keep_image_info, store, output):
print(f"generating test case for {output_format}")
generator = TestCaseGenerator(test_case_request)
test_case = generator.get_test_case(keep_image_info, store)
name = distro.replace("-", "_") + "-" + arch + "-" + output_format.replace("-", "_") + "-" + test_type + ".json"
file_name = output + "/" + name
if keep_image_info:
try:
with open(file_name, 'r') as case_file:
old_test_case = json.load(case_file)
image_info = old_test_case.get("image-info")
if image_info:
test_case["image-info"] = image_info
except:
pass
with open(file_name, 'w') as case_file:
json.dump(test_case, case_file, indent=2)
def main(distro, arch, image_types, keep_image_info, store, output):
with open("tools/test-case-generators/format-request-map.json") as format_request_json:
format_request_dict = json.load(format_request_json)
@ -81,25 +100,104 @@ def main(distro, arch, image_types, keep_image_info, store, output):
for output_format, test_case_request in format_request_dict.items():
if test_case_request["compose-request"]["image-type"] not in image_types:
continue
print(f"generating test case for {output_format}")
test_case_request["compose-request"]["distro"] = distro
test_case_request["compose-request"]["arch"] = arch
test_case_request["compose-request"]["repositories"] = repos_dict[distro][arch]
generator = TestCaseGenerator(test_case_request)
test_case = generator.get_test_case(keep_image_info, store)
name = distro.replace("-", "_") + "-" + arch + "-" + output_format.replace("-", "_") + "-boot.json"
file_name = output + "/" + name
if keep_image_info:
try:
with open(file_name, 'r') as case_file:
old_test_case = json.load(case_file)
image_info = old_test_case.get("image-info")
if image_info:
test_case["image-info"] = image_info
except:
pass
with open(file_name, 'w') as case_file:
json.dump(test_case, case_file, indent=2)
generate_test_case("boot", distro, arch, output_format, test_case_request, keep_image_info, store, output)
if "customize" in image_types:
test_case_request = {
"compose-request": {
"distro": distro,
"arch": arch,
"repositories": repos_dict[distro][arch],
"image-type": "qcow2",
"filename": "disk.qcow2",
"blueprint": {
"packages": [
{
"name": "bash",
"version": "*"
}
],
"groups": [
{
"name": "core"
}
],
"customizations": {
"hosname": "my-host",
"kernel": {
"append": "debug"
},
"sshkey": [
{
"user": "user1",
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC61wMCjOSHwbVb4VfVyl5sn497qW4PsdQ7Ty7aD6wDNZ/QjjULkDV/yW5WjDlDQ7UqFH0Sr7vywjqDizUAqK7zM5FsUKsUXWHWwg/ehKg8j9xKcMv11AkFoUoujtfAujnKODkk58XSA9whPr7qcw3vPrmog680pnMSzf9LC7J6kXfs6lkoKfBh9VnlxusCrw2yg0qI1fHAZBLPx7mW6+me71QZsS6sVz8v8KXyrXsKTdnF50FjzHcK9HXDBtSJS5wA3fkcRYymJe0o6WMWNdgSRVpoSiWaHHmFgdMUJaYoCfhXzyl7LtNb3Q+Sveg+tJK7JaRXBLMUllOlJ6ll5Hod root@localhost"
}
],
"user": [
{
"name": "user2",
"description": "description 2",
"password": "$6$BhyxFBgrEFh0VrPJ$MllG8auiU26x2pmzL4.1maHzPHrA.4gTdCvlATFp8HJU9UPee4zCS9BVl2HOzKaUYD/zEm8r/OF05F2icWB0K/",
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC61wMCjOSHwbVb4VfVyl5sn497qW4PsdQ7Ty7aD6wDNZ/QjjULkDV/yW5WjDlDQ7UqFH0Sr7vywjqDizUAqK7zM5FsUKsUXWHWwg/ehKg8j9xKcMv11AkFoUoujtfAujnKODkk58XSA9whPr7qcw3vPrmog680pnMSzf9LC7J6kXfs6lkoKfBh9VnlxusCrw2yg0qI1fHAZBLPx7mW6+me71QZsS6sVz8v8KXyrXsKTdnF50FjzHcK9HXDBtSJS5wA3fkcRYymJe0o6WMWNdgSRVpoSiWaHHmFgdMUJaYoCfhXzyl7LtNb3Q+Sveg+tJK7JaRXBLMUllOlJ6ll5Hod root@localhost",
"home": "/home/home2",
"shell": "/bin/sh",
"groups": [
"group1"
],
"uid": 1020,
"gid": 1050,
}
],
"group": [
{
"name": "group1",
"gid": 1030
},
{
"name": "group2",
"gid": 1050
}
],
"timezone": {
"timezone": "Europe/London",
"ntpservers": [
"time.example.com"
]
},
"locale": {
"languages": [
"en_US"
],
"keyboard": "dvorak"
},
# "firewall": {
# "ports": [
# "25:tcp"
# ],
# "services": {
# "enabled": [
# "cockpit"
# ],
# "disabled": [
# "ssh"
# ]
# }
# },
"services": {
"enabled": [
"sshd.socket"
],
"disabled": [
"bluetooth.service"
]
}
}
}
}
}
generate_test_case("customize", distro, arch, "qcow2", test_case_request, keep_image_info, store, output)
return
if __name__ == '__main__':