Skip to content

Commit

Permalink
Replace old method of registration with global registration in robott…
Browse files Browse the repository at this point in the history
…elo (#14034)
  • Loading branch information
shweta83 committed Jun 6, 2024
1 parent 9d3d758 commit 907104d
Show file tree
Hide file tree
Showing 19 changed files with 336 additions and 267 deletions.
9 changes: 9 additions & 0 deletions pytest_fixtures/component/activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def module_ak_with_cv(module_lce, module_org, module_promoted_cv, module_target_
).create()


@pytest.fixture
def function_ak_with_cv(function_lce, function_org, function_promoted_cv, target_sat):
return target_sat.api.ActivationKey(
content_view=function_promoted_cv,
environment=function_lce,
organization=function_org,
).create()


@pytest.fixture(scope='module')
def module_ak_with_synced_repo(module_org, module_target_sat):
"""Prepare an activation key with synced repository for host registration"""
Expand Down
15 changes: 15 additions & 0 deletions pytest_fixtures/component/contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def module_published_cv(module_org, module_target_sat):
return content_view.read()


@pytest.fixture
def function_published_cv(function_org, target_sat):
content_view = target_sat.api.ContentView(organization=function_org).create()
content_view.publish()
return content_view.read()


@pytest.fixture(scope="module")
def module_promoted_cv(module_lce, module_published_cv, module_target_sat):
"""Promote published content view"""
Expand All @@ -25,6 +32,14 @@ def module_promoted_cv(module_lce, module_published_cv, module_target_sat):
return module_published_cv


@pytest.fixture
def function_promoted_cv(function_lce, function_published_cv, target_sat):
"""Promote published content view"""
content_view_version = function_published_cv.version[0]
content_view_version.promote(data={'environment_ids': function_lce.id})
return function_published_cv


@pytest.fixture(scope='module')
def module_default_org_view(module_org, module_target_sat):
return module_target_sat.api.ContentView(organization=module_org, name=DEFAULT_CV).search()[0]
Expand Down
11 changes: 11 additions & 0 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,17 @@ def register(
cmd = target.satellite.cli.HostRegistration.generate_command(options)
return self.execute(cmd.strip('\n'))

def api_register(self, target, **kwargs):
"""Register a content host using global registration through API.
:param target: Satellite or Capsule object to register to.
:param kwargs: Additional keyword arguments to pass to the API call.
:return: The result of the API call.
"""
kwargs['insecure'] = kwargs.get('insecure', True)
command = target.satellite.api.RegistrationCommand(**kwargs).create()
return self.execute(command.strip('\n'))

def register_contenthost(
self,
org='Default_Organization',
Expand Down
24 changes: 12 additions & 12 deletions tests/foreman/api/test_convert2rhel.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ def centos(
c2r_sub = module_target_sat.api.Subscription(
organization=module_entitlement_manifest_org.id, name=repo.product.name
).search()[0]
act_key = create_activation_key(
ak = create_activation_key(
module_target_sat, module_entitlement_manifest_org, module_lce, cv, c2r_sub.id
)

# Register CentOS host with Satellite
command = module_target_sat.api.RegistrationCommand(
result = centos_host.api_register(
module_target_sat,
organization=module_entitlement_manifest_org,
activation_keys=[act_key.name],
activation_keys=[ak.name],
location=smart_proxy_location,
insecure=True,
).create()
assert centos_host.execute(command).status == 0
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

if centos_host.execute('needs-restarting -r').status == 1:
centos_host.power_control(state='reboot')
Expand Down Expand Up @@ -221,21 +221,21 @@ def oracle(
c2r_sub = module_target_sat.api.Subscription(
organization=module_entitlement_manifest_org, name=repo.product.name
).search()[0]
act_key = create_activation_key(
ak = create_activation_key(
module_target_sat, module_entitlement_manifest_org, module_lce, cv, c2r_sub.id
)
# UBI repo required for subscription-manager packages on Oracle
ubi_url = settings.repos.convert2rhel.ubi7 if major == '7' else settings.repos.convert2rhel.ubi8

# Register Oracle host with Satellite
command = module_target_sat.api.RegistrationCommand(
result = oracle_host.api_register(
module_target_sat,
organization=module_entitlement_manifest_org,
activation_keys=[act_key.name],
activation_keys=[ak.name],
location=smart_proxy_location,
insecure=True,
repo=ubi_url,
).create()
assert oracle_host.execute(command).status == 0
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

yield oracle_host
# close ssh session before teardown, because of reboot in conversion it may cause problems
Expand Down
9 changes: 7 additions & 2 deletions tests/foreman/api/test_hostcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,13 @@ def test_positive_add_remove_subscription(module_org, module_ak_cv_lce, target_s
# Create and register VMs as members of Host Collection
with Broker(nick='rhel7', host_class=ContentHost, _count=2) as hosts:
for client in hosts:
client.install_katello_ca(target_sat)
client.register_contenthost(module_org.label, module_ak_cv_lce.name)
result = client.api_register(
target_sat,
organization=module_org,
activation_keys=[module_ak_cv_lce.name],
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

# Read host_collection back from Satellite to get host_ids
host_collection = module_ak_cv_lce.host_collection[0].read()
host_ids = [host.id for host in host_collection.host]
Expand Down
73 changes: 35 additions & 38 deletions tests/foreman/api/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


@pytest.mark.e2e
@pytest.mark.rhel_ver_match('[^6]')
@pytest.mark.no_containers
def test_host_registration_end_to_end(
module_entitlement_manifest_org,
Expand All @@ -48,15 +49,12 @@ def test_host_registration_end_to_end(
:customerscenario: true
"""
org = module_entitlement_manifest_org
command = module_target_sat.api.RegistrationCommand(
result = rhel_contenthost.api_register(
module_target_sat,
organization=org,
activation_keys=[module_activation_key.name],
location=module_location,
).create()

result = rhel_contenthost.execute(command)
rc = 1 if rhel_contenthost.os_version.major == 6 else 0
assert result.status == rc, f'Failed to register host: {result.stderr}'
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

# Verify server.hostname and server.port from subscription-manager config
assert module_target_sat.hostname == rhel_contenthost.subscription_config['server']['hostname']
Expand All @@ -67,17 +65,14 @@ def test_host_registration_end_to_end(
module_target_sat.api.SmartProxy(id=nc.id, organization=[org]).update(['organization'])
module_target_sat.api.SmartProxy(id=nc.id, location=[module_location]).update(['location'])

command = module_target_sat.api.RegistrationCommand(
smart_proxy=nc,
result = rhel_contenthost.api_register(
nc,
organization=org,
activation_keys=[module_activation_key.name],
location=module_location,
force=True,
).create()
result = rhel_contenthost.execute(command)

rc = 1 if rhel_contenthost.os_version.major == 6 else 0
assert result.status == rc, f'Failed to register host: {result.stderr}'
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

# Verify server.hostname and server.port from subscription-manager config
assert (
Expand Down Expand Up @@ -111,30 +106,32 @@ def test_positive_allow_reregistration_when_dmi_uuid_changed(
uuid_2 = str(uuid.uuid4())
org = module_entitlement_manifest_org
target_sat.execute(f'echo \'{{"dmi.system.uuid": "{uuid_1}"}}\' > /etc/rhsm/facts/uuid.facts')
command = target_sat.api.RegistrationCommand(
result = rhel_contenthost.api_register(
target_sat,
organization=org,
activation_keys=[module_activation_key.name],
location=module_location,
).create()
result = rhel_contenthost.execute(command)
assert result.status == 0
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

result = rhel_contenthost.execute('subscription-manager clean')
assert result.status == 0
target_sat.execute(f'echo \'{{"dmi.system.uuid": "{uuid_2}"}}\' > /etc/rhsm/facts/uuid.facts')
command = target_sat.api.RegistrationCommand(
result = rhel_contenthost.api_register(
target_sat,
organization=org,
activation_keys=[module_activation_key.name],
location=module_location,
).create()
result = rhel_contenthost.execute(command)
assert result.status == 0
)
assert result.status == 0, f'Failed to register host: {result.stderr}'


@pytest.mark.rhel_ver_match('8')
def test_positive_update_packages_registration(
module_target_sat,
module_entitlement_manifest_org,
module_location,
rhel8_contenthost,
rhel_contenthost,
module_activation_key,
):
"""Test package update on host post registration
Expand All @@ -144,29 +141,29 @@ def test_positive_update_packages_registration(
:expectedresults: Package update is successful on host post registration.
"""
org = module_entitlement_manifest_org
org = module_entitlement_manifest_org
command = module_target_sat.api.RegistrationCommand(
result = rhel_contenthost.api_register(
module_target_sat,
organization=org,
location=module_location,
activation_keys=[module_activation_key.name],
location=module_location,
update_packages=True,
).create()
result = rhel8_contenthost.execute(command)
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

package = constants.FAKE_7_CUSTOM_PACKAGE
repo_url = settings.repos.yum_3['url']
rhel8_contenthost.create_custom_repos(fake_yum=repo_url)
result = rhel8_contenthost.execute(f"yum install -y {package}")
rhel_contenthost.create_custom_repos(fake_yum=repo_url)
result = rhel_contenthost.execute(f"yum install -y {package}")
assert result.status == 0


@pytest.mark.rhel_ver_match('8')
@pytest.mark.no_containers
def test_positive_rex_interface_for_global_registration(
module_target_sat,
module_entitlement_manifest_org,
module_location,
rhel8_contenthost,
rhel_contenthost,
module_activation_key,
):
"""Test remote execution interface is set for global registration
Expand All @@ -186,20 +183,21 @@ def test_positive_rex_interface_for_global_registration(
ip = gen_ipaddr()
# Create eth1 interface on the host
add_interface_command = f'ip link add eth1 type dummy;ifconfig eth1 hw ether {mac_address};ip addr add {ip}/24 brd + dev eth1 label eth1:1;ip link set dev eth1 up'
result = rhel8_contenthost.execute(add_interface_command)
result = rhel_contenthost.execute(add_interface_command)
assert result.status == 0
org = module_entitlement_manifest_org
command = module_target_sat.api.RegistrationCommand(
result = rhel_contenthost.api_register(
module_target_sat,
organization=org,
location=module_location,
activation_keys=[module_activation_key.name],
location=module_location,
update_packages=True,
remote_execution_interface='eth1',
).create()
result = rhel8_contenthost.execute(command)
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

host = module_target_sat.api.Host().search(
query={'search': f'name={rhel8_contenthost.hostname}'}
query={'search': f'name={rhel_contenthost.hostname}'}
)[0]
# Check if eth1 interface is set for remote execution
for interface in host.read_json()['interfaces']:
Expand Down Expand Up @@ -258,7 +256,6 @@ def test_negative_capsule_without_registration_enabled(
organization=org,
location=module_location,
activation_keys=[module_ak_with_cv.name],
insecure=True,
).create()
assert (
"Proxy lacks one of the following features: 'Registration', 'Templates'"
Expand Down
16 changes: 12 additions & 4 deletions tests/foreman/api/test_reporttemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,12 @@ def test_positive_generate_entitlements_report(setup_content, target_sat):
"""
with Broker(nick='rhel7', host_class=ContentHost) as vm:
ak, org = setup_content
vm.install_katello_ca(target_sat)
vm.register_contenthost(org.label, ak.name)
result = vm.api_register(
target_sat,
organization=org,
activation_keys=[ak.name],
)
assert result.status == 0, f'Failed to register host: {result.stderr}'
assert vm.subscribed
rt = (
target_sat.api.ReportTemplate()
Expand Down Expand Up @@ -567,8 +571,12 @@ def test_positive_schedule_entitlements_report(setup_content, target_sat):
"""
with Broker(nick='rhel7', host_class=ContentHost) as vm:
ak, org = setup_content
vm.install_katello_ca(target_sat)
vm.register_contenthost(org.label, ak.name)
result = vm.api_register(
target_sat,
organization=org,
activation_keys=[ak.name],
)
assert result.status == 0, f'Failed to register host: {result.stderr}'
assert vm.subscribed
rt = (
target_sat.api.ReportTemplate()
Expand Down
Loading

0 comments on commit 907104d

Please sign in to comment.