Skip to content

Commit

Permalink
PR checks without vault login
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare committed Sep 27, 2023
1 parent f2ce677 commit e3d7f13
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,25 @@ jobs:

- name: Collect Tests
run: |
# To skip vault login in pull request checks
export VAULT_SECRET_ID_FOR_DYNACONF=somesecret
pytest --collect-only --disable-pytest-warnings tests/foreman/ tests/robottelo/
pytest --collect-only --disable-pytest-warnings -m pre_upgrade tests/upgrades/
pytest --collect-only --disable-pytest-warnings -m post_upgrade tests/upgrades/
- name: Collect Tests with xdist
run: |
# To skip vault login in pull request checks
export VAULT_SECRET_ID_FOR_DYNACONF=somesecret
pytest --collect-only --setup-plan --disable-pytest-warnings -n 2 tests/foreman/ tests/robottelo/
pytest --collect-only --setup-plan --disable-pytest-warnings -n 2 -m pre_upgrade tests/upgrades/
pytest --collect-only --setup-plan --disable-pytest-warnings -n 2 -m post_upgrade tests/upgrades/
- name: Run Robottelo's Tests
run: pytest -sv tests/robottelo/
run: |
# To skip vault login in pull request checks
export VAULT_SECRET_ID_FOR_DYNACONF=somesecret
pytest -sv tests/robottelo/
- name: Make Docs
run: |
Expand Down
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Global Configurations for py.test runner"""
import pytest


pytest_plugins = [
# Plugins
'pytest_plugins.auto_vault',
Expand Down
4 changes: 2 additions & 2 deletions pytest_plugins/auto_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

def pytest_addoption(parser):
"""Options to allow user to update the requirements"""
vclient = Vault()
vclient.login(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
with Vault() as vclient:
vclient.login(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
21 changes: 13 additions & 8 deletions robottelo/utils/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import sys

from robottelo.exceptions import InvalidVaultURLForOIDC
from robottelo.logging import logger
from robottelo.logging import robottelo_root_dir
from robottelo.logging import logger, robottelo_root_dir


class Vault:
Expand All @@ -20,8 +19,13 @@ class Vault:

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

def setup(self):
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]
Expand Down Expand Up @@ -59,10 +63,7 @@ def exec_vault_command(self, command: str, **kwargs):
return vcommand

def login(self, **kwargs):
if (
re.search(r'\s*#.*VAULT_SECRET_ID_FOR_DYNACONF', self.env_path.read_text())
and 'VAULT_SECRET_ID_FOR_DYNACONF' not in os.environ
):
if '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 Down Expand Up @@ -105,5 +106,9 @@ def status(self, **kwargs):
logger.info(str(vstatus.stdout.decode('UTF-8')))
return vstatus

def __del__(self):
del os.environ['VAULT_ADDR']
def __enter__(self):
self.setup()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.teardown()
1 change: 0 additions & 1 deletion scripts/vault_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from robottelo.utils.vault import Vault


if __name__ == '__main__':
with Vault() as vclient:
if sys.argv[-1] == '--login':
Expand Down
4 changes: 1 addition & 3 deletions tests/foreman/api/test_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
from robottelo import constants
from robottelo.cli.base import CLIReturnCodeError
from robottelo.config import settings
from robottelo.constants import DEFAULT_ARCHITECTURE
from robottelo.constants import MIRRORING_POLICIES
from robottelo.constants import REPOS
from robottelo.constants import DEFAULT_ARCHITECTURE, MIRRORING_POLICIES, REPOS
from robottelo.utils.datafactory import parametrized


Expand Down

0 comments on commit e3d7f13

Please sign in to comment.