def test_get_global_nodelist_frm_wrklst_file(): # worker_list file should override env variables os.environ[ "LIBE_RESOURCES_TEST_NODE_LIST"] = "20-22,137-139,1234" # Should not be this exp_out = [ 'knl-0019', 'knl-0021', 'knl-0022', 'knl-0137', 'knl-0138', 'knl-0139', 'knl-2345' ] # Should be this open('worker_list', 'w').close() try: _ = Resources.get_global_nodelist(rundir=os.getcwd()) except ResourcesException as e: assert e.args[0] == 'Error. global_nodelist is empty' else: assert 0 with open('worker_list', 'w') as f: for node in exp_out: f.write(node + '\n') # Do not specify env vars. global_nodelist1 = Resources.get_global_nodelist(rundir=os.getcwd()) assert global_nodelist1 == exp_out, "global_nodelist returned does not match expected" # Specify env vars - should ignore env_resources = EnvResources( nodelist_env_slurm="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_cobalt="LIBE_RESOURCES_TEST_NODE_LIST", nodelist_env_lsf="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_lsf_shortform="THIS_ENV_VARIABLE_IS_DEF_NOT_SET") global_nodelist2 = Resources.get_global_nodelist( rundir=os.getcwd(), env_resources=env_resources) assert global_nodelist2 == exp_out, "global_nodelist returned does not match expected" os.remove('worker_list')
def test_get_global_nodelist_frm_cobalt(): os.environ["LIBE_RESOURCES_TEST_NODE_LIST"] = "20-22,137-139,1234" exp_out = ['20', '21', '22', '137', '138', '139', '1234'] env_resources = EnvResources( nodelist_env_slurm="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_cobalt="LIBE_RESOURCES_TEST_NODE_LIST", nodelist_env_lsf="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_lsf_shortform="THIS_ENV_VARIABLE_IS_DEF_NOT_SET") global_nodelist = Resources.get_global_nodelist( rundir=os.getcwd(), env_resources=env_resources) assert global_nodelist == exp_out, "global_nodelist returned does not match expected"
def test_get_global_nodelist_frm_lsf_shortform(): os.environ[ "LIBE_RESOURCES_TEST_NODE_LIST"] = 'batch5 1 g06n02 42 h21n18 42' exp_out = ['g06n02', 'h21n18'] env_resources = EnvResources( nodelist_env_slurm="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_cobalt="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_lsf="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_lsf_shortform="LIBE_RESOURCES_TEST_NODE_LIST") global_nodelist = Resources.get_global_nodelist( rundir=os.getcwd(), env_resources=env_resources) assert global_nodelist == exp_out, "global_nodelist returned does not match expected"
def test_get_global_nodelist_standalone(): mynode = socket.gethostname() env_resources = EnvResources( nodelist_env_slurm="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_cobalt="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_lsf="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_lsf_shortform="THIS_ENV_VARIABLE_IS_DEF_NOT_SET") global_nodelist = Resources.get_global_nodelist( rundir=os.getcwd(), env_resources=env_resources) assert global_nodelist == [ mynode ], "global_nodelist returned does not match expected"
def test_get_global_nodelist_frm_cobalt(): os.environ["LIBE_RESOURCES_TEST_NODE_LIST"] = "20-22,137-139,1234" exp_out = [ 'nid00020', 'nid00021', 'nid00022', 'nid00137', 'nid00138', 'nid00139', 'nid01234' ] global_nodelist = Resources.get_global_nodelist( rundir=os.getcwd(), central_mode=False, nodelist_env_slurm="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_cobalt="LIBE_RESOURCES_TEST_NODE_LIST") assert global_nodelist == exp_out, "global_nodelist returned does not match expected"
def test_get_global_nodelist_frm_wrklst_file(): # worker_list file should override env variables os.environ[ "LIBE_RESOURCES_TEST_NODE_LIST"] = "20-22,137-139,1234" # Should not be this exp_out = [ 'knl-0019', 'knl-0021', 'knl-0022', 'knl-0137', 'knl-0138', 'knl-0139', 'knl-2345' ] # Should be this #Try empty (really want to start testing error messages - should be "Error. global_nodelist is empty" open('worker_list', 'w').close() try: global_nodelist0 = Resources.get_global_nodelist(rundir=os.getcwd(), central_mode=False) except: assert 1 else: assert 0 with open('worker_list', 'w') as f: for node in exp_out: f.write(node + '\n') # Do not specify env vars. global_nodelist1 = Resources.get_global_nodelist(rundir=os.getcwd(), central_mode=False) assert global_nodelist1 == exp_out, "global_nodelist returned does not match expected" # Specify env vars - should ignore global_nodelist2 = Resources.get_global_nodelist( rundir=os.getcwd(), central_mode=False, nodelist_env_slurm="THIS_ENV_VARIABLE_IS_DEF_NOT_SET", nodelist_env_cobalt="LIBE_RESOURCES_TEST_NODE_LIST") assert global_nodelist2 == exp_out, "global_nodelist returned does not match expected" os.remove('worker_list')