diff --git a/examples/compound_job_simulator/simulator.py b/examples/compound_job_simulator/simulator.py index 59ac4df..1cafc88 100755 --- a/examples/compound_job_simulator/simulator.py +++ b/examples/compound_job_simulator/simulator.py @@ -23,7 +23,9 @@ simulation = wrench.Simulation() # Starting the simulation, with this simulated process running on the host ControllerHost - simulation.start(platform_file_path, "ControllerHost") + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() + simulation.start(xml_string, "ControllerHost") hosts = simulation.get_all_hostnames() print(f"Hosts in the platform are: {hosts}") @@ -142,12 +144,12 @@ print("Synchronously waiting for the next simulation event...") event = simulation.wait_for_next_event() - print(f" - Event: {event}") + print(f"\t- Event: {event}") print(f"Time is {simulation.get_simulated_time()}") print("Synchronously waiting for the next simulation event...") event = simulation.wait_for_next_event() - print(f" - Event: {event}") + print(f"\t- Event: {event}") print(f"Time is {simulation.get_simulated_time()}") # print("Synchronously waiting for the next simulation event...") diff --git a/examples/json_workflow_simulator/simulator.py b/examples/json_workflow_simulator/simulator.py index 61dbfa9..4f32761 100755 --- a/examples/json_workflow_simulator/simulator.py +++ b/examples/json_workflow_simulator/simulator.py @@ -116,13 +116,15 @@ def main(): print(f"Starting the simulation using the XML platform file...") current_dir = pathlib.Path(__file__).parent.resolve() platform_file_path = pathlib.Path(current_dir / "one_host_and_several_clusters.xml") - simulation.start(platform_file_path, user_host) + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() + simulation.start(xml_string, user_host) # Get the list of all hostnames in the platform print(f"Getting the list of all hostnames...") list_of_hostnames = simulation.get_all_hostnames() - if not "UserHost" in list_of_hostnames: + if "UserHost" not in list_of_hostnames: raise Exception("This simulator assumes that the XML platform files has a host with hostname UserHost that" " has a disk mounted at '/'") list_of_hostnames.remove("UserHost") @@ -183,7 +185,7 @@ def main(): # Wait for next event event = simulation.wait_for_next_event() if event["event_type"] != "standard_job_completion": - print(f" - Event: {event}") # Should make sure it's a job completion + print(f"\t- Event: {event}") # Should make sure it's a job completion raise wrench.WRENCHException("Received an unexpected event") else: completed_job = event["standard_job"] diff --git a/examples/simple_simulator/simulator.py b/examples/simple_simulator/simulator.py index f3bf6cb..9fd7748 100755 --- a/examples/simple_simulator/simulator.py +++ b/examples/simple_simulator/simulator.py @@ -22,7 +22,9 @@ simulation = wrench.Simulation() # Starting the simulation, with this simulated process running on the host ControllerHost - simulation.start(platform_file_path, "ControllerHost") + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() + simulation.start(xml_string, "ControllerHost") print(f"Simulation, time is {simulation.get_simulated_time()}") @@ -121,7 +123,7 @@ print("Getting simulation events that have occurred while I slept...") events = simulation.get_events() for event in events: - print(f" - Event: {event}") + print(f"\t- Event: {event}") print("Creating another task") task2 = workflow.add_task("task2", 100.0, 1, 1, 0) @@ -131,7 +133,7 @@ print("Creating a VM on the cloud compute service...") my_vm = ccs.create_vm(1, 100, - {"CloudComputeServiceProperty::VM_BOOT_OVERHEAD": "5s"},{}) + {"CloudComputeServiceProperty::VM_BOOT_OVERHEAD": "5s"}, {}) print("Starting the VM...") vm_cs = my_vm.start() @@ -141,7 +143,7 @@ print("Synchronously waiting for the next simulation event...") event = simulation.wait_for_next_event() - print(f" - Event: {event}") + print(f"\t- Event: {event}") print(f"Time is {simulation.get_simulated_time()}") @@ -158,7 +160,6 @@ # if (my_sleep_action_1.get_state_as_string() == "RUNNING"): # print("Action is still running!") - print("Terminating simulation") simulation.terminate() diff --git a/tests/bare_metal_compute_service_test.py b/tests/bare_metal_compute_service_test.py index dfb36ae..0fd49ec 100755 --- a/tests/bare_metal_compute_service_test.py +++ b/tests/bare_metal_compute_service_test.py @@ -21,8 +21,10 @@ simulation = wrench.Simulation() + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() try: - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") except wrench.WRENCHException as e: sys.stderr.write(f"Error: {e}\n") exit(1) diff --git a/tests/batch_compute_service_test.py b/tests/batch_compute_service_test.py index de15cd1..297db53 100755 --- a/tests/batch_compute_service_test.py +++ b/tests/batch_compute_service_test.py @@ -20,8 +20,10 @@ platform_file_path = pathlib.Path(current_dir / "sample_platform.xml") simulation = wrench.Simulation() + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() try: - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") except wrench.WRENCHException as e: sys.stderr.write(f"Error: {e}\n") exit(1) diff --git a/tests/cloud_compute_service_test.py b/tests/cloud_compute_service_test.py index 4ee36f5..49cd1c8 100755 --- a/tests/cloud_compute_service_test.py +++ b/tests/cloud_compute_service_test.py @@ -19,8 +19,10 @@ platform_file_path = pathlib.Path(current_dir / "sample_platform.xml") simulation = wrench.Simulation() + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() try: - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") except wrench.WRENCHException as e: sys.stderr.write(f"Error: {e}\n") exit(1) diff --git a/tests/compound_job_test.py b/tests/compound_job_test.py index 4e4ddf1..3f40a6f 100755 --- a/tests/compound_job_test.py +++ b/tests/compound_job_test.py @@ -23,7 +23,9 @@ simulation = wrench.Simulation() # Starting the simulation, with this simulated process running on the host ControllerHost - simulation.start(platform_file_path, "ControllerHost") + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() + simulation.start(xml_string, "ControllerHost") # Creating a compute services bmcs = simulation.create_bare_metal_compute_service( diff --git a/tests/file_registry_service_test.py b/tests/file_registry_service_test.py index 4b3a0d1..d617300 100755 --- a/tests/file_registry_service_test.py +++ b/tests/file_registry_service_test.py @@ -21,8 +21,10 @@ simulation = wrench.Simulation() + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() try: - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") except wrench.WRENCHException as e: sys.stderr.write(f"Error: {e}\n") exit(1) diff --git a/tests/simulation_events_test.py_DISABLED b/tests/simulation_events_test.py_DISABLED index eb316f8..97bf08d 100755 --- a/tests/simulation_events_test.py_DISABLED +++ b/tests/simulation_events_test.py_DISABLED @@ -19,9 +19,11 @@ if __name__ == "__main__": platform_file_path = pathlib.Path(current_dir / "sample_platform.xml") simulation = wrench.Simulation() + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() try: - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") except wrench.WRENCHException as e: sys.stderr.write(f"Error: {e}\n") exit(1) diff --git a/tests/storage_service_test.py b/tests/storage_service_test.py index 5fc7fa4..c670724 100755 --- a/tests/storage_service_test.py +++ b/tests/storage_service_test.py @@ -22,7 +22,9 @@ simulation = wrench.Simulation() - simulation.start(platform_file_path, "ControllerHost") + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() + simulation.start(xml_string, "ControllerHost") ss = simulation.create_simple_storage_service("StorageHost", ["/"]) # Coverage diff --git a/tests/workflow_job_task_test.py b/tests/workflow_job_task_test.py index 5153e08..e336b39 100755 --- a/tests/workflow_job_task_test.py +++ b/tests/workflow_job_task_test.py @@ -19,8 +19,10 @@ platform_file_path = pathlib.Path(current_dir / "sample_platform.xml") simulation = wrench.Simulation() + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() try: - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") except wrench.WRENCHException as e: sys.stderr.write(f"Error: {e}\n") exit(1) diff --git a/tests/workflow_test.py b/tests/workflow_test.py index d2fe8b3..78a7e8d 100755 --- a/tests/workflow_test.py +++ b/tests/workflow_test.py @@ -22,23 +22,27 @@ simulation = wrench.Simulation() + with open(platform_file_path, "r") as platform_file: + bogus_xml_string = platform_file.read() + "BOGUS" try: simulation_bogus = wrench.Simulation() - simulation_bogus.start(pathlib.Path("bogus/path/to/file"), "ControllerHost") - raise wrench.WRENCHException("Should be able to start a simulation with a bogus xml file") + simulation_bogus.start(bogus_xml_string, "ControllerHost") + raise wrench.WRENCHException("Should be able to start a simulation with a bogus xml") except wrench.WRENCHException as e: pass + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() try: simulation_bogus = wrench.Simulation() - simulation_bogus.start(platform_file_path, "ControllerHost_BOGUS") + simulation_bogus.start(xml_string, "ControllerHost_BOGUS") raise wrench.WRENCHException("Should be able to start a simulation with a bogus xml file") except wrench.WRENCHException as e: pass - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") # Bogus restart that does nothing - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") workflow1 = simulation.create_workflow() file1 = simulation.add_file("file1", 1024) @@ -97,8 +101,10 @@ simulation.terminate() + with open(platform_file_path, "r") as platform_file: + xml_string = platform_file.read() try: - simulation.start(platform_file_path, "ControllerHost") + simulation.start(xml_string, "ControllerHost") raise wrench.WRENCHException("Shouldn't be able to restart a simulation") except wrench.WRENCHException as e: pass diff --git a/wrench/compound_job.py b/wrench/compound_job.py index 9b68c71..f7d1566 100644 --- a/wrench/compound_job.py +++ b/wrench/compound_job.py @@ -119,7 +119,7 @@ def add_file_write_action(self, name: str, file: File, storage_service: StorageS return self._simulation._add_file_write_action(self, name, file, storage_service) def add_file_read_action(self, name: str, file: File, storage_service: StorageService, - num_bytes_to_read=-1.0) -> FileReadAction: + num_bytes_to_read=0.0) -> FileReadAction: """ Add a file write action to the compound job diff --git a/wrench/simulation.py b/wrench/simulation.py index 1bb9d02..3183278 100644 --- a/wrench/simulation.py +++ b/wrench/simulation.py @@ -84,19 +84,19 @@ def __send_request_to_daemon(requests_method, route, json_data): r = requests_method(route, json=json_data) return r except Exception as e: # pragma no cover - raise WRENCHException("Connection to wrench-daemon severed: " + str(e) + "\n" - "This could be an error on the " - "wrench-daemon side (likely an uncaught maestro exception, e.g., a deadlock). Enable " - "logging with the --simulation-logging and --daemon-logging " - "command-line arguments") + raise WRENCHException("Connection to wrench-daemon severed: " + + str(e) + "\n" + "This could be an error on the " + "wrench-daemon side (likely an uncaught maestro exception, e.g., a deadlock). Enable " + "logging with the --simulation-logging and --daemon-logging " + "command-line arguments") - def start(self, platform_file_path: pathlib.Path, - controller_hostname: str) -> None: + def start(self, platform_xml: str, controller_hostname: str) -> None: """ Start a new simulation (will do nothing if simulation has already started) - :param platform_file_path: path of a file that contains the simulated platform's description in XML - :type platform_file_path: pathlib.Path + :param platform_xml: platform description string in XML + :type platform_xml: str :param controller_hostname: the name of the (simulated) host in the platform on which the simulation controller will run :type controller_hostname: str @@ -108,14 +108,7 @@ def start(self, platform_file_path: pathlib.Path, raise WRENCHException("This simulation has been terminated.") if not self.started: - # Read the platform XML - try: - with open(platform_file_path, "r") as platform_file: - xml = platform_file.read() - except Exception as e: - raise WRENCHException(f"Cannot read platform file '{platform_file_path.absolute().name}' ({str(e)})") - - self.spec = {"platform_xml": xml, "controller_hostname": controller_hostname} + self.spec = {"platform_xml": platform_xml, "controller_hostname": controller_hostname} try: r = requests.post(f"{self.daemon_url}/startSimulation", json=self.spec) except Exception: # pragma: no cover @@ -1627,8 +1620,7 @@ def _add_entry_to_file_registry_service(self, file_registry_service: FileRegistr raise WRENCHException(response["failure_cause"]) return - def _lookup_entry_in_file_registry_service(self, file_registry_service: FileRegistryService, file: File) -> List[ - StorageService]: + def _lookup_entry_in_file_registry_service(self, file_registry_service: FileRegistryService, file: File) -> List[StorageService]: """ Blah :param file_registry_service: diff --git a/wrench/workflow.py b/wrench/workflow.py index 0694dba..bb4c62e 100644 --- a/wrench/workflow.py +++ b/wrench/workflow.py @@ -19,6 +19,7 @@ from typing import List + # noinspection GrazieInspection class Workflow(SimulationItem): """