Skip to content

Commit

Permalink
Load new configuration defaults for RPM sub-components of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mmathesius committed Apr 12, 2021
1 parent 10d5322 commit 523ebb8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/distrobaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,29 @@ def load_config(crepo):
"Configuration error: defaults.%s missing.", dk
)
return None
# parse defaults for module sub-components
for dk in ("rpms",):
n["defaults"]["modules"][dk] = dict()
for dkk in ("source", "destination"):
if (
dk in cnf["defaults"]["modules"]
and dkk in cnf["defaults"]["modules"][dk]
):
n["defaults"]["modules"][dk][dkk] = cnf["defaults"][
"modules"
][dk][dkk]
else:
logger.warning(
"Configuration warning: defaults.modules.%s.%s "
"not defined, using value from defaults.%s.%s",
dk,
dkk,
dk,
dkk,
)
n["defaults"]["modules"][dk][dkk] = str(
n["defaults"][dk][dkk]
)
else:
logger.error("Configuration error: defaults missing.")
return None
Expand Down Expand Up @@ -406,6 +429,26 @@ def load_config(crepo):
nc[k][p]["cache"][ck] = str(
cnf[k][p]["cache"][ck]
)
if k == "modules":
# parse overrides for module sub-components
for cn in ("rpms",):
nc[k][p][cn] = dict()
if cn in cnf[k][p]:
for cp in cnf[k][p][cn].keys():
nc[k][p][cn][cp] = dict()
for ck in ("source", "destination"):
nc[k][p][cn][cp][ck] = n["defaults"][
k
][cn][ck] % {
"component": cp,
"name": cname,
"ref": "%(ref)s",
"stream": sname,
}
if ck in cnf[k][p][cn][cp]:
nc[k][p][cn][cp][ck] = cnf[k][p][
cn
][cp][ck]
logger.info(
"Found %d configured component(s) in the %s namespace.",
len(nc[k]),
Expand Down
8 changes: 8 additions & 0 deletions tests/data/config/distrobaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ configuration:
modules:
source: "%(component)s.git#%(stream)s"
destination: "%(component)s.git#%(stream)s-fluff-42.0.0-alpha"
rpms:
source: "%(component)s.git"
destination: "%(component)s.git#stream-%(name)s-%(stream)s"
cache:
source: "%(component)s"
destination: "%(component)s"
Expand All @@ -64,3 +67,8 @@ components:
modules:
testmodule:master:
destination: testmodule#stream-master-fluff-42.0.0-alpha-experimental
rpms:
componentrpm:
source: componentsource.git#sourcebranch
destination: coomponentrpm.git#fluff-42.0.0-alpha-experimental
anotherrpm: {}
18 changes: 18 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def test_load_config(self):
# make sure what was loaded matches get_config()
self.assertEqual(cfg, distrobaker.get_config())

# verify modular RPM component defaults were loaded
self.assertEqual(
cfg["main"]["defaults"]["modules"]["rpms"],
{
"source": "%(component)s.git",
"destination": "%(component)s.git#stream-%(name)s-%(stream)s",
},
)
# verify some derived values are present in the configuration
# with the expected values
self.assertEqual(
Expand All @@ -55,6 +63,16 @@ def test_load_config(self):
"source": "testmodule.git#master",
"destination": "testmodule#stream-master-fluff-42.0.0-alpha-experimental",
"cache": {"source": "testmodule", "destination": "testmodule"},
"rpms": {
"componentrpm": {
"source": "componentsource.git#sourcebranch",
"destination": "coomponentrpm.git#fluff-42.0.0-alpha-experimental",
},
"anotherrpm": {
"source": "anotherrpm.git",
"destination": "anotherrpm.git#stream-testmodule-master",
},
},
},
)

Expand Down

0 comments on commit 523ebb8

Please sign in to comment.