Exemplo n.º 1
0
 def test_adapters_overwitten_by_others(self):
     dcc = divvy.ComputingConfiguration()
     dcc.activate_package("singularity_slurm")
     compute = YacAttMap({"mem": 1000})
     extra_vars = [{"compute": compute}, {"MEM": 333}]
     dcc.write_script("test1.sub", extra_vars)
     with open("test1.sub", "r") as f:
         contents = f.read()
         assert not (contents.find("1000") > 0)
         assert contents.find("333") > 0
     os.remove("test1.sub")
Exemplo n.º 2
0
    def __init__(self, name, record_identifier=None, schema_path=None,
                 results_file=None, database_config=None):
        """
        Initialize the object

        :param str name: namespace to report into. This will be the DB table
            name if using DB as the object back-end
        :param str record_identifier: record identifier to report for. This
            creates a weak bound to the record, which can be overriden in
            this object method calls
        :param str schema_path: path to the output schema that formalizes
            the results structure
        :param str results_file: YAML file to report into, if file is used as
            the object back-end
        :param str database_config: DB login credentials to report into,
            if DB is used as the object back-end
        """
        def _check_cfg_key(cfg, key):
            if key not in cfg:
                _LOGGER.warning(f"Key '{key}' not found in config")
                return False
            return True

        super(PipestatManager, self).__init__()

        self[NAME_KEY] = str(name)
        self[RECORD_ID_KEY] = record_identifier
        if schema_path:
            _, self[SCHEMA_KEY] = read_yaml_data(schema_path, "schema")
            self.validate_schema()
        if results_file:
            self[FILE_KEY] = expandpath(results_file)
            self._init_results_file()
        elif database_config:
            _, self[CONFIG_KEY] = read_yaml_data(database_config, "DB config")
            if not all([_check_cfg_key(self[CONFIG_KEY][CFG_DATABASE_KEY], key)
                        for key in DB_CREDENTIALS]):
                raise MissingConfigDataError(
                    "Must specify all database login credentials")
            self[DATA_KEY] = YacAttMap()
            self._init_postgres_table()
        else:
            raise MissingConfigDataError("Must specify either database login "
                                         "credentials or a YAML file path")
Exemplo n.º 3
0
class TestAdapters:
    @pytest.mark.parametrize(
        "compute",
        [
            dict({
                "mem": 1000,
                "test": 0
            }),
            YacAttMap({
                "mem": 1000,
                "test": 0
            }),
            OrderedDict({
                "mem": 1000,
                "test": 0
            }),
        ],
    )
    @pytest.mark.parametrize("package", ["singularity_slurm", "slurm"])
    def test_write_script_adapters(self, compute, package):
        """Test successful adapter sourcing from various Mapping types"""
        dcc = divvy.ComputingConfiguration()
        dcc.activate_package(package)
        extra_vars = {"compute": compute}
        dcc.write_script("test.sub", extra_vars)
        with open("test.sub", "r") as f:
            contents = f.read()
            assert contents.find("1000") > 0
        os.remove("test.sub")

    def test_adapters_overwitten_by_others(self):
        dcc = divvy.ComputingConfiguration()
        dcc.activate_package("singularity_slurm")
        compute = YacAttMap({"mem": 1000})
        extra_vars = [{"compute": compute}, {"MEM": 333}]
        dcc.write_script("test1.sub", extra_vars)
        with open("test1.sub", "r") as f:
            contents = f.read()
            assert not (contents.find("1000") > 0)
            assert contents.find("333") > 0
        os.remove("test1.sub")
Exemplo n.º 4
0
    def _init_results_file(self):
        """
        Initialize YAML results file if it does not exist.
        Read the data stored in the existing file into the memory otherwise.

        :return bool: whether the file has been created
        """
        if not os.path.exists(self.file):
            _LOGGER.info(f"Initializing results file '{self.file}'")
            data = YacAttMap(entries={self.name: PXAM()})
            data.write(filepath=self.file)
            self[DATA_KEY] = data
            return True
        _LOGGER.info(f"Reading data from '{self.file}'")
        data = YacAttMap(filepath=self.file)
        filtered = list(filter(lambda x: not x.startswith("_"), data.keys()))
        if filtered and self.name not in filtered:
            raise PipestatDatabaseError(
                f"'{self.file}' is already used to report results for "
                f"other namespace: {filtered[0]}")
        self[DATA_KEY] = data
        return False
Exemplo n.º 5
0
#!/usr/bin/env python3

import sys
from argparse import ArgumentParser
from random import random
from time import sleep

from yacman import YacAttMap

parser = ArgumentParser(description="Test script")

parser.add_argument("-p",
                    "--path",
                    help="path to the test file",
                    required=True)
parser.add_argument("-i", "--id", help="process id", required=True)
parser.add_argument("-w",
                    "--wait",
                    help="max wait time",
                    type=int,
                    required=True)
args = parser.parse_args()
yam = YacAttMap(filepath=args.path, wait_max=args.wait)
with yam as y:
    sleep(random())
    y.update({args.id: 1})

sys.exit(0)
Exemplo n.º 6
0
 def test_update_packages(self, dcc, config_file):
     """Test updating does not produce empty compute packages"""
     entries = load_yaml(config_file)
     dcc.update(entries)
     assert dcc.compute_packages != YacAttMap()
Exemplo n.º 7
0
 def test_reset_active_settings_works(self, dcc):
     """Test if the settings are cleared"""
     dcc.reset_active_settings()
     assert dcc.get_active_package() == YacAttMap({})
Exemplo n.º 8
0
 def test_settings_nonempty(self, dcc):
     """Test if get_active_package produces a nonempty YacAttMap object"""
     settings = dcc.get_active_package()
     assert settings != YacAttMap()