Skip to content

Commit

Permalink
Merge pull request #212 from shermdog/python-2.6
Browse files Browse the repository at this point in the history
Python 2.6 support
  • Loading branch information
shermdog committed May 15, 2014
2 parents 1421ce6 + 9e3d379 commit 4a772d3
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 101 deletions.
12 changes: 1 addition & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ language: python
cache: apt

python:
- "2.6"
- "2.7"
# - "3.3" dependent on ncclient 3.3 support
# - "pypy"

before_install:
- sudo apt-get install -qq python-dev libxml2-dev libxslt-dev
Expand All @@ -17,12 +16,3 @@ script: nosetests -v --with-coverage --cover-package=jnpr.junos --cover-inclusiv

notifications:
email: false

#deploy:
#provider: pypi # http://about.travis-ci.org/docs/user/deployment/pypi/
#user:
#password: see http://about.travis-ci.org/docs/user/encryption-keys/
#on:
#tags: true #only deploy to pypi when tags are updated
###
### possibly recommended for deployment: http://about.travis-ci.org/docs/user/travis-pro/
2 changes: 1 addition & 1 deletion lib/jnpr/junos/cfg/user_ssh_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ def _r_list(self):

def _r_catalog(self):
# no catalog but the keys
self._rcatalog = {k: None for k in self.list}
self._rcatalog = dict((k, None) for k in self.list)
26 changes: 18 additions & 8 deletions lib/jnpr/junos/exception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from lxml import etree
from jnpr.junos import jxml


class RpcError(Exception):
"""
Parent class for all junos-pyez RPC Exceptions
Expand All @@ -22,6 +23,7 @@ def __repr__(self):
if None != self.rsp:
return etree.tostring(self.rsp, pretty_print=True)


class CommitError(RpcError):
"""
Generated in response to a commit-check or a commit action.
Expand All @@ -43,13 +45,14 @@ def __init__(self, rsp):

class UnlockError(RpcError):
"""
Generated in response to attempting to unlock the
Generated in response to attempting to unlock the
configuration database.
"""
def __init__(self, rsp):
RpcError.__init__(self, rsp=rsp)
self.rpc_error = jxml.rpc_error(rsp)


class PermissionError(RpcError):
"""
Generated in response to invoking an RPC for which the
Expand All @@ -68,6 +71,7 @@ def __init__(self, cmd=None, rsp=None):
#### ================================================================
#### ================================================================


class ConnectError(Exception):
"""
Parent class for all connection related exceptions
Expand All @@ -87,31 +91,34 @@ def host(self):
def port(self):
""" login SSH port """
return self.dev._port

def __init__(self, dev):
self.dev = dev
# @@@ need to attach attributes for each access
# @@@ to user-name, host, jump-host, etc.

def __repr__(self):
return "{}({})".format(
self.__class__.__name__,
self.dev.hostname )
return "{0}({1})".format(
self.__class__.__name__,
self.dev.hostname)

__str__ = __repr__


class ProbeError(ConnectError):
"""
Generated if auto_probe is enabled and the probe action fails
"""
pass

class ConnectAuthError(ConnectError):


class ConnectAuthError(ConnectError):
"""
Generated if the user-name, password is invalid
"""
pass


class ConnectTimeoutError(ConnectError):
"""
Generated if the NETCONF session fails to connect, could
Expand All @@ -120,12 +127,14 @@ class ConnectTimeoutError(ConnectError):
"""
pass


class ConnectUnknownHostError(ConnectError):
"""
Generated if the specific hostname does not DNS resolve
"""
pass


class ConnectRefusedError(ConnectError):
"""
Generated if the specified host denies the NETCONF; could
Expand All @@ -134,10 +143,11 @@ class ConnectRefusedError(ConnectError):
"""
pass


class ConnectNotMasterError(ConnectError):
"""
Generated if the connection is made to a non-master
routing-engine. This could be a backup RE on an MX
device, or a virtual-chassis member (linecard), for example
"""
pass
pass
4 changes: 2 additions & 2 deletions lib/jnpr/junos/facts/swver.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ def facts_software_version(junos, facts):
# extract the version information out of the RPC response
# ------------------------------------------------------------------------

f_master = facts.get('master')
f_master = facts.get('master')

if x_swver.tag == 'multi-routing-engine-results':
# we need to find/identify each of the routing-engine (CPU) versions.

facts['2RE'] = True
versions = []

xpath = './multi-routing-engine-item[re-name="{}"]/software-information/host-name'.format(
xpath = './multi-routing-engine-item[re-name="{0}"]/software-information/host-name'.format(
f_master.lower())
facts['hostname'] = x_swver.findtext(xpath)
if facts['hostname'] is None:
Expand Down
9 changes: 3 additions & 6 deletions lib/jnpr/junos/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ def ls(self, path='.', brief=False, followlink=True):
if brief is True:
results['files'] = [f.findtext('file-name').strip() for f in files]
else:
results['files'] = {
f.findtext('file-name').strip(): FS._decode_file(f)
for f in files
}
results['files'] = dict((f.findtext('file-name').strip(), FS._decode_file(f)) for f in files)

return results

Expand Down Expand Up @@ -228,7 +225,7 @@ def _decode(fs):
r['avail_block'] = int(ab.text)
return r

return {_name(fs): _decode(fs) for fs in rsp.xpath('filesystem')}
return dict((_name(fs), _decode(fs)) for fs in rsp.xpath('filesystem'))

# -------------------------------------------------------------------------
### storage_cleanup_check, storage_cleanip
Expand All @@ -245,7 +242,7 @@ def _decode(f):
}

# return a dict of name/decode pairs for each file
return {_name(f): _decode(f) for f in files}
return dict((_name(f), _decode(f)) for f in files)

def storage_cleanup_check(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/jnpr/junos/utils/sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def _progress(report):
x).group(1) for x in self._RE_list]
for vc_id in vc_members:
_progress(
"installing software on VC member: {} ... please be"
"installing software on VC member: {0} ... please be"
" patient ...".format(vc_id))
ok &= self.pkgadd(remote_package, member=vc_id)
dev.timeout = restore_timeout
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_device_set_timeout(self):
assert self.dev.timeout == 35

def test_device_cli(self):
self.assertIn('srx210', self.dev.cli('show version'))
self.assertTrue('srx210' in self.dev.cli('show version'))

def test_device_rpc(self):
sw = self.dev.rpc.get_software_information()
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/facts/test_chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def test_2RE_true(self, mock_execute):
def test_chassis_exception_ConnectNotMasterError(self):
xmldata = etree.XML('<rpc-reply><output>test</output></rpc-reply>')
self.dev.rpc.get_chassis_inventory = MagicMock(side_effect=xmldata)
with self.assertRaises(ConnectNotMasterError):
chassis(self.dev, self.facts)
self.assertRaises(ConnectNotMasterError, chassis, self.dev, self.facts)

def _read_file(self, fname):
from ncclient.xml_ import NCElement
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/facts/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def test_resolv_conf_no_domain(self, mock_fs_cat):
"""
self.facts['hostname'] = 'test'
facts_domain(self.dev, self.facts)
self.assertIsNone(self.facts['domain'])
self.assertEqual(self.facts['domain'], None)
self.assertEqual(self.facts['fqdn'], 'test')
2 changes: 1 addition & 1 deletion tests/unit/facts/test_srx_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_srx_cluster(self, mock_execute):

def test_srx_cluster_none(self):
self.facts['personality'] = 'MX'
self.assertIsNone(srx_cluster(self.dev, self.facts))
self.assertEqual(srx_cluster(self.dev, self.facts), None)

@patch('jnpr.junos.Device.execute')
def test_srx_cluster_no_node(self, mock_execute):
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/facts/test_swver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class TestVersionInfo(unittest.TestCase):

def test_version_info_after_type_len_else(self):
self.assertIsNone(version_info('12.1X46-D10').build)
self.assertEqual(version_info('12.1X46-D10').build, None)

def test_version_info_constructor_else_exception(self):
self.assertEqual(version_info('11.4R7').build, '7')
Expand All @@ -27,16 +27,16 @@ def test_version_info_repr(self):
'type=R, minor=7, build=5)')

def test_version_info_lt(self):
self.assertLess(version_info('13.3-20131120'), (14, 1))
self.assertTrue(version_info('13.3-20131120') < (14, 1))

def test_version_info_lt_eq(self):
self.assertLessEqual(version_info('13.3-20131120'), (14, 1))
self.assertTrue(version_info('13.3-20131120') <= (14, 1))

def test_version_info_gt(self):
self.assertGreater(version_info('13.3-20131120'), (12, 1))
self.assertTrue(version_info('13.3-20131120') > (12, 1))

def test_version_info_gt_eq(self):
self.assertGreaterEqual(version_info('13.3-20131120'), (12, 1))
self.assertTrue(version_info('13.3-20131120') >= (12, 1))

def test_version_info_eq(self):
self.assertEqual(version_info('13.3-20131120'), (13, 3))
Expand Down
Loading

0 comments on commit 4a772d3

Please sign in to comment.