Commit 2816c415 authored by Brown, Joshua's avatar Brown, Joshua
Browse files

Remove extraneous print statements

parent 3076d005
Pipeline #267100 canceled with stage
......@@ -112,9 +112,7 @@ def test_git_checkCommitFailure2():
"path": current_dir + "/" + file_name,
"type": "posix absolute",
},
"destination": {
"path": file_name,
},
"destination": {"path": file_name},
"commit_message": "Adding a file",
"credentials": {
"user_name": "zambeze84",
......@@ -253,9 +251,7 @@ def test_git_processCommitAndDownload():
"type": "posix absolute",
},
"source": {"path": file_name, "type": "GitHub repository root"},
"credentials": {
"access_token": access_token,
},
"credentials": {"access_token": access_token},
}
}
]
......
......@@ -98,9 +98,10 @@ def test_checkAllItemsHaveValidEndpoints():
supported_source_path_types = ["posix absolute", "posix user home"]
supported_destination_path_types = ["globus relative"]
assert globus.checkAllItemsHaveValidEndpoints(
output = globus.checkAllItemsHaveValidEndpoints(
items, supported_source_path_types, supported_destination_path_types
)
assert output[0]
items2 = [
{
......@@ -111,9 +112,10 @@ def test_checkAllItemsHaveValidEndpoints():
# This should be false because in this case "globus relative" is not in the
# supported_source_path_types
assert not globus.checkAllItemsHaveValidEndpoints(
output = globus.checkAllItemsHaveValidEndpoints(
items2, supported_source_path_types, supported_destination_path_types
)
assert not output[0]
items3 = [
{
......@@ -124,9 +126,10 @@ def test_checkAllItemsHaveValidEndpoints():
# This should be false because in this case "destination" is missing a
# "path"
assert not globus.checkAllItemsHaveValidEndpoints(
output = globus.checkAllItemsHaveValidEndpoints(
items3, supported_source_path_types, supported_destination_path_types
)
assert not output[0]
@pytest.mark.globus
......@@ -376,7 +379,11 @@ def test_globus_transfer_check():
}
},
]
assert globus_plugin.check(package)
output = globus_plugin.check(package)
for item in output:
assert output[item][0]
@pytest.mark.globus
......@@ -500,7 +507,15 @@ def test_globus_process():
if os.path.exists(abs_path_destination_shared):
os.remove(abs_path_destination_shared)
if globus_plugin.check(package):
checked_items = globus_plugin.check(package)
all_checks_pass = True
for item in checked_items:
if not checked_items[item][0]:
print("Something went wrong.")
print(checked_items[item][1])
all_checks_pass = False
if all_checks_pass:
globus_plugin.process(package)
# After processing we should verify that the file exists at the final location
......@@ -559,22 +574,16 @@ def test_globus_process_from_esnet():
{
"transfer": {
"source_collection_UUID": ESNET_GLOBUS_ENDPOINT_UUID,
"destination_collection_UUID": os.getenv(required_env_variables[3]),
"destination_collection_UUID": os.getenv(required_env_variables[2]),
"type": "synchronous",
"items": [
{
"source": {
"type": "globus relative",
"path": "/1M.dat",
},
"destination": {
"type": "globus relative",
"path": "/1M.dat",
},
"source": {"type": "globus relative", "path": "/1M.dat"},
"destination": {"type": "globus relative", "path": "/1M.dat"},
}
],
}
},
}
]
# This test is designed to move a file to the globus endpoint
......@@ -585,8 +594,12 @@ def test_globus_process_from_esnet():
if os.path.exists(abs_path_destination):
os.remove(abs_path_destination)
if globus_plugin.check(package):
output = globus_plugin.check(package)
if output["transfer"][0]:
globus_plugin.process(package)
else:
print("Check failed no transfer was conducted.")
print(output["transfer"][1])
# After processing we should verify that the file exists at the final location
assert os.path.exists(abs_path_destination)
......@@ -80,7 +80,7 @@ class Plugin(ABC):
:type arguments: list[dict]
:return: Returns the list of actions that are vaid
:rtype: dict with the actions valid actions listed with bool set to
True and invalid ones False
True and invalid ones False, along with a message.
:Example:
......@@ -93,8 +93,8 @@ class Plugin(ABC):
>>> for action in checked_actions:
>>> print(f"{action}: {checked_actions[action]}")
>>> # Should print
>>> # action1 True
>>> # action2 False
>>> # action1 True, ""
>>> # action2 False, "This was the problem"
"""
@abstractmethod
......
......@@ -96,7 +96,7 @@ def getGlobusScopes(mapped_collections: list[str]) -> str:
return scopes
def checkEndpoint(item: dict, supported_types: list[str]) -> bool:
def checkEndpoint(item: dict, supported_types: list[str]) -> (bool, str):
"""Check that the approprite keys and values exist in the endpoint
:param item: these are the values that help define either the source or
......@@ -120,26 +120,30 @@ def checkEndpoint(item: dict, supported_types: list[str]) -> bool:
>>> "type": "globus relative",
>>> "path": "/file1.txt"
>>> }
>>> assert checkEndpoint(item)
>>> valid, msg = checkEndpoint(item)
>>> assert valid
"""
if "type" not in item:
return False
return False, "Missing type"
else:
# Only "globus relative" path type supported
if item["type"].lower() not in supported_types:
return False
return (
False,
f"Missing {item['type'].lower()} not in supported types {supported_types}",
)
if "path" not in item:
return False
return False, "Missing path"
return True
return True, ""
def checkAllItemsHaveValidEndpoints(
items: list[dict],
supported_source_path_types: list[str],
supported_destination_path_types: list[str],
) -> bool:
) -> (bool, str):
"""Check that all items that are too be moved are schematically correct
:return: Returns true if the schema of the items is valid and false otherwise
......@@ -180,20 +184,25 @@ def checkAllItemsHaveValidEndpoints(
"""
for item in items:
if "source" not in item:
return False
return False, "Missing source key"
if "destination" not in item:
return False
return False, "Missing destination key"
if not checkEndpoint(item["source"], supported_source_path_types):
return False
if not checkEndpoint(item["destination"], supported_destination_path_types):
return False
valid, msg = checkEndpoint(item["source"], supported_source_path_types)
if not valid:
return False, "Invalid source\n" + msg
valid, msg = checkEndpoint(
item["destination"], supported_destination_path_types
)
if not valid:
return False, "Invalid destination\n" + msg
if item["source"]["type"].lower() == "posix absolute":
if not exists(item["source"]["path"]):
return False
return False, f"Item does not exist {item['source']['path']}"
return True
return True, ""
class Globus(Plugin):
......@@ -319,8 +328,6 @@ class Globus(Plugin):
def __clientCredentialAuthFlow(self, config: dict):
# https://globus-sdk-python.readthedocs.io/en/stable/examples/client_credentials.html
print("Config is")
print(f"client id is {self.__client_id}")
if config["authentication_flow"]["secret"] is None:
raise Exception(
......@@ -330,12 +337,10 @@ class Globus(Plugin):
f"{config}"
)
print(json.dumps(config, indent=4))
confidential_client = globus_sdk.ConfidentialAppAuthClient(
client_id=self.__client_id,
client_secret=config["authentication_flow"]["secret"],
)
print(f"client secret: {config['authentication_flow']['secret']}")
self.__authorizer = globus_sdk.ClientCredentialsAuthorizer(
confidential_client, self.__scopes
)
......@@ -387,7 +392,6 @@ class Globus(Plugin):
tdata.add_item(clean_source_path, clean_destination_path)
transfer_result = self.__tc.submit_transfer(tdata)
if "synchronous" == transfer["type"].lower():
task_id = transfer_result["task_id"]
while not self.__tc.task_wait(task_id, timeout=60):
......@@ -447,8 +451,6 @@ class Globus(Plugin):
if isfile(source):
destination = destination + "/" + basename(source)
print(f"Source is: {source}")
print(f"Destination is: {destination}")
shutil.copyfile(source, destination)
def __runTransferSanityCheck(self, action_package: dict) -> (bool, str):
......@@ -469,23 +471,17 @@ class Globus(Plugin):
if "source" not in item:
return False, "'source' missing from 'items' in 'transfer'"
else:
if not checkEndpoint(item["source"], ["globus relative"]):
return (
False,
"'source' in ['transfer']['items'] must \
have a value of 'globus relative'",
)
valid, msg = checkEndpoint(item["source"], ["globus relative"])
if not valid:
return (False, f"Error in source\n" + msg)
if "destination" not in item:
return False, "'destination' missing from 'items' in 'transfer'"
else:
if not checkEndpoint(item["destination"], ["globus relative"]):
return (
False,
"'destination' in ['transfer']['items'] must \
have a value of 'globus relative'",
)
return True
valid, msg = checkEndpoint(item["destination"], ["globus relative"])
if not valid:
return (False, f"Error in destination\n" + msg)
return True, ""
def __runMoveToGlobusSanityCheck(self, action_package: dict) -> (bool, str):
supported_source_path_types = ["posix absolute", "posix user home"]
......@@ -511,13 +507,10 @@ class Globus(Plugin):
{action_package['source_host_name']} in 'move_to_globus_collection'",
)
return (
checkAllItemsHaveValidEndpoints(
action_package["items"],
supported_source_path_types,
supported_destination_path_types,
),
"",
return checkAllItemsHaveValidEndpoints(
action_package["items"],
supported_source_path_types,
supported_destination_path_types,
)
def __runMoveFromGlobusSanityCheck(self, action_package: dict) -> (bool, str):
......@@ -589,7 +582,7 @@ class Globus(Plugin):
)
def __checkAccessToGlobusCloud(self):
"""Will chech if we can reach the internet and caches access to globus
"""Will check if we can reach the internet and caches access to globus
cloud if cannot reach it.
"""
if externalNetworkConnectionDetected() is False:
......@@ -758,7 +751,7 @@ class Globus(Plugin):
checks[action] = (False, "action is not supported.")
continue
if action == "transfers":
if action == "transfer":
# Any agent with the globus plugin can submit a job to globus if it
# has access to the globus cloud
checks[action] = self.__runTransferSanityCheck(
......@@ -774,6 +767,8 @@ class Globus(Plugin):
checks[action] = self.__runMoveFromGlobusSanityCheck(
package[index][action]
)
else:
checks[action] = (False, "Unrecognized action keyworkd")
return checks
def process(self, arguments: list[dict]) -> dict:
......@@ -881,14 +876,10 @@ class Globus(Plugin):
if not self.__configured:
raise Exception("Cannot run globus plugin, must first be configured.")
print("Running Globus plugin")
for action_obj in arguments:
# Make sure that the action is supported
for key in action_obj:
print(key)
if key not in self.__supported_actions:
raise Exception(f"{key} is not supported.")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment