Skip to content

Commit

Permalink
Merge branch '6.13.z' into cherry-pick-6.13.z-bb8eb50bc8ed34b1933db62…
Browse files Browse the repository at this point in the history
…ea4a07f603da59788
  • Loading branch information
adarshdubey-star authored Nov 6, 2023
2 parents 65ba353 + 03511f3 commit 319920c
Show file tree
Hide file tree
Showing 35 changed files with 1,321 additions and 1,575 deletions.
20 changes: 20 additions & 0 deletions conf/docker.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@ DOCKER:
PRIVATE_REGISTRY_USERNAME:
# Private docker registry password
PRIVATE_REGISTRY_PASSWORD:
# Image Pass Registry
IMAGE_REGISTRY:
# image repository URL
URL:
# Pull a non-namespace image using the image pass registry proxy
NON_NAMESPACE:
# Proxy for the non-namespace image
PROXY:
# Username for the non-namespace image pass registry proxy
USERNAME:
# Password for the non-namespace image pass registry proxy
PASSWORD:
# Pull a namespace image using the image pass registry proxy
NAMESPACE:
# proxy for the namespace image
PROXY:
# Username for the namespace image pass registry proxy
USERNAME:
# Password for the namespace image pass registry proxy
PASSWORD:
10 changes: 5 additions & 5 deletions pytest_fixtures/component/domain.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Domain Fixtures
from nailgun import entities
import pytest


@pytest.fixture(scope='session')
def default_domain(session_target_sat, default_smart_proxy):
domain_name = session_target_sat.hostname.partition('.')[-1]
dom = entities.Domain().search(query={'search': f'name={domain_name}'})[0]
dom.dns = default_smart_proxy
dom.update(['dns'])
return entities.Domain(id=dom.id).read()
dom = session_target_sat.api.Domain().search(query={'search': f'name={domain_name}'})[0]
if 'dns' in session_target_sat.get_features():
dom.dns = default_smart_proxy
dom.update(['dns'])
return session_target_sat.api.Domain(id=dom.id).read()


@pytest.fixture(scope='module')
Expand Down
27 changes: 27 additions & 0 deletions pytest_fixtures/component/provision_pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,33 @@ def provisioning_host(module_ssh_key_file, pxe_loader):
prov_host.blank = getattr(prov_host, 'blank', False)


@pytest.fixture
def provision_multiple_hosts(module_ssh_key_file, pxe_loader, request):
"""Fixture to check out two blank VMs"""
vlan_id = settings.provisioning.vlan_id
cd_iso = (
"" # TODO: Make this an optional fixture parameter (update vm_firmware when adding this)
)
# Keeping the default value to 2
count = request.param if request.param is not None else 2

with Broker(
workflow="deploy-configure-pxe-provisioning-host-rhv",
host_class=ContentHost,
_count=count,
target_vlan_id=vlan_id,
target_vm_firmware=pxe_loader.vm_firmware,
target_vm_cd_iso=cd_iso,
blank=True,
target_memory='6GiB',
auth=module_ssh_key_file,
) as hosts:
yield hosts

for prov_host in hosts:
prov_host.blank = getattr(prov_host, 'blank', False)


@pytest.fixture
def provisioning_hostgroup(
module_provisioning_sat,
Expand Down
3 changes: 1 addition & 2 deletions pytest_plugins/auto_vault.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Plugin enables pytest to notify and update the requirements"""
import subprocess

from robottelo.utils.vault import Vault


def pytest_addoption(parser):
"""Options to allow user to update the requirements"""
with Vault() as vclient:
vclient.login(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
vclient.login()
7 changes: 4 additions & 3 deletions pytest_plugins/fixture_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def pytest_addoption(parser):
example: pytest tests/foreman --uses-fixtures target_sat module_target_sat
'''
parser.addoption("--uses-fixtures", nargs='+', help=help_text)
parser.addoption("--uses-fixtures", nargs='?', help=help_text)


def pytest_collection_modifyitems(items, config):
Expand All @@ -22,17 +22,18 @@ def pytest_collection_modifyitems(items, config):
return

filter_fixtures = config.getvalue('uses_fixtures')
fixtures_list = filter_fixtures.split(',') if ',' in filter_fixtures else [filter_fixtures]
selected = []
deselected = []

for item in items:
if set(item.fixturenames).intersection(set(filter_fixtures)):
if set(item.fixturenames).intersection(set(fixtures_list)):
selected.append(item)
else:
deselected.append(item)
logger.debug(
f'Selected {len(selected)} and deselected {len(deselected)} '
f'tests based on given fixtures {filter_fixtures} used by tests'
f'tests based on given fixtures {fixtures_list} used by tests'
)
config.hook.pytest_deselected(items=deselected)
items[:] = selected
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

betelgeuse==1.10.0
broker[docker]==0.4.1
cryptography==41.0.4
deepdiff==6.6.0
dynaconf[vault]==3.2.3
cryptography==41.0.5
deepdiff==6.6.1
dynaconf[vault]==3.2.4
fauxfactory==3.1.0
jinja2==3.1.2
manifester==0.0.14
navmazing==1.1.6
productmd==1.37
pyotp==2.9.0
python-box==7.1.1
pytest==7.4.2
pytest==7.4.3
pytest-services==2.2.1
pytest-mock==3.11.1
pytest-reportportal==5.2.2
pytest-mock==3.12.0
pytest-reportportal==5.3.0
pytest-xdist==3.3.1
pytest-ibutsu==2.2.4
PyYAML==6.0.1
requests==2.31.0
tenacity==8.2.3
testimony==2.3.0
wait-for==1.2.0
wrapanapi==3.5.18
wrapanapi==3.6.0

# Get airgun, nailgun and upgrade from 6.13.z
git+https://github.com/SatelliteQE/[email protected]#egg=airgun
Expand Down
4 changes: 4 additions & 0 deletions robottelo/cli/sm_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ class Packages(Base):
def lock(cls, options=None):
"""Build satellite-maintain packages lock"""
cls.command_sub = 'lock'
cls.command_end = None
options = options or {}
return cls.sm_execute(cls._construct_command(options))

@classmethod
def unlock(cls, options=None):
"""Build satellite-maintain packages unlock"""
cls.command_sub = 'unlock'
cls.command_end = None
options = options or {}
return cls.sm_execute(cls._construct_command(options))

@classmethod
def is_locked(cls, options=None):
"""Build satellite-maintain packages is-locked"""
cls.command_sub = 'is-locked'
cls.command_end = None
options = options or {}
return cls.sm_execute(cls._construct_command(options))

Expand Down Expand Up @@ -75,5 +78,6 @@ def update(cls, packages='', options=None):
def check_update(cls, options=None):
"""Build satellite-maintain packages check-update"""
cls.command_sub = 'check-update'
cls.command_end = None
options = options or {}
return cls.sm_execute(cls._construct_command(options))
12 changes: 6 additions & 6 deletions robottelo/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ class Colored(Box):
'rhsc7': 'Red Hat Satellite Capsule 6.11 (for RHEL 7 Server) (RPMs)',
'rhsc8': 'Red Hat Satellite Capsule 6.13 for RHEL 8 x86_64 (RPMs)',
'rhsc7_iso': 'Red Hat Satellite Capsule 6.4 (for RHEL 7 Server) (ISOs)',
'rhsclient7': 'Red Hat Satellite Client 6 for RHEL 7 Server RPMs x86_64',
'rhsclient8': 'Red Hat Satellite Client 6 for RHEL 8 x86_64 RPMs',
'rhsclient9': 'Red Hat Satellite Client 6 for RHEL 9 x86_64 RPMs',
'rhsclient7': 'Red Hat Satellite Client 6 (for RHEL 7 Server) (RPMs)',
'rhsclient8': 'Red Hat Satellite Client 6 for RHEL 8 x86_64 (RPMs)',
'rhsclient9': 'Red Hat Satellite Client 6 for RHEL 9 x86_64 (RPMs)',
'rhst7': 'Red Hat Satellite Tools 6.9 (for RHEL 7 Server) (RPMs)',
'rhst7_610': 'Red Hat Satellite Tools 6.10 (for RHEL 7 Server) (RPMs)',
'rhst6': 'Red Hat Satellite Tools 6.9 (for RHEL 6 Server) (RPMs)',
Expand Down Expand Up @@ -406,7 +406,7 @@ class Colored(Box):
'name': ('Red Hat Satellite Client 6 for RHEL 8 x86_64 RPMs'),
'version': '6',
'reposet': REPOSET['rhsclient8'],
'product': PRDS['rhel'],
'product': PRDS['rhel8'],
'distro': 'rhel8',
'key': PRODUCT_KEY_SAT_CLIENT,
},
Expand All @@ -415,7 +415,7 @@ class Colored(Box):
'name': ('Red Hat Satellite Client 6 for RHEL 9 x86_64 RPMs'),
'version': '6',
'reposet': REPOSET['rhsclient9'],
'product': PRDS['rhel'],
'product': PRDS['rhel9'],
'distro': 'rhel9',
'key': PRODUCT_KEY_SAT_CLIENT,
},
Expand Down Expand Up @@ -1729,7 +1729,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
56 changes: 33 additions & 23 deletions robottelo/utils/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,32 @@ 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('^(?:.*\n)*VAULT_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']
if os.environ.get('VAULT_ADDR') is not None:
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 @@ -47,7 +54,7 @@ def exec_vault_command(self, command: str, **kwargs):
:param comamnd str: The vault CLI command
:param kwargs dict: Arguments to the subprocess run command to customize the run behavior
"""
vcommand = subprocess.run(command, shell=True, **kwargs) # capture_output=True
vcommand = subprocess.run(command, shell=True, capture_output=True, **kwargs)
if vcommand.returncode != 0:
verror = str(vcommand.stderr)
if vcommand.returncode == 127:
Expand All @@ -57,15 +64,19 @@ def exec_vault_command(self, command: str, **kwargs):
if 'Error revoking token' in verror:
logger.info("Token is alredy revoked!")
elif 'Error looking up token' in verror:
logger.warning("Warning! Vault not logged in!")
logger.info("Vault is not logged in!")
else:
logger.error(f"Error! {verror}")
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(
logger.info(
"Warning! The browser is about to open for vault OIDC login, "
"close the tab once the sign-in is done!"
)
Expand All @@ -76,29 +87,28 @@ def login(self, **kwargs):
self.exec_vault_command(command="vault token renew -i 10h", **kwargs)
logger.info("Success! Vault OIDC Logged-In and extended for 10 hours!")
# Fetching tokens
token = self.exec_vault_command(
"vault token lookup --format json", capture_output=True
).stdout
token = self.exec_vault_command("vault token lookup --format json").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.exec_vault_command('vault token revoke -self')
logger.info("Success! OIDC token removed from Env file successfully!")
self.env_path.write_text(_envdata)
vstatus = self.exec_vault_command('vault token revoke -self')
if vstatus.returncode == 0:
logger.info("Success! OIDC token removed from Env file successfully!")

def status(self, **kwargs):
vstatus = self.exec_vault_command('vault token lookup', **kwargs)
Expand Down
Loading

0 comments on commit 319920c

Please sign in to comment.