Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
testing++
  • Loading branch information
henricasanova committed Sep 15, 2024
1 parent af55c5e commit b95462d
Show file tree
Hide file tree
Showing 26 changed files with 179 additions and 97 deletions.
4 changes: 0 additions & 4 deletions tests/bare_metal_compute_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
pass

ss = simulation.create_simple_storage_service("StorageHost", ["/"])
# Coverage
ss.get_name()
str(ss)
repr(ss)

workflow = simulation.create_workflow()
workflow.get_name()
Expand Down
20 changes: 20 additions & 0 deletions tests/cloud_compute_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@
raise wrench.WRENCHException("VM should be running")

task2 = workflow.add_task("task2", 10000000000.0, 1, 1, 0)

# Bogus job submission
try:
bogus_job = simulation.create_standard_job([task2], {})
ccs.submit_standard_job(bogus_job)
raise wrench.WRENCHException("Should not be able to submit a standard job to a cloud compute service")
except wrench.WRENCHException as e:
pass

# Bogus job submission
try:
bogus_cjob = simulation.create_compound_job("cjob")
bogus_cjob.add_sleep_action("", 10)
ccs.submit_compound_job(bogus_cjob)
raise wrench.WRENCHException("Should not be able to submit a compound job to a cloud compute service")
except wrench.WRENCHException as e:
print(e)
pass


job = simulation.create_standard_job([task2], {})
vm_cs.submit_standard_job(job)
event = simulation.wait_for_next_event()
Expand Down
2 changes: 1 addition & 1 deletion tests/sample_platform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<host id="StorageHost" speed="1f" core="1">
<disk id="hard_drive" read_bw="100MBps" write_bw="100MBps">
<prop id="size" value="5000GiB"/>
<prop id="size" value="5MB"/>
<prop id="mount" value="/"/>
</disk>
</host>
Expand Down
56 changes: 56 additions & 0 deletions tests/storage_service_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021 The WRENCH Team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

import pathlib
import json
import sys

import wrench

if __name__ == "__main__":

current_dir = pathlib.Path(__file__).parent.resolve()
platform_file_path = pathlib.Path(current_dir / "sample_platform.xml")
json_workflow_file_path = pathlib.Path(current_dir / "sample_wfcommons_workflow.json")

simulation = wrench.Simulation()

simulation.start(platform_file_path, "ControllerHost")

ss = simulation.create_simple_storage_service("StorageHost", ["/"])
# Coverage
ss.get_name()
str(ss)
repr(ss)

file1 = simulation.add_file("file1", 1024)
ss.create_file_copy(file1)

file2 = simulation.add_file("file2", 100000000)
try:
ss.create_file_copy(file2)
raise wrench.WRENCHException("Shouldn't be able to store big file on storage service")
except wrench.WRENCHException as e:
pass

ss.lookup_file(file1)
ss.lookup_file(file2)

try:
file2._name = "BOGUS" # Really horrible
ss.lookup_file(file2)
raise wrench.WRENCHException("Shouldn't be able to lookup bogus file")
except wrench.WRENCHException as e:
pass





14 changes: 14 additions & 0 deletions tests/workflow_simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@
task1.add_input_file(file1)
task1.add_output_file(file2)

bogus_file = simulation.add_file("bogus", 1)
bogus_file._name = "really_bogus"
try:
task1.add_input_file(bogus_file)
raise wrench.WRENCHException("Shouldn't be able to add bogus file as input to a task")
except wrench.WRENCHException as e:
pass

try:
task1.add_output_file(bogus_file)
raise wrench.WRENCHException("Shouldn't be able to add bogus file as input to a task")
except wrench.WRENCHException as e:
pass

if workflow1.is_done():
raise wrench.WRENCHException("The workflow should not be done")

Expand Down
10 changes: 5 additions & 5 deletions wrench/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_start_date(self) -> float:
:return: a date (or -1 if not started)
:rtype: float
"""
return self.simulation._action_get_start_date(self)
return self._simulation._action_get_start_date(self)

def get_end_date(self) -> float:
"""
Expand All @@ -83,7 +83,7 @@ def get_end_date(self) -> float:
:return: a date (or -1 if not ended)
:rtype: float
"""
return self.simulation._action_get_end_date(self)
return self._simulation._action_get_end_date(self)

def get_failure_cause(self) -> str:
"""
Expand All @@ -92,20 +92,20 @@ def get_failure_cause(self) -> str:
:return: a failure cause (or None if no failure has occurred)
:rtype: str
"""
return self.simulation._action_get_failure_cause(self)
return self._simulation._action_get_failure_cause(self)

def __str__(self) -> str: # pragma: no cover
"""
:return: String representation of the action
:rtype: str
"""
s = f"Action {self.name}"
s = f"Action {self._name}"
return s

def __repr__(self) -> str: # pragma: no cover
"""
:return: String representation of the action object
:rtype: str
"""
s = f"Action(name={self.name})"
s = f"Action(name={self._name})"
return s
2 changes: 0 additions & 2 deletions wrench/bare_metal_compute_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
from wrench.compound_job import CompoundJob
from wrench.compute_service import ComputeService
from wrench.standard_job import StandardJob


# noinspection GrazieInspection
Expand Down
4 changes: 2 additions & 2 deletions wrench/batch_compute_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def submit_standard_job(self, standard_job: StandardJob, service_specific_args:
:param service_specific_args: the service-specific arguments
:type service_specific_args: dict[str, str]
"""
return self.simulation._submit_standard_job(standard_job, self, json.dumps(service_specific_args))
return self._simulation._submit_standard_job(standard_job, self, json.dumps(service_specific_args))

def submit_compound_job(self, compound_job: CompoundJob, service_specific_args: dict[str, str]) -> None:
"""
Expand All @@ -51,4 +51,4 @@ def submit_compound_job(self, compound_job: CompoundJob, service_specific_args:
:param service_specific_args: the service-specific arguments
:type service_specific_args: dict[str, str]
"""
return self.simulation._submit_compound_job(compound_job, self, json.dumps(service_specific_args))
return self._simulation._submit_compound_job(compound_job, self, json.dumps(service_specific_args))
4 changes: 2 additions & 2 deletions wrench/cloud_compute_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def create_vm(self, num_cores: int, ram_memory: float, property_list: dict[str,
:return: a VirtualMachine object
:rtype: VirtualMachine
"""
return self.simulation._create_vm(self, num_cores, ram_memory, property_list, message_payload_list)
return self._simulation._create_vm(self, num_cores, ram_memory, property_list, message_payload_list)

def destroy_vm(self, vm: VirtualMachine) -> None:
"""
Expand All @@ -53,4 +53,4 @@ def destroy_vm(self, vm: VirtualMachine) -> None:
:param vm: A virtual machine
:type vm: VirtualMachine
"""
return self.simulation._destroy_vm(vm)
return self._simulation._destroy_vm(vm)
20 changes: 10 additions & 10 deletions wrench/compound_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def add_compute_action(self, name: str, flops: float, ram: float,
The CONSTANTEFFICIENCY model's parameter is simply the parallel efficiency. For instance, one could pass ("AMDAHL", 0.8).
:type parallel_model: tuple
"""
return self.simulation._add_compute_action(self, name, flops, ram, max_num_cores, min_num_cores, parallel_model)
return self._simulation._add_compute_action(self, name, flops, ram, max_num_cores, min_num_cores, parallel_model)

def add_file_copy_action(self, name: str, file: File, src_storage_service: StorageService,
dest_storage_service: StorageService) -> FileCopyAction:
Expand All @@ -90,7 +90,7 @@ def add_file_copy_action(self, name: str, file: File, src_storage_service: Stora
:param dest_storage_service: destination storage service being copied to
:type dest_storage_service: StorageService
"""
return self.simulation._add_file_copy_action(self, name, file, src_storage_service, dest_storage_service)
return self._simulation._add_file_copy_action(self, name, file, src_storage_service, dest_storage_service)

def add_file_delete_action(self, name: str, file: File, storage_service: StorageService) -> FileDeleteAction:
"""
Expand All @@ -103,7 +103,7 @@ def add_file_delete_action(self, name: str, file: File, storage_service: Storage
:param storage_service: storage service file is deleted from
:type storage_service: StorageService
"""
return self.simulation._add_file_delete_action(self, name, file, storage_service)
return self._simulation._add_file_delete_action(self, name, file, storage_service)

def add_file_write_action(self, name: str, file: File, storage_service: StorageService) -> FileWriteAction:
"""
Expand All @@ -116,7 +116,7 @@ def add_file_write_action(self, name: str, file: File, storage_service: StorageS
:param storage_service: storage service to write the file to
:type storage_service: StorageService
"""
return self.simulation._add_file_write_action(self, name, file, storage_service)
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:
Expand All @@ -132,7 +132,7 @@ def add_file_read_action(self, name: str, file: File, storage_service: StorageSe
:param num_bytes_to_read: number of bytes to read in file
:type num_bytes_to_read: float
"""
return self.simulation._add_file_read_action(self, name, file, storage_service, num_bytes_to_read)
return self._simulation._add_file_read_action(self, name, file, storage_service, num_bytes_to_read)

def add_sleep_action(self, name: str, sleep_time: float) -> SleepAction:
"""
Expand All @@ -144,7 +144,7 @@ def add_sleep_action(self, name: str, sleep_time: float) -> SleepAction:
:type sleep_time: float
:return:
"""
return self.simulation._add_sleep_action(self, name, sleep_time)
return self._simulation._add_sleep_action(self, name, sleep_time)

def add_action_dependency(self, parent_action: Action, child_action: Action):
"""
Expand All @@ -156,7 +156,7 @@ def add_action_dependency(self, parent_action: Action, child_action: Action):
:type child_action: Action
:return:
"""
return self.simulation._add_action_dependency(self, parent_action, child_action)
return self._simulation._add_action_dependency(self, parent_action, child_action)

def add_parent_job(self, parent_compound_job: CompoundJob):
"""
Expand All @@ -166,20 +166,20 @@ def add_parent_job(self, parent_compound_job: CompoundJob):
:type parent_compound_job: CompoundJob
:return:
"""
return self.simulation._add_parent_job(self, parent_compound_job)
return self._simulation._add_parent_job(self, parent_compound_job)

def __str__(self) -> str:
"""
:return: String representation of the compound job
:rtype: str
"""
s = f"Compound Job {self.name}"
s = f"Compound Job {self._name}"
return s

def __repr__(self) -> str:
"""
:return: String representation of the CompoundJob object
:rtype: str
"""
s = f"CompoundJob(name={self.name})"
s = f"CompoundJob(name={self._name})"
return s
4 changes: 2 additions & 2 deletions wrench/compute_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ def __str__(self) -> str:
:return: String representation of the sleep action
:rtype: str
"""
s = f"Sleep Action {self.name}"
s = f"Sleep Action {self._name}"
return s

def __repr__(self) -> str:
"""
:return: String representation of the sleep action object
:rtype: str
"""
s = f"SleepAction(name={self.name})"
s = f"SleepAction(name={self._name})"
return s
18 changes: 9 additions & 9 deletions wrench/compute_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def supports_compound_jobs(self) -> bool:
:return: True if compound jobs are supported, false otherwise
:rtype: bool
"""
return self.simulation._supports_compound_jobs(self)
return self._simulation._supports_compound_jobs(self)

def supports_pilot_jobs(self) -> bool:
"""
Expand All @@ -47,7 +47,7 @@ def supports_pilot_jobs(self) -> bool:
:return: True if pilot jobs are supported, false otherwise
:rtype: bool
"""
return self.simulation._supports_pilot_jobs(self)
return self._simulation._supports_pilot_jobs(self)

def supports_standard_jobs(self) -> bool:
"""
Expand All @@ -56,7 +56,7 @@ def supports_standard_jobs(self) -> bool:
:return: True if standard jobs are supported, false otherwise
:rtype: bool
"""
return self.simulation._supports_standard_jobs(self)
return self._simulation._supports_standard_jobs(self)

def get_core_flop_rates(self) -> Dict[str, float]:
"""
Expand All @@ -65,7 +65,7 @@ def get_core_flop_rates(self) -> Dict[str, float]:
:return: A dictionary of core speeds
:rtype: Dict[str, float]
"""
return self.simulation._get_core_flop_rates(self)
return self._simulation._get_core_flop_rates(self)

def get_core_counts(self) -> Dict[str, int]:
"""
Expand All @@ -74,7 +74,7 @@ def get_core_counts(self) -> Dict[str, int]:
:return: A dictionary of core counts
:rtype: Dict[str, int]
"""
return self.simulation._get_core_counts(self)
return self._simulation._get_core_counts(self)

def submit_standard_job(self, standard_job: StandardJob) -> None:
"""
Expand All @@ -83,7 +83,7 @@ def submit_standard_job(self, standard_job: StandardJob) -> None:
:param standard_job: the standard job
:type standard_job: StandardJob
"""
return self.simulation._submit_standard_job(standard_job, self)
return self._simulation._submit_standard_job(standard_job, self)

def submit_compound_job(self, compound_job: CompoundJob) -> None:
"""
Expand All @@ -92,21 +92,21 @@ def submit_compound_job(self, compound_job: CompoundJob) -> None:
:param compound_job: the compound job
:type compound_job: CompoundJob
"""
return self.simulation._submit_compound_job(compound_job, self)
return self._simulation._submit_compound_job(compound_job, self)

def __str__(self) -> str:
"""
:return: String representation of the compute service
:rtype: str
"""
s = f"Compute Service {self.name}"
s = f"Compute Service {self._name}"
return s

def __repr__(self) -> str:
"""
:return: String representation of the ComputeService object
:rtype: str
"""
s = f"ComputeService(name={self.name})"
s = f"ComputeService(name={self._name})"
return s
Loading

0 comments on commit b95462d

Please sign in to comment.