Repository: ansible/ansible-modules-core

Issue:
network/eos/eos_facts.py  - Code review
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

eos_facts
##### ANSIBLE VERSION

```
ansible --version
ansible 2.2.0 (devel c81fe70fbf) last updated 2016/09/09 11:02:57 (GMT +100)
  lib/ansible/modules/core: (devel 684c6897e2) last updated 2016/09/09 11:03:28 (GMT +100)
  lib/ansible/modules/extras: (devel f83aa9fff3) last updated 2016/09/09 11:04:04 (GMT +100)
  config file = /home/johnb/.ansible.cfg
  configured module search path = Default w/o overrides

```
##### CONFIGURATION
##### OS / ENVIRONMENT
##### SUMMARY

Some critical bugs found by linters
##### STEPS TO REPRODUCE

```
pylint ../ansible/lib/ansible/modules/core/network/eos/eos_facts.py
```
##### EXPECTED RESULTS

No errors from pylint
##### ACTUAL RESULTS

```
pylint ../ansible/lib/ansible/modules/core/network/eos/eos_facts.py

1) 
# Will give backtrace rather than going cleaner message from `module.exit_json`
W:369, 8: Unreachable code (unreachable)

2) 
# Not sure why we don't hit this case when go into `__init__`
# How can I generate a test case that triggers this?
E:164, 8: Instance of 'FactsBase' has no 'load_commands' member (no-member)

3) 
W:144, 0: Unused get_exception imported from ansible.module_utils.basic (unused-import)

```

4) 

```
if subset not in VALID_SUBSETS:
    module.fail_json(msg='Bad subset')
```

Minor improvement suggestion, print out the invalid subset



Discussion:

Resolving patch:
diff --git a/network/eos/eos_facts.py b/network/eos/eos_facts.py
--- a/network/eos/eos_facts.py
+++ b/network/eos/eos_facts.py
@@ -141,8 +141,8 @@
 """
 import re
 
-from ansible.module_utils.basic import get_exception
 from ansible.module_utils.netcli import CommandRunner, AddCommandError
+from ansible.module_utils.six import iteritems
 from ansible.module_utils.eos import NetworkModule
 
 
@@ -163,6 +163,10 @@ def __init__(self, runner):
 
         self.load_commands()
 
+    def load_commands(self):
+        raise NotImplementedError
+
+
 class Default(FactsBase):
 
     SYSTEM_MAP = {
@@ -178,7 +182,7 @@ def load_commands(self):
 
     def populate(self):
         data = self.runner.get_command('show version', 'json')
-        for key, value in self.SYSTEM_MAP.iteritems():
+        for key, value in iteritems(self.SYSTEM_MAP):
             if key in data:
                 self.facts[value] = data[key]
 
@@ -256,10 +260,10 @@ def populate(self):
 
     def populate_interfaces(self, data):
         facts = dict()
-        for key, value in data['interfaces'].iteritems():
+        for key, value in iteritems(data['interfaces']):
             intf = dict()
 
-            for remote, local in self.INTERFACE_MAP.iteritems():
+            for remote, local in iteritems(self.INTERFACE_MAP):
                 if remote in value:
                     intf[local] = value[remote]
 
@@ -336,7 +340,8 @@ def main():
             exclude = False
 
         if subset not in VALID_SUBSETS:
-            module.fail_json(msg='Bad subset')
+            module.fail_json(msg='Subset must be one of [%s], got %s' %
+                             (', '.join(VALID_SUBSETS), subset))
 
         if exclude:
             exclude_subsets.add(subset)
@@ -365,11 +370,10 @@ def main():
             inst.populate()
             facts.update(inst.facts)
     except Exception:
-        raise
         module.exit_json(out=module.from_json(runner.items))
 
     ansible_facts = dict()
-    for key, value in facts.iteritems():
+    for key, value in iteritems(facts):
         key = 'ansible_net_%s' % key
         ansible_facts[key] = value
 
@@ -378,4 +382,3 @@ def main():
 
 if __name__ == '__main__':
     main()
-


Test patch: