def upload_deployment(executable, testbed, app_folder='/tmp'): """ It uploads a executable to the testbed to be executed """ # TODO app_folder needs to go via configuration. # TODO upload the executable # TODO Updates the status of the deployment if executable.compilation_type == Executable.__type_singularity_pm__ and testbed.category == Testbed.slurm_category and 'SINGULARITY' in testbed.package_formats: path = str(uuid.uuid4()) if testbed.protocol == Testbed.protocol_ssh: # TODO for local protocol deployment = db.session.query(Deployment).filter_by( executable_id=executable.id, testbed_id=testbed.id).first() shell.execute_command('mkdir', testbed.endpoint, [path]) filename = os.path.basename(executable.singularity_image_file) path = path + "/" deployment.path = os.path.join(path, filename) # Uploading the file to the testbed shell.scp_file(executable.singularity_image_file, testbed.endpoint, path) deployment.status = Deployment.__status_uploaded_updated__ db.session.commit()
def upload_zip_file_application(executable, connection_url, destination_folder, upload_folder): """ It uploads the zip file of the application to the selected destination folder """ filename = os.path.join(upload_folder, executable.source_code_file) destination = os.path.join('.', destination_folder) if connection_url != '': shell.scp_file(filename, connection_url, destination) else: shell.execute_command('cp', params=[filename, destination])
def create_singularity_template(configuration, executable, connection_url, compilation_folder): """ It creates the template, returns its name and it uploads it to the singularity compilation node """ singularity_pm_template = configuration['singularity_template'] output_template = template.update_template(singularity_pm_template, executable.compilation_script, compilation_folder) shell.scp_file(output_template, connection_url, '.') return output_template
def build_singularity_container(connection_url, template, image_file, upload_folder, become=True): """ It builds a singularity container following an specific definition sudo singularity bootstrap test.img docker.def """ img_file_name = str(uuid.uuid4()) + '.img' local_filename = os.path.join(upload_folder, img_file_name) if connection_url != '': template = os.path.basename(template) if become: logging.info("Executing [%s], 'sudo singulary build -F %s %s'", connection_url, image_file, template) shell.execute_command( 'sudo', connection_url, ['singularity', 'build', '-F', image_file, template]) else: logging.info("Executing [%s], 'singulary build -F %s %s'", connection_url, image_file, template) shell.execute_command('singularity', connection_url, ['build', '-F', image_file, template]) if connection_url != '': logging.info("Downloading image from %s", connection_url) shell.scp_file(local_filename, connection_url, image_file, False) else: logging.info("Moving image to final destination") shell.execute_command('mv', connection_url, [image_file, local_filename]) return local_filename
def test_scp_file(self, mock_subprocess): """ Test that the command to scp a file is correctly done """ shell.scp_file('/path/file', 'user@host', 'destination_path') # We verify that the right params are passed to the mock_subproces mock_subprocess.check_output.assert_called_with(' scp /path/file user@host:destination_path', shell=True) shell.scp_file('/path/file', 'user@host:5000', 'destination_path') # We verify that the right params are passed to the mock_subproces mock_subprocess.check_output.assert_called_with(' scp -P 5000 /path/file user@host:destination_path', shell=True) shell.scp_file('/path/file', 'user@host', 'destination_path', False) # We verify that the right params are passed to the mock_subproces mock_subprocess.check_output.assert_called_with(' scp user@host:destination_path /path/file', shell=True)