11import unittest
22import json
3+ import os
4+ import tempfile
35import pymysql
4- from slurmdb import SlurmDB
6+ from slurmdb import SlurmDB , _find_slurm_conf
57from slurm_schema import extract_schema , extract_schema_from_dump
68
79class SlurmDBValidationTests (unittest .TestCase ):
@@ -17,6 +19,22 @@ def test_valid_config_allowed(self):
1719 db = SlurmDB (host = "localhost" , port = 3306 , user = "slurm" , password = "" , database = "slurm_acct_db" , cluster = "cluster1" )
1820 self .assertEqual (db .cluster , "cluster1" )
1921
22+ def test_slurm_conf_from_service_file (self ):
23+ with tempfile .TemporaryDirectory () as tmp :
24+ svc = os .path .join (tmp , "slurmctld.service" )
25+ slurm_conf = os .path .join (tmp , "slurm.conf" )
26+ with open (svc , "w" ) as fh :
27+ fh .write (f"ConditionPathExists={ slurm_conf } \n " )
28+ with open (slurm_conf , "w" ) as fh :
29+ fh .write ("ClusterName=test\n " )
30+ slurmdbd = os .path .join (tmp , "slurmdbd.conf" )
31+ with open (slurmdbd , "w" ) as fh :
32+ fh .write ("StorageHost=localhost\n " )
33+ path = _find_slurm_conf ([svc ])
34+ self .assertEqual (path , slurm_conf )
35+ db = SlurmDB (slurm_conf = path )
36+ self .assertEqual (db ._config_file , slurmdbd )
37+
2038 def test_invalid_time_format (self ):
2139 db = SlurmDB ()
2240 with self .assertRaises (ValueError ):
0 commit comments