| 1 |
__author__ = "rsherman, vnitinv" |
| 2 |
|
| 3 |
try: |
| 4 |
import unittest2 as unittest |
| 5 |
except ImportError: |
| 6 |
import unittest |
| 7 |
|
| 8 |
from jnpr.junos.exception import RpcTimeoutError |
| 9 |
|
| 10 |
|
| •11 |
class __TestCore(object): |
| 12 |
@classmethod |
| 13 |
def setUpClass(self): |
| 14 |
from jnpr.junos import Device |
| 15 |
|
| 16 |
self.dev = Device(host="xxxx", user="jenkins", password="password") |
| 17 |
self.dev.open() |
| 18 |
|
| 19 |
@classmethod |
| 20 |
def tearDownClass(self): |
| 21 |
self.dev.close() |
| 22 |
|
| 23 |
def test_device_open(self): |
| 24 |
self.assertEqual(self.dev.connected, True) |
| 25 |
|
| 26 |
def test_device_facts(self): |
| 27 |
assert self.dev.facts["hostname"] == "highlife" |
| 28 |
|
| 29 |
def test_device_get_timeout(self): |
| 30 |
assert self.dev.timeout == 30 |
| 31 |
|
| 32 |
def test_device_set_timeout(self): |
| 33 |
self.dev.timeout = 35 |
| 34 |
assert self.dev.timeout == 35 |
| 35 |
|
| 36 |
def test_device_cli(self): |
| 37 |
self.assertTrue("qfx5100" in self.dev.cli("show version")) |
| 38 |
|
| 39 |
def test_device_rpc(self): |
| 40 |
res = self.dev.rpc.get_route_information(destination="10.48.21.71") |
| 41 |
self.assertEqual(res.tag, "route-information") |
| 42 |
|
| 43 |
def test_device_rpc_format_text(self): |
| 44 |
res = self.dev.rpc.get_interface_information({"format": "text"}) |
| 45 |
self.assertEqual(res.tag, "output") |
| 46 |
|
| 47 |
def test_device_rpc_timeout(self): |
| 48 |
with self.assertRaises(RpcTimeoutError): |
| 49 |
self.dev.rpc.get_route_information(dev_timeout=0.01) |
| 50 |
|
| 51 |
def test_device_rpc_normalize_true(self): |
| 52 |
rsp = self.dev.rpc.get_interface_information( |
| 53 |
interface_name="ge-0/0/1", normalize=True |
| 54 |
) |
| 55 |
self.assertEqual(rsp.xpath("physical-interface/name")[0].text, "ge-0/0/1") |
| 56 |
|
| 57 |
def test_load_config(self): |
| 58 |
from jnpr.junos.utils.config import Config |
| 59 |
|
| 60 |
cu = Config(self.dev) |
| 61 |
data = """interfaces { |
| 62 |
ge-1/0/0 { |
| 63 |
description "MPLS interface"; |
| 64 |
unit 0 { |
| 65 |
family mpls; |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
""" |
| 70 |
cu.load(data, format="text") |
| 71 |
self.assertTrue(cu.commit_check()) |
| 72 |
if cu.commit_check(): |
| 73 |
cu.rollback() |