Skip to content

Commit

Permalink
Fix OEL Convert2Rhel tests (SatelliteQE#13236)
Browse files Browse the repository at this point in the history
* Fix OEL Convert2Rhel tests

Signed-off-by: Gaurav Talreja <[email protected]>

* Use SCA enabled org for C2R tests

Signed-off-by: Gaurav Talreja <[email protected]>

* Remove use of create_activation_key helper

Signed-off-by: Gaurav Talreja <[email protected]>

---------

Signed-off-by: Gaurav Talreja <[email protected]>
  • Loading branch information
Gauravtalreja1 authored and shweta83 committed Apr 10, 2024
1 parent 64b8eb8 commit 2c774dd
Showing 1 changed file with 102 additions and 104 deletions.
206 changes: 102 additions & 104 deletions tests/foreman/api/test_convert2rhel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
:CaseComponent: Registration
:CaseImportance: Critical
:Team: Rocket
"""
import pytest
import requests

from robottelo.config import settings
from robottelo.constants import DEFAULT_ARCHITECTURE, DEFAULT_SUBSCRIPTION_NAME, REPOS
from robottelo.constants import DEFAULT_ARCHITECTURE, REPOS


def create_repo(sat, org, repo_url, ssl_cert=None):
Expand All @@ -34,79 +36,41 @@ def create_repo(sat, org, repo_url, ssl_cert=None):
return repo


def create_activation_key(sat, org, lce, cv, subscription_id):
"""Create activation key with subscription"""
act_key = sat.api.ActivationKey(
organization=org,
content_view=cv,
environment=lce,
).create()
act_key.add_subscriptions(data={'subscription_id': subscription_id})
content = sat.cli.ActivationKey.product_content({'id': act_key.id, 'organization-id': org.id})
act_key.content_override(
data={'content_overrides': [{'content_label': content[0]['label'], 'value': '1'}]}
)
ak_subscriptions = act_key.product_content()['results']
ak_subscriptions[0]['enabled'] = True
return act_key


def update_cv(sat, cv, lce, repos):
"""Update and publish Content view with repos"""
cv = sat.api.ContentView(id=cv.id, repository=repos).update(["repository"])
cv = sat.api.ContentView(id=cv.id, repository=repos).update(['repository'])
cv.publish()
cv = cv.read()
cv.version.sort(key=lambda version: version.id)
cv.version[-1].promote(data={'environment_ids': lce.id, 'force': False})
return cv


def register_host(sat, act_key, org, module_loc, host, ubi=None):
"""Register host to satellite"""
# generate registration command
command = sat.api.RegistrationCommand(
organization=org,
activation_keys=[act_key.name],
location=module_loc,
insecure=True,
repo=ubi,
).create()
assert host.execute(command).status == 0


@pytest.fixture(scope='module')
def ssl_cert(module_target_sat, module_org):
def ssl_cert(module_target_sat, module_sca_manifest_org):
"""Create credetial with SSL cert for Oracle Linux"""
res = requests.get(settings.repos.convert2rhel.ssl_cert_oracle)
res.raise_for_status()
return module_target_sat.api.ContentCredential(
content=res.text, organization=module_org, content_type='cert'
content=res.text, organization=module_sca_manifest_org, content_type='cert'
).create()


@pytest.fixture
def activation_key_rhel(
module_target_sat, module_entitlement_manifest_org, module_lce, module_promoted_cv, version
):
def activation_key_rhel(module_target_sat, module_sca_manifest_org, module_lce, module_promoted_cv):
"""Create activation key that will be used after conversion for registration"""
subs = module_target_sat.api.Subscription(
organization=module_entitlement_manifest_org.id
).search(query={'search': f'{DEFAULT_SUBSCRIPTION_NAME}'})
assert subs
return create_activation_key(
module_target_sat,
module_entitlement_manifest_org,
module_lce,
module_promoted_cv,
subs[0].id,
)
return module_target_sat.api.ActivationKey(
organization=module_sca_manifest_org,
content_view=module_promoted_cv,
environment=module_lce,
).create()


@pytest.fixture(scope='module')
def enable_rhel_subscriptions(module_target_sat, module_entitlement_manifest_org, version):
def enable_rhel_subscriptions(module_target_sat, module_sca_manifest_org, version):
"""Enable and sync RHEL rpms repos"""
major = version.split('.')[0]
minor = ""
minor = ''
if major == '8':
repo_names = ['rhel8_bos', 'rhel8_aps']
minor = version[1:]
Expand All @@ -118,7 +82,7 @@ def enable_rhel_subscriptions(module_target_sat, module_entitlement_manifest_org
for name in repo_names:
rh_repo_id = module_target_sat.api_factory.enable_rhrepo_and_fetchid(
basearch=DEFAULT_ARCHITECTURE,
org_id=module_entitlement_manifest_org.id,
org_id=module_sca_manifest_org.id,
product=REPOS[name]['product'],
repo=REPOS[name]['name'] + minor,
reposet=REPOS[name]['reposet'],
Expand All @@ -145,39 +109,43 @@ def enable_rhel_subscriptions(module_target_sat, module_entitlement_manifest_org
def centos(
module_target_sat,
centos_host,
module_entitlement_manifest_org,
module_sca_manifest_org,
smart_proxy_location,
module_promoted_cv,
module_lce,
version,
enable_rhel_subscriptions,
):
"""Deploy and register Centos host"""
# updating centos packages on CentOS 8 is necessary for conversion
major = version.split('.')[0]
if major == '8':
centos_host.execute('yum -y update centos-*')
assert centos_host.execute('yum -y update').status == 0
repo_url = settings.repos.convert2rhel.convert_to_rhel_repo.format(major)
repo = create_repo(module_target_sat, module_entitlement_manifest_org, repo_url)
repo = create_repo(module_target_sat, module_sca_manifest_org, repo_url)
cv = update_cv(
module_target_sat, module_promoted_cv, module_lce, enable_rhel_subscriptions + [repo]
)
c2r_sub = module_target_sat.api.Subscription(
organization=module_entitlement_manifest_org.id, name=repo.product.name
).search()[0]
act_key = create_activation_key(
module_target_sat, module_entitlement_manifest_org, module_lce, cv, c2r_sub.id
)
register_host(
module_target_sat,
act_key,
module_entitlement_manifest_org,
smart_proxy_location,
centos_host,
)
centos_host.execute('yum -y update kernel*')
ak = module_target_sat.api.ActivationKey(
organization=module_sca_manifest_org,
content_view=cv,
environment=module_lce,
).create()
# Ensure C2R repo is enabled in the activation key
all_content = ak.product_content(data={'content_access_mode_all': '1'})['results']
repo_label = [content['label'] for content in all_content if content['name'] == repo.name][0]
ak.content_override(data={'content_overrides': [{'content_label': repo_label, 'value': '1'}]})

# Register CentOS host with Satellite
command = module_target_sat.api.RegistrationCommand(
organization=module_sca_manifest_org,
activation_keys=[ak.name],
location=smart_proxy_location,
insecure=True,
).create()
assert centos_host.execute(command).status == 0

if centos_host.execute('needs-restarting -r').status == 1:
centos_host.power_control(state='reboot')

yield centos_host
# close ssh session before teardown, because of reboot in conversion it may cause problems
centos_host.close()
Expand All @@ -187,7 +155,7 @@ def centos(
def oracle(
module_target_sat,
oracle_host,
module_entitlement_manifest_org,
module_sca_manifest_org,
smart_proxy_location,
module_promoted_cv,
module_lce,
Expand All @@ -196,39 +164,61 @@ def oracle(
enable_rhel_subscriptions,
):
"""Deploy and register Oracle host"""
major = version.split('.')[0]
assert oracle_host.execute('yum -y update').status == 0
# disable rhn-client-tools because it obsoletes the subscription manager package
oracle_host.execute('echo "exclude=rhn-client-tools" >> /etc/yum.conf')
# install and set correct kernel, based on convert2rhel docs

# Install and set correct RHEL compatible kernel and using non-UEK kernel, based on C2R docs
result = oracle_host.execute(
'yum install -y kernel && '
'grubby --set-default /boot/vmlinuz-'
'`rpm -q --qf "%{BUILDTIME}\t%{EVR}.%{ARCH}\n" kernel | sort -nr | head -1 | cut -f2`'
)
assert result.status == 0
oracle_host.power_control(state='reboot')
major = version.split('.')[0]

if major == '8':
# needs-restarting missing in OEL8
assert oracle_host.execute('dnf install -y yum-utils').status == 0
# Fix inhibitor CHECK_FIREWALLD_AVAILABILITY::FIREWALLD_MODULES_CLEANUP_ON_EXIT_CONFIG -
# Firewalld is set to cleanup modules after exit
result = oracle_host.execute(
'sed -i -- "s/CleanupModulesOnExit=yes/CleanupModulesOnExit=no/g" '
'/etc/firewalld/firewalld.conf && firewall-cmd --reload'
)
assert result.status == 0

if oracle_host.execute('needs-restarting -r').status == 1:
oracle_host.power_control(state='reboot')

repo_url = settings.repos.convert2rhel.convert_to_rhel_repo.format(major)
repo = create_repo(module_target_sat, module_entitlement_manifest_org, repo_url, ssl_cert)
repo = create_repo(module_target_sat, module_sca_manifest_org, repo_url, ssl_cert)
cv = update_cv(
module_target_sat, module_promoted_cv, module_lce, enable_rhel_subscriptions + [repo]
)
c2r_sub = module_target_sat.api.Subscription(
organization=module_entitlement_manifest_org, name=repo.product.name
).search()[0]
act_key = create_activation_key(
module_target_sat, module_entitlement_manifest_org, module_lce, cv, c2r_sub.id
)
ak = module_target_sat.api.ActivationKey(
organization=module_sca_manifest_org,
content_view=cv,
environment=module_lce,
).create()
# Ensure C2R repo is enabled in the activation key
all_content = ak.product_content(data={'content_access_mode_all': '1'})['results']
repo_label = [content['label'] for content in all_content if content['name'] == repo.name][0]
ak.content_override(data={'content_overrides': [{'content_label': repo_label, 'value': '1'}]})

# UBI repo required for subscription-manager packages on Oracle
ubi_url = settings.repos.convert2rhel.ubi7 if major == '7' else settings.repos.convert2rhel.ubi8
ubi = create_repo(module_target_sat, module_entitlement_manifest_org, ubi_url)
ubi_repo = ubi.full_path.replace('https', 'http')
register_host(
module_target_sat,
act_key,
module_entitlement_manifest_org,
smart_proxy_location,
oracle_host,
ubi_repo,
)

# Register Oracle host with Satellite
command = module_target_sat.api.RegistrationCommand(
organization=module_sca_manifest_org,
activation_keys=[ak.name],
location=smart_proxy_location,
insecure=True,
repo=ubi_url,
).create()
assert oracle_host.execute(command).status == 0

yield oracle_host
# close ssh session before teardown, because of reboot in conversion it may cause problems
oracle_host.close()
Expand All @@ -241,11 +231,7 @@ def version(request):


@pytest.mark.e2e
@pytest.mark.parametrize(
"version",
['oracle7', 'oracle8'],
indirect=True,
)
@pytest.mark.parametrize('version', ['oracle7', 'oracle8'], indirect=True)
def test_convert2rhel_oracle(module_target_sat, oracle, activation_key_rhel, version):
"""Convert Oracle linux to RHEL
Expand All @@ -260,9 +246,16 @@ def test_convert2rhel_oracle(module_target_sat, oracle, activation_key_rhel, ver
and subscription status
:parametrized: yes
:CaseImportance: Medium
"""
major = version.split('.')[0]
assert oracle.execute('yum -y update').status == 0
if major == '8':
# Fix inhibitor TAINTED_KMODS::TAINTED_KMODS_DETECTED - Tainted kernel modules detected
blacklist_cfg = '/etc/modprobe.d/blacklist.conf'
assert oracle.execute('modprobe -r nvme_tcp').status == 0
assert oracle.execute(f'echo "blacklist nvme_tcp" >> {blacklist_cfg}').status == 0
assert oracle.execute(f'echo "install nvme_tcp /bin/false" >> {blacklist_cfg}').status == 0

host_content = module_target_sat.api.Host(id=oracle.hostname).read_json()
assert host_content['operatingsystem_name'] == f"OracleLinux {version}"

Expand Down Expand Up @@ -292,14 +285,20 @@ def test_convert2rhel_oracle(module_target_sat, oracle, activation_key_rhel, ver

# check facts: correct os and valid subscription status
host_content = module_target_sat.api.Host(id=oracle.hostname).read_json()

assert host_content['subscription_status'] == 0
# workaround for BZ 2080347
assert (
host_content['operatingsystem_name'].startswith(f'RHEL Server {version}')
or host_content['operatingsystem_name'].startswith(f'RedHat {version}')
or host_content['operatingsystem_name'].startswith(f'RHEL {version}')
)
assert host_content['subscription_status_label'] == 'Simple Content Access'
assert host_content['subscription_status'] == 5


@pytest.mark.e2e
@pytest.mark.parametrize('version', ['centos7', 'centos8'], indirect=True)
def test_convert2rhel_centos(module_target_sat, centos, activation_key_rhel, version):
"""Convert Centos linux to RHEL
"""Convert CentOS linux to RHEL
:id: 6f698440-7d85-4deb-8dd9-363ea9003b92
Expand All @@ -312,8 +311,6 @@ def test_convert2rhel_centos(module_target_sat, centos, activation_key_rhel, ver
and subscription status
:parametrized: yes
:CaseImportance: Medium
"""
host_content = module_target_sat.api.Host(id=centos.hostname).read_json()
major = version.split('.')[0]
Expand Down Expand Up @@ -352,4 +349,5 @@ def test_convert2rhel_centos(module_target_sat, centos, activation_key_rhel, ver
or host_content['operatingsystem_name'].startswith(f'RedHat {version}')
or host_content['operatingsystem_name'].startswith(f'RHEL {version}')
)
assert host_content['subscription_status'] == 0
assert host_content['subscription_status_label'] == 'Simple Content Access'
assert host_content['subscription_status'] == 5

0 comments on commit 2c774dd

Please sign in to comment.