Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.14.z] Replace old method of registration with global registration in robottelo #15329

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -807,6 +807,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
86 changes: 42 additions & 44 deletions tests/foreman/api/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -51,15 +52,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 @@ -70,17 +68,15 @@ 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(
result = rhel_contenthost.api_register(
module_target_sat,
smart_proxy=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 @@ -114,30 +110,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 @@ -147,29 +145,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 @@ -189,20 +187,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 @@ -257,11 +256,11 @@ def test_negative_capsule_without_registration_enabled(
error_message = '422 Client Error'
with pytest.raises(HTTPError, match=f'{error_message}') as context:
module_target_sat.api.RegistrationCommand(
module_target_sat,
smart_proxy=nc,
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 Expand Up @@ -307,7 +306,8 @@ def test_positive_host_registration_with_non_admin_user_with_setup_false(
location=[module_location],
).create()
user_cfg = user_nailgun_config(login, password)
command = module_target_sat.api.RegistrationCommand(
result = rhel_contenthost.api_register(
module_target_sat,
server_config=user_cfg,
organization=module_org,
activation_keys=[module_activation_key.name],
Expand All @@ -316,8 +316,7 @@ def test_positive_host_registration_with_non_admin_user_with_setup_false(
setup_remote_execution=False,
setup_remote_execution_pull=False,
update_packages=False,
).create()
result = rhel_contenthost.execute(command)
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

# verify package install for insights-client didn't run when Setup Insights is false
Expand Down Expand Up @@ -355,13 +354,12 @@ def test_negative_verify_bash_exit_status_failing_host_registration(
"""
ak = module_target_sat.api.ActivationKey(name=gen_string('alpha')).create()
# Try registration command generated with AK not in same as selected organization
command = module_target_sat.api.RegistrationCommand(
result = rhel_contenthost.api_register(
module_target_sat,
organization=module_sca_manifest_org,
activation_keys=[ak.name],
location=module_location,
).create()
result = rhel_contenthost.execute(command)

)
# verify status code when registrationCommand fails to register on host
assert result.status == 1
assert 'Couldn\'t find activation key' in result.stderr
16 changes: 12 additions & 4 deletions tests/foreman/api/test_reporttemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,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 @@ -631,8 +635,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
Loading