Skip to content

Commit

Permalink
Merge pull request #6121 from vaishnavibhat/distro_version
Browse files Browse the repository at this point in the history
Add support for SLES16 to work with NetworkManager
  • Loading branch information
richtja authored Feb 13, 2025
2 parents c142906 + 11a9a6d commit 949a813
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions avocado/utils/network/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, if_name, host, if_type="Ethernet"):
self.if_type = if_type
self.host = host
self.distro_is_rhel9_or_later = False
self.distro_is_suse16_or_later = False

@property
def config_filename(self):
Expand All @@ -60,11 +61,14 @@ def config_filename(self):
else:
path = "/etc/sysconfig/network-scripts"
elif current_distro.name == "SuSE":
path = "/etc/sysconfig/network"
if self.distro_is_suse16_or_later:
path = "/etc/NetworkManager/system-connections"
else:
path = "/etc/sysconfig/network"
else:
msg = "Distro not supported by API. Could not get interface filename."
raise NWException(msg)
if self.distro_is_rhel9_or_later:
if self.distro_is_rhel9_or_later or self.distro_is_suse16_or_later:
return f"{path}/{self.name}.nmconnection"
else:
return f"{path}/ifcfg-{self.name}"
Expand All @@ -78,7 +82,10 @@ def config_file_path(self):
else:
return "/etc/sysconfig/network-scripts"
elif current_distro.name == "SuSE":
return "/etc/sysconfig/network"
if self.distro_is_suse16_or_later:
return "/etc/NetworkManager/system-connections"
else:
return "/etc/sysconfig/network"
else:
msg = "Distro not supported by API. Could not get interface filename."
LOG.error(msg)
Expand All @@ -87,7 +94,7 @@ def config_file_path(self):
def slave_config_filename(self):
try:
slave_dict = self._get_bondinterface_details()
if self.distro_is_rhel9_or_later:
if self.distro_is_rhel9_or_later or self.distro_is_suse16_or_later:
return [
f"{self.config_file_path}/{slave}.nmconnection"
for slave in slave_dict["slaves"]
Expand Down Expand Up @@ -409,6 +416,8 @@ def save(self, ipaddr, netmask):
current_distro = distro_detect()
if current_distro.name == "rhel" and int(current_distro.version) >= 9:
self.distro_is_rhel9_or_later = True
if current_distro.name == "SuSE" and int(current_distro.version) >= 16:
self.distro_is_suse16_or_later = True

filename = f"ifcfg-{self.name}"
prefix = self.netmask_to_cidr(netmask)
Expand All @@ -419,12 +428,16 @@ def save(self, ipaddr, netmask):
else:
path = "/etc/sysconfig/network-scripts"
elif current_distro.name == "SuSE":
path = "/etc/sysconfig/network"
if self.distro_is_suse16_or_later:
filename = f"{self.name}.nmconnection"
path = "/etc/NetworkManager/system-connections"
else:
path = "/etc/sysconfig/network"
else:
msg = "Distro not supported by API. Could not save ipaddr."
raise NWException(msg)

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

if self.if_type == "Bond":
bond_dict = self._get_bondinterface_details()
if self.distro_is_rhel9_or_later:
if self.distro_is_rhel9_or_later or self.distro_is_suse16_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 949a813

Please sign in to comment.