Skip to content

Commit

Permalink
Merge branch 'master' of github.com:SatelliteQE/robottelo into no-bla…
Browse files Browse the repository at this point in the history
…nk-cvpage
  • Loading branch information
sambible committed Oct 16, 2023
2 parents b8d4cbd + 2a013f8 commit 2e0f977
Show file tree
Hide file tree
Showing 49 changed files with 1,114 additions and 1,747 deletions.
56 changes: 30 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# configuration for pre-commit git hooks

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: tests/foreman/data/
- id: check-yaml
- id: debug-statements
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: local
hooks:
- id: fix-uuids
name: Robottelo Custom Fix UUIDs script
description: This hook runs the scripts/fix_uuids.sh script
language: script
entry: scripts/fix_uuids.sh
verbose: true
types: [text]
require_serial: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: tests/foreman/data/
- id: check-yaml
- id: debug-statements
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: local
hooks:
- id: fix-uuids
name: Robottelo Custom Fix UUIDs script
description: This hook runs the scripts/fix_uuids.sh script
language: script
entry: scripts/fix_uuids.sh
verbose: true
types: [text]
require_serial: true
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.0
hooks:
- id: gitleaks
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ test-docstrings: uuid-check
testimony $(TESTIMONY_OPTIONS) validate tests/foreman/ui
testimony $(TESTIMONY_OPTIONS) validate tests/foreman/virtwho
testimony $(TESTIMONY_OPTIONS) validate tests/foreman/maintain
testimony $(TESTIMONY_OPTIONS) validate tests/upgrades

test-robottelo:
$(info "Running robottelo framework unit tests...")
Expand Down
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'pytest_fixtures.component.computeprofile',
'pytest_fixtures.component.contentview',
'pytest_fixtures.component.domain',
'pytest_fixtures.component.discovery',
'pytest_fixtures.component.host',
'pytest_fixtures.component.hostgroup',
'pytest_fixtures.component.http_proxy',
Expand Down
31 changes: 31 additions & 0 deletions pytest_fixtures/component/discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from fauxfactory import gen_string
import pytest


@pytest.fixture(scope='module')
def module_discovery_hostgroup(module_org, module_location, module_target_sat):
host = module_target_sat.api.Host(organization=module_org, location=module_location).create()
return module_target_sat.api.HostGroup(
organization=[module_org],
location=[module_location],
medium=host.medium,
root_pass=gen_string('alpha'),
operatingsystem=host.operatingsystem,
ptable=host.ptable,
domain=host.domain,
architecture=host.architecture,
).create()


@pytest.fixture(scope='module')
def discovery_org(module_org, module_target_sat):
discovery_org = module_target_sat.update_setting('discovery_organization', module_org.name)
yield module_org
module_target_sat.update_setting('discovery_organization', discovery_org)


@pytest.fixture(scope='module')
def discovery_location(module_location, module_target_sat):
discovery_loc = module_target_sat.update_setting('discovery_location', module_location.name)
yield module_location
module_target_sat.update_setting('discovery_location', discovery_loc)
2 changes: 1 addition & 1 deletion requirements-optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
flake8==6.1.0
pytest-cov==4.1.0
redis==5.0.1
pre-commit==3.4.0
pre-commit==3.5.0

# For generating documentation.
sphinx==7.2.6
Expand Down
1 change: 1 addition & 0 deletions robottelo/cli/sm_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def is_locked(cls, options=None):
def status(cls, options=None):
"""Build satellite-maintain packages status"""
cls.command_sub = 'status'
cls.command_end = None
options = options or {}
return cls.sm_execute(cls._construct_command(options))

Expand Down
2 changes: 1 addition & 1 deletion robottelo/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ class Colored(Box):

VMWARE_CONSTANTS = {
'folder': 'vm',
'guest_os': 'Red Hat Enterprise Linux 8 (64-bit)',
'guest_os': 'Red Hat Enterprise Linux 8 (64 bit)',
'scsicontroller': 'LSI Logic Parallel',
'virtualhw_version': 'Default',
'pool': 'Resources',
Expand Down
1 change: 1 addition & 0 deletions robottelo/host_helpers/contenthost_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class HostInfo:
@property
def applicable_errata_count(self):
"""return the applicable errata count for a host"""
self.run('subscription-manager repos')
return self.nailgun_host.read().content_facet_attributes['errata_counts']['total']


Expand Down
4 changes: 2 additions & 2 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def register(
raise ValueError('Global registration method can be used with Satellite/Capsule only')

if lifecycle_environment is not None:
options['lifecycle_environment_id'] = lifecycle_environment.id
options['lifecycle-environment-id'] = lifecycle_environment.id
if operating_system is not None:
options['operatingsystem-id'] = operating_system.id
if hostgroup is not None:
Expand Down Expand Up @@ -1968,7 +1968,7 @@ def delete_puppet_class(self, puppetclass_name):
for hostgroup in puppet_class.read().hostgroup:
hostgroup.delete_puppetclass(data={'puppetclass_id': puppet_class.id})
# Search and remove puppet class from affected hosts
for host in self.api.Host().search(query={'search': f'class={puppet_class.name}'}):
for host in self.api.Host(puppetclass=f'{puppet_class.name}').search():
host.delete_puppetclass(data={'puppetclass_id': puppet_class.id})
# Remove puppet class entity
puppet_class.delete()
Expand Down
38 changes: 24 additions & 14 deletions robottelo/utils/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,31 @@ class Vault:

def __init__(self, env_file='.env'):
self.env_path = robottelo_root_dir.joinpath(env_file)
self.envdata = None
self.vault_enabled = None

def setup(self):
self.export_vault_addr()
if self.env_path.exists():
self.envdata = self.env_path.read_text()
is_enabled = re.findall('\nVAULT_ENABLED_FOR_DYNACONF=(.*)', self.envdata)
if is_enabled:
self.vault_enabled = is_enabled[0]
self.export_vault_addr()

def teardown(self):
del os.environ['VAULT_ADDR']

def export_vault_addr(self):
envdata = self.env_path.read_text()
vaulturl = re.findall('VAULT_URL_FOR_DYNACONF=(.*)', envdata)[0]
vaulturl = re.findall('VAULT_URL_FOR_DYNACONF=(.*)', self.envdata)[0]

# Set Vault CLI Env Var
os.environ['VAULT_ADDR'] = vaulturl

# Dynaconf Vault Env Vars
if re.findall('VAULT_ENABLED_FOR_DYNACONF=(.*)', envdata)[0] == 'true':
if self.vault_enabled and self.vault_enabled in ['True', 'true']:
if 'localhost:8200' in vaulturl:
raise InvalidVaultURLForOIDC(
f"{vaulturl} doesnt supports OIDC login,"
f"{vaulturl} doesn't support OIDC login,"
"please change url to corp vault in env file!"
)

Expand All @@ -63,7 +69,11 @@ def exec_vault_command(self, command: str, **kwargs):
return vcommand

def login(self, **kwargs):
if 'VAULT_SECRET_ID_FOR_DYNACONF' not in os.environ:
if (
self.vault_enabled
and self.vault_enabled in ['True', 'true']
and 'VAULT_SECRET_ID_FOR_DYNACONF' not in os.environ
):
if self.status(**kwargs).returncode != 0:
logger.warning(
"Warning! The browser is about to open for vault OIDC login, "
Expand All @@ -81,22 +91,22 @@ def login(self, **kwargs):
).stdout
token = json.loads(str(token.decode('UTF-8')))['data']['id']
# Setting new token in env file
envdata = self.env_path.read_text()
envdata = re.sub(
'.*VAULT_TOKEN_FOR_DYNACONF=.*', f"VAULT_TOKEN_FOR_DYNACONF={token}", envdata
_envdata = re.sub(
'.*VAULT_TOKEN_FOR_DYNACONF=.*',
f"VAULT_TOKEN_FOR_DYNACONF={token}",
self.envdata,
)
self.env_path.write_text(envdata)
self.env_path.write_text(_envdata)
logger.info(
"Success! New OIDC token added to .env file to access secrets from vault!"
)

def logout(self):
# Teardown - Setting dymmy token in env file
envdata = self.env_path.read_text()
envdata = re.sub(
'.*VAULT_TOKEN_FOR_DYNACONF=.*', "# VAULT_TOKEN_FOR_DYNACONF=myroot", envdata
_envdata = re.sub(
'.*VAULT_TOKEN_FOR_DYNACONF=.*', "# VAULT_TOKEN_FOR_DYNACONF=myroot", self.envdata
)
self.env_path.write_text(envdata)
self.env_path.write_text(_envdata)
self.exec_vault_command('vault token revoke -self')
logger.info("Success! OIDC token removed from Env file successfully!")

Expand Down
71 changes: 57 additions & 14 deletions tests/foreman/api/test_discoveredhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ def test_positive_provision_pxe_less_host(
:expectedresults: Host should be provisioned successfully
:CaseAutomation: NotAutomated
:CaseImportance: Critical
"""
sat = module_discovery_sat.sat
Expand All @@ -274,9 +272,10 @@ def test_positive_provision_pxe_less_host(
assert not sat.api.Host().search(query={"search": f'name={host.name}'})
pxeless_discovery_host.blank = True

@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_auto_provision_pxe_host(self):
def test_positive_auto_provision_pxe_host(
self, module_discovery_hostgroup, module_target_sat, discovery_org, discovery_location
):
"""Auto provision a pxe-based host by executing discovery rules
:id: c93fd7c9-41ef-4eb5-8042-f72e87e67e10
Expand All @@ -290,14 +289,24 @@ def test_positive_auto_provision_pxe_host(self):
:expectedresults: Selected Host should be auto-provisioned successfully
:CaseAutomation: Automated
:CaseImportance: Critical
"""
discovered_host = module_target_sat.api_factory.create_discovered_host()

rule = module_target_sat.api.DiscoveryRule(
max_count=1,
hostgroup=module_discovery_hostgroup,
search_=f'name = {discovered_host["name"]}',
location=[discovery_location],
organization=[discovery_org],
).create()
result = module_target_sat.api.DiscoveredHost(id=discovered_host['id']).auto_provision()
assert f'provisioned with rule {rule.name}' in result['message']

@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_auto_provision_all(self):
def test_positive_auto_provision_all(
self, module_discovery_hostgroup, module_target_sat, discovery_org, discovery_location
):
"""Auto provision all host by executing discovery rules
:id: 954d3688-62d9-47f7-9106-a4fff8825ffa
Expand All @@ -314,6 +323,19 @@ def test_positive_auto_provision_all(self):
:CaseImportance: High
"""
module_target_sat.api.DiscoveryRule(
max_count=25,
hostgroup=module_discovery_hostgroup,
search_=f'location = "{discovery_location.name}"',
location=[discovery_location],
organization=[discovery_org],
).create()

for _ in range(2):
module_target_sat.api_factory.create_discovered_host()

result = module_target_sat.api.DiscoveredHost().auto_provision_all()
assert '2 discovered hosts were provisioned' in result['message']

@pytest.mark.stubbed
@pytest.mark.tier3
Expand All @@ -337,9 +359,19 @@ def test_positive_refresh_facts_pxe_host(self):
:CaseImportance: High
"""

@pytest.mark.stubbed
@pytest.mark.on_premises_provisioning
@pytest.mark.parametrize('module_provisioning_sat', ['discovery'], indirect=True)
@pytest.mark.parametrize('pxe_loader', ['bios', 'uefi'], indirect=True)
@pytest.mark.rhel_ver_match('9')
@pytest.mark.tier3
def test_positive_reboot_pxe_host(self):
def test_positive_reboot_pxe_host(
self,
module_provisioning_rhel_content,
module_discovery_sat,
provisioning_host,
provisioning_hostgroup,
pxe_loader,
):
"""Rebooting a pxe based discovered host
:id: 69c807f8-5646-4aa6-8b3c-5ecab69560fc
Expand All @@ -352,10 +384,23 @@ def test_positive_reboot_pxe_host(self):
:expectedresults: Selected host should be rebooted successfully
:CaseAutomation: Automated
:CaseImportance: Medium
"""
sat = module_discovery_sat.sat
provisioning_host.power_control(ensure=False)
mac = provisioning_host._broker_args['provisioning_nic_mac_addr']
wait_for(
lambda: sat.api.DiscoveredHost().search(query={'mac': mac}) != [],
timeout=240,
delay=20,
)
discovered_host = sat.api.DiscoveredHost().search(query={'mac': mac})[0]
discovered_host.hostgroup = provisioning_hostgroup
discovered_host.location = provisioning_hostgroup.location[0]
discovered_host.organization = provisioning_hostgroup.organization[0]
discovered_host.build = True
result = sat.api.DiscoveredHost(id=discovered_host.id).reboot()
assert 'Unable to perform reboot' not in result

@pytest.mark.stubbed
@pytest.mark.tier3
Expand All @@ -381,8 +426,6 @@ def test_positive_reboot_all_pxe_hosts(self):
class TestFakeDiscoveryTests:
"""Tests that use fake discovered host.
:CaseAutomation: Automated
:CaseImportance: High
"""

Expand Down
Loading

0 comments on commit 2e0f977

Please sign in to comment.