Skip to content

Commit

Permalink
add tests for iosxrd
Browse files Browse the repository at this point in the history
  • Loading branch information
jmussmann committed Sep 11, 2024
1 parent 7c7e9ee commit 71e23b0
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^
% Invalid input detected at '^' marker.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hostname iosxr01
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Wed Sep 11 09:56:44.796 UTC
Cisco IOS XR Software, Version 7.9.1 LNT
Copyright (c) 2013-2023 by Cisco Systems, Inc.

Build Information:
Built By : ingunawa
Built On : Sun Apr 02 06:50:19 UTC 2023
Build Host : iox-ucs-075
Workspace : /auto/srcarchive15/prod/7.9.1/xrd-control-plane/ws
Version : 7.9.1
Label : 7.9.1

cisco XRd Control Plane
cisco XRd-CP-C-01 processor with 64GB of memory
iosxr01 uptime is 1 day, 2 hours, 0 minutes
XRd Control Plane Containe
98 changes: 98 additions & 0 deletions tests/unit/modules/network/iosxr/test_iosxr_xrd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#
# (c) 2022 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import absolute_import, division, print_function


__metaclass__ = type

from os import path
from unittest import TestCase
from unittest.mock import MagicMock

from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes, to_text

from ansible_collections.cisco.iosxr.plugins.cliconf import iosxr


class TestPluginCLIConfIOSXR(TestCase):
"""Test class for IOSXR CLI Conf Methods"""

def setUp(self):
self._mock_connection = MagicMock()
self._prepare()
self._cliconf = iosxr.Cliconf(self._mock_connection)
self.maxDiff = None

def _prepare(self, platform="iosxr"):
b_FIXTURE_DIR = b"%s/fixtures/cliconf_xrd/%s" % (
to_bytes(
path.dirname(path.abspath(__file__)),
errors="surrogate_or_strict",
),
to_bytes(platform),
)

def _connection_side_effect(*args, **kwargs):
try:
if args:
value = args[0]
else:
value = kwargs.get("command")
if value == b"show inventory":
raise AnsibleConnectionFailure
if b"|" in value:
value = value.replace(b"|", b"")
fixture_path = path.abspath(
b"%s/%s" % (b_FIXTURE_DIR, b"_".join(value.split(b" "))),
)
with open(fixture_path, "rb") as file_desc:
return to_text(file_desc.read())
except (OSError, IOError):
if args:
value = args[0]
return value
elif kwargs.get("command"):
value = kwargs.get("command")
return value
return "NO-OP"

self._mock_connection.send.side_effect = _connection_side_effect

def tearDown(self):
pass

def test_get_device_info_iosxr(self):
"""Test get_device_info for nxos"""
device_info = self._cliconf.get_device_info()

mock_device_info = {
"network_os_version": "7.9.1 LNT",
"network_os": "iosxr",
"network_os_hostname": "iosxr01",
}

self.assertEqual(device_info, mock_device_info)

def test_get_command_output_iosxr(self):
"""Test _get_command_with_output for iosxr"""
self._prepare()
cmd = self._cliconf.get_command_output("show running-config hostname")

self.assertEqual(cmd, "hostname iosxr01")

0 comments on commit 71e23b0

Please sign in to comment.