{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/16282","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/16282/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/16282/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/16282/events","html_url":"https://github.com/ansible/ansible/issues/16282","id":160248939,"number":16282,"title":"IOS NetworkModule never calls disconnect()","user":{"login":"pstch","id":1682742,"avatar_url":"https://avatars.githubusercontent.com/u/1682742?v=3","gravatar_id":"","url":"https://api.github.com/users/pstch","html_url":"https://github.com/pstch","followers_url":"https://api.github.com/users/pstch/followers","following_url":"https://api.github.com/users/pstch/following{/other_user}","gists_url":"https://api.github.com/users/pstch/gists{/gist_id}","starred_url":"https://api.github.com/users/pstch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pstch/subscriptions","organizations_url":"https://api.github.com/users/pstch/orgs","repos_url":"https://api.github.com/users/pstch/repos","events_url":"https://api.github.com/users/pstch/events{/privacy}","received_events_url":"https://api.github.com/users/pstch/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04"},{"url":"https://api.github.com/repos/ansible/ansible/labels/networking","name":"networking","color":"c7def8"}],"state":"closed","locked":false,"assignee":{"login":"Qalthos","id":649648,"avatar_url":"https://avatars.githubusercontent.com/u/649648?v=3","gravatar_id":"","url":"https://api.github.com/users/Qalthos","html_url":"https://github.com/Qalthos","followers_url":"https://api.github.com/users/Qalthos/followers","following_url":"https://api.github.com/users/Qalthos/following{/other_user}","gists_url":"https://api.github.com/users/Qalthos/gists{/gist_id}","starred_url":"https://api.github.com/users/Qalthos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Qalthos/subscriptions","organizations_url":"https://api.github.com/users/Qalthos/orgs","repos_url":"https://api.github.com/users/Qalthos/repos","events_url":"https://api.github.com/users/Qalthos/events{/privacy}","received_events_url":"https://api.github.com/users/Qalthos/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2016-06-14T18:17:17Z","updated_at":"2016-06-20T16:31:43Z","closed_at":"2016-06-20T16:31:43Z","body":"I found no open/closed issues referring to `NetworkModule`, or `disconnect()` methods.\r\n\r\n##### ISSUE TYPE\r\n\r\n - Bug Report (low-importance)\r\n\r\n\r\n##### ANSIBLE VERSION\r\n```\r\nansible 2.1.0.0\r\n  config file = /etc/ansible/ansible.cfg\r\n  configured module search path = Default w/o overrides\r\n```\r\n\r\nCode is identical in `devel` branch.\r\n\r\n##### REFERRED CODE \r\n\r\nhttps://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/ios.py#L154\r\n\r\n##### SUMMARY\r\n\r\nAlthough the `NetworkModule` class in `ansible.module_utils.ios` defines a `disconnect` method it is never called in the current code. Additionally, if it was called, it would raise a `NameError` as the `Cli` class does not define a `close` method. \r\n\r\nIt seems that this code was inspired from the JunOS utility module, which does call its `disconnect` method, by wrapping all calls to `fail_*` in a `_fail` method that calls `disconnect`\r\n\r\nAlthough this may seem easy to fix, I don't feel familiar enough with Ansible's object-oriented module architecture. I'm still pretty new to all of this, and I noticed this while reading the IOS module in an attempt to write a Mikrotik configuration module."},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/227195379","html_url":"https://github.com/ansible/ansible/issues/16282#issuecomment-227195379","issue_url":"https://api.github.com/repos/ansible/ansible/issues/16282","id":227195379,"user":{"login":"Qalthos","id":649648,"avatar_url":"https://avatars.githubusercontent.com/u/649648?v=3","gravatar_id":"","url":"https://api.github.com/users/Qalthos","html_url":"https://github.com/Qalthos","followers_url":"https://api.github.com/users/Qalthos/followers","following_url":"https://api.github.com/users/Qalthos/following{/other_user}","gists_url":"https://api.github.com/users/Qalthos/gists{/gist_id}","starred_url":"https://api.github.com/users/Qalthos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Qalthos/subscriptions","organizations_url":"https://api.github.com/users/Qalthos/orgs","repos_url":"https://api.github.com/users/Qalthos/repos","events_url":"https://api.github.com/users/Qalthos/events{/privacy}","received_events_url":"https://api.github.com/users/Qalthos/received_events","type":"User","site_admin":false},"created_at":"2016-06-20T16:31:43Z","updated_at":"2016-06-20T16:31:43Z","body":"So you have it mostly correct, IOS' NetworkModule does not call disconnect, but it is not intended to directly. The code in module_utils is not the modules themselves, but common code for modules in ansible/ansible-modules-core or ansible/ansible-modules-extra (or your own modules) to use. If you have a need for a connection to disconnect at some point, it would be put in there\r\n\r\n(ex https://github.com/ansible/ansible-modules-core/blob/devel/network/ios/ios_command.py)\r\n\r\nAll that said, it does look like disconnect is unused throughout IOS' module code, and in fact broken. These two facts are likely related. Happily, thanks to some of the changes made in 2.1 there is a bit of refactoring going on in the network modules for greater code reuse (#16158 does this for EOS, the rest should follow reasonably quickly) which should at least ensure less broken copy-pasted code.\r\n\r\nAs for actually calling disconnect, I'm not all that sure that it really is necessary to be called. JunOS does it as part of its failure handling for NETCONF transports to make sure the jnpr library cleans up after itself properly, but we have no such need on the simpler devices. Modules certainly could be more explicit about closing connections, but ultimately it is up to the module author to use what tools are made available."}}
{"actor":{"display_login":"Qalthos"}}