Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,22 @@ def get_sys_name(self):
"""
Subclass update interface information
"""
# If hostname is already set to dot notation
if "." in self.hostname:
return self.hostname

try:
with open('/etc/resolv.conf', 'r') as fd_resolv:
for line in fd_resolv.readlines():
if 'search' in line:
domain = line.split()[1]
return "{}.{}".format(self.hostname, domain)

except Exception:
# If error in reading data from file
mibs.logger.warning("Cannot read domain from /etc/resolv.conf Using"
" {} in sysName".format(self.hostname))

return self.hostname


Expand Down
3 changes: 2 additions & 1 deletion tests/namespace/test_sysname.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def test_getpdu_sysname(self):
value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.OCTET_STRING)
self.assertEqual(str(value0.name), str(ObjectIdentifier(9, 0, 0, 0, (1, 3, 6, 1, 2, 1, 1, 5, 0))))
self.assertEqual(str(value0.data), 'namespace_hostname')
hostname_value = str(value0.data).split(".")[0]
self.assertEqual(str(hostname_value), 'namespace_hostname')

@classmethod
def tearDownClass(cls):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_sysname.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ def test_getpdu_sysname(self):
value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.OCTET_STRING)
self.assertEqual(str(value0.name), str(ObjectIdentifier(9, 0, 0, 0, (1, 3, 6, 1, 2, 1, 1, 5, 0))))
self.assertEqual(str(value0.data), 'test_hostname')
hostname_value = str(value0.data).split(".")[0]
self.assertEqual(str(hostname_value), 'test_hostname')
Loading