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

Commit 6ad79cb

Browse files
committed
Merge pull request #9 from dbarrosop/master
Unified unittests
2 parents e8cca1f + 10d64b8 commit 6ad79cb

12 files changed

+527
-378
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ coverage.xml
5353
docs/_build/
5454

5555
.idea
56+
.DS_Store

napalm/junos.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
from jnpr.junos import Device
1818
from jnpr.junos.utils.config import Config
19-
19+
from jnpr.junos.exception import ConfigLoadError
20+
from exceptions import ReplaceConfigException, MergeConfigException
2021

2122
class JunOSDriver(NetworkDriver):
2223

@@ -25,6 +26,7 @@ def __init__(self, hostname, username, password):
2526
self.username = username
2627
self.password = password
2728
self.device = Device(hostname, user=username, password=password)
29+
self.config_replace = False
2830

2931
def open(self):
3032
self.device.open()
@@ -35,23 +37,28 @@ def close(self):
3537
self.device.cu.unlock()
3638
self.device.close()
3739

38-
def load_replace_candidate(self, filename=None, config=None):
40+
def _load_candidate(self, filename, config, overwrite):
3941
if filename is None:
4042
configuration = config
4143
else:
4244
with open(filename) as f:
4345
configuration = f.read()
4446

45-
self.device.cu.load(configuration, format='text', overwrite=True)
47+
try:
48+
self.device.cu.load(configuration, format='text', overwrite=overwrite)
49+
except ConfigLoadError as e:
50+
if self.config_replace:
51+
raise ReplaceConfigException(e.message)
52+
else:
53+
raise MergeConfigException(e.message)
4654

47-
def load_merge_candidate(self, filename=None, config=None):
48-
if filename is None:
49-
configuration = config
50-
else:
51-
with open(filename) as f:
52-
configuration = f.read()
55+
def load_replace_candidate(self, filename=None, config=None):
56+
self.config_replace = True
57+
self._load_candidate(filename, config, True)
5358

54-
self.device.cu.load(configuration, format='text')
59+
def load_merge_candidate(self, filename=None, config=None):
60+
self.config_replace = False
61+
self._load_candidate(filename, config, False)
5562

5663
def compare_config(self):
5764
diff = self.device.cu.diff()
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014 Spotify AB. All rights reserved.
1+
# Copyright 2015 Spotify AB. All rights reserved.
22
#
33
# The contents of this file are licensed under the Apache License, Version 2.0
44
# (the "License"); you may not use this file except in compliance with the
@@ -12,9 +12,20 @@
1212
# License for the specific language governing permissions and limitations under
1313
# the License.
1414

15-
hostname = '10.48.71.3'
16-
username = 'admin'
17-
password = 'sp0tify'
18-
use_ssl = True
19-
config_file_1 = 'config01.txt'
20-
config_file_2 = 'config02.txt'
15+
import unittest
16+
17+
from napalm.junos import JunOSDriver
18+
from base import TestNetworkDriver
19+
20+
21+
class TestJunOSDriver(unittest.TestCase, TestNetworkDriver):
22+
23+
@classmethod
24+
def setUpClass(cls):
25+
hostname = '192.168.76.11'
26+
username = 'dbarroso'
27+
password = 'this_is_not_a_secure_password'
28+
cls.vendor = 'junos'
29+
30+
cls.device = JunOSDriver(hostname, username, password)
31+
cls.device.open()

test/unit/config01.txt

-197
This file was deleted.

0 commit comments

Comments
 (0)