From 1c54b7edab165ad3ed24a811c55c8eb792b3aa4f Mon Sep 17 00:00:00 2001 From: Michel Jouvin Date: Sat, 14 Jul 2018 10:39:25 +0200 Subject: [PATCH] check_feature_template: allow relaxed check of template existence When config option relaxed_feature_template_check is true (default: false), only display a warning if the template existence cannot be assessed rather than raising an exception. This allows to support direct use of features defined in the plenary templates (e.g. features from the template library). Contributes to https://github.com/quattor/aquilon/issues/111 Change-Id: I0b3319cd39a2c962da0464c511a2c42de2595407 --- etc/aqd.conf.defaults | 3 +++ lib/aquilon/worker/commands/bind_feature.py | 2 +- lib/aquilon/worker/commands/manage_list.py | 2 +- lib/aquilon/worker/dbwrappers/feature.py | 11 +++++++---- lib/aquilon/worker/dbwrappers/host.py | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/etc/aqd.conf.defaults b/etc/aqd.conf.defaults index e97165af0..44993780c 100644 --- a/etc/aqd.conf.defaults +++ b/etc/aqd.conf.defaults @@ -353,6 +353,9 @@ gzip_output = false transparent_gzip = true template_extension = .tpl object_declarations_template = false +# When true, only display a warning if a feature template doesn't +# exist in a domain Git repository +relaxed_feature_template_check = False [tool_timeout] # If set to True, timeout will be set to 'default_value' for any tools run via subprocess diff --git a/lib/aquilon/worker/commands/bind_feature.py b/lib/aquilon/worker/commands/bind_feature.py index 20e7163f6..2d1813af0 100755 --- a/lib/aquilon/worker/commands/bind_feature.py +++ b/lib/aquilon/worker/commands/bind_feature.py @@ -141,7 +141,7 @@ def do_link(self, session, logger, dbfeature, params): q = q.filter(or_(*filters)) for dbdomain in q: - check_feature_template(self.config, dbarchetype, dbfeature, + check_feature_template(self.config, logger, dbarchetype, dbfeature, dbdomain) add_link(session, logger, dbfeature, params) diff --git a/lib/aquilon/worker/commands/manage_list.py b/lib/aquilon/worker/commands/manage_list.py index e6a014afe..0cbc8850c 100755 --- a/lib/aquilon/worker/commands/manage_list.py +++ b/lib/aquilon/worker/commands/manage_list.py @@ -181,7 +181,7 @@ def render(self, session, logger, plenaries, domain, sandbox, force, for dbarch, featureset in features.items(): for dbfeature in featureset: - check_feature_template(self.config, dbarch, dbfeature, + check_feature_template(self.config, logger, dbarch, dbfeature, dbbranch) for dbobj in objects: diff --git a/lib/aquilon/worker/dbwrappers/feature.py b/lib/aquilon/worker/dbwrappers/feature.py index 2d90b5617..d800da2c8 100644 --- a/lib/aquilon/worker/dbwrappers/feature.py +++ b/lib/aquilon/worker/dbwrappers/feature.py @@ -27,7 +27,6 @@ from aquilon.worker.templates import PlenaryHost, PlenaryPersonality from aquilon.worker.templates.domain import template_branch_basedir - def add_link(session, logger, dbfeature, params): FeatureLink.get_unique(session, feature=dbfeature, preclude=True, **params) @@ -59,7 +58,7 @@ def add_link(session, logger, dbfeature, params): dbfeature.links.append(FeatureLink(**params)) -def check_feature_template(config, dbarchetype, dbfeature, dbdomain): +def check_feature_template(config, logger, dbarchetype, dbfeature, dbdomain): basedir = template_branch_basedir(config, dbdomain) # Features can be defined either in the archetype directory or as # features shared by all the archetypes if they are defined in basedir @@ -73,8 +72,12 @@ def check_feature_template(config, dbarchetype, dbfeature, dbdomain): if os.path.exists("{}/config.{}" .format(feature_dir, ext)): return - raise ArgumentError("{0} does not have templates present in {1:l} " - "for {2:l}.".format(dbfeature, dbdomain, dbarchetype)) + if config.getboolean("panc", "relaxed_feature_template_check"): + logger.client_info("WARNING: {0} templates not present in {1:l} for {2:l} " + "(assumed to be present in plenary templates).".format(dbfeature, dbdomain, dbarchetype)) + else: + raise ArgumentError("{0} does not have templates present in {1:l} " + "for {2:l}.".format(dbfeature, dbdomain, dbarchetype)) def get_affected_plenaries(session, dbfeature, plenaries, diff --git a/lib/aquilon/worker/dbwrappers/host.py b/lib/aquilon/worker/dbwrappers/host.py index fff7b6f4d..322b03d65 100644 --- a/lib/aquilon/worker/dbwrappers/host.py +++ b/lib/aquilon/worker/dbwrappers/host.py @@ -84,7 +84,7 @@ def create_host(session, logger, config, dbhw, dbarchetype, domain=None, pre, post = host_features(dbstage) hw_features = hardware_features(dbstage, dbhw.model) for dbfeature in pre | post | hw_features: - check_feature_template(config, dbarchetype, dbfeature, dbbranch) + check_feature_template(config, logger, dbarchetype, dbfeature, dbbranch) if not osname: if config.has_option(section, "default_osname"):