Skip to content

Commit

Permalink
Update according to comments from Miroslav and Petr
Browse files Browse the repository at this point in the history
Signed-off-by: Vector Li <[email protected]>
  • Loading branch information
idorax authored and psss committed Feb 2, 2024
1 parent 438f120 commit f93ed22
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
9 changes: 5 additions & 4 deletions tmt/steps/prepare/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class Feature(tmt.utils.Common):
""" Base class for feature implementations """
""" Base class for ``feature`` prepare plugin implementations """

NAME: str

Expand All @@ -41,6 +41,7 @@ def _find_playbook(self, filename: str) -> Optional[Path]:

class ToggleableFeature(Feature):
def get_root_path(self) -> Path:
""" Get the root path for getting the path of a playbook"""
assert self.parent is not None # narrow type
assert self.parent.parent is not None # narrow type
assert self.parent.parent.parent is not None # narrow type
Expand All @@ -53,8 +54,8 @@ def get_root_path(self) -> Path:
def _run_playbook(self, op: str, playbook_filename: str) -> None:
playbook_path = self._find_playbook(playbook_filename)
if not playbook_path:
self.warn(f'{op.capitalize()} {self.NAME.upper()} is not supported on this guest.')
return
raise tmt.utils.GeneralError(
f"{op.capitalize()} {self.NAME.upper()} is not supported on this guest.")

self.info(f'{op.capitalize()} {self.NAME.upper()}')
self.guest.ansible(playbook_path.relative_to(self.get_root_path()))
Expand Down Expand Up @@ -100,7 +101,7 @@ class PrepareFeatureData(tmt.steps.prepare.PrepareStepData):
@tmt.steps.provides_method('feature')
class PrepareFeature(tmt.steps.prepare.PreparePlugin[PrepareFeatureData]):
"""
Enable or disable common feature `epel` on the guest
Enable or disable common feature ``epel`` on the guest
Example config:
Expand Down
13 changes: 3 additions & 10 deletions tmt/steps/prepare/feature/epel-disable.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- hosts: all
user: root
tasks:
# RHEL 7 or CentOS 7
- when: ansible_distribution_major_version|int == 7
Expand All @@ -14,12 +13,10 @@
command: rpm -q epel-release
register: result
ignore_errors: True

- name: Disable repos of 'epel'
shell: yum-config-manager --disable epel epel-debuginfo epel-source
when: result.rc == 0
- name: Fetch attribute 'enabled' of repos of 'epel'
shell: grep enabled /etc/yum.repos.d/epel.repo
when: result.rc == 0

# RHEL N or CentOS Stream N where N >= 8
- when: ansible_distribution_major_version|int >= 8
Expand All @@ -32,21 +29,17 @@
command: rpm -q epel-release
register: result
ignore_errors: True

- name: Disable repos of 'epel' if package 'epel-release' is installed
shell: dnf config-manager --disable epel epel-debuginfo epel-source
when: result.rc == 0
- name: Fetch attribute 'enabled' of repos of 'epel'
shell: grep enabled /etc/yum.repos.d/epel.repo
when: result.rc == 0

# Disable repos of 'epel-next' if package 'epel-next-release' is installed
- name: Detect package 'epel-next-release' is installed
command: rpm -q epel-next-release
register: result
ignore_errors: True

- name: Disable repos of 'epel-next'
shell: dnf config-manager --disable epel-next epel-next-debuginfo epel-next-source
when: result.rc == 0
- name: Fetch attribute 'enabled' of repos of 'epel-next'
shell: grep enabled /etc/yum.repos.d/epel-next.repo
when: result.rc == 0
13 changes: 0 additions & 13 deletions tmt/steps/prepare/feature/epel-enable.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- hosts: all
user: root
tasks:
# RHEL 7
- when: ansible_distribution == 'RedHat' and ansible_distribution_major_version|int == 7
Expand All @@ -17,8 +16,6 @@

- name: Enable repos of 'epel'
shell: yum-config-manager --enable epel epel-debuginfo epel-source
- name: Fetch attribute 'enabled' of repos of 'epel'
shell: grep enabled /etc/yum.repos.d/epel.repo

# RHEL N, where N >= 8
- when: ansible_distribution == "RedHat" and ansible_distribution_major_version|int >= 8
Expand All @@ -40,13 +37,9 @@

- name: Enable repos of 'epel'
shell: dnf config-manager --enable epel epel-debuginfo epel-source
- name: Fetch attribute 'enabled' of repos of 'epel'
shell: grep enabled /etc/yum.repos.d/epel.repo

- name: Enable repos of 'epel-next'
shell: dnf config-manager --enable epel-next epel-next-debuginfo epel-next-source
- name: Fetch attribute 'enabled' of repos of 'epel-next'
shell: grep enabled /etc/yum.repos.d/epel-next.repo

# CentOS 7
- when: ansible_distribution == "CentOS" and ansible_distribution_major_version|int == 7
Expand All @@ -63,8 +56,6 @@

- name: Enable repos of 'epel'
shell: yum-config-manager --enable epel epel-debuginfo epel-source
- name: Fetch attribute 'enabled' of repos of 'epel'
shell: grep enabled /etc/yum.repos.d/epel.repo

# CentOS Stream N where N >= 8
- when: ansible_distribution == "CentOS" and ansible_distribution_major_version|int >= 8
Expand All @@ -84,10 +75,6 @@

- name: Enable repos of 'epel'
shell: dnf config-manager --enable epel epel-debuginfo epel-source
- name: Fetch attribute 'enabled' of repos of 'epel'
shell: grep enabled /etc/yum.repos.d/epel.repo

- name: Enable repos of 'epel-next'
shell: dnf config-manager --enable epel-next epel-next-debuginfo epel-next-source
- name: Fetch attribute 'enabled' of repos of 'epel-next'
shell: grep enabled /etc/yum.repos.d/epel-next.repo

0 comments on commit f93ed22

Please sign in to comment.