-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pytest verifies and log-in into vault #12378
Conversation
4e7ec8d
to
7c27fe5
Compare
What is the problem that this PR is trying to solve? What would be a typical use of this new plugin? |
@ogajduse This saves you from getting out of pytest session for vault-login if its not already logged in into the vault by building the vault login facilities in pytest session itself. So without worrying if the vault session is expired or not do the process by yourself of vault-login (helps new bees / devs where they would be unaware of they had to to login into vault first), you can directly execute pytest session. Updated the description how the pytest session runs ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a few questions
pytest_plugins/auto_vault.py
Outdated
re.search(r'\s*#.*VAULT_SECRET_ID_FOR_DYNACONF', envpath.read_text()) | ||
and 'VAULT_SECRET_ID_FOR_DYNACONF' not in os.environ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this wouldn't handle the case where this variables are already set in dotenv?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handles with the condition re.search(r'\s*#.*VAULT_SECRET_ID_FOR_DYNACONF', envpath.read_text())
, this variable wouldnt be set by Users because this is APPRole credentials.
The make vault-status
is the main entity to find the current status of vault session and does not matters whats set in DotEnv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gauravtalreja1 The condition is now changed to just verify if VAULT_SECRET_ID_FOR_DYNACONF
environment var is set as thats the feasible check as per our CI, Local execution and PR checks!
pytest_plugins/auto_vault.py
Outdated
vstatus = subprocess.run("make vault-status", shell=True, capture_output=True).returncode | ||
if vstatus != 0: | ||
print('Vault token is expired, Logging you in ...') | ||
subprocess.run('make vault-login', shell=True, stdout=subprocess.PIPE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, when vault-login script opens up a browser to authenticate, then how this is going to handle it? and is it going to wait until its ready?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The auth window will open and until we dont authenticate it holds, and finally after authentication it continues !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you stay inside Python?
Stack Python -> shell -> make -> Python is a really ugly way to achieve what you want.
7c27fe5
to
e2db134
Compare
@ogajduse I Agree that it's an ugly way to achieve it but then functions in scripts are not made to be importable outside scripts. Hence same applies to We are wrapping on If we dont want to go this way, we had to externalize the vault function in utils and then use them in both scripting and this plugin. |
pytest_plugins/auto_vault.py
Outdated
if ( | ||
re.search(r'\s*#.*VAULT_SECRET_ID_FOR_DYNACONF', envpath.read_text()) | ||
and 'VAULT_SECRET_ID_FOR_DYNACONF' not in os.environ | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain why did you construct the condition in this way and how it is supposed to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checks if the pytest session is runing locally not in CI. In CI, the value VAULT_SECRET_ID_FOR_DYNACONF
is set in env var and hence it does not need to login via OIDC, it logs in using AppRole credentials.
It is less likely the value is directly set in .env
file from CI , but could be possible when one have app role creds and executes from local system. When this value is set , we should not run OIDC for vault login.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who requested this feature? I would like to see real people asking for this feature if we plan to merge it into our codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no such ask but this is an enhancement in user experience. Also helps new bees / outside collaborators like DEVs to quickly execute the tests and no need to learn and worry about vault login first!
Something to consider, if we're wanting to run this in every pytest session, is to bring the script logic into robottelo itself. This way we make the functionality here first-class and not offloaded to a script. Alternatively, if we want to be less hand-holdy, we could log a warning/error informing the user that they need to run the vault-login make command. |
1e92eb9
to
f328479
Compare
Output that I got from
Successfully loaded the settings object:
And from
I must say that I liked the current version more as this new version spits out too much text that the users do not really need to see when they are "just logging in". |
2051a3e
to
cc0ac14
Compare
trigger: test-robottelo |
@ogajduse Thanks for verifying it locally on your system. Helps great!! Though it looks good, I would like to :
|
@jyejare is this ready or should it be in draft? |
@JacobCallahan I think I can quickly fix the destructor exception in this PR and hiding logs for broker could be done in a separate follow up PR. I haven't identified at how do I hide the broker logs yet , and even that should not block us from using this utility ! Rest of the testing looks good already including PRT, local testing, Make testing by @ogajduse etc. Also the failed tests are not related to this PR ! |
@jyejare one simple option to try is copying the current environment variables, settings broker's log level to info/warn and passing that to subprocess.run via the env argument |
@JacobCallahan As per our last discussion we should be good to merge this now ? |
65f1cc6
to
e3d7f13
Compare
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
Pytest verifies and log-in into vault (#12378) * Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
This broke local robottelo runs for me. I don't have vault config file and it shouldn't be required, as per docs:
But when I run pytest, I get:
|
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
* Pytest verifies and logs in into vault * New vault lib utils for both * PR checks without vault login
Pytest session now verifies the vault session first.
Pytest STDOUT: