Context
As part of in-place upgrade testing initiative, we already have speial
tests that (simplified) will do setup on RHEL-N and test on RHEL-N+1.
A newer, initiative -- convert2rhel has similar needs: there we have
use cases for "upgrade" tests that start on CentOS and end on RHEL.
Both types of tests are identical in structure:
- get source distro (RHEL-7 / CentOS-7 / ...),
- set up -- here we use BeakerLib code,
- upgrade or convert (to RHEL-7 / ...)
- test -- here we use same BeakerLib code again,
and because some components are long-term stable in CLI and behavior,
even the content is often almost identical.
Hence, we want to re-use the code as much as possible.
But the CLI/behavior is not 100% identical - they need to code branch
per distro -- hence the use of rlIsRHEL()
is common.
Problem
When we try to take a test code that uses rlIsRHEL
and re-use it in
a convert2rhel testing, we end up having to go to the code and change from
if rlIsRHEL '>6'; then
...
to
if rlIsRHEL '>6' || rlsCentOS '>6'; then
...
which can become really messy and confusing, especially if the rlIsRHEL
condition is already part of
a more complex boolean expression.
Furthermore, there's a perspective that we may want to run this on other
distros, eg. OracleLinux. BeakerLib does not have rlIsOracleLinux
but I think you can see where this would go.
Solution
In most (not all, though) cases, the behavior of RHEL and RHEL-like
distro can be assumed to be identical. In these cases, rlIsRHEL
could be effectively replaced by something like this:
rlIsRHELLike() {
#
# True if rlIsRHEL $@ OR rlIsCentOS $@ would be true
#
rlIsCentOS "$@" && return 0
rlIsRHEL "$@" && return 0
return 1
}
This would make the code re-usable on CentOS without further complexity.
Furthermore, the rlIsRHELLike
function could be easily extended to
support other RHEL forks (where the major/minor assumption can be made),
making tests re-usable with no changes.