diff --git a/pyflow/nodes.py b/pyflow/nodes.py index f0b1042..c30679c 100644 --- a/pyflow/nodes.py +++ b/pyflow/nodes.py @@ -1077,11 +1077,7 @@ def deploy_suite(self, target=FileSystem, **options): target = target(self, **options) for t in self.all_tasks: script, includes = t.generate_script() - try: - target.deploy_task(t.deploy_path, script, includes) - except RuntimeError: - print(f"\nERROR when deploying task: {t.fullname}\n") - raise + target.deploy_task(t.deploy_path, script, includes) for f in self.all_families: manual = self.generate_stub(f.manual) if manual: diff --git a/pyflow/resource.py b/pyflow/resource.py index 6d4d01b..c4f6884 100644 --- a/pyflow/resource.py +++ b/pyflow/resource.py @@ -80,30 +80,7 @@ def get_resource(self, filename): return [] - def install_file_stub(self, target): - """ - Installs any data associated with the resource object that is going to be deployed from the **ecFlow** server. - - Parameters: - target(Deployment): The target deployment where the resource data should be installed. - """ - - """ - n.b. If a resource does not need to save data at deployment time, it should not do so (e.g. WebResource) - """ - # Install path is for the suite, so we don't need to include the suite name - assert self.fullname.count("/") > 1 - subpath = self.fullname[self.fullname.find("/", 1) + 1 :] - - self._server_filename = os.path.join( - target.files_install_path(), subpath, self.name - ) - - super().install_file_stub(target) - - self.save_data(target, self._server_filename) - - def build_script(self): + def generate_script(self): """ Returns the installer script for the data resource. @@ -128,7 +105,7 @@ def build_script(self): for h in self._hosts: lines += h.copy_file_to(self._server_filename, self.location()).split("\n") - return lines + return lines, [] def location(self): """ @@ -183,6 +160,8 @@ def save_data(self, target, filename): filename(str): The filename for the resource data. """ + self._server_filename = filename + """ Resources don't all need to save data at generation time """ @@ -206,9 +185,8 @@ class FileResource(Resource): """ def __init__(self, name, hosts, source_file): - self._source = source_file - super().__init__(name, hosts) + self._server_filename = source_file def md5(self): """ @@ -230,7 +208,7 @@ def data(self): The resource data. """ - with open(self._source, "rb") as f: + with open(self._server_filename, "rb") as f: return f.read() def save_data(self, target, filename): diff --git a/tests/file_resource.txt b/tests/file_resource.txt new file mode 100644 index 0000000..c53e6c6 --- /dev/null +++ b/tests/file_resource.txt @@ -0,0 +1 @@ +# Example for a file resource diff --git a/tests/test_resource.py b/tests/test_resource.py new file mode 100644 index 0000000..bda8046 --- /dev/null +++ b/tests/test_resource.py @@ -0,0 +1,44 @@ +from os import path +from os.path import join + +from pyflow import FileResource, Notebook, Suite +from pyflow.host import SSHHost + + +def test_file_resource(): + + resouces_directory = "/resources_directory" + + sshhost_1 = SSHHost("example_ssh_host_1", resources_directory=resouces_directory) + sshhost_2 = SSHHost("example_ssh_host_2", resources_directory=resouces_directory) + host_set = [sshhost_1, sshhost_2] + + source_file = path.join(path.dirname(path.abspath(__file__)), "file_resource.txt") + name = "file_resource" + + with Suite("s", host=sshhost_1) as s: + s.resource_file = FileResource(name, hosts=host_set, source_file=source_file) + + # Check that variables are set correctly + assert s.resource_file.host == sshhost_1 + assert s.resource_file.location() == join( + str(sshhost_1.resources_directory), s.name, name + ) + assert s.resource_file._hosts == host_set + + # Check that the deployment scripts have been generated + s.check_definition() + s.generate_node() + + s.deploy_suite(target=Notebook) + + generate_file_resource_script_lines, _ = s.resource_file.generate_script() + assert any(sshhost_1.name in s for s in generate_file_resource_script_lines) + assert any(sshhost_2.name in s for s in generate_file_resource_script_lines) + + +if __name__ == "__main__": + + import pytest + + pytest.main(path.abspath(__file__))