Skip to content

Commit

Permalink
issue:37306 Fix issue with vlan support for onyx version 3.6.6000 (an…
Browse files Browse the repository at this point in the history
…sible#37310)

* issue:37306 Fix issue with vlan support for onyx version 3.6.6000

Signed-off-by: Samer Deeb <samerd@mellanox.com>
  • Loading branch information
samerd authored and gundalow committed Mar 20, 2018
1 parent 6308047 commit a89bafc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/ansible/module_utils/network/onyx/onyx.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,24 @@ def get_interfaces_config(module, interface_type, flags=None, json_fmt=True):
return show_cmd(module, cmd, json_fmt)


def show_version(module):
return show_cmd(module, "show version")


def get_bgp_summary(module):
cmd = "show running-config protocol bgp"
return show_cmd(module, cmd, json_fmt=False, fail_on_error=False)


class BaseOnyxModule(object):
ONYX_API_VERSION = "3.6.6000"

def __init__(self):
self._module = None
self._commands = list()
self._current_config = None
self._required_config = None
self._os_version = None

def init_module(self):
pass
Expand All @@ -162,6 +168,11 @@ def load_current_config(self):
def get_required_config(self):
pass

def _get_os_version(self):
version_data = show_version(self._module)
return self.get_config_attr(
version_data, "Product release")

# pylint: disable=unused-argument
def check_declarative_intent_params(self, result):
return None
Expand Down
3 changes: 3 additions & 0 deletions lib/ansible/modules/network/onyx/onyx_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def get_required_config(self):
self._required_config.append(params)

def _create_vlan_data(self, vlan_id, vlan_data):
if self._os_version >= self.ONYX_API_VERSION:
vlan_data = vlan_data[0]
return {
'vlan_id': vlan_id,
'name': self.get_config_attr(vlan_data, 'Name')
Expand All @@ -148,6 +150,7 @@ def _get_vlan_config(self):

def load_current_config(self):
# called in base class in run function
self._os_version = self._get_os_version()
self._current_config = dict()
vlan_config = self._get_vlan_config()
if not vlan_config:
Expand Down
8 changes: 6 additions & 2 deletions test/units/modules/network/onyx/test_onyx_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import json

from ansible.compat.tests.mock import patch
from ansible.modules.network.onyx import onyx_vlan
from units.modules.utils import set_module_args
Expand All @@ -42,15 +40,21 @@ def setUp(self):
'ansible.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()

self.mock_get_version = patch.object(
onyx_vlan.OnyxVlanModule, "_get_os_version")
self.get_version = self.mock_get_version.start()

def tearDown(self):
super(TestOnyxVlanModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_get_version.stop()

def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_vlan_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"

def test_vlan_no_change(self):
set_module_args(dict(vlan_id=20))
Expand Down

0 comments on commit a89bafc

Please sign in to comment.