Skip to content

Commit

Permalink
Remove cli_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
shweta83 committed Nov 9, 2023
1 parent 034dcac commit 242c412
Show file tree
Hide file tree
Showing 92 changed files with 5,231 additions and 4,207 deletions.
5 changes: 2 additions & 3 deletions pytest_fixtures/component/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from nailgun import entities
import pytest

from robottelo.cli.factory import setup_org_for_a_rh_repo
from robottelo.constants import DEFAULT_CV, ENVIRONMENT, PRDS, REPOS, REPOSET


Expand All @@ -24,7 +23,7 @@ def module_model():

@pytest.mark.skip_if_not_set('clients', 'fake_manifest')
@pytest.fixture(scope="module")
def setup_rhst_repo():
def setup_rhst_repo(module_target_sat):
"""Prepare Satellite tools repository for usage in specified organization"""
org = entities.Organization().create()
cv = entities.ContentView(organization=org).create()
Expand All @@ -34,7 +33,7 @@ def setup_rhst_repo():
organization=org,
).create()
repo_name = 'rhst7'
setup_org_for_a_rh_repo(
module_target_sat.cli_factory.setup_org_for_a_rh_repo(
{
'product': PRDS['rhel'],
'repository-set': REPOSET[repo_name],
Expand Down
2 changes: 1 addition & 1 deletion pytest_fixtures/component/maintain.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def setup_sync_plan(request, sat_maintain):
"""
org = sat_maintain.api.Organization().create()
# Setup sync-plan
new_sync_plan = sat_maintain.cli_factory.make_sync_plan(
new_sync_plan = sat_maintain.cli_factory.sync_plan(
{
'enabled': 'true',
'interval': 'weekly',
Expand Down
7 changes: 4 additions & 3 deletions pytest_fixtures/component/oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from nailgun import entities
import pytest

from robottelo.cli.factory import make_scapcontent
from robottelo.config import robottelo_tmp_dir, settings
from robottelo.constants import OSCAP_PROFILE, OSCAP_TAILORING_FILE, DataFile

Expand All @@ -29,9 +28,11 @@ def oscap_content_path(session_target_sat):


@pytest.fixture(scope="module")
def scap_content(import_ansible_roles):
def scap_content(import_ansible_roles, module_target_sat):
title = f"rhel-content-{gen_string('alpha')}"
scap_info = make_scapcontent({'title': title, 'scap-file': f'{settings.oscap.content_path}'})
scap_info = module_target_sat.cli_factory.make_scapcontent(
{'title': title, 'scap-file': f'{settings.oscap.content_path}'}
)
scap_id = scap_info['id']
scap_info = entities.ScapContents(id=scap_id).read()

Expand Down
52 changes: 2 additions & 50 deletions robottelo/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,11 @@
from robottelo import ssh
from robottelo.cli import hammer
from robottelo.config import settings
from robottelo.exceptions import CLIDataBaseError, CLIError, CLIReturnCodeError
from robottelo.logging import logger
from robottelo.utils.ssh import get_client


class CLIError(Exception):
"""Indicates that a CLI command could not be run."""


class CLIBaseError(Exception):
"""Indicates that a CLI command has finished with return code different
from zero.
:param status: CLI command return code
:param stderr: contents of the ``stderr``
:param msg: explanation of the error
"""

def __init__(self, status, stderr, msg):
self.status = status
self.stderr = stderr
self.msg = msg
super().__init__(msg)
self.message = msg

def __str__(self):
"""Include class name, status, stderr and msg to string repr so
assertRaisesRegexp can be used to assert error present on any
attribute
"""
return repr(self)

def __repr__(self):
"""Include class name status, stderr and msg to improve logging"""
return '{}(status={!r}, stderr={!r}, msg={!r}'.format(
type(self).__name__, self.status, self.stderr, self.msg
)


class CLIReturnCodeError(CLIBaseError):
"""Error to be raised when an error occurs due to some validation error
when execution hammer cli.
See: https://github.com/SatelliteQE/robottelo/issues/3790 for more details
"""


class CLIDataBaseError(CLIBaseError):
"""Error to be raised when an error occurs due to some missing parameter
which cause a data base error on hammer
See: https://github.com/SatelliteQE/robottelo/issues/3790 for more details
"""


class Base:
"""Base class for hammer CLI interaction
Expand All @@ -84,7 +36,7 @@ def _handle_response(cls, response, ignore_stderr=None):
:param ignore_stderr: indicates whether to throw a warning in logs if
``stderr`` is not empty.
:returns: contents of ``stdout``.
:raises robottelo.cli.base.CLIReturnCodeError: If return code is
:raises robottelo.exceptions.CLIReturnCodeError: If return code is
different from zero.
"""
if isinstance(response.stderr, tuple):
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion robottelo/cli/report_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
from tempfile import mkstemp

from robottelo import ssh
from robottelo.cli.base import Base, CLIError
from robottelo.cli.base import Base
from robottelo.constants import REPORT_TEMPLATE_FILE, DataFile
from robottelo.exceptions import CLIError


class ReportTemplate(Base):
Expand Down
2 changes: 1 addition & 1 deletion robottelo/content_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests

from robottelo import ssh
from robottelo.cli.base import CLIReturnCodeError
from robottelo.exceptions import CLIReturnCodeError


def get_repo_files(repo_path, extension='rpm', hostname=None):
Expand Down
53 changes: 53 additions & 0 deletions robottelo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,56 @@ class ProxyError(Exception):

class DownloadFileError(Exception):
"""Indicates an error when failure in downloading file from server."""


class CLIFactoryError(Exception):
"""Indicates an error occurred while creating an entity using hammer"""


class CLIError(Exception):
"""Indicates that a CLI command could not be run."""


class CLIBaseError(Exception):
"""Indicates that a CLI command has finished with return code different
from zero.
:param status: CLI command return code
:param stderr: contents of the ``stderr``
:param msg: explanation of the error
"""

def __init__(self, status, stderr, msg):
self.status = status
self.stderr = stderr
self.msg = msg
super().__init__(msg)
self.message = msg

def __str__(self):
"""Include class name, status, stderr and msg to string repr so
assertRaisesRegexp can be used to assert error present on any
attribute
"""
return repr(self)

def __repr__(self):
"""Include class name status, stderr and msg to improve logging"""
return '{}(status={!r}, stderr={!r}, msg={!r}'.format(
type(self).__name__, self.status, self.stderr, self.msg
)


class CLIReturnCodeError(CLIBaseError):
"""Error to be raised when an error occurs due to some validation error
when execution hammer cli.
See: https://github.com/SatelliteQE/robottelo/issues/3790 for more details
"""


class CLIDataBaseError(CLIBaseError):
"""Error to be raised when an error occurs due to some missing parameter
which cause a data base error on hammer
See: https://github.com/SatelliteQE/robottelo/issues/3790 for more details
"""
6 changes: 1 addition & 5 deletions robottelo/host_helpers/cli_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@
)

from robottelo import constants
from robottelo.cli.base import CLIReturnCodeError
from robottelo.cli.proxy import CapsuleTunnelError
from robottelo.config import settings
from robottelo.exceptions import CLIFactoryError, CLIReturnCodeError
from robottelo.host_helpers.repository_mixins import initiate_repo_helpers
from robottelo.utils.manifest import clone


class CLIFactoryError(Exception):
"""Indicates an error occurred while creating an entity using hammer"""


def create_object(cli_object, options, values=None, credentials=None):
"""
Creates <object> with dictionary of arguments.
Expand Down
2 changes: 1 addition & 1 deletion robottelo/host_helpers/satellite_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import requests

from robottelo.cli.base import CLIReturnCodeError
from robottelo.cli.proxy import CapsuleTunnelError
from robottelo.config import settings
from robottelo.constants import (
Expand All @@ -16,6 +15,7 @@
PUPPET_COMMON_INSTALLER_OPTS,
PUPPET_SATELLITE_INSTALLER,
)
from robottelo.exceptions import CLIReturnCodeError
from robottelo.host_helpers.api_factory import APIFactory
from robottelo.host_helpers.cli_factory import CLIFactory
from robottelo.host_helpers.ui_factory import UIFactory
Expand Down
28 changes: 15 additions & 13 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from robottelo import constants
from robottelo.cli.base import Base
from robottelo.cli.factory import CLIFactoryError
from robottelo.config import (
configure_airgun,
configure_nailgun,
Expand All @@ -53,7 +52,7 @@
RHSSO_USER_UPDATE,
SATELLITE_VERSION,
)
from robottelo.exceptions import DownloadFileError, HostPingFailed
from robottelo.exceptions import CLIFactoryError, DownloadFileError, HostPingFailed
from robottelo.host_helpers import CapsuleMixins, ContentHostMixins, SatelliteMixins
from robottelo.logging import logger
from robottelo.utils import validate_ssh_pub_key
Expand Down Expand Up @@ -1248,18 +1247,19 @@ def virt_who_hypervisor_config(
:param bool upload_manifest: whether to upload the organization manifest
:param list extra_repos: (Optional) repositories dict options to setup additionally.
"""
from robottelo.cli import factory as cli_factory
from robottelo.cli.lifecycleenvironment import LifecycleEnvironment
from robottelo.cli.org import Org
from robottelo.cli.subscription import Subscription
from robottelo.cli.virt_who_config import VirtWhoConfig

org = cli_factory.make_org() if org_id is None else Org.info({'id': org_id})
org = (
satellite.cli_factory.make_org()
if org_id is None
else satellite.cli.Org.info({'id': org_id})
)

if lce_id is None:
lce = cli_factory.make_lifecycle_environment({'organization-id': org['id']})
lce = satellite.cli_factory.make_lifecycle_environment({'organization-id': org['id']})
else:
lce = LifecycleEnvironment.info({'id': lce_id, 'organization-id': org['id']})
lce = satellite.cli.LifecycleEnvironment.info(
{'id': lce_id, 'organization-id': org['id']}
)
extra_repos = extra_repos or []
repos = [
# Red Hat Satellite Tools
Expand All @@ -1273,7 +1273,7 @@ def virt_who_hypervisor_config(
}
]
repos.extend(extra_repos)
content_setup_data = cli_factory.setup_cdn_and_custom_repos_content(
content_setup_data = satellite.cli_factory.setup_cdn_and_custom_repos_content(
org[id],
lce[id],
repos,
Expand Down Expand Up @@ -1317,7 +1317,7 @@ def virt_who_hypervisor_config(
# create the virt-who directory on satellite
satellite = Satellite()
satellite.execute(f'mkdir -p {virt_who_deploy_directory}')
VirtWhoConfig.fetch({'id': config_id, 'output': virt_who_deploy_file})
satellite.cli.VirtWhoConfig.fetch({'id': config_id, 'output': virt_who_deploy_file})
# remote_copy from satellite to self
satellite.session.remote_copy(virt_who_deploy_file, self)

Expand Down Expand Up @@ -1383,7 +1383,9 @@ def virt_who_hypervisor_config(
virt_who_hypervisor_host = org_hosts[0]
subscription_id = None
if hypervisor_hostname and subscription_name:
subscriptions = Subscription.list({'organization-id': org_id}, per_page=False)
subscriptions = satellite.cli.Subscription.list(
{'organization-id': org_id}, per_page=False
)
for subscription in subscriptions:
if subscription['name'] == subscription_name:
subscription_id = subscription['id']
Expand Down
24 changes: 12 additions & 12 deletions tests/foreman/api/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import pytest

from robottelo import constants
from robottelo.cli.factory import setup_org_for_a_custom_repo, setup_org_for_a_rh_repo
from robottelo.cli.host import Host
from robottelo.config import settings
from robottelo.constants import DEFAULT_SUBSCRIPTION_NAME

Expand All @@ -47,8 +45,10 @@ def activation_key(module_org, module_lce, module_target_sat):


@pytest.fixture(scope='module')
def rh_repo(module_entitlement_manifest_org, module_lce, module_cv, activation_key):
return setup_org_for_a_rh_repo(
def rh_repo(
module_entitlement_manifest_org, module_lce, module_cv, activation_key, module_target_sat
):
return module_target_sat.cli_factory.setup_org_for_a_rh_repo(
{
'product': constants.PRDS['rhel'],
'repository-set': constants.REPOSET['rhst7'],
Expand All @@ -62,8 +62,8 @@ def rh_repo(module_entitlement_manifest_org, module_lce, module_cv, activation_k


@pytest.fixture(scope='module')
def custom_repo(module_org, module_lce, module_cv, activation_key):
return setup_org_for_a_custom_repo(
def custom_repo(module_org, module_lce, module_cv, activation_key, module_target_sat):
return module_target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': settings.repos.yum_9.url,
'organization-id': module_org.id,
Expand Down Expand Up @@ -491,7 +491,7 @@ def test_positive_get_diff_for_cv_envs(target_sat):
content_view = target_sat.api.ContentView(organization=org).create()
activation_key = target_sat.api.ActivationKey(environment=env, organization=org).create()
for repo_url in [settings.repos.yum_9.url, CUSTOM_REPO_URL]:
setup_org_for_a_custom_repo(
target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': repo_url,
'organization-id': org.id,
Expand Down Expand Up @@ -678,7 +678,7 @@ def test_errata_installation_with_swidtags(
_run_remote_command_on_content_host(
module_org, f'dnf -y module install {module_name}:0:{version}', rhel8_contenthost
)
Host.errata_recalculate({'host-id': rhel8_contenthost.nailgun_host.id})
target_sat.cli.Host.errata_recalculate({'host-id': rhel8_contenthost.nailgun_host.id})
# validate swid tags Installed
before_errata_apply_result = _run_remote_command_on_content_host(
module_org,
Expand All @@ -695,7 +695,7 @@ def test_errata_installation_with_swidtags(
module_org, f'dnf -y module update {module_name}', rhel8_contenthost
)
_run_remote_command_on_content_host(module_org, 'dnf -y upload-profile', rhel8_contenthost)
Host.errata_recalculate({'host-id': rhel8_contenthost.nailgun_host.id})
target_sat.cli.Host.errata_recalculate({'host-id': rhel8_contenthost.nailgun_host.id})
applicable_errata_count -= 1
assert rhel8_contenthost.applicable_errata_count == applicable_errata_count
after_errata_apply_result = _run_remote_command_on_content_host(
Expand Down Expand Up @@ -733,9 +733,9 @@ def rh_repo_module_manifest(module_entitlement_manifest_org, module_target_sat):


@pytest.fixture(scope='module')
def rhel8_custom_repo_cv(module_entitlement_manifest_org):
def rhel8_custom_repo_cv(module_entitlement_manifest_org, module_target_sat):
"""Create repo and publish CV so that packages are in Library"""
return setup_org_for_a_custom_repo(
return module_target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': settings.repos.module_stream_1.url,
'organization-id': module_entitlement_manifest_org.id,
Expand Down Expand Up @@ -839,7 +839,7 @@ def test_apply_modular_errata_using_default_content_view(
assert result.status == 0
# Check that there is now two errata applicable
errata = _fetch_available_errata(module_entitlement_manifest_org, host, 2)
Host.errata_recalculate({'host-id': rhel8_contenthost.nailgun_host.id})
target_sat.cli.Host.errata_recalculate({'host-id': rhel8_contenthost.nailgun_host.id})
assert len(errata) == 2
# Assert that errata package is required
assert constants.FAKE_3_CUSTOM_PACKAGE in errata[0]['module_streams'][0]['packages']
Expand Down
Loading

0 comments on commit 242c412

Please sign in to comment.