Beispiel #1
0
def get_squeue_query_model(client: SSHClient, config, params=""):
    """
    get response of squeue query.

    :param client: SSH clinet
    :param config: config dict
        {
            category_list: a list of categories
                [
                    {
                        id: "llq.id",
                        display_name: "Id",
                        label: "Job Step Id",
                        record_parser_class: "DetailLabelParser",
                        record_parser_arguments: ["Job Step Id"],
                        value_saver_class: "StringSaver",
                        value_saver_arguments: []
                    }
                ]
    :param params:
    :return: model, see nwpc_hpc_model.workflow.query_model.QueryModel

    """
    std_out_string, std_error_out_string = run_squeue_command(client,
                                                              params=params)
    output_lines = std_out_string.split("\n")
    category_list = build_category_list(config['squeue']['category_list'])

    model = SlurmQueryModel.build_from_table_category_list(
        output_lines, category_list, '|')
    return model
Beispiel #2
0
def build_query_model(job_dict, category_list):
    model = SlurmQueryModel()

    for _, job in job_dict.items():
        item = QueryItem.build_from_category_list(job, category_list)
        model.items.append(item)

    return model
Beispiel #3
0
def get_result(category_list, client) -> SlurmQueryModel or None:
    std_out_string, std_error_out_string = run_sinfo_command(client)
    result_lines = std_out_string.split("\n")

    category_list = build_category_list(category_list)

    model = SlurmQueryModel.build_from_table_category_list(result_lines, category_list)
    if model is None:
        return None
    return model
def test_empty_build_from_table_category_list():
    category_list = SlurmQueryCategoryList()
    category_list.extend([
        QueryCategory("sinfo.partition", "Partition", "PARTITION",
                      record_parser.TokenRecordParser, (-1, ),
                      value_saver.StringSaver, ())
    ])

    model = SlurmQueryModel.build_from_table_category_list([], category_list)
    assert model is None

    model = SlurmQueryModel.build_from_table_category_list(
        ['PARTITION AVAIL  TIMELIMIT  NODES  STATE NODELIST', ''],
        category_list)
    assert len(model.items) == 0

    model = SlurmQueryModel.build_from_table_category_list(
        ['PARTITION AVAIL  TIMELIMIT  NODES  STATE NODELIST'], category_list)
    assert len(model.items) == 0
Beispiel #5
0
def get_query_model(config, params=""):
    """
    get response of sacct query.

    :param config: config dict
    :param params:
    :return: model, see nwpc_hpc_model.workflow.query_model.QueryModel

    """
    output_lines = run_command(config, params=params).split("\n")
    category_list = build_category_list(config['sacct']['category_list'])

    model = SlurmQueryModel.build_from_table_category_list(output_lines, category_list, sep='|')
    return model
def get_sinfo_query_model(client: SSHClient, config, params=""):
    """
    get response of sinfo query.

    :param client:
    :param config: config dict
    :param params:
    :return: model, see nwpc_hpc_model.workflow.query_model.QueryModel

    """
    std_out_string, std_error_out_string = run_sinfo_command(client, config, params=params)
    output_lines = std_out_string.split("\n")
    category_list = build_category_list(config['sinfo']['category_list'])

    model = SlurmQueryModel.build_from_table_category_list(output_lines, category_list)
    return model
Beispiel #7
0
    def check_build_model(self, test_case):
        record = test_case['record']
        category_list = test_case['category_list']
        records = test_case['records']

        model = SlurmQueryModel.build_from_table_category_list(record, category_list)

        for record in records:
            index = record['index']
            properties = record['properties']
            item = model.items[index]

            for a_prop in properties:
                category_id = a_prop['category_id']
                text = a_prop['text']
                category_index = category_list.index_from_id(category_id)
                p = item.props[category_index]

                assert(p.map['text'] == text)
Beispiel #8
0
    def test_to_dict(self):
        category_list = SlurmQueryCategoryList()

        category_list.extend([
            QueryCategory("sinfo.partition", "Partition", "PARTITION",
                          record_parser.TokenRecordParser,  (-1,),
                          value_saver.StringSaver, ()),
            QueryCategory("sinfo.avail", "Avail", "AVAIL",
                          record_parser.TokenRecordParser,  (-1,),
                          value_saver.StringSaver, ()),
            QueryCategory("sinfo.time_limit", "Time Limit", "TIMELIMIT",
                          record_parser.TokenRecordParser,  (-1,),
                          value_saver.StringSaver, ()),
            QueryCategory("sinfo.nodes", "Nodes", "NODES",
                          record_parser.TokenRecordParser,  (-1,),
                          value_saver.NumberSaver, ()),
            QueryCategory("sinfo.state", "State", "STATE",
                          record_parser.TokenRecordParser,  (-1,),
                          value_saver.StringSaver, ()),
            QueryCategory("sinfo.node_list", "Node List", "NODELIST",
                          record_parser.TokenRecordParser,  (-1,),
                          value_saver.StringSaver, ()),
        ])

        test_case_list = list()

        nwp_output = Path(
            Path(__file__).parent,
            "../data/sinfo/default.txt"
        )
        with open(nwp_output) as nwp_output_file:
            lines = nwp_output_file.read().split('\n')
            model = SlurmQueryModel.build_from_table_category_list(lines, category_list)
            model_dict = model.to_dict()
            assert(('items' in model_dict) is True)
            assert(len(model_dict['items']) == 12)