Skip to content

Commit

Permalink
[6.15.z] Add flake8-simplify and flake8-return to ruff config (#14100) (
Browse files Browse the repository at this point in the history
#14342)

* Add flake8-simplify and flake8-return to ruff config (#14100)

(cherry picked from commit db19610)

* fixed sanity suite, AttributeError due to not matching scope (#14309)

(cherry picked from commit 063ac02)

---------

Co-authored-by: Omkar Khatavkar <[email protected]>
  • Loading branch information
ogajduse and omkarkhatavkar authored Mar 12, 2024
1 parent 6222301 commit 425c2b6
Show file tree
Hide file tree
Showing 129 changed files with 537 additions and 699 deletions.
3 changes: 1 addition & 2 deletions conf/dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ def get_dogfood_satclient_repos(settings):


def get_ohsnap_repo_url(settings, repo, product=None, release=None, os_release=None, snap=''):
repourl = dogfood_repository(
return dogfood_repository(
settings.ohsnap,
repo=repo,
product=product,
release=release,
os_release=os_release,
snap=snap,
).baseurl
return repourl
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ select = [
"I", # isort
# "Q", # flake8-quotes
"PT", # flake8-pytest
"RET", # flake8-return
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle
]
Expand Down
15 changes: 5 additions & 10 deletions pytest_fixtures/component/activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,37 @@
@pytest.fixture(scope='module')
def module_activation_key(module_sca_manifest_org, module_target_sat):
"""Create activation key using default CV and library environment."""
activation_key = module_target_sat.api.ActivationKey(
return module_target_sat.api.ActivationKey(
content_view=module_sca_manifest_org.default_content_view.id,
environment=module_sca_manifest_org.library.id,
organization=module_sca_manifest_org,
).create()
return activation_key


@pytest.fixture(scope='module')
def module_ak(module_lce, module_org, module_target_sat):
ak = module_target_sat.api.ActivationKey(
return module_target_sat.api.ActivationKey(
environment=module_lce,
organization=module_org,
).create()
return ak


@pytest.fixture(scope='module')
def module_ak_with_cv(module_lce, module_org, module_promoted_cv, module_target_sat):
ak = module_target_sat.api.ActivationKey(
return module_target_sat.api.ActivationKey(
content_view=module_promoted_cv,
environment=module_lce,
organization=module_org,
).create()
return ak


@pytest.fixture(scope='module')
def module_ak_with_cv_repo(module_lce, module_org, module_cv_repo, module_target_sat):
ak = module_target_sat.api.ActivationKey(
return module_target_sat.api.ActivationKey(
content_view=module_cv_repo,
environment=module_lce,
organization=module_org,
).create()
return ak


@pytest.fixture(scope='module')
Expand All @@ -55,12 +51,11 @@ def module_ak_with_synced_repo(module_org, module_target_sat):
{'product-id': new_product['id'], 'content-type': 'yum'}
)
Repository.synchronize({'id': new_repo['id']})
ak = module_target_sat.cli_factory.make_activation_key(
return module_target_sat.cli_factory.make_activation_key(
{
'lifecycle-environment': 'Library',
'content-view': 'Default Organization View',
'organization-id': module_org.id,
'auto-attach': False,
}
)
return ak
6 changes: 2 additions & 4 deletions pytest_fixtures/component/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@

@pytest.fixture(scope='session')
def default_architecture(session_target_sat):
arch = (
return (
session_target_sat.api.Architecture()
.search(query={'search': f'name="{DEFAULT_ARCHITECTURE}"'})[0]
.read()
)
return arch


@pytest.fixture(scope='session')
def session_puppet_default_architecture(session_puppet_enabled_sat):
arch = (
return (
session_puppet_enabled_sat.api.Architecture()
.search(query={'search': f'name="{DEFAULT_ARCHITECTURE}"'})[0]
.read()
)
return arch


@pytest.fixture(scope='module')
Expand Down
3 changes: 1 addition & 2 deletions pytest_fixtures/component/contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ def module_ak_cv_lce(module_org, module_lce, module_published_cv, module_target_
content_view_version = module_published_cv.version[0]
content_view_version.promote(data={'environment_ids': module_lce.id})
module_published_cv = module_published_cv.read()
module_ak_with_cv_lce = module_target_sat.api.ActivationKey(
return module_target_sat.api.ActivationKey(
content_view=module_published_cv,
environment=module_lce,
organization=module_org,
).create()
return module_ak_with_cv_lce


@pytest.fixture(scope='module')
Expand Down
3 changes: 1 addition & 2 deletions pytest_fixtures/component/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def default_os(
os.ptable.append(default_partitiontable)
os.provisioning_template.append(default_pxetemplate)
os.update(['architecture', 'ptable', 'provisioning_template'])
os = entities.OperatingSystem(id=os.id).read()
return os
return entities.OperatingSystem(id=os.id).read()


@pytest.fixture(scope='module')
Expand Down
24 changes: 8 additions & 16 deletions pytest_fixtures/component/provision_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,23 @@ def sat_azure_default_os(sat_azure):

@pytest.fixture(scope='module')
def sat_azure_default_architecture(sat_azure):
arch = (
return (
sat_azure.api.Architecture()
.search(query={'search': f'name="{DEFAULT_ARCHITECTURE}"'})[0]
.read()
)
return arch


@pytest.fixture(scope='session')
def azurerm_settings():
deps = {
return {
'tenant': settings.azurerm.tenant_id,
'app_ident': settings.azurerm.client_id,
'sub_id': settings.azurerm.subscription_id,
'resource_group': settings.azurerm.resource_group,
'secret': settings.azurerm.client_secret,
'region': settings.azurerm.azure_region.lower().replace(' ', ''),
}
return deps


@pytest.fixture(scope='session')
Expand All @@ -86,7 +84,7 @@ def azurermclient(azurerm_settings):
@pytest.fixture(scope='module')
def module_azurerm_cr(azurerm_settings, sat_azure_org, sat_azure_loc, sat_azure):
"""Create AzureRM Compute Resource"""
azure_cr = sat_azure.api.AzureRMComputeResource(
return sat_azure.api.AzureRMComputeResource(
name=gen_string('alpha'),
provider='AzureRm',
tenant=azurerm_settings['tenant'],
Expand All @@ -97,7 +95,6 @@ def module_azurerm_cr(azurerm_settings, sat_azure_org, sat_azure_loc, sat_azure)
organization=[sat_azure_org],
location=[sat_azure_loc],
).create()
return azure_cr


@pytest.fixture(scope='module')
Expand All @@ -108,15 +105,14 @@ def module_azurerm_finishimg(
module_azurerm_cr,
):
"""Creates Finish Template image on AzureRM Compute Resource"""
finish_image = sat_azure.api.Image(
return sat_azure.api.Image(
architecture=sat_azure_default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
operatingsystem=sat_azure_default_os,
username=settings.azurerm.username,
uuid=AZURERM_RHEL7_FT_IMG_URN,
).create()
return finish_image


@pytest.fixture(scope='module')
Expand All @@ -127,15 +123,14 @@ def module_azurerm_byos_finishimg(
sat_azure,
):
"""Creates BYOS Finish Template image on AzureRM Compute Resource"""
finish_image = sat_azure.api.Image(
return sat_azure.api.Image(
architecture=sat_azure_default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
operatingsystem=sat_azure_default_os,
username=settings.azurerm.username,
uuid=AZURERM_RHEL7_FT_BYOS_IMG_URN,
).create()
return finish_image


@pytest.fixture(scope='module')
Expand All @@ -146,7 +141,7 @@ def module_azurerm_cloudimg(
module_azurerm_cr,
):
"""Creates cloudinit image on AzureRM Compute Resource"""
finish_image = sat_azure.api.Image(
return sat_azure.api.Image(
architecture=sat_azure_default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
Expand All @@ -155,7 +150,6 @@ def module_azurerm_cloudimg(
uuid=AZURERM_RHEL7_UD_IMG_URN,
user_data=True,
).create()
return finish_image


@pytest.fixture(scope='module')
Expand All @@ -166,15 +160,14 @@ def module_azurerm_gallery_finishimg(
module_azurerm_cr,
):
"""Creates Shared Gallery Finish Template image on AzureRM Compute Resource"""
finish_image = sat_azure.api.Image(
return sat_azure.api.Image(
architecture=sat_azure_default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
operatingsystem=sat_azure_default_os,
username=settings.azurerm.username,
uuid=AZURERM_RHEL7_FT_GALLERY_IMG_URN,
).create()
return finish_image


@pytest.fixture(scope='module')
Expand All @@ -185,12 +178,11 @@ def module_azurerm_custom_finishimg(
module_azurerm_cr,
):
"""Creates Custom Finish Template image on AzureRM Compute Resource"""
finish_image = sat_azure.api.Image(
return sat_azure.api.Image(
architecture=sat_azure_default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
operatingsystem=sat_azure_default_os,
username=settings.azurerm.username,
uuid=AZURERM_RHEL7_FT_CUSTOM_IMG_URN,
).create()
return finish_image
2 changes: 1 addition & 1 deletion pytest_fixtures/component/provision_capsule_pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def capsule_provisioning_rhel_content(
releasever=constants.REPOS['kickstart'][name]['version'],
)
# do not sync content repos for discovery based provisioning.
if not capsule_provisioning_sat.provisioning_type == 'discovery':
if capsule_provisioning_sat.provisioning_type != 'discovery':
rh_repo_id = sat.api_factory.enable_rhrepo_and_fetchid(
basearch=constants.DEFAULT_ARCHITECTURE,
org_id=module_sca_manifest_org.id,
Expand Down
18 changes: 6 additions & 12 deletions pytest_fixtures/component/provision_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ def sat_gce_default_partition_table(sat_gce):

@pytest.fixture(scope='module')
def sat_gce_default_architecture(sat_gce):
arch = (
return (
sat_gce.api.Architecture()
.search(query={'search': f'name="{DEFAULT_ARCHITECTURE}"'})[0]
.read()
)
return arch


@pytest.fixture(scope='session')
Expand Down Expand Up @@ -96,8 +95,7 @@ def gce_latest_rhel_uuid(googleclient):
filter_expr=f'name:{GCE_TARGET_RHEL_IMAGE_NAME}*',
)
latest_template_name = max(tpl.name for tpl in templates)
latest_template_uuid = next(tpl for tpl in templates if tpl.name == latest_template_name).uuid
return latest_template_uuid
return next(tpl for tpl in templates if tpl.name == latest_template_name).uuid


@pytest.fixture(scope='session')
Expand All @@ -116,15 +114,14 @@ def session_default_os(session_target_sat):

@pytest.fixture(scope='module')
def module_gce_compute(sat_gce, sat_gce_org, sat_gce_loc, gce_cert):
gce_cr = sat_gce.api.GCEComputeResource(
return sat_gce.api.GCEComputeResource(
name=gen_string('alphanumeric'),
provider='GCE',
key_path=settings.gce.cert_path,
zone=settings.gce.zone,
organization=[sat_gce_org],
location=[sat_gce_loc],
).create()
return gce_cr


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -206,7 +203,7 @@ def gce_hostgroup(
googleclient,
):
"""Sets Hostgroup for GCE Host Provisioning"""
hgroup = sat_gce.api.HostGroup(
return sat_gce.api.HostGroup(
architecture=sat_gce_default_architecture,
compute_resource=module_gce_compute,
domain=sat_gce_domain,
Expand All @@ -216,7 +213,6 @@ def gce_hostgroup(
organization=[sat_gce_org],
ptable=sat_gce_default_partition_table,
).create()
return hgroup


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -250,7 +246,7 @@ def module_gce_cloudimg(
sat_gce,
):
"""Creates cloudinit image on GCE Compute Resource"""
cloud_image = sat_gce.api.Image(
return sat_gce.api.Image(
architecture=sat_gce_default_architecture,
compute_resource=module_gce_compute,
name=gen_string('alpha'),
Expand All @@ -259,7 +255,6 @@ def module_gce_cloudimg(
uuid=gce_custom_cloudinit_uuid,
user_data=True,
).create()
return cloud_image


@pytest.fixture(scope='module')
Expand All @@ -271,15 +266,14 @@ def module_gce_finishimg(
sat_gce,
):
"""Creates finish image on GCE Compute Resource"""
finish_image = sat_gce.api.Image(
return sat_gce.api.Image(
architecture=sat_gce_default_architecture,
compute_resource=module_gce_compute,
name=gen_string('alpha'),
operatingsystem=sat_gce_default_os,
username=gen_string('alpha'),
uuid=gce_latest_rhel_uuid,
).create()
return finish_image


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion pytest_fixtures/component/provision_pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def module_provisioning_rhel_content(
releasever=constants.REPOS['kickstart'][name]['version'],
)
# do not sync content repos for discovery based provisioning.
if not module_provisioning_sat.provisioning_type == 'discovery':
if module_provisioning_sat.provisioning_type != 'discovery':
rh_repo_id = sat.api_factory.enable_rhrepo_and_fetchid(
basearch=constants.DEFAULT_ARCHITECTURE,
org_id=module_sca_manifest_org.id,
Expand Down
3 changes: 1 addition & 2 deletions pytest_fixtures/component/provision_vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def vmware(request):

@pytest.fixture(scope='module')
def module_vmware_cr(module_provisioning_sat, module_sca_manifest_org, module_location, vmware):
vmware_cr = module_provisioning_sat.sat.api.VMWareComputeResource(
return module_provisioning_sat.sat.api.VMWareComputeResource(
name=gen_string('alpha'),
provider='Vmware',
url=vmware.hostname,
Expand All @@ -25,7 +25,6 @@ def module_vmware_cr(module_provisioning_sat, module_sca_manifest_org, module_lo
organization=[module_sca_manifest_org],
location=[module_location],
).create()
return vmware_cr


@pytest.fixture
Expand Down
Loading

0 comments on commit 425c2b6

Please sign in to comment.