Skip to content

Commit

Permalink
Merge a13e49a into db3886c
Browse files Browse the repository at this point in the history
  • Loading branch information
pgajdos committed Sep 18, 2020
2 parents db3886c + a13e49a commit 7460b09
Show file tree
Hide file tree
Showing 69 changed files with 218 additions and 207 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
tests/unit/cover

# Translations
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ install:

script:
- if [[ $TRAVIS_PYTHON_VERSION > 3.5 ]]; then black --check --exclude=docs/* . ; fi
- nosetests -v --with-coverage --cover-package=jnpr.junos --cover-inclusive -a unit
- pytest --cov=jnpr.junos -m unit --forked

after_success:
coveralls
Expand Down
5 changes: 4 additions & 1 deletion development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

coverage # http://nedbatchelder.com/code/coverage/
mock # http://www.voidspace.org.uk/python/mock/
nose # http://nose.readthedocs.org/en/latest/
pytest # https://docs.pytest.org/
pytest-cov
pytest-forked
yamlloader
pep8 # https://github.com/jcrocholl/pep8
pyflakes # https://launchpad.net/pyflakes
coveralls # https://coveralls.io/
7 changes: 4 additions & 3 deletions lib/jnpr/junos/cfg/phyport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

class PhyPort(object):
def __new__(cls, dev, name=None):
supercls = {"CLASSIC": PhyPortClassic, "SWITCH": PhyPortSwitch,}.get(
dev.facts["ifd_style"]
)
supercls = {
"CLASSIC": PhyPortClassic,
"SWITCH": PhyPortSwitch,
}.get(dev.facts["ifd_style"])
newcls = type(cls.__name__, (supercls,), {})
return newcls(dev, name)
24 changes: 12 additions & 12 deletions lib/jnpr/junos/cfg/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,11 @@ def __setattr__(self, name, value):

def __repr__(self):
"""
stringify for debug/printing
stringify for debug/printing
this will show the resource manager (class) name,
the resource (Junos) name, and the contents
of the :has: dict and the contents of the :should: dict
this will show the resource manager (class) name,
the resource (Junos) name, and the contents
of the :has: dict and the contents of the :should: dict
"""
mgr_name = self.__class__.__name__
return (
Expand Down Expand Up @@ -600,9 +600,9 @@ def _xml_at_res(self, xml):

def _xml_build_change(self):
"""
iterate through the :should: properties creating the
necessary configuration change structure. if there
are no changes, then return :None:
iterate through the :should: properties creating the
necessary configuration change structure. if there
are no changes, then return :None:
"""
edit_xml = self._xml_edit_at_res()

Expand Down Expand Up @@ -638,8 +638,8 @@ def _xml_build_change(self):

def _r_config_write_xml(self, xml):
"""
write the xml change to the Junos device,
trapping on exceptions.
write the xml change to the Junos device,
trapping on exceptions.
"""
top_xml = xml.getroottree().getroot()

Expand Down Expand Up @@ -757,8 +757,8 @@ def _xml_hook_on_new(self, xml):

def _r_when_new(self):
"""
called by :read(): when the resource is new; i.e.
there is no existing Junos configuration
called by :read(): when the resource is new; i.e.
there is no existing Junos configuration
"""
pass

Expand Down Expand Up @@ -786,7 +786,7 @@ def _r_has_init(self):
@classmethod
def _r_has_xml_status(klass, as_xml, as_py):
"""
set the 'exists' and 'active' :has: values
set the 'exists' and 'active' :has: values
"""
as_py[P_JUNOS_ACTIVE] = False if as_xml.attrib.get("inactive") else True
as_py[P_JUNOS_EXISTS] = True
Expand Down
4 changes: 2 additions & 2 deletions lib/jnpr/junos/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from jnpr.junos.factory.factory_loader import FactoryLoader

import yamlordereddictloader
import yamlloader

__all__ = []

Expand All @@ -30,7 +30,7 @@ def load_module(self, fullname):
with open(os.path.join(os.path.dirname(__file__), mod + ".yml"), "r") as stream:
try:
modules = FactoryLoader().load(
yaml.load(stream, Loader=yamlordereddictloader.Loader)
yaml.load(stream, Loader=yamlloader.ordereddict.Loader)
)
except yaml.YAMLError as exc:
raise ImportError("%s is not loaded" % mod)
Expand Down
20 changes: 10 additions & 10 deletions lib/jnpr/junos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,15 @@ def re_name(self, value):
raise RuntimeError("re_name is read-only!")

def _sshconf_lkup(self):
""" Controls the ssh connection:
If using ssh_private_key_file on MacOS Mojave or greater
(specifically > OpenSSH_7.4p1) ensure that the keys are generated
in PEM format or convert existing 'new' keys to the PEM format:
Check format: `head -n1 ~/.ssh/some_key`
Correct RSA fomat: -----BEGIN RSA PRIVATE KEY-----
Incorrect OPENSSH format: -----BEGIN OPENSSH PRIVATE KEY-----
Convert an OPENSSH key to an RSA key: `ssh-keygen -p -m PEM -f ~/.ssh/some_key`
"""
"""Controls the ssh connection:
If using ssh_private_key_file on MacOS Mojave or greater
(specifically > OpenSSH_7.4p1) ensure that the keys are generated
in PEM format or convert existing 'new' keys to the PEM format:
Check format: `head -n1 ~/.ssh/some_key`
Correct RSA fomat: -----BEGIN RSA PRIVATE KEY-----
Incorrect OPENSSH format: -----BEGIN OPENSSH PRIVATE KEY-----
Convert an OPENSSH key to an RSA key: `ssh-keygen -p -m PEM -f ~/.ssh/some_key`
"""
if self.__class__.__name__ == "Device" and self._sock_fd is not None:
return None
if self._ssh_config:
Expand Down Expand Up @@ -1116,7 +1116,7 @@ def __init__(self, *vargs, **kvargs):
:param str sock_fd:
**REQUIRED** file descriptor of an existing socket instead of providing a host.
Used for outbound ssh.
Used for outbound ssh.
:param str user:
*OPTIONAL* login user-name, uses $USER if not provided
Expand Down
14 changes: 7 additions & 7 deletions lib/jnpr/junos/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class RpcError(Exception):

def __init__(self, cmd=None, rsp=None, errs=None, dev=None, timeout=None, re=None):
"""
:cmd: is the rpc command
:rsp: is the rpc response (after <rpc-reply>)
:errs: is a list of dictionaries of extracted <rpc-error> elements.
:dev: is the device rpc was executed on
:timeout: is the timeout value of the device
:re: is the RE or member exception occured on
:cmd: is the rpc command
:rsp: is the rpc response (after <rpc-reply>)
:errs: is a list of dictionaries of extracted <rpc-error> elements.
:dev: is the device rpc was executed on
:timeout: is the timeout value of the device
:re: is the RE or member exception occured on
"""
self.cmd = cmd
self.rsp = rsp
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, cmd=None, rsp=None, errs=None, dev=None, timeout=None, re=Non

def __repr__(self):
"""
pprints the response XML attribute
pprints the response XML attribute
"""
if self.rpc_error is not None:
return "{}(severity: {}, bad_element: {}, message: {})".format(
Expand Down
9 changes: 6 additions & 3 deletions lib/jnpr/junos/factory/cfgtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ def _validate_value(self, field_name, value, opt):
"""

def _get_field_type(ftype):
ft = {"str": str, "int": int, "float": float, "bool": bool,}.get(
ftype, None
)
ft = {
"str": str,
"int": int,
"float": float,
"bool": bool,
}.get(ftype, None)

if ft is None:
raise TypeError("Unsupported type %s\n" % (ftype))
Expand Down
4 changes: 3 additions & 1 deletion lib/jnpr/junos/facts/current_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def get_facts(device):
current_re.append(re_name[0].text)
else:
rsp = device.rpc.get_interface_information(
normalize=True, routing_instance="__juniper_private1__", terse=True,
normalize=True,
routing_instance="__juniper_private1__",
terse=True,
)

# Get the local IPv4 addresses from the response.
Expand Down
4 changes: 2 additions & 2 deletions lib/jnpr/junos/jxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def remove_namespaces_and_spaces(xml):

def rpc_error(rpc_xml):
"""
extract the various bits from an <rpc-error> element
into a dictionary
extract the various bits from an <rpc-error> element
into a dictionary
"""
remove_namespaces(rpc_xml)

Expand Down
24 changes: 12 additions & 12 deletions lib/jnpr/junos/rpcmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class _RpcMetaExec(object):

def __init__(self, junos):
"""
~PRIVATE CLASS~
creates an RPC meta-executor object bound to the provided
ez-netconf :junos: object
~PRIVATE CLASS~
creates an RPC meta-executor object bound to the provided
ez-netconf :junos: object
"""
self._junos = junos

Expand Down Expand Up @@ -303,12 +303,12 @@ def cli(self, command, format="text", normalize=False):

def __getattr__(self, rpc_cmd_name):
"""
metaprograms a function to execute the :rpc_cmd_name:
metaprograms a function to execute the :rpc_cmd_name:
the caller will be passing (*vargs, **kvargs) on
execution of the meta function; these are the specific
rpc command arguments(**kvargs) and options bound
as XML attributes (*vargs)
the caller will be passing (*vargs, **kvargs) on
execution of the meta function; these are the specific
rpc command arguments(**kvargs) and options bound
as XML attributes (*vargs)
"""

rpc_cmd = re.sub("_", "-", rpc_cmd_name)
Expand Down Expand Up @@ -378,10 +378,10 @@ def _exec_rpc(*vargs, **kvargs):

def __call__(self, rpc_cmd, **kvargs):
"""
callable will execute the provided :rpc_cmd: against the
attached :junos: object and return the RPC response per
:junos:execute()
callable will execute the provided :rpc_cmd: against the
attached :junos: object and return the RPC response per
:junos:execute()
kvargs is simply passed 'as-is' to :junos:execute()
kvargs is simply passed 'as-is' to :junos:execute()
"""
return self._junos.execute(rpc_cmd, **kvargs)
2 changes: 1 addition & 1 deletion lib/jnpr/junos/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def load(self, *vargs, **kvargs):
:param dict template_vars:
Used in conjunction with the other template options. This parameter
contains a dictionary of variables to render into the template.
:param ignore_warning: A boolean, string or list of string.
If the value is True, it will ignore all warnings regardless of the
warning message. If the value is a string, it will ignore
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import unittest2 as unittest
except ImportError:
import unittest
from nose.plugins.attrib import attr
import pytest
from jnpr.junos.exception import RpcTimeoutError


@attr("functional")
@pytest.mark.functional
class TestCore(unittest.TestCase):
@classmethod
def setUpClass(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_device_ssh.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
__author__ = "rsherman, vnitinv"

import unittest
from nose.plugins.attrib import attr
import pytest

from jnpr.junos import Device


@attr("functional")
@pytest.mark.functional
class TestDeviceSsh(unittest.TestCase):
def tearDown(self):
self.dev.close()
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_outbound_ssh.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
__author__ = "mwiget"

import unittest
from nose.plugins.attrib import attr
import pytest

import socket
from jnpr.junos import Device


@attr("functional")
@pytest.mark.functional
class TestDeviceSsh(unittest.TestCase):
def tearDown(self):
self.dev.close()
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import unittest2 as unittest
except ImportError:
import unittest
from nose.plugins.attrib import attr
import pytest

from jnpr.junos.op.routes import RouteTable
import json


@attr("functional")
@pytest.mark.functional
class TestTable(unittest.TestCase):
@classmethod
def setUpClass(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import unittest
import sys

from nose.plugins.attrib import attr
import pytest
from mock import patch

__author__ = "Nitin Kumar"
__credits__ = "Jeremy Schulman"


@attr("unit")
@pytest.mark.unit
class TestJunosInit(unittest.TestCase):
def test_warning(self):
with patch.object(sys.modules["sys"], "version_info", (2, 6, 3)) as mock_sys:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/factory/test_cfgtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import sys

from nose.plugins.attrib import attr
import pytest
import yaml

from jnpr.junos import Device
Expand Down Expand Up @@ -85,7 +85,7 @@
globals().update(FactoryLoader().load(yaml.load(yaml_bgp_data, Loader=yaml.FullLoader)))


@attr("unit")
@pytest.mark.unit
@unittest.skipIf(sys.platform == "win32", "will work for windows in coming days")
class TestFactoryCfgTable(unittest.TestCase):
@patch("ncclient.manager.connect")
Expand Down

0 comments on commit 7460b09

Please sign in to comment.