Skip to content

adding relevant nmcli command based on if_type #6151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 18 additions & 12 deletions avocado/utils/network/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,25 +409,29 @@
filename = f"{self.name}.nmconnection"
prefix = self.netmask_to_cidr(netmask)
path = "/etc/NetworkManager/system-connections"
if os.path.exists(f"{path}/{filename}") is False:
if self.if_type == "Ethernet":
if os.path.exists(f"{path}/{filename}") is False:
run_command(

Check warning on line 414 in avocado/utils/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/network/interfaces.py#L412-L414

Added lines #L412 - L414 were not covered by tests
f"nmcli connection add con-name {self.name} ifname {self.name} type ethernet ipv4.address {ipaddr}/{prefix}",
self.host,
)
self._move_file_to_backup(f"{path}/{filename}")
if os.path.exists(f"{path}/{filename}.backup"):
destination = f"{path}/{filename}"
shutil.copy(f"{path}/{filename}.backup", destination)

Check warning on line 421 in avocado/utils/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/network/interfaces.py#L418-L421

Added lines #L418 - L421 were not covered by tests
run_command(
f"nmcli connection add con-name {self.name} ifname {self.name} type ethernet ipv4.address {ipaddr}/{prefix}",
f"nmcli c mod id {self.name} ipv4.method manual ipv4.address {ipaddr}/{prefix}",
self.host,
)
self._move_file_to_backup(f"{path}/{filename}")
if os.path.exists(f"{path}/{filename}.backup"):
destination = f"{path}/{filename}"
shutil.copy(f"{path}/{filename}.backup", destination)
run_command(
f"nmcli c mod id {self.name} ipv4.method manual ipv4.address {ipaddr}/{prefix}",
self.host,
)
run_command(f"nmcli connection up {self.name}", self.host)
run_command(f"nmcli connection up {self.name}", self.host)

Check warning on line 426 in avocado/utils/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/network/interfaces.py#L426

Added line #L426 was not covered by tests

if self.if_type == "Bond":
bond_dict = self._get_bondinterface_details()
mode = bond_dict["mode"][0]

Check warning on line 430 in avocado/utils/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/network/interfaces.py#L429-L430

Added lines #L429 - L430 were not covered by tests
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}",
f"nmcli connection add con-name {self.name} ifname {self.name} type bond ipv4.address {ipaddr}/{prefix}"
f" bond.options \"mode={mode},miimon=100\"",
self.host,
)
self._move_file_to_backup(f"{path}/{filename}")
Expand Down Expand Up @@ -509,10 +513,12 @@

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

Check warning on line 516 in avocado/utils/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/network/interfaces.py#L516

Added line #L516 was not covered by tests
save_distro_rhel9_and_suse16_or_later()
elif current_distro.name == "rhel" and int(current_distro.version) <= 9:
save_distro_rhel8_or_older()
elif current_distro.name == "SuSE" and int(current_distro.version) >= 16:
self.distro_is_suse16_or_later = True

Check warning on line 521 in avocado/utils/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/network/interfaces.py#L521

Added line #L521 was not covered by tests
save_distro_rhel9_and_suse16_or_later()
elif current_distro.name == "SuSE":
save_suse()
Expand Down
Loading