Skip to content
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

example testing on env script #1440

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

example testing on env script #1440

wants to merge 1 commit into from

Conversation

LeiGlobus
Copy link
Contributor

@LeiGlobus LeiGlobus commented Jan 23, 2024

An example script to test on any environment. More details on # dev

See show_help() for example usage, but something like:

python3 run_env.py sand

With results like below:

 (test_env_local) $ p3 run_env.py sand
Testing on GLOBUS_SDK_ENVIRONMENT: (sandbox)
Registering echo function...successfully with FN_UUID: 790c0c73-95cf-408c-9d85-f0e90d36dd49
Submitting task via Client...successfully with TASK_UUID: fbc41535-8621-4189-93fb-93ef8a686e53, waiting 8s...
Client run result nominal: Hello Compute user, your argument is 0.9167879134019866
Submitting task via Executor...result nominal: Hello Compute user, your argument is 0.9167879134019866
Test finished successfully on (sandbox)!

Note that a 3-5 second delay before getting results vi Client() is fine for all environments except Staging, which needed 8 sometimes, thus the delay is currently set to 8.

@LeiGlobus LeiGlobus added Documentation Doc improvements/fixes no-news-is-good-news This change does not require a news file quick-review Review of this should be quick and easy labels Jan 23, 2024
Copy link
Contributor

@chris-janidlo chris-janidlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking through old PRs to see what we can clean up, and this looks good - just have one small suggestion.

also, would we expect to have any more env_testing related files in this directory? I wouldn't really expect any more, so maybe putting this in a directory called scripts or similar would be more appropriate

Comment on lines +36 to +52
ENV_UNIQUE = {
"preview": "pre",
"production": "pro",
"sandbox": "sa",
"test": "t",
"staging": "st",
"integration": "i",
}


def get_env(arg: str) -> str | None:
if arg:
arg = arg.lower()
for k, v in ENV_UNIQUE.items():
if arg.startswith(v) and k.startswith(arg):
return k
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, stealing it for my own scripts 👿

Comment on lines +56 to +79
fn_id = None
if len(sys.argv) < 2 or len(sys.argv) > 3:
show_help()
elif len(sys.argv) == 3:
try:
fn_id = UUID(sys.argv[2])
except Exception:
show_help(f"Invalid function UUID: {sys.argv[2]}")

env_id = get_env(sys.argv[1])
if env_id is None:
show_help(f"Invalid/non-unique environment: {env_id}")

os.environ["GLOBUS_SDK_ENVIRONMENT"] = env_id
print(f"Testing on GLOBUS_SDK_ENVIRONMENT: ({env_id})")
try:
gcc = Client(environment=env_id)
except AuthAPIError as e:
print(
"Encountered AuthAPIError, you probably need to delete/refresh"
" your token for this environment (delete storage.db is quickest)"
)
print(e)
sys.exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest using argparse here instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Doc improvements/fixes no-news-is-good-news This change does not require a news file quick-review Review of this should be quick and easy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants