Skip to content

Commit 3c10984

Browse files
authored
Merge pull request #95 from Mathias-gt/patch-1
Closes: #143 - Adding the new login URL of NSO 5.7.5.1
2 parents eeb4eb7 + 12b9794 commit 3c10984

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/rest/connector/libs/nso/implementation.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def connect(self,
118118
ip=ip,
119119
port=port)
120120

121-
self.login_url = '{f}/api'.format(f=self.base_url)
121+
self.login_urls = ['{f}/api'.format(f=self.base_url),'{f}/restconf'.format(f=self.base_url)]
122122

123123
log.info("Connecting to '{d}' with alias "
124124
"'{a}'".format(d=self.device.name, a=self.alias))
@@ -129,10 +129,14 @@ def connect(self,
129129
self.session.auth = (username, password)
130130

131131
# Connect to the device via requests
132-
response = self.session.get(self.login_url, timeout=timeout)
132+
for login_url in self.login_urls:
133+
response = self.session.get(login_url, timeout=timeout)
134+
log.debug("Response: {c} {r}, headers: {h}".format(c=response.status_code,
135+
r=response.reason, h=response.headers))
136+
if response.status_code == requests.codes.ok:
137+
self.login_url = login_url
138+
break
133139
output = response.text
134-
log.debug("Response: {c} {r}, headers: {h}".format(c=response.status_code,
135-
r=response.reason, h=response.headers))
136140
if verbose:
137141
log.info("Response text:\n%s" % output)
138142

src/rest/connector/tests/test_nso.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ def test_connect(self, **kwargs):
4040
self.assertEqual(output, response_text)
4141
return connection
4242

43+
def test_connect_restconf(self, **kwargs):
44+
connection = Rest(device=self.device, alias='rest', via='rest')
45+
46+
response_text ="""\
47+
<restconf xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf">
48+
<data/>
49+
<operations/>
50+
<yang-library-version>2019-01-04</yang-library-version>
51+
</restconf>
52+
"""
53+
54+
kwargs['mock'].get('http://198.51.100.2:8080/restconf', text=response_text)
55+
output = connection.connect(verbose=True).text
56+
self.assertEqual(output, response_text)
57+
return connection
4358

4459
def test_get(self, **kwargs):
4560
connection = self.test_connect()

0 commit comments

Comments
 (0)