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 1, 2023
1 parent 8c87808 commit 7af4bfd
Show file tree
Hide file tree
Showing 86 changed files with 5,114 additions and 4,202 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
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
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
20 changes: 7 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,13 @@ 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 +1267,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 +1311,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 +1377,7 @@ 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
26 changes: 13 additions & 13 deletions tests/foreman/api/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,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 @@ -48,8 +46,10 @@ def activation_key(module_org, module_lce):


@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 @@ -63,8 +63,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 @@ -467,7 +467,7 @@ def test_positive_get_applicable_for_host(setup_content_rhel6, rhel6_contenthost


@pytest.mark.tier3
def test_positive_get_diff_for_cv_envs():
def test_positive_get_diff_for_cv_envs(module_target_sat):
"""Generate a difference in errata between a set of environments
for a content view
Expand All @@ -490,7 +490,7 @@ def test_positive_get_diff_for_cv_envs():
content_view = entities.ContentView(organization=org).create()
activation_key = entities.ActivationKey(environment=env, organization=org).create()
for repo_url in [settings.repos.yum_9.url, CUSTOM_REPO_URL]:
setup_org_for_a_custom_repo(
module_target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': repo_url,
'organization-id': org.id,
Expand Down Expand Up @@ -677,7 +677,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 @@ -694,7 +694,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 @@ -732,9 +732,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 @@ -832,7 +832,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
2 changes: 1 addition & 1 deletion tests/foreman/api/test_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from requests.exceptions import HTTPError

from robottelo import constants
from robottelo.cli.base import CLIReturnCodeError
from robottelo.config import settings
from robottelo.constants import DEFAULT_ARCHITECTURE, MIRRORING_POLICIES, REPOS
from robottelo.exceptions import CLIReturnCodeError
from robottelo.utils.datafactory import parametrized


Expand Down
Loading

0 comments on commit 7af4bfd

Please sign in to comment.