Skip to content

Commit

Permalink
Merge branch 'sw-install-dep-warn' of https://github.com/vnitinv/py-j…
Browse files Browse the repository at this point in the history
…unos-eznc into sw-install-dep-warn
  • Loading branch information
Nitin Kumar committed Apr 29, 2020
2 parents adededc + 7c205b4 commit 37f64ab
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 10 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ matrix:
dist: xenial
- python: 3.8
dist: xenial

- os: windows
language: shell
python: 3.7
before_install:
- choco install python3 --version=3.7.4
env:
- PATH=/c/Python37:/c/Python37/Scripts:$PATH
- TRAVIS_PYTHON_VERSION=3.7
addons:
apt:
packages:
Expand All @@ -22,6 +29,7 @@ addons:
install:
- "pip install -r development.txt"
- "pip install -r requirements.txt"
- "pip install ."

script: nosetests -v --with-coverage --cover-package=jnpr.junos --cover-inclusive -a unit

Expand Down
4 changes: 3 additions & 1 deletion lib/jnpr/junos/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def __init__(self, **kvargs):
self.junos_dev_handler = JunosDeviceHandler(
device_params={'name': 'junos',
'local': False})
self._conn = None
self._j2ldr = _Jinja2ldr
if self._fact_style == 'old':
self.facts = self.ofacts
Expand Down Expand Up @@ -237,6 +238,7 @@ def open(self, *vargs, **kvargs):
logger.info('facts: retrieving device facts...')
self.facts_refresh()
self.results['facts'] = self.facts
self._conn = self._tty
return self

def close(self, skip_logout=False):
Expand Down Expand Up @@ -333,7 +335,7 @@ def zeroize(self):
# -----------------------------------------------------------------------

def __enter__(self):
self._conn = self.open()
self.open()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
Expand Down
2 changes: 1 addition & 1 deletion lib/jnpr/junos/transport/tty_netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def rpc(self, cmd):
def _receive(self):
# On windows select.select throws io.UnsupportedOperation: fileno
# so use read function for windows serial COM ports
if hasattr(self._tty, 'port') and self._tty.port.startswith('COM'):
if hasattr(self._tty, 'port') and str(self._tty.port).startswith('COM'):
return self._receive_serial_win()
else:
return self._receive_serial()
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
req_lines = [line.strip() for line in open(
'requirements.txt').readlines()]
install_reqs = list(filter(None, req_lines))
if sys.version_info[:2] == (2, 6):
install_reqs.append('importlib>=1.0.3')

# refer: https://github.com/Juniper/py-junos-eznc/issues/1015
# should be removed when textfsm releases >=1.1.1
if sys.platform == 'win32':
install_reqs.append('textfsm==0.4.1')

setup(
name="junos-eznc",
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/factory/test_cfgtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import unittest
import os
import sys

from nose.plugins.attrib import attr
import yaml
Expand Down Expand Up @@ -84,6 +85,8 @@


@attr('unit')
@unittest.skipIf(sys.platform == 'win32',
"will work for windows in coming days")
class TestFactoryCfgTable(unittest.TestCase):

@patch('ncclient.manager.connect')
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/facts/test_get_virtual_chassis_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from nose.plugins.attrib import attr
from mock import patch, MagicMock
import os
import sys
from lxml import etree

from jnpr.junos import Device
Expand Down Expand Up @@ -57,6 +58,8 @@ def test_vc_empty(self, mock_execute):
self.assertEqual(self.dev.facts['vc_master'], None)

@patch('jnpr.junos.Device.execute')
@unittest.skipIf(sys.platform == 'win32',
"will work for windows in coming days")
def test_vc_mmvcf(self, mock_execute):
mock_execute.side_effect = self._mock_manager_vc_mmvcf
self.assertEqual(self.dev.facts['vc_capable'], True)
Expand All @@ -65,6 +68,8 @@ def test_vc_mmvcf(self, mock_execute):
self.assertEqual(self.dev.facts['vc_master'], '0')

@patch('jnpr.junos.Device.execute')
@unittest.skipIf(sys.platform == 'win32',
"will work for windows in coming days")
def test_vc_mmvc(self, mock_execute):
mock_execute.side_effect = self._mock_manager_vc_mmvc
self.assertEqual(self.dev.facts['vc_capable'], True)
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/ofacts/test_routing_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from nose.plugins.attrib import attr
from mock import patch, MagicMock
import os
import sys

from jnpr.junos import Device
from jnpr.junos.ofacts.routing_engines import facts_routing_engines as routing_engines
Expand All @@ -30,6 +31,8 @@ def setUp(self, mock_warnings, mock_connect):
self.vcf = False

@patch('jnpr.junos.Device.execute')
@unittest.skipIf(sys.platform == 'win32',
"will work for windows in coming days")
def test_multi_re_vc(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.mode = 'multi'
Expand All @@ -52,6 +55,8 @@ def test_vc_info_true(self, mock_execute):
self.assertEqual(self.facts['RE1']['mastership_state'], 'backup')

@patch('jnpr.junos.Device.execute')
@unittest.skipIf(sys.platform == 'win32',
"will work for windows in coming days")
def test_mixed_mode_vcf(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.mode = 'multi'
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ def test_device_execute_rpc_error(self):
self.dev._conn.rpc = MagicMock(side_effect=self._mock_manager)
self.assertRaises(RpcError, self.dev.rpc.get_rpc_error)

@unittest.skipIf(sys.platform == 'win32',
"will work for windows in coming days")
def test_device_execute_permission_error(self):
self.dev._conn.rpc = MagicMock(side_effect=self._mock_manager)
self.assertRaises(
Expand Down
16 changes: 11 additions & 5 deletions tests/unit/utils/test_ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nose.plugins.attrib import attr
import ftplib
import sys
import os

from jnpr.junos import Device
import jnpr.junos.utils.ftp
Expand All @@ -16,6 +17,8 @@


@attr('unit')
@unittest.skipIf(sys.platform == 'win32',
"will work for windows in coming days")
class TestFtp(unittest.TestCase):

@patch('ftplib.FTP.connect')
Expand Down Expand Up @@ -121,15 +124,18 @@ def test_ftp_upload_file_rem_path(self, mock_open, mock_ftpstore):
@patch('ftplib.FTP.storbinary')
@patch(builtin_string + '.open')
def test_ftp_upload_file_rem_full_path(self, mock_open, mock_ftpstore):
self.assertEqual(self.dev_ftp.put(local_file="/var/tmp/conf.txt",
remote_path="/var/tmp/test.txt"), True)
self.assertEqual(self.dev_ftp.put(local_file=os.path.abspath(
"/var/tmp/conf.txt"),
remote_path=os.path.abspath(
"/var/tmp/test.txt")), True)
self.assertEqual(tuple(mock_ftpstore.call_args)[1]['cmd'],
'STOR /var/tmp/test.txt')
'STOR '+os.path.abspath("/var/tmp/test.txt"))

@patch('ftplib.FTP.storbinary')
@patch(builtin_string + '.open')
def test_ftp_upload_file_rem_path_create(self, mock_open, mock_ftpstore):
self.assertEqual(self.dev_ftp.put(local_file="conf.txt",
remote_path="/var/tmp"), True)
remote_path=os.path.abspath(
"/var/tmp")), True)
self.assertEqual(tuple(mock_ftpstore.call_args)[1]['cmd'],
'STOR /var/tmp/conf.txt')
'STOR '+os.path.abspath("/var/tmp/conf.txt"))
2 changes: 2 additions & 0 deletions tests/unit/utils/test_sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ def test_sw_rollback_multi(self, mock_execute):
self.assertEqual(eval(self.sw.rollback()), msg)

@patch('jnpr.junos.Device.execute')
@unittest.skipIf(sys.platform == 'win32',
"will work for windows in coming days")
def test_sw_rollback_multi_exception(self, mock_execute):
fname = 'request-package-rollback-multi-error.xml'
mock_execute.side_effect = self._read_file(fname)
Expand Down

0 comments on commit 37f64ab

Please sign in to comment.