Skip to content

Commit

Permalink
Added test cases for gcc_workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandloria committed Apr 15, 2022
1 parent 37f869e commit 537a6f1
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gcc_exec/gcc_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def set_config_commands(self) -> None:
"exit",
]

def configure(self) -> None:
def configure_virtual_machine(self) -> None:
"""Execute configuration commands on a virtual machine."""
keyfile = StringIO(self.__node_virtual_machine["pem"])
mykey = paramiko.RSAKey.from_private_key(keyfile)
Expand Down
38 changes: 25 additions & 13 deletions gcc_exec/gcc_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

import xmltodict
from botocore.exceptions import ClientError
from gcc_drbx import GccDrbx
from gcc_ec2 import GccEc2
from gcc_node import GccNode
from gcc_user import GccUser

from gcc_exec.gcc_drbx import GccDrbx
from gcc_exec.gcc_ec2 import GccEc2
from gcc_exec.gcc_node import GccNode
from gcc_exec.gcc_user import GccUser


class GccWorkflow:
Expand Down Expand Up @@ -46,16 +47,16 @@ def __init__(self, gcc_user_obj: GccUser, workflow_name: str) -> None:
"machines_initialized": None,
}

def plan(
self, available_machines: list, xml_specification: str = None
) -> list:
def plan(self, available_machines: list, xml_specification: str = None) -> list:
"""This method creates an execution plan based on a workflow specification."""
if xml_specification is None:
xml_specification = xmltodict.parse(
self.__gcc_drbx_obj.get_file_contents(
f"/{self.__workflow_dict['name']}/spec.xml"
)
)
elif isinstance(xml_specification, str):
xml_specification = xmltodict.parse(xml_specification)

self.__workflow_dict["type"] = int(xml_specification["workflow"]["@type"])

Expand All @@ -71,14 +72,15 @@ def plan(
node_virtual_machine = None

if gcc_node_vm is not None:
vm_ip = gcc_node_vm["#text"]

try:
if isinstance(gcc_node_vm, str):
vm_pem = None
vm_ip = gcc_node_vm
elif isinstance(gcc_node_vm, OrderedDict):
vm_pem = self.__gcc_drbx_obj.get_file_contents(
f"/{self.__workflow_dict['name']}/pem/{gcc_node_vm['@pem']}"
).strip("\n")
except KeyError:
vm_pem = None

vm_ip = gcc_node_vm["#text"]

node_virtual_machine = {"ip": vm_ip, "pem": vm_pem, "instance_id": None}

Expand Down Expand Up @@ -352,7 +354,9 @@ def configure(self) -> None:
max_workers=len(self.__workflow_dict["nodes"])
) as executor:
for node in self.__workflow_dict["nodes"]:
executor.submit(self.__workflow_dict["nodes"][node].configure)
executor.submit(
self.__workflow_dict["nodes"][node].configure_virtual_machine
)
executor.shutdown()

def initialize(self) -> None:
Expand Down Expand Up @@ -447,6 +451,14 @@ def get_tmp_dir(self) -> str:
"""Return tmp directory string."""
return self.__tmp_dir

def set_gcc_security_group(self, gcc_security_group: dict) -> None:
"""Set gcc_security_group private variable."""
self.__gcc_security_group = gcc_security_group

def set_gcc_key_pair(self, gcc_key_pair: dict) -> None:
"""Set gcc_key_pair private variable."""
self.__gcc_key_pair = gcc_key_pair


def generate_random_string() -> str:
"""Generate a random 7 character string."""
Expand Down
2 changes: 1 addition & 1 deletion gcc_exec/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def main(
aws_access_key_id: str,
aws_secret_access_key: str,
workflow_name: str,
):
) -> None:
"""This method contains code to execute a wofkflow."""
gcc_user_obj = GccUser(
oauth2_refresh_token, aws_access_key_id, aws_secret_access_key
Expand Down
14 changes: 14 additions & 0 deletions gcc_exec/tests/data/spec/spec_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<workflow type="0">
<task id="n1"></task>
<task id="n2">
<dep node="n1">x</dep>
</task>
<task id="n3">
<dep node="n1">x</dep>
</task>
<task id="n4">
<dep node="n2">x</dep>
<dep node="n3">x</dep>
</task>
</workflow>
14 changes: 14 additions & 0 deletions gcc_exec/tests/data/spec/spec_2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<workflow type="1">
<task id="n1"></task>
<task id="n2">
<dep node="n1">x</dep>
</task>
<task id="n3">
<dep node="n1">x</dep>
</task>
<task id="n4">
<dep node="n2">x</dep>
<dep node="n3">x</dep>
</task>
</workflow>
19 changes: 19 additions & 0 deletions gcc_exec/tests/data/spec/spec_3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<workflow type="0">
<task id="n1">
<vm>0.0.0.0</vm>
</task>
<task id="n2">
<vm>0.0.0.0</vm>
<dep node="n1">x</dep>
</task>
<task id="n3">
<vm>0.0.0.0</vm>
<dep node="n1">x</dep>
</task>
<task id="n4">
<vm>0.0.0.0</vm>
<dep node="n2">x</dep>
<dep node="n3">x</dep>
</task>
</workflow>
19 changes: 19 additions & 0 deletions gcc_exec/tests/data/spec/spec_4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<workflow type="1">
<task id="n1">
<vm>0.0.0.0</vm>
</task>
<task id="n2">
<vm>0.0.0.0</vm>
<dep node="n1">x</dep>
</task>
<task id="n3">
<vm>0.0.0.0</vm>
<dep node="n1">x</dep>
</task>
<task id="n4">
<vm>0.0.0.0</vm>
<dep node="n2">x</dep>
<dep node="n3">x</dep>
</task>
</workflow>
Loading

0 comments on commit 537a6f1

Please sign in to comment.