Skip to content

Commit

Permalink
Merge pull request #4065 from ingvagabund/introduce-get-rpm-version-role
Browse files Browse the repository at this point in the history
Introduce excluder-free rpm version detection role
  • Loading branch information
ingvagabund authored May 12, 2017
2 parents 52c19f7 + 13b5884 commit 57185bd
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 67 deletions.
30 changes: 28 additions & 2 deletions roles/lib_utils/library/repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import os # noqa: F401
import re # noqa: F401
import shutil # noqa: F401
import tempfile # noqa: F401

try:
import ruamel.yaml as yaml # noqa: F401
Expand Down Expand Up @@ -421,22 +422,25 @@ def _repoquery_cmd(self, cmd, output=False, output_type='json'):
class Repoquery(RepoqueryCLI):
''' Class to wrap the repoquery
'''
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(self, name, query_type, show_duplicates,
match_version, verbose):
match_version, ignore_excluders, verbose):
''' Constructor for YumList '''
super(Repoquery, self).__init__(None)
self.name = name
self.query_type = query_type
self.show_duplicates = show_duplicates
self.match_version = match_version
self.ignore_excluders = ignore_excluders
self.verbose = verbose

if self.match_version:
self.show_duplicates = True

self.query_format = "%{version}|%{release}|%{arch}|%{repo}|%{version}-%{release}"

self.tmp_file = None

def build_cmd(self):
''' build the repoquery cmd options '''

Expand All @@ -448,6 +452,9 @@ def build_cmd(self):
if self.show_duplicates:
repo_cmd.append('--show-duplicates')

if self.ignore_excluders:
repo_cmd.append('--config=' + self.tmp_file.name)

repo_cmd.append(self.name)

return repo_cmd
Expand Down Expand Up @@ -519,6 +526,20 @@ def format_versions(self, formatted_versions):
def repoquery(self):
'''perform a repoquery '''

if self.ignore_excluders:
# Duplicate yum.conf and reset exclude= line to an empty string
# to clear a list of all excluded packages
self.tmp_file = tempfile.NamedTemporaryFile()

with open("/etc/yum.conf", "r") as file_handler:
yum_conf_lines = file_handler.readlines()

yum_conf_lines = ["exclude=" if l.startswith("exclude=") else l for l in yum_conf_lines]

with open(self.tmp_file.name, "w") as file_handler:
file_handler.writelines(yum_conf_lines)
file_handler.flush()

repoquery_cmd = self.build_cmd()

rval = self._repoquery_cmd(repoquery_cmd, True, 'raw')
Expand All @@ -541,6 +562,9 @@ def repoquery(self):
else:
rval['package_found'] = False

if self.ignore_excluders:
self.tmp_file.close()

return rval

@staticmethod
Expand All @@ -552,6 +576,7 @@ def run_ansible(params, check_mode):
params['query_type'],
params['show_duplicates'],
params['match_version'],
params['ignore_excluders'],
params['verbose'],
)

Expand Down Expand Up @@ -592,6 +617,7 @@ def main():
verbose=dict(default=False, required=False, type='bool'),
show_duplicates=dict(default=False, required=False, type='bool'),
match_version=dict(default=None, required=False, type='str'),
ignore_excluders=dict(default=False, required=False, type='bool'),
),
supports_check_mode=False,
required_if=[('show_duplicates', True, ['name'])],
Expand Down
1 change: 1 addition & 0 deletions roles/lib_utils/library/yedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import os # noqa: F401
import re # noqa: F401
import shutil # noqa: F401
import tempfile # noqa: F401

try:
import ruamel.yaml as yaml # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions roles/lib_utils/src/ansible/repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def main():
verbose=dict(default=False, required=False, type='bool'),
show_duplicates=dict(default=False, required=False, type='bool'),
match_version=dict(default=None, required=False, type='str'),
ignore_excluders=dict(default=False, required=False, type='bool'),
),
supports_check_mode=False,
required_if=[('show_duplicates', True, ['name'])],
Expand Down
28 changes: 26 additions & 2 deletions roles/lib_utils/src/class/repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
class Repoquery(RepoqueryCLI):
''' Class to wrap the repoquery
'''
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(self, name, query_type, show_duplicates,
match_version, verbose):
match_version, ignore_excluders, verbose):
''' Constructor for YumList '''
super(Repoquery, self).__init__(None)
self.name = name
self.query_type = query_type
self.show_duplicates = show_duplicates
self.match_version = match_version
self.ignore_excluders = ignore_excluders
self.verbose = verbose

if self.match_version:
self.show_duplicates = True

self.query_format = "%{version}|%{release}|%{arch}|%{repo}|%{version}-%{release}"

self.tmp_file = None

def build_cmd(self):
''' build the repoquery cmd options '''

Expand All @@ -32,6 +35,9 @@ def build_cmd(self):
if self.show_duplicates:
repo_cmd.append('--show-duplicates')

if self.ignore_excluders:
repo_cmd.append('--config=' + self.tmp_file.name)

repo_cmd.append(self.name)

return repo_cmd
Expand Down Expand Up @@ -103,6 +109,20 @@ def format_versions(self, formatted_versions):
def repoquery(self):
'''perform a repoquery '''

if self.ignore_excluders:
# Duplicate yum.conf and reset exclude= line to an empty string
# to clear a list of all excluded packages
self.tmp_file = tempfile.NamedTemporaryFile()

with open("/etc/yum.conf", "r") as file_handler:
yum_conf_lines = file_handler.readlines()

yum_conf_lines = ["exclude=" if l.startswith("exclude=") else l for l in yum_conf_lines]

with open(self.tmp_file.name, "w") as file_handler:
file_handler.writelines(yum_conf_lines)
file_handler.flush()

repoquery_cmd = self.build_cmd()

rval = self._repoquery_cmd(repoquery_cmd, True, 'raw')
Expand All @@ -125,6 +145,9 @@ def repoquery(self):
else:
rval['package_found'] = False

if self.ignore_excluders:
self.tmp_file.close()

return rval

@staticmethod
Expand All @@ -136,6 +159,7 @@ def run_ansible(params, check_mode):
params['query_type'],
params['show_duplicates'],
params['match_version'],
params['ignore_excluders'],
params['verbose'],
)

Expand Down
1 change: 1 addition & 0 deletions roles/lib_utils/src/lib/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os # noqa: F401
import re # noqa: F401
import shutil # noqa: F401
import tempfile # noqa: F401

try:
import ruamel.yaml as yaml # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions roles/lib_utils/src/test/unit/test_repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_querying_a_package(self, mock_cmd):
'verbose': False,
'show_duplicates': False,
'match_version': None,
'ignore_excluders': False,
}

valid_stderr = '''Repo rhel-7-server-extras-rpms forced skip_if_unavailable=True due to: /etc/pki/entitlement/3268107132875399464-key.pem
Expand Down
13 changes: 8 additions & 5 deletions roles/openshift_excluder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ None

Dependencies
------------
- openshift_facts
- openshift_repos
- lib_utils

Tasks to include
----------------

- exclude: enable excluders (assuming excluders are installed)
- unexclude: disable excluders (assuming excluders are installed)
- exclude: enable excluders
- unexclude: disable excluders
- install: install excluders (installation is followed by excluder enabling)
- enable: enable excluders (optionally with installation step)
- disabled: disable excluders (optionally with installation and status step, the status check that can override which excluder gets enabled/disabled)
- status: determine status of excluders
- enable: enable excluders (install excluder(s) if not installed)
- disabled: disable excluders (install excluder(s) if not installed)


Example Playbook
----------------
Expand Down
1 change: 1 addition & 0 deletions roles/openshift_excluder/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ galaxy_info:
dependencies:
- { role: openshift_facts }
- { role: openshift_repos }
- { role: lib_utils }
24 changes: 15 additions & 9 deletions roles/openshift_excluder/tasks/verify_excluder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@
# - openshift_upgrade_target
- block:
- name: Get available excluder version
command: >
{{ repoquery_cmd }} --qf '%{version}' "{{ excluder }}"
register: excluder_version
failed_when: false
changed_when: false
repoquery:
name: "{{ excluder }}"
ignore_excluders: true
register: excluder_out

- fail:
msg: "Package {{ excluder }} not found"
when: not excluder_out.results.package_found

- set_fact:
excluder_version: "{{ excluder_out.results.versions.available_versions.0 }}"

- name: "{{ excluder }} version detected"
debug:
msg: "{{ excluder }}: {{ excluder_version.stdout }}"
msg: "{{ excluder }}: {{ excluder_version }}"

- name: Printing upgrade target version
debug:
msg: "{{ openshift_upgrade_target }}"

- name: Check the available {{ excluder }} version is at most of the upgrade target version
fail:
msg: "Available {{ excluder }} version {{ excluder_version.stdout }} is higher than the upgrade target version"
msg: "Available {{ excluder }} version {{ excluder_version }} is higher than the upgrade target version"
when:
- "{{ excluder_version.stdout != '' }}"
- "{{ excluder_version.stdout.split('.')[0:2] | join('.') | version_compare(openshift_upgrade_target.split('.')[0:2] | join('.'), '>', strict=True) }}"
- "{{ excluder_version != '' }}"
- "{{ excluder_version.split('.')[0:2] | join('.') | version_compare(openshift_upgrade_target.split('.')[0:2] | join('.'), '>', strict=True) }}"
when:
- not openshift.common.is_atomic | bool
1 change: 1 addition & 0 deletions roles/openshift_version/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ dependencies:
- role: openshift_docker_facts
- role: docker
when: openshift.common.is_containerized | default(False) | bool and not skip_docker_role | default(False) | bool
- role: lib_utils
12 changes: 10 additions & 2 deletions roles/openshift_version/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,16 @@
- block:
- name: Set openshift_version for containerized installation
include: set_version_containerized.yml
- name: Determine openshift rpm version
include: rpm_version.yml
- name: Get available {{ openshift.common.service_type}} version
repoquery:
name: "{{ openshift.common.service_type}}"
ignore_excluders: true
register: rpm_results
- fail:
msg: "Package {{ openshift.common.service_type}} not found"
when: not rpm_results.results.package_found
- set_fact:
openshift_rpm_version: "{{ rpm_results.results.versions.available_versions.0 | default('0.0', True) }}"
- name: Fail if rpm version and docker image version are different
fail:
msg: "OCP rpm version {{ openshift_rpm_version }} is different from OCP image version {{ openshift_version }}"
Expand Down
44 changes: 0 additions & 44 deletions roles/openshift_version/tasks/rpm_version.yml

This file was deleted.

16 changes: 13 additions & 3 deletions roles/openshift_version/tasks/set_version_rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
- openshift_version is not defined

- block:
- include: rpm_version.yml
- name: Get available {{ openshift.common.service_type}} version
repoquery:
name: "{{ openshift.common.service_type}}"
ignore_excluders: true
register: rpm_results

- fail:
msg: "Package {{ openshift.common.service_type}} not found"
when: not rpm_results.results.package_found

- set_fact:
openshift_version: "{{ openshift_rpm_version }}"
when: openshift_version is not defined
openshift_version: "{{ rpm_results.results.versions.available_versions.0 | default('0.0', True) }}"
when:
- openshift_version is not defined

0 comments on commit 57185bd

Please sign in to comment.