From a36aca1433527d96faf71b1c31a98e209842e268 Mon Sep 17 00:00:00 2001 From: agahhulusi Date: Thu, 18 Mar 2021 10:49:44 +0300 Subject: [PATCH] fqdn bug fixed --- .../execute_cancel_sssd_ad_authentication.py | 20 ++++++++++++++----- .../execute_sssd_ad_authentication.py | 6 ------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/base/registration/execute_cancel_sssd_ad_authentication.py b/src/base/registration/execute_cancel_sssd_ad_authentication.py index 8c58d8b..dab64b0 100644 --- a/src/base/registration/execute_cancel_sssd_ad_authentication.py +++ b/src/base/registration/execute_cancel_sssd_ad_authentication.py @@ -4,6 +4,7 @@ from base.scope import Scope from base.util.util import Util +from base.system.system import System import re class ExecuteCancelSSSDAdAuthentication: @@ -11,6 +12,7 @@ class ExecuteCancelSSSDAdAuthentication: scope = Scope().get_instance() self.logger = scope.get_logger() self.util = Util() + self.system = System() self.ad_info_path = "/etc/ahenk/ad_info" def cancel(self): @@ -21,8 +23,10 @@ class ExecuteCancelSSSDAdAuthentication: file_data = self.util.read_file_by_line(self.ad_info_path) self.ip_address = file_data[0].strip("\n") self.host_name = file_data[1].strip("\n") + self.domain_name = file_data[2].strip("\n") self.logger.info(self.ip_address) self.logger.info(self.host_name) + self.logger.info(self.domain_name) self.logger.info("Information read successfully from ad_info.") else: self.logger.error("ad_info file not found") @@ -51,17 +55,23 @@ class ExecuteCancelSSSDAdAuthentication: file_dhclient.write(file_data) file_dhclient.close() - # Configure hosts for deleting AD "IP address" and "AD hostname" hosts_conf_path = "/etc/hosts" file_hosts = open(hosts_conf_path, 'r') file_data = file_hosts.read() - if ("{0} {1}".format(self.ip_address, self.host_name)) in file_data: - file_data = file_data.replace(("{0} {1}".format(self.ip_address, self.host_name)), " ") - self.logger.info("hosts is configured") + if ("{0} {1}".format(self.ip_address, self.domain_name)) in file_data: + file_data = file_data.replace(("{0} {1}".format(self.ip_address, self.domain_name)), " ") + self.logger.info("hosts is deleted") else: - self.logger.error("hosts is not configured") + self.logger.error("hosts domain is not deleted") + + if ("{0} {1}".format(self.ip_address, self.host_name)) in file_data: + file_data = file_data.replace(("{0} {1}".format(self.ip_address, self.host_name)), " ") + self.logger.info("hosts is deleted") + else: + self.logger.error("hosts hostname is not deleted") + file_hosts.close() file_hosts = open(hosts_conf_path, 'w') file_hosts.write(file_data) diff --git a/src/base/registration/execute_sssd_ad_authentication.py b/src/base/registration/execute_sssd_ad_authentication.py index bdd882c..94fdeb5 100644 --- a/src/base/registration/execute_sssd_ad_authentication.py +++ b/src/base/registration/execute_sssd_ad_authentication.py @@ -101,12 +101,6 @@ class ExecuteSSSDAdAuthentication: file_default_hosts = open(host_path, 'r') file_data = file_default_hosts.read() - if ("{0} {1}.{2} {1}".format("127.0.1.1",self.system.Os.hostname(),domain_name)) not in file_data: - file_data = file_data + "\n" + ("{0} {1}.{2} {1}".format("127.0.1.1",self.system.Os.hostname(),domain_name)) - self.logger.info("FQDN is configured") - else: - self.logger.info("FQDN is not configured") - if ("{0} {1}".format(ip_address, host_name)) not in file_data: file_data = file_data + "\n" + ("{0} {1}".format(ip_address, host_name)) self.logger.info("/etc/hosts is configured for hostname")