Skip to content

Commit a9d79fc

Browse files
Merge pull request #42 from ansible-network/bt_fix_truthy_bug
Fix for elif truthy Reviewed-by: Bradley A. Thornton https://github.com/cidrblock
2 parents e875410 + b436033 commit a9d79fc

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

rmb_tests/roles/my_role/module_utils/network/myos/facts/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def generate_final_config(self, cfg_dict):
111111
child_val = self.generate_final_config(val)
112112
if child_val:
113113
dct = {key: child_val}
114-
elif val:
114+
elif val is not None:
115115
dct = {key: val}
116116
if dct:
117117
final_cfg.update(dct)

rmb_tests/roles/my_role/module_utils/network/myos/facts/interfaces/interfaces.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ def render_config(self, spec, conf):
8484
if match:
8585
config['some_dict']['property_01'] = match.groups()[0]
8686

87-
try:
88-
config['some_bool'] = bool(self.parse_conf_arg(conf, 'a_bool'))
89-
except TypeError:
87+
a_bool = self.parse_conf_arg(conf, 'a_bool')
88+
if a_bool == 'true':
89+
config['some_bool'] = True
90+
elif a_bool == 'false':
91+
config['some_bool'] = False
92+
else:
9093
config['some_bool'] = None
9194

9295
try:

roles/resource_module/templates/module_utils/network_os/facts/base.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class FactsBase(object):
111111
child_val = self.generate_final_config(val)
112112
if child_val:
113113
dct = {key: child_val}
114-
elif val:
114+
elif val is not None:
115115
dct = {key: val}
116116
if dct:
117117
final_cfg.update(dct)

roles/resource_module/templates/module_utils/network_os/facts/resource/resource.py.j2

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ class {{ resource|capitalize }}Facts(FactsBase):
8484
if match:
8585
config['some_dict']['property_01'] = match.groups()[0]
8686

87-
try:
88-
config['some_bool'] = bool(self.parse_conf_arg(conf, 'a_bool'))
89-
except TypeError:
87+
a_bool = self.parse_conf_arg(conf, 'a_bool')
88+
if a_bool == 'true':
89+
config['some_bool'] = True
90+
elif a_bool == 'false':
91+
config['some_bool'] = False
92+
else:
9093
config['some_bool'] = None
9194

9295
try:

0 commit comments

Comments
 (0)