Skip to content
This repository was archived by the owner on Feb 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #49 from mirceaulinic/HACK-CLEANUP-ALL
Browse files Browse the repository at this point in the history
Cleanup all and enable pylama
  • Loading branch information
mirceaulinic authored Sep 18, 2016
2 parents a1a61f0 + 6e9be67 commit 354d721
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: python
python:
- 2.7
install:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install .
- pip install -e git+https://github.com/napalm-automation/napalm-base.git@develop#egg=napalm-base
deploy:
Expand All @@ -14,7 +14,7 @@ deploy:
tags: true
branch: master
script:

- pylama .
- cd test/unit
- nosetests -v TestJunOSDriver:TestGetterJunOSDriver.test_get_bgp_config
- nosetests -v TestJunOSDriver:TestGetterJunOSDriver.test_get_bgp_neighbors
Expand Down
2 changes: 1 addition & 1 deletion napalm_junos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import pkg_resources

# Import local modules
from junos import JunOSDriver
from junos import JunOSDriver # noqa

try:
__version__ = pkg_resources.get_distribution('napalm-junos').version
Expand Down
2 changes: 1 addition & 1 deletion napalm_junos/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# TODO move utils folder inside napalm
# -*- coding: utf-8 -*-
30 changes: 16 additions & 14 deletions test/unit/TestJunOSDriver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Spotify AB. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
Expand Down Expand Up @@ -29,8 +30,12 @@ def setUpClass(cls):
password = 'vagrant123'
cls.vendor = 'junos'

optional_args = {'port': 12203,}
cls.device = JunOSDriver(hostname, username, password, timeout=60, optional_args=optional_args)
optional_args = {'port': 12203, }
cls.device = JunOSDriver(hostname,
username,
password,
timeout=60,
optional_args=optional_args)
cls.device.open()


Expand Down Expand Up @@ -82,16 +87,14 @@ def __init__(self):
'personality': 'SRX_BRANCH'
}


def read_txt_file(self, filename):
with open(filename) as data_file:
return data_file.read()


def cli(self, command=''):
return self.read_txt_file(
'junos/mock_data/{parsed_command}.txt'.format(
parsed_command = command.replace(' ', '_')
parsed_command=command.replace(' ', '_')
)
)

Expand All @@ -105,35 +108,36 @@ class FakeRPCObject:
def __init__(self, device):
self._device = device


def __getattr__(self, item):
self.item = item
return self


def response(self, **rpc_args):
instance = rpc_args.pop('instance', '')

xml_string = self._device.read_txt_file('junos/mock_data/{}{}.txt'.format(self.item, instance))
xml_string = self._device.read_txt_file(
'junos/mock_data/{}{}.txt'.format(self.item, instance))
return lxml.etree.fromstring(xml_string)


def get_config(self, get_cmd='', options={}):

# get_cmd is an XML tree that requests a specific part of the config
# E.g.: <configuration><protocols><bgp><group/></bgp></protocols></configuration>

get_cmd_str = lxml.etree.tostring(get_cmd)
filename = get_cmd_str.replace('<', '_').replace('>', '_').replace('/', '_').replace('\n', '').replace(' ', '')
filename = get_cmd_str.replace('<', '_')\
.replace('>', '_')\
.replace('/', '_')\
.replace('\n', '')\
.replace(' ', '')

xml_string = self._device.read_txt_file(
'junos/mock_data/{filename}.txt'.format(
filename = filename[0:150]
filename=filename[0:150]
)
)
return lxml.etree.fromstring(xml_string)


__call__ = response


Expand All @@ -146,15 +150,13 @@ class FakeConnectionRPCObject:
def __init__(self, rpc):
self._rpc = rpc


def response(self, non_std_command=None):
class RPCReply:
def __init__(self, reply):
self._NCElement__doc = reply
rpc_reply = RPCReply(self._rpc.get_config(get_cmd=non_std_command))
return rpc_reply


__call__ = response


Expand Down

0 comments on commit 354d721

Please sign in to comment.