diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/common.py b/tests/common.py deleted file mode 100644 index 75ba7d78..00000000 --- a/tests/common.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Common utilities for test cases.""" - -import subprocess - - -def scontrol_show(subcommand, *args): - """Return output of 'scontrol show '""" - if args: - extra_args = " ".join(args) - else: - extra_args = "" - - sctl = subprocess.Popen( - ["scontrol", "-d", "show", subcommand, extra_args], stdout=subprocess.PIPE - ).communicate() - - sctl_stdout = sctl[0].strip().decode("UTF-8", "replace").split() - sctl_dict = dict( - (value.split("=")[0], value.split("=")[1] if len(value.split("=")) > 1 else "") - for value in sctl_stdout - ) - - return sctl_dict diff --git a/tests/test_config.py b/tests/test_config.py deleted file mode 100644 index 854edcf8..00000000 --- a/tests/test_config.py +++ /dev/null @@ -1,107 +0,0 @@ -"""Test cases for Slurm Config.""" - -import subprocess - -import pyslurm - - -def test_config_get(): - """Config: Test config().get() return type.""" - config_info = pyslurm.config().get() - assert isinstance(config_info, dict) - - -def test_config_key_pairs(): - """Config: Test config().key_pairs() function and return type.""" - config_key_pairs = pyslurm.config().key_pairs() - assert isinstance(config_key_pairs, dict) - - -def test_config_scontrol(): - """Config: Compare scontrol values to PySlurm values.""" - config_info = pyslurm.config().get() - - sctl = subprocess.Popen( - ["scontrol", "-d", "show", "config"], stdout=subprocess.PIPE - ).communicate() - sctl_stdout = sctl[0].strip().decode("UTF-8").split("\n") - sctl_dict = dict( - (item.split("=", 1)[0].strip(), item.split("=", 1)[1].strip()) - for item in sctl_stdout - if "=" in item - ) - - assert config_info["accounting_storage_host"] == sctl_dict["AccountingStorageHost"] - assert config_info["accounting_storage_port"] == int( - sctl_dict["AccountingStoragePort"] - ) - assert config_info["accounting_storage_type"] == sctl_dict["AccountingStorageType"] - assert config_info["accounting_storage_tres"] == sctl_dict["AccountingStorageTRES"] - assert config_info["accounting_storage_user"] == sctl_dict["AccountingStorageUser"] - assert config_info["acct_gather_energy_type"] == sctl_dict["AcctGatherEnergyType"] - assert ( - config_info["acct_gather_filesystem_type"] - == sctl_dict["AcctGatherFilesystemType"] - ) - - assert ( - config_info["acct_gather_interconnect_type"] - == sctl_dict["AcctGatherInterconnectType"] - ) - - assert config_info["acct_gather_profile_type"] == sctl_dict["AcctGatherProfileType"] - assert config_info["authtype"] == sctl_dict["AuthType"] - assert config_info["cluster_name"] == sctl_dict["ClusterName"] - assert config_info["core_spec_plugin"] == sctl_dict["CoreSpecPlugin"] - assert config_info["ext_sensors_type"] == sctl_dict["ExtSensorsType"] - assert config_info["first_job_id"] == int(sctl_dict["FirstJobId"]) - assert config_info["job_acct_gather_type"] == sctl_dict["JobAcctGatherType"] - assert config_info["job_comp_host"] == sctl_dict["JobCompHost"] - assert config_info["job_comp_loc"] == sctl_dict["JobCompLoc"] - assert config_info["job_comp_port"] == int(sctl_dict["JobCompPort"]) - assert config_info["job_comp_type"] == sctl_dict["JobCompType"] - assert config_info["launch_type"] == sctl_dict["LaunchType"] - assert config_info["mail_prog"] == sctl_dict["MailProg"] - assert config_info["max_array_sz"] == int(sctl_dict["MaxArraySize"]) - assert config_info["max_job_cnt"] == int(sctl_dict["MaxJobCount"]) - assert config_info["max_job_id"] == int(sctl_dict["MaxJobId"]) - assert config_info["max_step_cnt"] == int(sctl_dict["MaxStepCount"]) - assert config_info["max_step_cnt"] == int(sctl_dict["MaxStepCount"]) - assert config_info["mpi_default"] == sctl_dict["MpiDefault"] - assert config_info["next_job_id"] == int(sctl_dict["NEXT_JOB_ID"]) - assert config_info["plugindir"] == sctl_dict["PluginDir"] - # assert config_info["plugstack"] == sctl_dict["PlugStackConfig"] - assert config_info["preempt_mode"] == sctl_dict["PreemptMode"] - assert config_info["preempt_type"] == sctl_dict["PreemptType"] - assert config_info["priority_type"] == sctl_dict["PriorityType"] - assert config_info["proctrack_type"] == sctl_dict["ProctrackType"] - assert config_info["propagate_rlimits"] == sctl_dict["PropagateResourceLimits"] - assert config_info["route_plugin"] == sctl_dict["RoutePlugin"] - assert config_info["schedtype"] == sctl_dict["SchedulerType"] - assert config_info["select_type"] == sctl_dict["SelectType"] - - assert ( - config_info["slurm_user_name"] + "(" + str(config_info["slurm_user_id"]) + ")" - == sctl_dict["SlurmUser"] - ) - - assert config_info["slurmctld_logfile"] == sctl_dict["SlurmctldLogFile"] - assert config_info["slurmctld_pidfile"] == sctl_dict["SlurmctldPidFile"] - assert config_info["slurmctld_port"] == int(sctl_dict["SlurmctldPort"]) - assert config_info["slurmd_logfile"] == sctl_dict["SlurmdLogFile"] - assert config_info["slurmd_pidfile"] == sctl_dict["SlurmdPidFile"] - assert config_info["slurmd_port"] == int(sctl_dict["SlurmdPort"]) - assert config_info["slurmd_spooldir"] == sctl_dict["SlurmdSpoolDir"] - assert config_info["slurmd_spooldir"] == sctl_dict["SlurmdSpoolDir"] - - assert ( - config_info["slurmd_user_name"] + "(" + str(config_info["slurmd_user_id"]) + ")" - == sctl_dict["SlurmdUser"] - ) - - assert config_info["slurm_conf"] == sctl_dict["SLURM_CONF"] - assert config_info["state_save_location"] == sctl_dict["StateSaveLocation"] - assert config_info["switch_type"] == sctl_dict["SwitchType"] - assert config_info["task_plugin"] == sctl_dict["TaskPlugin"] - assert config_info["topology_plugin"] == sctl_dict["TopologyPlugin"] - assert config_info["tree_width"] == int(sctl_dict["TreeWidth"]) diff --git a/tests/test_hostlist.py b/tests/test_hostlist.py deleted file mode 100644 index 3aae42df..00000000 --- a/tests/test_hostlist.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Test cases for hostlist.""" - -import pyslurm - - -def test_hostlist_create_new(): - """Hostlist: Create new hostlist""" - hl = pyslurm.hostlist() - hosts = "c1, c[2-3]" - - assert hl.create(hosts) - assert hl.count() == 3 - - assert hl.find("c3") == 2 - - assert hl.push("c[4-5]") == 2 - assert hl.count() == 5 - - assert hl.push_host("c6") == 1 - - assert hl.ranged_string() == "c[1-6]" - - assert hl.shift() == "c1" - assert hl.count() == 5 - - assert hl.push_host("c6") == 1 - assert hl.ranged_string() == "c[2-6,6]" - - hl.uniq() - assert hl.ranged_string() == "c[2-6]" - - hl.destroy() - assert hl.count() == -1 - - -def test_hostlist_create_empty(): - """Hostlist: Test create empty hostlist.""" - hl = pyslurm.hostlist() - - hl.create() - assert hl.count() == 0 - - hl.destroy() - assert hl.count() == -1 diff --git a/tests/test_job.py b/tests/test_job.py deleted file mode 100644 index e11bb65c..00000000 --- a/tests/test_job.py +++ /dev/null @@ -1,188 +0,0 @@ -"""Test cases for a Slurm Job.""" - -import sys -import time - -import pyslurm -from tests.common import scontrol_show - - -def test_job_submit(): - """Job: Test job().submit_batch_job().""" - test_job = { - "wrap": "sleep 3600", - "job_name": "pyslurm_test_job", - "ntasks": 2, - "cpus_per_task": 3, - } - test_job_id = pyslurm.job().submit_batch_job(test_job) - test_job_search = pyslurm.job().find(name="name", val=test_job["job_name"]) - test_job_info = pyslurm.job().find_id(test_job_id) - - assert test_job_id in test_job_search - assert len(test_job_info) == 1 - assert test_job_info[0]["cpus_per_task"] == test_job["cpus_per_task"] - assert test_job_info[0]["num_tasks"] == test_job["ntasks"] - - -def test_job_get(): - """Job: Test job().get() return type.""" - all_jobs = pyslurm.job().get() - assert isinstance(all_jobs, dict) - - -def test_job_ids(): - """Job: Test job().ids() return type.""" - all_job_ids = pyslurm.job().ids() - assert isinstance(all_job_ids, list) - - -def test_job_count(): - """Job: Test job count.""" - all_jobs = pyslurm.job().get() - all_job_ids = pyslurm.job().ids() - assert len(all_jobs) == len(all_job_ids) - - -def test_job_scontrol(): - """Job: Compare scontrol values to PySlurm values.""" - all_job_ids = pyslurm.job().ids() - - # Make sure job is running first - test_job = all_job_ids[0] - - test_job_info = pyslurm.job().find_id(test_job)[0] - assert test_job == test_job_info["job_id"] - - sctl_dict = scontrol_show("job", str(test_job)) - - assert test_job_info["batch_flag"] == int(sctl_dict["BatchFlag"]) - assert test_job_info["cpus_per_task"] == int(sctl_dict["CPUs/Task"]) - assert test_job_info["contiguous"] == int(sctl_dict["Contiguous"]) - assert test_job_info["exit_code"] == sctl_dict["ExitCode"] - assert test_job_info["job_id"] == int(sctl_dict["JobId"]) - assert test_job_info["name"] == sctl_dict["JobName"] - assert test_job_info["job_state"] == sctl_dict["JobState"] - assert test_job_info["nice"] == int(sctl_dict["Nice"]) - assert test_job_info["num_cpus"] == int(sctl_dict["NumCPUs"]) - assert test_job_info["num_nodes"] == int(sctl_dict["NumNodes"]) - assert test_job_info["num_tasks"] == int(sctl_dict["NumTasks"]) - assert test_job_info["partition"] == sctl_dict["Partition"] - assert test_job_info["priority"] == int(sctl_dict["Priority"]) - assert test_job_info["state_reason"] == sctl_dict["Reason"] - assert test_job_info["reboot"] == int(sctl_dict["Reboot"]) - assert test_job_info["requeue"] == int(sctl_dict["Requeue"]) - assert test_job_info["restart_cnt"] == int(sctl_dict["Restarts"]) - assert test_job_info["std_err"] == sctl_dict["StdErr"] - assert test_job_info["std_in"] == sctl_dict["StdIn"] - assert test_job_info["std_out"] == sctl_dict["StdOut"] - assert test_job_info["time_limit_str"] == sctl_dict["TimeLimit"] - assert test_job_info["work_dir"] == sctl_dict["WorkDir"] - - -def test_job_find_user_string(): - """Job: Test job().find_user() (String).""" - user = "root" - - if sys.version_info < (3, 0): - user = user.encode("UTF-8") - - test_job_output = pyslurm.job().find_user(user) - assert isinstance(test_job_output, dict) - - -def test_job_find_user_int(): - """Job: Test job().find_user() (Integer).""" - user = 0 - test_job_output = pyslurm.job().find_user(user) - assert isinstance(test_job_output, dict) - - -def test_job_kill(): - """Job: Test job().slurm_kill_job().""" - test_job_search_before = pyslurm.job().find(name="name", val="pyslurm_test_job") - test_job_id = test_job_search_before[-1] - time.sleep(3) - - rc = pyslurm.slurm_kill_job(test_job_id, Signal=9, BatchFlag=pyslurm.KILL_JOB_BATCH) - assert rc == 0 - - # time.sleep(3) - # test_job_search_after = pyslurm.job().find_id(test_job_id)[0] - # assert_equals(test_job_search_after.get("job_state"), "FAILED") - - -def test_job_wait_finished(): - """Job: Test job().wait_finished().""" - test_job = { - "wrap": "sleep 30", - "job_name": "pyslurm_test_job", - "ntasks": 1, - "cpus_per_task": 1, - } - test_job_id = pyslurm.job().submit_batch_job(test_job) - start_job_state = pyslurm.job().find_id(test_job_id)[0]["job_state"] - - # wait for the job to finish - exit_code = pyslurm.job().wait_finished(test_job_id) - - end_job_state = pyslurm.job().find_id(test_job_id)[0]["job_state"] - assert start_job_state != "COMPLETED" - assert end_job_state == "COMPLETED" - assert exit_code == 0 - - # test again with another wrap - test_job = { - "wrap": "sleep 300; exit 1", # "exit 1" should yield failure ending - "job_name": "pyslurm_test_job", - "ntasks": 1, - "cpus_per_task": 1, - } - test_job_id = pyslurm.job().submit_batch_job(test_job) - start_job_state = pyslurm.job().find_id(test_job_id)[0]["job_state"] - - # wait for the job to finish - exit_code = pyslurm.job().wait_finished(test_job_id) - - end_job_state = pyslurm.job().find_id(test_job_id)[0]["job_state"] - assert start_job_state != "COMPLETED" - assert end_job_state == "FAILED" - assert exit_code == 1 - - -def test_job_wait_finished_w_arrays(): - """Job: Test job().wait_finished() with job arrays.""" - test_job = { - "wrap": "sleep 30; exit 0", - "job_name": "pyslurm_array_test_job", - "ntasks": 1, - "cpus_per_task": 1, - "array_inx": "0,1,2", - } - test_job_id = pyslurm.job().submit_batch_job(test_job) - start_job_state = pyslurm.job().find_id(test_job_id)[0]["job_state"] - # wait for the job to finish - exit_code = pyslurm.job().wait_finished(test_job_id) - end_job_state = pyslurm.job().find_id(test_job_id)[0]["job_state"] - assert start_job_state != "COMPLETED" - assert end_job_state == "COMPLETED" - assert exit_code == 0 - - # test for exit codes: maximum exit code of all array jobs - test_job = { - # use array ID as exit code to yield different exit codes: 0, 1, 2 - "wrap": "sleep 30; exit $SLURM_ARRAY_TASK_ID", - "job_name": "pyslurm_array_test_job", - "ntasks": 1, - "cpus_per_task": 1, - "array_inx": "0,1,2", - } - test_job_id = pyslurm.job().submit_batch_job(test_job) - start_job_state = pyslurm.job().find_id(test_job_id)[0]["job_state"] - # wait for the job to finish - exit_code = pyslurm.job().wait_finished(test_job_id) - end_job_state = pyslurm.job().find_id(test_job_id)[0]["job_state"] - assert start_job_state != "COMPLETED" - # exit code 2 (the maximum of all) should yield FAILED for the entire job - assert end_job_state == "FAILED" - assert exit_code == 2 diff --git a/tests/test_jobstep.py b/tests/test_jobstep.py deleted file mode 100644 index 5aa52035..00000000 --- a/tests/test_jobstep.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Test cases for Job Steps.""" - -import pyslurm - - -def test_jobstep_get(): - """Jobstep: Test jobstep().get() return type.""" - all_jobsteps = pyslurm.jobstep().get() - assert isinstance(all_jobsteps, dict) - - -def test_jobstep_ids(): - """Jobstep: Test jobstep().ids() return type.""" - all_jobstep_ids = pyslurm.jobstep().ids() - assert isinstance(all_jobstep_ids, dict) - - -def test_jobstep_count(): - """Jobstep: Test jobstep count.""" - all_jobsteps = pyslurm.jobstep().get() - all_jobstep_ids = pyslurm.jobstep().ids() - assert len(all_jobsteps) == len(all_jobstep_ids) - - -# def test_jobstep_scontrol(): -# """Jobstep: Compare scontrol values to PySlurm values.""" -# all_jobstep_ids = pyslurm.jobstep().ids() -# -# # Make sure jobstep is running first -# test_jobstep = next(iter(all_jobstep_ids) -# -# test_jobstep_info = pyslurm.jobstep().find(test_jobstep) -# assert_equals(test_jobstep, test_jobstep_info["job_id"]) -# -# sctl = subprocess.Popen(["scontrol", "-d", "show", "steps", str(test_job)], -# stdout=subprocess.PIPE).communicate() -# sctl_stdout = sctl[0].strip().decode("UTF-8", "replace").split() -# sctl_dict = dict((value.split("=")[0], value.split("=")[1]) -# for value in sctl_stdout) -# -# assert_equals(test_job_info["batch_flag"], int(sctl_dict["BatchFlag"])) diff --git a/tests/test_license.py b/tests/test_license.py deleted file mode 100644 index b1e251d6..00000000 --- a/tests/test_license.py +++ /dev/null @@ -1,42 +0,0 @@ -"""Test cases for Slurm license.""" - -import subprocess - -import pyslurm - - -def test_get_license(): - """License: Test licenses().get() return type""" - licenses = pyslurm.licenses().get() - assert isinstance(licenses, dict) - - -def test_license_scontrol(): - """License: Compare scontrol values to PySlurm values.""" - all_licenses = pyslurm.licenses().get() - test_license = all_licenses["matlab"] - - scontrol = subprocess.Popen( - ["scontrol", "-ddo", "show", "license", "matlab"], stdout=subprocess.PIPE - ).communicate() - - scontrol_stdout = scontrol[0].strip().decode("UTF-8", "replace").split() - - # Convert scontrol show license into a dictionary of key value pairs. - sctl = {} - for item in scontrol_stdout: - kv = item.split("=", 1) - if kv[1] in ["None", "(null)"]: - sctl.update({kv[0]: None}) - elif kv[1].isdigit(): - sctl.update({kv[0]: int(kv[1])}) - else: - sctl.update({kv[0]: kv[1]}) - - assert "matlab" == sctl.get("LicenseName") - assert test_license.get("total") == sctl.get("Total") - assert test_license.get("in_use") == sctl.get("Used") - assert test_license.get("available") == sctl.get("Free") - - -# assert_equals(test_license.get("remote"), sctl.get("Remote")) diff --git a/tests/test_misc.py b/tests/test_misc.py deleted file mode 100644 index 40707874..00000000 --- a/tests/test_misc.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Test cases for loose Slurm functions.""" - -import subprocess - -import pyslurm - - -def test_slurm_reconfigure(): - """Misc: Test slurm_reconfigure() return.""" - slurm_reconfigure = pyslurm.slurm_reconfigure() - assert slurm_reconfigure == 0 - - -def test_slurm_api_version(): - """Misc: Test slurm_api_version().""" - ver = pyslurm.slurm_api_version() - assert ver[0] == 21 - assert ver[1] == 8 - - -def test_slurm_load_slurmd_status(): - """Misc: Test slurm_load_slurmd_status().""" - status_info = pyslurm.slurm_load_slurmd_status()["slurmctl"] - - sctl = subprocess.Popen( - ["scontrol", "-d", "show", "slurmd"], stdout=subprocess.PIPE - ).communicate() - sctl_stdout = sctl[0].strip().decode("UTF-8").split("\n") - sctl_dict = dict( - (item.split("=", 1)[0].strip(), item.split("=", 1)[1].strip()) - for item in sctl_stdout - if "=" in item - ) - - assert status_info["step_list"] == sctl_dict["Active Steps"] - assert status_info["actual_boards"] == int(sctl_dict["Actual Boards"]) - assert status_info["actual_cpus"] == int(sctl_dict["Actual CPUs"]) - assert status_info["actual_sockets"] == int(sctl_dict["Actual sockets"]) - assert status_info["actual_cores"] == int(sctl_dict["Actual cores"]) - assert status_info["slurmd_logfile"] == sctl_dict["Slurmd Logfile"] - assert status_info["version"] == sctl_dict["Version"] diff --git a/tests/test_node.py b/tests/test_node.py deleted file mode 100644 index 2b816b96..00000000 --- a/tests/test_node.py +++ /dev/null @@ -1,109 +0,0 @@ -"""Test cases for a Slurm Node.""" - -import time - -import pyslurm -from tests.common import scontrol_show - - -def test_node_get(): - """Node: Test node().get() return type.""" - all_nodes = pyslurm.node().get() - assert isinstance(all_nodes, dict) - - -def test_node_ids(): - """Node: Test node().ids() return type.""" - all_node_ids = pyslurm.node().ids() - assert isinstance(all_node_ids, list) - - -def test_node_count(): - """Node: Test node count.""" - all_nodes = pyslurm.node().get() - all_node_ids = pyslurm.node().ids() - assert len(all_nodes) == len(all_node_ids) - - -def test_node_scontrol(): - """Node: Compare scontrol values to PySlurm values.""" - all_node_ids = pyslurm.node().ids() - test_node = all_node_ids[-1] - - test_node_info = pyslurm.node().find_id(test_node) - assert test_node == test_node_info["name"] - - sctl_dict = scontrol_show("node", test_node) - - assert test_node_info["alloc_mem"] == int(sctl_dict["AllocMem"]) - assert test_node_info["boards"] == int(sctl_dict["Boards"]) - assert test_node_info["alloc_cpus"] == int(sctl_dict["CPUAlloc"]) - assert test_node_info["cpus"] == int(sctl_dict["CPUTot"]) - assert test_node_info["cores"] == int(sctl_dict["CoresPerSocket"]) - assert test_node_info["energy"]["current_watts"] == int(sctl_dict["CurrentWatts"]) - assert test_node_info["name"] == sctl_dict["NodeName"] - assert test_node_info["node_addr"] == sctl_dict["NodeAddr"] - assert test_node_info["node_hostname"] == sctl_dict["NodeHostName"] - assert test_node_info["partitions"] == sctl_dict["Partitions"].split(",") - assert test_node_info["real_memory"] == int(sctl_dict["RealMemory"]) - assert test_node_info["sockets"] == int(sctl_dict["Sockets"]) - assert test_node_info["state"] == sctl_dict["State"] - assert test_node_info["threads"] == int(sctl_dict["ThreadsPerCore"]) - assert test_node_info["tmp_disk"] == int(sctl_dict["TmpDisk"]) - assert test_node_info["weight"] == int(sctl_dict["Weight"]) - - -def test_node_update(): - """Node: Test node().update().""" - - time.sleep(3) - test_node = pyslurm.node().ids()[-1] - node_test_before = pyslurm.node().find_id(test_node) - assert node_test_before["state"] == "IDLE" - - node_test_update = { - "node_names": "c10", - "node_state": pyslurm.NODE_STATE_DRAIN, - "reason": "unit testing", - } - - rc = pyslurm.node().update(node_test_update) - assert rc == 0 - - node_test_during = pyslurm.node().find_id("c10") - assert node_test_during["state"] == "IDLE+DRAIN" - - node_test_update = {"node_names": "c10", "node_state": pyslurm.NODE_RESUME} - - rc = pyslurm.node().update(node_test_update) - assert rc == 0 - - node_test_after = pyslurm.node().find_id("c10") - assert node_test_after["state"] == "IDLE" - - -def test_gres_used_parser(): - """Node: Test node().parse_gres().""" - assert pyslurm.node().parse_gres("gpu:p100:2(IDX:1,3),lscratch:0") == [ - "gpu:p100:2(IDX:1,3)", - "lscratch:0", - ] - assert pyslurm.node().parse_gres("gpu:0,hbm:0") == ["gpu:0", "hbm:0"] - assert pyslurm.node().parse_gres("gpu:p100:0(IDX:N/A),hbm:0") == [ - "gpu:p100:0(IDX:N/A)", - "hbm:0", - ] - assert pyslurm.node().parse_gres("gpu:p100:1(IDX:0),hbm:0") == [ - "gpu:p100:1(IDX:0)", - "hbm:0", - ] - assert pyslurm.node().parse_gres("gpu:p100:1(IDX:1),hbm:0") == [ - "gpu:p100:1(IDX:1)", - "hbm:0", - ] - assert pyslurm.node().parse_gres("gpu:p100:2(IDX:0-1),hbm:0") == [ - "gpu:p100:2(IDX:0-1)", - "hbm:0", - ] - assert pyslurm.node().parse_gres("hbm:0") == ["hbm:0"] - assert pyslurm.node().parse_gres("lscratch:0,hbm:0") == ["lscratch:0", "hbm:0"] diff --git a/tests/test_partition.py b/tests/test_partition.py deleted file mode 100644 index fd57e474..00000000 --- a/tests/test_partition.py +++ /dev/null @@ -1,85 +0,0 @@ -"""Test cases for Slurm Partitions.""" - -import pyslurm -from tests.common import scontrol_show - - -def test_partition_get(): - """Partition: Test partition().get() return type.""" - all_partitions = pyslurm.partition().get() - assert isinstance(all_partitions, dict) - - -def test_partition_ids(): - """Partition: Test partition().ids() return type.""" - all_partition_ids = pyslurm.partition().ids() - assert isinstance(all_partition_ids, list) - - -def test_partition_count(): - """Partition: Test partition count.""" - all_partitions = pyslurm.partition().get() - all_partition_ids = pyslurm.partition().ids() - assert len(all_partitions) == len(all_partition_ids) - - -def test_partition_scontrol(): - """Partition: Compare scontrol values to PySlurm values.""" - all_partition_ids = pyslurm.partition().ids() - test_partition = all_partition_ids[0] - - test_partition_info = pyslurm.partition().find_id(test_partition) - assert test_partition == test_partition_info["name"] - - sctl_dict = scontrol_show("partition", str(test_partition)) - - assert test_partition_info["allow_alloc_nodes"] == sctl_dict["AllocNodes"] - assert test_partition_info["allow_accounts"] == sctl_dict["AllowAccounts"] - assert test_partition_info["allow_groups"] == sctl_dict["AllowGroups"] - assert test_partition_info["allow_qos"] == sctl_dict["AllowQos"] - # assert test_partition_info["def_mem_per_node"] == sctl_dict["DefMemPerNode"] - assert test_partition_info["default_time_str"] == sctl_dict["DefaultTime"] - assert test_partition_info["grace_time"] == int(sctl_dict["GraceTime"]) - assert test_partition_info["max_cpus_per_node"] == sctl_dict["MaxCPUsPerNode"] - assert test_partition_info["max_mem_per_node"] == sctl_dict["MaxMemPerNode"] - assert test_partition_info["max_nodes"] == int(sctl_dict["MaxNodes"]) - assert test_partition_info["max_time_str"] == sctl_dict["MaxTime"] - assert test_partition_info["min_nodes"] == int(sctl_dict["MinNodes"]) - assert test_partition_info["nodes"] == sctl_dict["Nodes"] - assert test_partition_info["name"] == sctl_dict["PartitionName"] - # assert test_partition_info["preempt_mode"] == sctl_dict["PreemptMode"] - assert test_partition_info["state"] == sctl_dict["State"] - assert test_partition_info["total_cpus"] == int(sctl_dict["TotalCPUs"]) - assert test_partition_info["total_nodes"] == int(sctl_dict["TotalNodes"]) - - -def test_partition_create(): - """Partition: Test partition().create().""" - part_test = {"Name": "part_test"} - rc = pyslurm.partition().create(part_test) - assert rc == 0 - - partition_ids = pyslurm.partition().ids() - assert "part_test" in partition_ids - - -def test_partition_update(): - """Partition: Test partition().update().""" - part_test_before = pyslurm.partition().find_id("part_test") - assert part_test_before["state"] == "UP" - - part_test_update = {"Name": "part_test", "State": "DOWN"} - rc = pyslurm.partition().update(part_test_update) - assert rc == 0 - - part_test_after = pyslurm.partition().find_id("part_test") - assert part_test_after["state"] == "DOWN" - - -def test_partition_delete(): - """Partition: Test partition().delete().""" - rc = pyslurm.partition().delete("part_test") - assert rc == 0 - - partition_ids = pyslurm.partition().ids() - assert "part_test" not in partition_ids diff --git a/tests/test_qos.py b/tests/test_qos.py deleted file mode 100644 index c7e00094..00000000 --- a/tests/test_qos.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Test cases for QoS.""" - -import pyslurm - - -def test_get_qos(): - """QoS: Test get_qos() return type""" - test_qos = pyslurm.qos().get() - assert isinstance(test_qos, dict) diff --git a/tests/test_reservation.py b/tests/test_reservation.py deleted file mode 100644 index fc3a2bd6..00000000 --- a/tests/test_reservation.py +++ /dev/null @@ -1,65 +0,0 @@ -"""Test cases for Slurm reservations.""" - -import time - -import pyslurm -from tests.common import scontrol_show - - -def test_reservation_create(): - """Reservation: Test reservation().create().""" - resv_test = { - "node_cnt": 1, - "users": "root,slurm", - "start_time": int(time.time()), - "duration": 600, - "licenses": "matlab:1", - "name": "resv_test", - } - r = pyslurm.reservation().create(resv_test) - assert r == "resv_test" - - -def test_reservation_get(): - """Reservation: Test reservation().get().""" - resv = pyslurm.reservation().get() - - assert isinstance(resv, dict) - assert resv["resv_test"]["licenses"] == {"matlab": "1"} - assert resv["resv_test"]["users"] == ["root", "slurm"] - - start = resv["resv_test"]["start_time"] - end = resv["resv_test"]["end_time"] - - assert end - start == 600 * 60 - - -def test_reservation_update(): - """Reservation: Test reservation().update().""" - resv_update = {"name": "resv_test", "duration": 8000} - rc = pyslurm.reservation().update(resv_update) - assert rc == 0 - - -def test_reservation_count(): - """Reservation: Test reservation count.""" - resv = pyslurm.reservation().get() - assert len(resv) == 1 - - -def test_reservation_scontrol(): - """Reservation: Compare scontrol values to PySlurm values.""" - test_resv_info = pyslurm.reservation().get()["resv_test"] - sctl_dict = scontrol_show("reservation", "resv_test") - - assert test_resv_info["node_list"] == sctl_dict["Nodes"] - assert test_resv_info["node_cnt"] == int(sctl_dict["NodeCnt"]) - assert ",".join(test_resv_info["users"]) == sctl_dict["Users"] - - -def test_reservation_delete(): - """Reservation: Test reservation().delete().""" - delete = pyslurm.reservation().delete("resv_test") - count = pyslurm.reservation().get() - assert delete == 0 - assert len(count) == 0 diff --git a/tests/test_slurmdb.py b/tests/test_slurmdb.py deleted file mode 100644 index d64dd787..00000000 --- a/tests/test_slurmdb.py +++ /dev/null @@ -1,127 +0,0 @@ -"""Test cases for Slurmdb.""" - -import datetime -import json -import pwd -import subprocess -import time - -import pyslurm - - -def njobs_sacct_jobs(start, end, username=None): - """ - Count the number of jobs reported by sacct - For comparison with the reults of slurmdb_jobs.get - """ - sacctcmd = ["sacct", "-S", start, "-E", end, "-n", "-X"] - if username is not None: - sacctcmd.extend(["-u", username]) - else: - sacctcmd.append("-a") - sacct = subprocess.Popen( - sacctcmd, stdout=subprocess.PIPE, stderr=None - ).communicate() - return len(sacct[0].splitlines()) - - -def njobs_slurmdb_jobs_get(start, end, uid=None): - """ - Count the number of jobs reported by slurmdb - """ - if uid is None: - jobs = pyslurm.slurmdb_jobs().get( - starttime=start.encode("utf-8"), endtime=end.encode("utf-8") - ) - else: - jobs = pyslurm.slurmdb_jobs().get( - starttime=start.encode("utf-8"), endtime=end.encode("utf-8"), userids=[uid] - ) - return len(jobs) - - -def get_user(): - """ - Return a list of usernames and their uid numbers - """ - users = subprocess.Popen( - ["squeue", "-O", "username", "-h"], stdout=subprocess.PIPE, stderr=None - ).communicate() - for username in users[0].splitlines(): - uid = pwd.getpwnam("{}".format(username.strip().decode())) - yield username.strip().decode(), uid.pw_uid - - -def test_slurmdb_jobs_get(): - """ - Slurmdb: Compare sacct and slurmdb_jobs.get() for all users - """ - starttime = (datetime.datetime.now() - datetime.timedelta(days=2)).strftime( - "%Y-%m-%dT00:00:00" - ) - endtime = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime( - "%Y-%m-%dT00:00:00" - ) - njobs_pyslurm = njobs_slurmdb_jobs_get(starttime, endtime) - njobs_sacct = njobs_sacct_jobs(starttime, endtime) - assert njobs_pyslurm == njobs_sacct - - -def test_slurmdb_jobs_get_steps(): - """ - Slurmdb: Get jobs with steps for all users - """ - job = { - "wrap": """ - srun hostname - srun sleep 1 - """, - "job_name": "pyslurm_test_job_steps", - "ntasks": 1, - "cpus_per_task": 1, - } - job_id = pyslurm.job().submit_batch_job(job) - - # wait for job to finish - time.sleep(10) - - # get `sacct` jobs - start = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime( - "%Y-%m-%dT00:00:00" - ) - end = (datetime.datetime.now() + datetime.timedelta(days=1)).strftime( - "%Y-%m-%dT00:00:00" - ) - jobs = pyslurm.slurmdb_jobs().get( - starttime=start.encode("utf-8"), endtime=end.encode("utf-8") - ) - - # make sure results are valid json - assert json.dumps(jobs, sort_keys=True, indent=4) - - # we should get our job in the results - assert jobs.get(job_id, None) - - # and it should have steps - assert jobs[job_id]["steps"] - - # and 3 steps, 1 batch + 2 srun - assert 3 == len(jobs[job_id]["steps"]) - - -def test_slurmdb_jobs_get_byuser(): - """ - Slurmdb: Compare sacct and slurmdb_jobs.get() for individual users - """ - - userlist = list(get_user()) - for user in userlist[:10]: - starttime = (datetime.datetime.now() - datetime.timedelta(days=2)).strftime( - "%Y-%m-%dT00:00:00" - ) - endtime = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime( - "%Y-%m-%dT00:00:00" - ) - njobs_pyslurm = njobs_slurmdb_jobs_get(starttime, endtime, int(user[1])) - njobs_sacct = njobs_sacct_jobs(starttime, endtime, username=user[0]) - assert njobs_pyslurm == njobs_sacct diff --git a/tests/test_statistics.py b/tests/test_statistics.py deleted file mode 100644 index dba5ef23..00000000 --- a/tests/test_statistics.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Test cases for Slurm statistics.""" - -import pyslurm - - -def test_get_statistics(): - """Statistics: Test get_statistics() return type""" - test_statistics = pyslurm.statistics().get() - assert isinstance(test_statistics, dict) diff --git a/tests/test_topology.py b/tests/test_topology.py deleted file mode 100644 index 9712c8cd..00000000 --- a/tests/test_topology.py +++ /dev/null @@ -1,47 +0,0 @@ -"""Test cases for Slurm Topologies.""" - -import subprocess - -import pyslurm - - -def test_get_topology(): - """Topology: Test get_topology() return type""" - test_topology = pyslurm.topology().get() - assert isinstance(test_topology, dict) - - -def test_topology_scontrol(): - """Topology: Compare scontrol values to PySlurm values.""" - - test_topology = pyslurm.topology().get() - - scontrol = subprocess.Popen( - ["scontrol", "-ddo", "show", "topology", "s2"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ).communicate() - - scontrol_stdout = scontrol[0].strip().decode("UTF-8") - scontrol_stderr = scontrol[1].strip().decode("UTF-8") - - if "No topology information" in scontrol_stderr: - pass - else: - # Convert scontrol show topology into a dictionary of key value pairs. - sctl = {} - for item in scontrol_stdout.split(): - kv = item.split("=", 1) - if kv[1] in ["None", "(null)"]: - sctl.update({kv[0]: None}) - elif kv[1].isdigit(): - sctl.update({kv[0]: int(kv[1])}) - else: - sctl.update({kv[0]: kv[1]}) - - s2 = test_topology["s2"] - assert s2.get("name") == sctl.get("SwitchName") - assert s2.get("level") == sctl.get("Level") - assert s2.get("link_speed") == sctl.get("LinkSpeed") - assert s2.get("nodes") == sctl.get("Nodes") - assert s2.get("switches") == sctl.get("Switches")