Skip to content

Commit

Permalink
Merge remote-tracking branch 'PavamanSubramaniyam/adding_support_for_…
Browse files Browse the repository at this point in the history
…RHEL10'

Signed-off-by: Cleber Rosa <[email protected]>
  • Loading branch information
clebergnu committed Sep 11, 2024
2 parents b00cf3e + d080518 commit 6ad5b87
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions avocado/utils/network/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def __init__(self, if_name, host, if_type="Ethernet"):
self.name = if_name
self.if_type = if_type
self.host = host
self.distro_is_rhel9 = False
self.distro_is_rhel9_or_later = False

@property
def config_filename(self):
current_distro = distro_detect()
if current_distro.name in ["rhel", "fedora"]:
if self.distro_is_rhel9:
if self.distro_is_rhel9_or_later:
path = "/etc/NetworkManager/system-connections"
else:
path = "/etc/sysconfig/network-scripts"
Expand All @@ -64,7 +64,7 @@ def config_filename(self):
else:
msg = "Distro not supported by API. Could not get interface filename."
raise NWException(msg)
if self.distro_is_rhel9:
if self.distro_is_rhel9_or_later:
return f"{path}/{self.name}.nmconnection"
else:
return f"{path}/ifcfg-{self.name}"
Expand All @@ -73,7 +73,7 @@ def config_filename(self):
def config_file_path(self):
current_distro = distro_detect()
if current_distro.name in ["rhel", "fedora"]:
if self.distro_is_rhel9:
if self.distro_is_rhel9_or_later:
return "/etc/NetworkManager/system-connections"
else:
return "/etc/sysconfig/network-scripts"
Expand All @@ -87,7 +87,7 @@ def config_file_path(self):
def slave_config_filename(self):
try:
slave_dict = self._get_bondinterface_details()
if self.distro_is_rhel9:
if self.distro_is_rhel9_or_later:
return [
f"{self.config_file_path}/{slave}.nmconnection"
for slave in slave_dict["slaves"]
Expand Down Expand Up @@ -405,13 +405,13 @@ def save(self, ipaddr, netmask):
raise NWException(msg)

current_distro = distro_detect()
if current_distro.name == "rhel" and current_distro.version == "9":
self.distro_is_rhel9 = "rhel9"
if current_distro.name == "rhel" and int(current_distro.version) >= 9:
self.distro_is_rhel9_or_later = True

filename = f"ifcfg-{self.name}"
prefix = self.netmask_to_cidr(netmask)
if current_distro.name in ["rhel", "fedora"]:
if self.distro_is_rhel9:
if self.distro_is_rhel9_or_later:
filename = f"{self.name}.nmconnection"
path = "/etc/NetworkManager/system-connections"
else:
Expand All @@ -422,7 +422,7 @@ def save(self, ipaddr, netmask):
msg = "Distro not supported by API. Could not save ipaddr."
raise NWException(msg)

if self.distro_is_rhel9:
if self.distro_is_rhel9_or_later:
ifcfg_dict = ""
if os.path.exists(f"{path}/{filename}") is False:
run_command(
Expand Down Expand Up @@ -461,7 +461,7 @@ def save(self, ipaddr, netmask):

if self.if_type == "Bond":
bond_dict = self._get_bondinterface_details()
if self.distro_is_rhel9:
if self.distro_is_rhel9_or_later:
if os.path.exists(f"{path}/{filename}") is False:
run_command(
f"nmcli connection add con-name {self.name} ifname {self.name} type ethernet ipv4.address {ipaddr}/{prefix}",
Expand Down

0 comments on commit 6ad5b87

Please sign in to comment.