Skip to content

Commit 0e76ae3

Browse files
committed
Improve simple group logging
1 parent 8f6a650 commit 0e76ae3

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

cloudselect/group/simple.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,30 @@ def run(self, name, metadata):
2424
"""Return dictionary with options for the group of instances."""
2525
options = self.config().get("options")
2626
if not options:
27-
self.log.warning("'options' block not found in %s", self.config())
27+
self.log.warning("%s: 'options' block not found in %s", name, self.config())
2828
return None
2929
if not isinstance(options, list):
3030
self.log.warning(
31-
"'options' block should be list of dictionaries in %s", self.config(),
31+
"%s: 'options' block should be list of dictionaries in %s",
32+
name,
33+
self.config(),
3234
)
3335
return None
3436
for group in self.config().get("options", []):
3537
try:
36-
self.log.debug("Process group %s", group)
38+
self.log.debug("%s: Process group %s", name, group)
3739
entry = group.get("match")
3840
if not entry:
39-
self.log.warning("Unable to find 'match' key in %s", group)
41+
self.log.warning(
42+
"%s: Unable to find 'match' key in %s", name, group,
43+
)
4044
continue
4145
if ":" not in entry:
4246
self.log.warning(
43-
"Unable to parse 'match' value %s for %s", entry, group,
47+
"%s: Unable to parse 'match' value %s for %s",
48+
name,
49+
entry,
50+
group,
4451
)
4552
continue
4653
key, pattern = entry.split(":", 1)
@@ -50,18 +57,21 @@ def run(self, name, metadata):
5057
try:
5158
value = value.get(key_part)
5259
if not value:
53-
self.log.debug("Unable to find key %s", key_part)
60+
self.log.debug("%s: Unable to find key %s", name, key_part)
5461
break
5562
except (AttributeError, NameError):
56-
self.log.debug("Unable to find key %s", key_part)
63+
self.log.debug("%s: Unable to find key %s", name, key_part)
5764
break
5865
if isinstance(value, str) and regex.match(value) is not None:
5966
self.log.debug(
60-
"Match pattern %s and value %s", pattern, value,
67+
"%s: Pattern %s and value %s is matched",
68+
name,
69+
pattern,
70+
value,
6171
)
6272
result = group.get(name)
6373
if result is not None:
6474
return result
6575
except AttributeError:
66-
self.log.warning("Unable to find 'match' key in %s", group)
76+
self.log.warning("%s: Unable to find 'match' key in %s", name, group)
6777
return None

test/group/test_simple.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ def test_options_errors(caplog, cfgdir):
7979
assert len(caplog.records) == 1
8080
assert (
8181
caplog.records[0].getMessage()
82-
== "'options' block not found in {'type': 'simple'}"
82+
== "option: 'options' block not found in {'type': 'simple'}"
8383
)
8484

8585
caplog.clear()
8686
configuration["group"]["options"] = 123
8787
Container.options("option")
8888
assert len(caplog.records) == 1
8989
assert (
90-
caplog.records[0].msg == "'options' block should be list of dictionaries in %s"
90+
caplog.records[0].msg
91+
== "%s: 'options' block should be list of dictionaries in %s"
9192
)
9293

9394

0 commit comments

Comments
 (0)