Skip to content

Commit

Permalink
formatting of stale files
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Aug 23, 2024
1 parent 2865c38 commit 54efb90
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
28 changes: 16 additions & 12 deletions test/unit/TestNokiaSRLDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,50 @@
# the License.

import unittest

import pytest
from napalm_srlinux import srlinux
from napalm.base.test.base import TestConfigNetworkDriver
from napalm.base.exceptions import (
MergeConfigException,
)
from napalm.base.test.base import TestConfigNetworkDriver

from napalm_srlinux import srlinux


class TestConfigSRLDriver(unittest.TestCase, TestConfigNetworkDriver):
@classmethod
def setUpClass(cls):
hostname = "172.20.20.10"
username = "admin"
password = "admin"
cls.vendor = "test/unit/" + "srl" #to facilitate executing test without errors prepended path
cls.vendor = (
"test/unit/" + "srl"
) # to facilitate executing test without errors prepended path

optional_args = {
"port": 57400,
"target_name": "srl",
"tls_cert":"/root/gnmic_certs/srl_certs/clientCert.crt",
"tls_cert": "/root/gnmic_certs/srl_certs/clientCert.crt",
"tls_ca": "/etc/containerlab/lab-examples/srlceos01/clab-srlceos01/ca/root/root-ca.pem",
"tls_key": "/root/gnmic_certs/srl_certs/clientKey.pem",
# "skip_verify": True,
# "insecure": False
"encoding": "JSON_IETF"
"encoding": "JSON_IETF",
}
cls.device = srl.NokiaSRLinuxDriver(
cls.device = srlinux.NokiaSRLinuxDriver(
hostname, username, password, timeout=60, optional_args=optional_args
)
cls.device.open()

cls.device.load_replace_candidate(filename="%s/initial.conf" % cls.vendor)
#auto commit for load replace
#cls.device.commit_config()
# auto commit for load replace
# cls.device.commit_config()

def test_merge_configuration(self):
intended_diff = self.read_file("%s/merge_good.diff" % self.vendor)

self.device.load_merge_candidate(filename="%s/merge_good.conf" % self.vendor)
#self.device.commit_config()
# self.device.commit_config()

# Reverting changes

Expand All @@ -64,7 +70,7 @@ def test_merge_configuration(self):
self.assertEqual(str(diff).strip(), intended_diff)

def test_merge_configuration_typo_and_rollback(self):
#because of autocommit in load_replace_candidate - this requires a discard_config before test begins
# because of autocommit in load_replace_candidate - this requires a discard_config before test begins
result = False
try:
self.device.discard_config()
Expand All @@ -89,5 +95,3 @@ def test_load_template(self):
def test_replacing_config_and_diff_and_discard(self):
# because of autocommit in load_replace_candidate - this test case cannot be passed
pytest.skip("Constraint due to auto commit in load_replace_candidate")


29 changes: 15 additions & 14 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,36 @@
# SPDX-License-Identifier: Apache-2.0

"""Test fixtures."""

import json
import os
from builtins import super

import pytest
import os
from napalm.base.test import conftest as parent_conftest

from napalm.base.test.double import BaseTestDouble

from napalm_srlinux import srlinux
import json


@pytest.fixture(scope="session", autouse=True)
def setenv():
# Set timezone such that timestamps are generated/parsed correctly
os.environ["TZ"] = "GMT"

@pytest.fixture(scope='class')

@pytest.fixture(scope="class")
def set_device_parameters(request):
"""Set up the class."""

def fin():
request.cls.device.close()

request.addfinalizer(fin)

request.cls.driver = srl.NokiaSRLinuxDriver
request.cls.driver = srlinux.NokiaSRLinuxDriver
request.cls.patched_driver = PatchedsrlDriver
request.cls.vendor = 'srl'
request.cls.vendor = "srlinux"
parent_conftest.set_device_parameters(request)


Expand All @@ -37,19 +41,18 @@ def pytest_generate_tests(metafunc):
parent_conftest.pytest_generate_tests(metafunc, __file__)


class PatchedsrlDriver(srl.NokiaSRLinuxDriver):
class PatchedsrlDriver(srlinux.NokiaSRLinuxDriver):
"""Patched Skeleton Driver."""

def __init__(self, hostname, username, password, timeout=60, optional_args=None):
"""Patched Skeleton Driver constructor."""
super().__init__(hostname, username, password, timeout, optional_args)

self.patched_attrs = ['device']
self.patched_attrs = ["device"]
self.device = FakesrlDevice()


class FakesrlDevice(BaseTestDouble):

def _jsonrpcRunCli(self, command_list):
"""Fake run_commands."""
#
Expand All @@ -59,9 +62,7 @@ def _jsonrpcRunCli(self, command_list):
full_path = self.find_file(filename)
with open(full_path) as f:
out.append(json.load(f))
result = {
"result":out
}
result = {"result": out}
print(result)
return result

Expand All @@ -75,11 +76,11 @@ def _gnmiGet(self, prefix, path, pathType):

def open(self):
pass

def close(self):
pass


def _jsonrpcGet(self,cmds, other_params=None):
def _jsonrpcGet(self, cmds, other_params=None):
filename = "{}.txt".format(self.sanitize_text(str(sorted(cmds)).strip("{}' ")))
full_path = self.find_file(filename)
with open(full_path) as f:
Expand Down
6 changes: 2 additions & 4 deletions test/unit/test_getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

"""Tests for getters."""

from napalm.base.test.getters import BaseTestGetters


import pytest
from napalm.base.test.getters import BaseTestGetters


@pytest.mark.usefixtures("set_device_parameters")
class TestGetter(BaseTestGetters):
"""Test get_* methods."""

def test_get_route_to_longer(self):
pytest.skip("Longer option not Supported")
return

0 comments on commit 54efb90

Please sign in to comment.