-
Notifications
You must be signed in to change notification settings - Fork 47
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
LeiGlobus
wants to merge
1
commit into
main
Choose a base branch
from
test_env_local
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import sys | ||
import time | ||
from random import random | ||
from uuid import UUID | ||
|
||
from globus_compute_sdk import Client, Executor | ||
from globus_sdk.services.auth.errors import AuthAPIError | ||
|
||
TUTORIAL_EP_UUID = "4b116d3c-1703-4f8f-9f6f-39921e5864df" | ||
WAIT_CLIENT_SEC = 8 | ||
|
||
|
||
def show_help(err_msg: str = None): | ||
if err_msg: | ||
print(err_msg) | ||
print( | ||
"Usage:\n python3 run_env.py " | ||
+ "(prod|staging|preview|sandbox|test|integration) [optional_func_uuid]\n" | ||
+ "The environment keyword can be abbreviated as long as the first " | ||
"chars uniquely identify it. ie. pro for production, sa for sandbox.\n\n" | ||
"If you specify an optional function UUID, that will be used. Otherwise " | ||
"a new function that takes one argument and echos it as output is " | ||
"registered and used to test.\n\n" | ||
"Note providing existing FN_UUID yields KeyError TBD Fix" | ||
) | ||
sys.exit(1) | ||
|
||
|
||
def echo_arg_tutorial_ep_testing(s): | ||
return f"Hello Compute user, your argument is {s}" | ||
|
||
|
||
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 | ||
|
||
|
||
if __name__ == "__main__": | ||
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) | ||
Comment on lines
+56
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggest using |
||
|
||
if fn_id is None: | ||
print("Registering echo function...", end="") | ||
fn_id = gcc.register_function(echo_arg_tutorial_ep_testing) | ||
print(f"successfully with FN_UUID: {fn_id}") | ||
else: | ||
print(f"Using provided FN_UUID {fn_id}") | ||
|
||
echo_arg = str(random()) | ||
print("Submitting task via Client...", end="") | ||
try: | ||
task_id = gcc.run(echo_arg, endpoint_id=TUTORIAL_EP_UUID, function_id=fn_id) | ||
except KeyError: | ||
print("TBD investigate KeyError") | ||
raise | ||
print(f"successfully with TASK_UUID: {task_id}, waiting {WAIT_CLIENT_SEC}s...") | ||
time.sleep(WAIT_CLIENT_SEC) | ||
result = gcc.get_result(task_id) | ||
if echo_arg in result: | ||
print(f"Client run result nominal: {result}") | ||
else: | ||
print(f"ERROR: Client run result was invalid: {result} ") | ||
sys.exit(1) | ||
|
||
print("Submitting task via Executor...", end="") | ||
with Executor(client=gcc, endpoint_id=TUTORIAL_EP_UUID) as gce: | ||
fut = gce.submit_to_registered_function(fn_id, args=(echo_arg,)) | ||
result = fut.result() | ||
if echo_arg in result: | ||
print(f"result nominal: {result}") | ||
else: | ||
print(f"ERROR: submit result was invalid: {result} ") | ||
sys.exit(1) | ||
|
||
print(f"Test finished successfully on ({env_id})!") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 like this, stealing it for my own scripts 👿