Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roll up of fixes for eos modules #21406

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/ansible/module_utils/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
import os
import re
import time

Expand Down Expand Up @@ -166,7 +167,7 @@ def send_config(self, commands):
def configure(self, commands):
"""Sends configuration commands to the remote device
"""
if not check_authorization(self):
if not self.check_authorization():
self._module.fail_json(msg='configuration operations require privilege escalation')

conn = get_connection(self)
Expand All @@ -175,7 +176,7 @@ def configure(self, commands):
if rc != 0:
self._module.fail_json(msg='unable to enter configuration mode', output=err)

rc, out, err = send_config(self, commands)
rc, out, err = self.send_config(commands)
if rc != 0:
self._module.fail_json(msg=err)

Expand All @@ -185,7 +186,7 @@ def configure(self, commands):
def load_config(self, commands, commit=False, replace=False):
"""Loads the config commands onto the remote device
"""
if not check_authorization(self):
if not self.check_authorization():
self._module.fail_json(msg='configuration operations require privilege escalation')

use_session = os.getenv('ANSIBLE_EOS_USE_SESSIONS', True)
Expand All @@ -194,7 +195,7 @@ def load_config(self, commands, commit=False, replace=False):
except ValueError:
pass

if not all((bool(use_session), supports_sessions(self))):
if not all((bool(use_session), self.supports_sessions())):
return configure(self, commands)

conn = get_connection(self)
Expand All @@ -208,10 +209,10 @@ def load_config(self, commands, commit=False, replace=False):
if replace:
self.exec_command('rollback clean-config', check_rc=True)

rc, out, err = send_config(self, commands)
rc, out, err = self.send_config(commands)
if rc != 0:
self.exec_command('abort')
conn.fail_json(msg=err, commands=commands)
self._module.fail_json(msg=err, commands=commands)

rc, out, err = self.exec_command('show session-config diffs')
if rc == 0:
Expand All @@ -230,7 +231,7 @@ def __init__(self, module):
self._module = module
self._enable = None
self._session_support = None
self._device_config = {}
self._device_configs = {}

host = module.params['host']
port = module.params['port']
Expand Down
8 changes: 7 additions & 1 deletion lib/ansible/modules/network/eos/eos_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
import time

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.six import string_types
from ansible.module_utils.netcli import Conditional
from ansible.module_utils.network_common import ComplexList
Expand Down Expand Up @@ -193,7 +194,12 @@ def main():
result['warnings'] = warnings

wait_for = module.params['wait_for'] or list()
conditionals = [Conditional(c) for c in wait_for]

try:
conditionals = [Conditional(c) for c in wait_for]
except AttributeError:
exc = get_exception()
module.fail_json(msg=str(exc))

retries = module.params['retries']
interval = module.params['interval']
Expand Down
1 change: 1 addition & 0 deletions lib/ansible/modules/network/eos/eos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def run(module, result):
commands.extend(module.params['after'])

result['commands'] = commands
result['updates'] = commands

replace = module.params['replace'] == 'config'
commit = not module.check_mode
Expand Down
11 changes: 7 additions & 4 deletions lib/ansible/modules/network/eos/eos_eapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.eos import run_commands, load_config
from ansible.module_utils.six import iteritems
from ansible.module_utils.eos import eos_argument_spec, check_args

def validate_http_port(value, module):
if not 1 <= value <= 65535:
Expand All @@ -198,8 +199,8 @@ def validate_local_http_port(value, module):
module.fail_json(msg='http_port must be between 1 and 65535')

def validate_vrf(value, module):
rc, out, err = run_commands(module, ['show vrf'])
configured_vrfs = re.findall('^\s+(\w+)(?=\s)', out[0],re.M)
out = run_commands(module, ['show vrf'])
configured_vrfs = re.findall('^\s+(\w+)(?=\s)', out[0], re.M)
configured_vrfs.append('default')
if value not in configured_vrfs:
module.fail_json(msg='vrf `%s` is not configured on the system' % value)
Expand Down Expand Up @@ -255,7 +256,7 @@ def parse_state(data):


def map_config_to_obj(module):
rc, out, err = run_commands(module, ['show management api http-commands | json'])
out = run_commands(module, ['show management api http-commands | json'])
return {
'http': out[0]['httpServer']['configured'],
'http_port': out[0]['httpServer']['port'],
Expand Down Expand Up @@ -290,7 +291,7 @@ def map_params_to_obj(module):
return obj

def collect_facts(module, result):
rc, out, err = run_commands(module, ['show management api http-commands | json'])
out = run_commands(module, ['show management api http-commands | json'])
facts = dict(eos_eapi_urls=dict())
for each in out[0]['urls']:
intf, url = each.split(' : ')
Expand Down Expand Up @@ -320,6 +321,8 @@ def main():
state=dict(default='started', choices=['stopped', 'started']),
)

argument_spec.update(eos_argument_spec)

module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)

Expand Down
3 changes: 3 additions & 0 deletions lib/ansible/modules/network/eos/eos_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import ComplexList
from ansible.module_utils.eos import load_config, get_config
from ansible.module_utils.eos import eos_argument_spec

_CONFIGURED_VRFS = None

Expand Down Expand Up @@ -304,6 +305,8 @@ def main():
state=dict(default='present', choices=['present', 'absent'])
)

argument_spec.update(eos_argument_spec)

module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)

Expand Down
15 changes: 7 additions & 8 deletions lib/ansible/plugins/action/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ def _get_socket_path(self, play_context):
def load_provider(self):
provider = self._task.args.get('provider', {})
for key, value in iteritems(eos_argument_spec):
if key == 'provider':
continue
elif key in self._task.args:
provider[key] = self._task.args[key]
elif 'fallback' in value:
provider[key] = self._fallback(value['fallback'])
elif key not in provider:
provider[key] = None
if key != 'provider' and key not in provider:
if key in self._task.args:
provider[key] = self._task.args[key]
elif 'fallback' in value:
provider[key] = self._fallback(value['fallback'])
elif key not in provider:
provider[key] = None
return provider

def _fallback(self, fallback):
Expand Down
6 changes: 3 additions & 3 deletions test/units/modules/network/eos/test_eos_eapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run_commands(module, commands, **kwargs):
output = list()
for cmd in commands:
output.append(load_fixture(self.command_fixtures[cmd]))
return (0, output, '')
return output

self.run_commands.side_effect = run_commands
self.load_config.return_value = dict(diff=None, session='session')
Expand Down Expand Up @@ -86,9 +86,9 @@ def test_eos_eapi_http_port(self):
self.start_configured(changed=True, commands=commands)

def test_eos_eapi_http_invalid(self):
set_module_args(dict(port=80000))
set_module_args(dict(http_port=80000))
commands = []
self.start_unconfigured(failed=True)
self.start_unconfigured(failed=True, commands=commands)

def test_eos_eapi_https_enable(self):
set_module_args(dict(https=True))
Expand Down