Support loading groups from the kickstart template files.

(cherry picked from commit 1de67f4f63)
This commit is contained in:
Chris Lumens 2018-07-11 14:07:45 -04:00 committed by Brian C. Lane
parent 22ddaa667e
commit 67b4a6c1eb
6 changed files with 50 additions and 13 deletions

View File

@ -74,8 +74,9 @@ def test_templates(dbo, share_dir):
ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False) ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False)
ks.readKickstartFromString(ks_template+"\n%end\n") ks.readKickstartFromString(ks_template+"\n%end\n")
pkgs = [(name, "*") for name in ks.handler.packages.packageList] pkgs = [(name, "*") for name in ks.handler.packages.packageList]
grps = [grp.name for grp in ks.handler.packages.groupList]
try: try:
_ = projects_depsolve(dbo, pkgs, []) _ = projects_depsolve(dbo, pkgs, grps)
except ProjectsError as e: except ProjectsError as e:
template_errors.append("Error depsolving %s: %s" % (compose_type, str(e))) template_errors.append("Error depsolving %s: %s" % (compose_type, str(e)))
@ -271,11 +272,11 @@ def start_build(cfg, dnflock, gitlock, branch, recipe_name, compose_type, test_m
ks_version = makeVersion() ks_version = makeVersion()
ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False) ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False)
ks.readKickstartFromString(ks_template+"\n%end\n") ks.readKickstartFromString(ks_template+"\n%end\n")
ks_projects = [(name, "*") for name in ks.handler.packages.packageList] pkgs = [(name, "*") for name in ks.handler.packages.packageList]
grps = [grp.name for grp in ks.handler.packages.groupList]
try: try:
with dnflock.lock: with dnflock.lock:
(template_size, _) = projects_depsolve_with_size(dnflock.dbo, ks_projects, [], (template_size, _) = projects_depsolve_with_size(dnflock.dbo, pkgs, grps, with_core=not ks.handler.packages.nocore)
with_core=not ks.handler.packages.nocore)
except ProjectsError as e: except ProjectsError as e:
log.error("start_build depsolve: %s", str(e)) log.error("start_build depsolve: %s", str(e))
raise RuntimeError("Problem depsolving %s: %s" % (recipe["name"], str(e))) raise RuntimeError("Problem depsolving %s: %s" % (recipe["name"], str(e)))

View File

@ -0,0 +1 @@
{'description': u'An example e-mail server.', 'packages': [], 'groups': [{'name': u'mail-server'}], 'modules': [], 'version': u'0.0.1', 'name': u'mail-server'}

View File

@ -0,0 +1,6 @@
name = "mail-server"
description = "An example e-mail server."
version = "0.0.1"
[[groups]]
name = "mail-server"

View File

@ -158,7 +158,7 @@ class ProjectsTest(unittest.TestCase):
def test_projects_depsolve(self): def test_projects_depsolve(self):
deps = projects_depsolve(self.dbo, [("bash", "*.*")], []) deps = projects_depsolve(self.dbo, [("bash", "*.*")], [])
self.assertTrue(len(deps) > 3) self.assertTrue(len(deps) > 3)
self.assertEqual(deps[0]["name"], "basesystem") self.assertTrue("basesystem" in [dep["name"] for dep in deps])
def test_projects_depsolve_version(self): def test_projects_depsolve_version(self):
"""Test that depsolving with a partial wildcard version works""" """Test that depsolving with a partial wildcard version works"""
@ -195,6 +195,13 @@ class ProjectsTest(unittest.TestCase):
self.assertEqual(modules[0]["name"], "bash") self.assertEqual(modules[0]["name"], "bash")
self.assertEqual(modules[0]["dependencies"][0]["name"], "basesystem") self.assertEqual(modules[0]["dependencies"][0]["name"], "basesystem")
def test_groups_depsolve(self):
deps = projects_depsolve(self.dbo, [], ["c-development"])
names = [grp["name"] for grp in deps]
self.assertTrue("autoconf" in names) # mandatory package
self.assertTrue("ctags" in names) # default package
self.assertFalse("cmake" in names) # optional package
class ConfigureTest(unittest.TestCase): class ConfigureTest(unittest.TestCase):
@classmethod @classmethod

View File

@ -32,6 +32,7 @@ class BasicRecipeTest(unittest.TestCase):
("minimal.toml", "minimal.dict"), ("minimal.toml", "minimal.dict"),
("modules-only.toml", "modules-only.dict"), ("modules-only.toml", "modules-only.dict"),
("packages-only.toml", "packages-only.dict"), ("packages-only.toml", "packages-only.dict"),
("groups-only.toml", "groups-only.dict"),
("custom-base.toml", "custom-base.dict")] ("custom-base.toml", "custom-base.dict")]
results_path = "./tests/pylorax/results/" results_path = "./tests/pylorax/results/"
self.input_toml = [] self.input_toml = []
@ -47,12 +48,16 @@ class BasicRecipeTest(unittest.TestCase):
recipes.RecipeModule("httpd", "3.7.*")] recipes.RecipeModule("httpd", "3.7.*")]
self.old_packages = [recipes.RecipePackage("python", "2.7.*"), self.old_packages = [recipes.RecipePackage("python", "2.7.*"),
recipes.RecipePackage("parted", "3.2")] recipes.RecipePackage("parted", "3.2")]
self.old_groups = [recipes.RecipeGroup("backup-client"),
recipes.RecipeGroup("standard")]
self.new_modules = [recipes.RecipeModule("toml", "2.1"), self.new_modules = [recipes.RecipeModule("toml", "2.1"),
recipes.RecipeModule("httpd", "3.8.*"), recipes.RecipeModule("httpd", "3.8.*"),
recipes.RecipeModule("openssh", "2.8.1")] recipes.RecipeModule("openssh", "2.8.1")]
self.new_packages = [recipes.RecipePackage("python", "2.7.*"), self.new_packages = [recipes.RecipePackage("python", "2.7.*"),
recipes.RecipePackage("parted", "3.2"), recipes.RecipePackage("parted", "3.2"),
recipes.RecipePackage("git", "2.13.*")] recipes.RecipePackage("git", "2.13.*")]
self.new_groups = [recipes.RecipeGroup("console-internet"),
recipes.RecipeGroup("standard")]
self.modules_result = [{"new": {"Modules": {"version": "2.8.1", "name": "openssh"}}, self.modules_result = [{"new": {"Modules": {"version": "2.8.1", "name": "openssh"}},
"old": None}, "old": None},
{"new": None, {"new": None,
@ -60,6 +65,9 @@ class BasicRecipeTest(unittest.TestCase):
{"new": {"Modules": {"version": "3.8.*", "name": "httpd"}}, {"new": {"Modules": {"version": "3.8.*", "name": "httpd"}},
"old": {"Modules": {"version": "3.7.*", "name": "httpd"}}}] "old": {"Modules": {"version": "3.7.*", "name": "httpd"}}}]
self.packages_result = [{"new": {"Packages": {"name": "git", "version": "2.13.*"}}, "old": None}] self.packages_result = [{"new": {"Packages": {"name": "git", "version": "2.13.*"}}, "old": None}]
self.groups_result = [{'new': {'Groups': {'name': 'console-internet'}}, 'old': None},
{'new': None, 'old': {'Groups': {'name': 'backup-client'}}}]
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(self):
@ -133,6 +141,7 @@ class BasicRecipeTest(unittest.TestCase):
"""Test the diff_items function""" """Test the diff_items function"""
self.assertEqual(recipes.diff_items("Modules", self.old_modules, self.new_modules), self.modules_result) self.assertEqual(recipes.diff_items("Modules", self.old_modules, self.new_modules), self.modules_result)
self.assertEqual(recipes.diff_items("Packages", self.old_packages, self.new_packages), self.packages_result) self.assertEqual(recipes.diff_items("Packages", self.old_packages, self.new_packages), self.packages_result)
self.assertEqual(recipes.diff_items("Groups", self.old_groups, self.new_groups), self.groups_result)
def recipe_diff_test(self): def recipe_diff_test(self):
"""Test the recipe_diff function""" """Test the recipe_diff function"""

View File

@ -124,8 +124,9 @@ class ServerTestCase(unittest.TestCase):
{"name": "php-mysqlnd", "version":"7.2.4"}], {"name": "php-mysqlnd", "version":"7.2.4"}],
"name":"http-server", "name":"http-server",
"packages": [{"name":"openssh-server", "version": "7.*"}, "packages": [{"name":"openssh-server", "version": "7.*"},
{"name": "rsync", "version": "3.1.3"}, {"name": "rsync", "version": "3.1.*"},
{"name": "tmux", "version": "2.7"}], {"name": "tmux", "version": "2.7"}],
"groups": [],
"version": "0.0.1"}]} "version": "0.0.1"}]}
resp = self.server.get("/api/v0/blueprints/info/http-server") resp = self.server.get("/api/v0/blueprints/info/http-server")
data = json.loads(resp.data) data = json.loads(resp.data)
@ -141,6 +142,7 @@ class ServerTestCase(unittest.TestCase):
{"name":"glusterfs-cli", "version":"4.0.*"}], {"name":"glusterfs-cli", "version":"4.0.*"}],
"name":"glusterfs", "name":"glusterfs",
"packages":[{"name":"samba", "version":"4.8.*"}], "packages":[{"name":"samba", "version":"4.8.*"}],
"groups": [],
"version": "0.0.1"}, "version": "0.0.1"},
{"description":"An example http server with PHP and MySQL support.", {"description":"An example http server with PHP and MySQL support.",
"modules":[{"name":"httpd", "version":"2.4.*"}, "modules":[{"name":"httpd", "version":"2.4.*"},
@ -150,8 +152,9 @@ class ServerTestCase(unittest.TestCase):
{"name": "php-mysqlnd", "version":"7.2.4"}], {"name": "php-mysqlnd", "version":"7.2.4"}],
"name":"http-server", "name":"http-server",
"packages": [{"name":"openssh-server", "version": "7.*"}, "packages": [{"name":"openssh-server", "version": "7.*"},
{"name": "rsync", "version": "3.1.3"}, {"name": "rsync", "version": "3.1.*"},
{"name": "tmux", "version": "2.7"}], {"name": "tmux", "version": "2.7"}],
"groups": [],
"version": "0.0.1"}, "version": "0.0.1"},
]} ]}
resp = self.server.get("/api/v0/blueprints/info/http-server,glusterfs") resp = self.server.get("/api/v0/blueprints/info/http-server,glusterfs")
@ -197,7 +200,8 @@ class ServerTestCase(unittest.TestCase):
"modules":[{"name":"glusterfs", "version":"4.0.*"}, "modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}], {"name":"glusterfs-cli", "version":"4.0.*"}],
"packages":[{"name":"samba", "version":"4.8.*"}, "packages":[{"name":"samba", "version":"4.8.*"},
{"name":"tmux", "version":"2.7"}]} {"name":"tmux", "version":"2.7"}],
"groups": []}
resp = self.server.post("/api/v0/blueprints/new", resp = self.server.post("/api/v0/blueprints/new",
data=json.dumps(test_blueprint), data=json.dumps(test_blueprint),
@ -231,6 +235,12 @@ class ServerTestCase(unittest.TestCase):
test_blueprint = toml.loads(test_blueprint) test_blueprint = toml.loads(test_blueprint)
test_blueprint["version"] = "0.2.1" test_blueprint["version"] = "0.2.1"
# The test_blueprint generated by toml.loads will not have any groups property
# defined, since there are no groups listed. However, /api/v0/blueprints/new will
# return an object with groups=[]. So, add that here to keep the equality test
# working.
test_blueprint["groups"] = []
self.assertEqual(blueprints[0], test_blueprint) self.assertEqual(blueprints[0], test_blueprint)
def test_07_blueprints_ws_json(self): def test_07_blueprints_ws_json(self):
@ -241,7 +251,8 @@ class ServerTestCase(unittest.TestCase):
"modules":[{"name":"glusterfs", "version":"4.0.*"}, "modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}], {"name":"glusterfs-cli", "version":"4.0.*"}],
"packages":[{"name":"samba", "version":"4.8.*"}, "packages":[{"name":"samba", "version":"4.8.*"},
{"name":"tmux", "version":"2.7"}]} {"name":"tmux", "version":"2.7"}],
"groups": []}
resp = self.server.post("/api/v0/blueprints/workspace", resp = self.server.post("/api/v0/blueprints/workspace",
data=json.dumps(test_blueprint), data=json.dumps(test_blueprint),
@ -267,7 +278,8 @@ class ServerTestCase(unittest.TestCase):
"modules":[{"name":"glusterfs", "version":"4.0.*"}, "modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}], {"name":"glusterfs-cli", "version":"4.0.*"}],
"packages":[{"name":"samba", "version":"4.8.*"}, "packages":[{"name":"samba", "version":"4.8.*"},
{"name":"tmux", "version":"2.7"}]} {"name":"tmux", "version":"2.7"}],
"groups": []}
resp = self.server.post("/api/v0/blueprints/workspace", resp = self.server.post("/api/v0/blueprints/workspace",
data=json.dumps(test_blueprint), data=json.dumps(test_blueprint),
@ -491,7 +503,7 @@ class ServerTestCase(unittest.TestCase):
self.assertNotEqual(data, None) self.assertNotEqual(data, None)
deps = data.get("projects") deps = data.get("projects")
self.assertEqual(len(deps) > 10, True) self.assertEqual(len(deps) > 10, True)
self.assertEqual(deps[0]["name"], "basesystem") self.assertTrue("basesystem" in [dep["name"] for dep in deps])
def test_projects_source_00_list(self): def test_projects_source_00_list(self):
"""Test /api/v0/projects/source/list""" """Test /api/v0/projects/source/list"""
@ -654,7 +666,7 @@ class ServerTestCase(unittest.TestCase):
modules = data.get("modules") modules = data.get("modules")
self.assertEqual(len(modules) > 0, True) self.assertEqual(len(modules) > 0, True)
self.assertEqual(modules[0]["name"], "bash") self.assertEqual(modules[0]["name"], "bash")
self.assertEqual(modules[0]["dependencies"][0]["name"], "basesystem") self.assertTrue("basesystem" in [dep["name"] for dep in modules[0]["dependencies"]])
def test_blueprint_new_branch(self): def test_blueprint_new_branch(self):
"""Test the /api/v0/blueprints/new route with a new branch""" """Test the /api/v0/blueprints/new route with a new branch"""
@ -664,7 +676,8 @@ class ServerTestCase(unittest.TestCase):
"modules":[{"name":"glusterfs", "version":"4.0.*"}, "modules":[{"name":"glusterfs", "version":"4.0.*"},
{"name":"glusterfs-cli", "version":"4.0.*"}], {"name":"glusterfs-cli", "version":"4.0.*"}],
"packages":[{"name":"samba", "version":"4.8.*"}, "packages":[{"name":"samba", "version":"4.8.*"},
{"name":"tmux", "version":"2.7"}]} {"name":"tmux", "version":"2.7"}],
"groups": []}
resp = self.server.post("/api/v0/blueprints/new?branch=test", resp = self.server.post("/api/v0/blueprints/new?branch=test",
data=json.dumps(test_blueprint), data=json.dumps(test_blueprint),