Skip to content

Commit

Permalink
Remove cli_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
shweta83 committed Oct 11, 2023
1 parent a1dade8 commit a442ceb
Show file tree
Hide file tree
Showing 73 changed files with 1,868 additions and 1,574 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
3 changes: 1 addition & 2 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
19 changes: 10 additions & 9 deletions tests/foreman/api/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 @@ -49,8 +48,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 @@ -64,8 +65,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 @@ -471,7 +472,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 @@ -494,7 +495,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 @@ -739,9 +740,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
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
2 changes: 1 addition & 1 deletion tests/foreman/cli/test_acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from fauxfactory import gen_alphanumeric
import pytest

from robottelo.cli.base import CLIReturnCodeError
from robottelo.constants.repos import PULP_FIXTURE_ROOT, PULP_SUBPATHS_COMBINED
from robottelo.exceptions import CLIReturnCodeError

ACS_UPDATED = 'Alternate Content Source updated.'
ACS_DELETED = 'Alternate Content Source deleted.'
Expand Down
Loading

0 comments on commit a442ceb

Please sign in to comment.