diff --git a/src/sonic_ax_impl/mibs/ietf/rfc1213.py b/src/sonic_ax_impl/mibs/ietf/rfc1213.py index e17c0c0a8..51b3a9775 100644 --- a/src/sonic_ax_impl/mibs/ietf/rfc1213.py +++ b/src/sonic_ax_impl/mibs/ietf/rfc1213.py @@ -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 diff --git a/tests/namespace/test_sysname.py b/tests/namespace/test_sysname.py index 96c9024ba..a9fdd73aa 100644 --- a/tests/namespace/test_sysname.py +++ b/tests/namespace/test_sysname.py @@ -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): diff --git a/tests/test_sysname.py b/tests/test_sysname.py index b8bcaf2e1..e38bce2e8 100644 --- a/tests/test_sysname.py +++ b/tests/test_sysname.py @@ -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')