Skip to content

Commit 03f7bf9

Browse files
committed
Move code from osg-ce-attribs-gen to ce_attributes.py
1 parent c9a9224 commit 03f7bf9

File tree

2 files changed

+88
-85
lines changed

2 files changed

+88
-85
lines changed

osg_configure/modules/ce_attributes.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# BATCH_SYSTEMS here is both the config sections for the batch systems
22
# and the values in the OSG_BatchSystems attribute since they are
33
# coincidentally the same. If they ever change, make a mapping.
4+
from configparser import ConfigParser
5+
from typing import Dict
6+
7+
from osg_configure.modules import utilities, subcluster
8+
from osg_configure.modules.exceptions import SettingError
9+
410
BATCH_SYSTEMS_CASE_MAP = {
511
'condor': 'Condor',
612
'lsf': 'LSF',
@@ -9,3 +15,83 @@
915
'slurm': 'SLURM',
1016
}
1117
BATCH_SYSTEMS = list(BATCH_SYSTEMS_CASE_MAP.values())
18+
19+
20+
def empty_if_blank(value: str) -> str:
21+
return "" if utilities.blank(value) else value
22+
23+
24+
def get_resource_from_config(config: ConfigParser) -> str:
25+
return utilities.classad_quote(
26+
empty_if_blank(
27+
config.get("Site Information", "resource", fallback="")
28+
)
29+
)
30+
31+
32+
def get_resource_group_from_config(config: ConfigParser) -> str:
33+
return utilities.classad_quote(
34+
empty_if_blank(
35+
config.get("Site Information", "resource_group", fallback="")
36+
)
37+
)
38+
39+
40+
def get_batch_systems_from_config(config: ConfigParser) -> str:
41+
batch_systems = []
42+
43+
siteinfo_batch_systems = config.get("Site Information", "batch_systems", fallback=None)
44+
if siteinfo_batch_systems is not None:
45+
# Site Information.batch_systems specified -- this one wins
46+
split_batch_systems = utilities.split_comma_separated_list(siteinfo_batch_systems)
47+
for batch_system in split_batch_systems:
48+
try:
49+
batch_systems.append(BATCH_SYSTEMS_CASE_MAP[batch_system.lower()])
50+
except KeyError:
51+
raise SettingError("Unrecognized batch system %s" % batch_system)
52+
else:
53+
# Add each batch system that's enabled from the sections in the 20-*.ini files.
54+
for batch_system in BATCH_SYSTEMS:
55+
if batch_system in config:
56+
if config.getboolean(section=batch_system, option="enabled", fallback=None):
57+
batch_systems.append(batch_system)
58+
59+
# Special case: Bosco (see SOFTWARE-3720); use the Bosco.batch argument.
60+
if config.getboolean("Bosco", "enabled", fallback=False):
61+
bosco_batch = config.get("Bosco", "batch", fallback=None)
62+
if bosco_batch:
63+
try:
64+
batch_systems.append(BATCH_SYSTEMS_CASE_MAP[bosco_batch.lower()])
65+
except KeyError:
66+
raise SettingError("Unrecognized batch system %s in Bosco section" % bosco_batch)
67+
68+
return utilities.classad_quote(",".join(batch_systems))
69+
70+
71+
def get_resource_catalog_from_config(config: ConfigParser) -> str:
72+
return subcluster.resource_catalog_from_config(config, default_allowed_vos=[]).format_value()
73+
74+
75+
def get_attributes(config: ConfigParser) -> Dict[str, str]:
76+
"""Turn config from .ini files into a dict of condor settings.
77+
78+
"""
79+
attributes = {}
80+
81+
resource = get_resource_from_config(config)
82+
if resource and resource != '""':
83+
attributes["OSG_Resource"] = resource
84+
85+
resource_group = get_resource_group_from_config(config)
86+
if resource_group and resource_group != '""':
87+
attributes["OSG_ResourceGroup"] = resource_group
88+
89+
batch_systems = get_batch_systems_from_config(config)
90+
if batch_systems and batch_systems != '""':
91+
attributes["OSG_BatchSystems"] = batch_systems
92+
93+
resource_catalog = get_resource_catalog_from_config(config)
94+
if resource_catalog and resource_catalog != "{}":
95+
attributes["OSG_ResourceCatalog"] = resource_catalog
96+
97+
return attributes

scripts/osg-ce-attribs-gen

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ from configparser import ConfigParser
1313
import glob
1414
import os
1515
import sys
16-
from typing import Dict
1716

1817
if __name__ == "__main__" and __package__ is None:
1918
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
2019

2120
# local imports here
22-
from osg_configure.modules.ce_attributes import BATCH_SYSTEMS, BATCH_SYSTEMS_CASE_MAP
23-
from osg_configure.modules.exceptions import Error, SettingError
24-
from osg_configure.modules import subcluster
25-
from osg_configure.modules import utilities
21+
from osg_configure.modules.ce_attributes import BATCH_SYSTEMS, get_attributes
22+
from osg_configure.modules.exceptions import Error
2623
from osg_configure.version import __version__
2724

2825

@@ -51,86 +48,6 @@ def load_configs(config_location: str) -> ConfigParser:
5148
return config
5249

5350

54-
def empty_if_blank(value: str) -> str:
55-
return "" if utilities.blank(value) else value
56-
57-
58-
def get_resource_from_config(config: ConfigParser) -> str:
59-
return utilities.classad_quote(
60-
empty_if_blank(
61-
config.get("Site Information", "resource", fallback="")
62-
)
63-
)
64-
65-
66-
def get_resource_group_from_config(config: ConfigParser) -> str:
67-
return utilities.classad_quote(
68-
empty_if_blank(
69-
config.get("Site Information", "resource_group", fallback="")
70-
)
71-
)
72-
73-
74-
def get_batch_systems_from_config(config: ConfigParser) -> str:
75-
batch_systems = []
76-
77-
siteinfo_batch_systems = config.get("Site Information", "batch_systems", fallback=None)
78-
if siteinfo_batch_systems is not None:
79-
# Site Information.batch_systems specified -- this one wins
80-
split_batch_systems = utilities.split_comma_separated_list(siteinfo_batch_systems)
81-
for batch_system in split_batch_systems:
82-
try:
83-
batch_systems.append(BATCH_SYSTEMS_CASE_MAP[batch_system.lower()])
84-
except KeyError:
85-
raise SettingError("Unrecognized batch system %s" % batch_system)
86-
else:
87-
# Add each batch system that's enabled from the sections in the 20-*.ini files.
88-
for batch_system in BATCH_SYSTEMS:
89-
if batch_system in config:
90-
if config.getboolean(section=batch_system, option="enabled", fallback=None):
91-
batch_systems.append(batch_system)
92-
93-
# Special case: Bosco (see SOFTWARE-3720); use the Bosco.batch argument.
94-
if config.getboolean("Bosco", "enabled", fallback=False):
95-
bosco_batch = config.get("Bosco", "batch", fallback=None)
96-
if bosco_batch:
97-
try:
98-
batch_systems.append(BATCH_SYSTEMS_CASE_MAP[bosco_batch.lower()])
99-
except KeyError:
100-
raise SettingError("Unrecognized batch system %s in Bosco section" % bosco_batch)
101-
102-
return utilities.classad_quote(",".join(batch_systems))
103-
104-
105-
def get_resource_catalog_from_config(config: ConfigParser) -> str:
106-
return subcluster.resource_catalog_from_config(config, default_allowed_vos=[]).format_value()
107-
108-
109-
def get_attributes(config: ConfigParser) -> Dict[str, str]:
110-
"""Turn config from .ini files into a dict of condor settings.
111-
112-
"""
113-
attributes = {}
114-
115-
resource = get_resource_from_config(config)
116-
if resource and resource != '""':
117-
attributes["OSG_Resource"] = resource
118-
119-
resource_group = get_resource_group_from_config(config)
120-
if resource_group and resource_group != '""':
121-
attributes["OSG_ResourceGroup"] = resource_group
122-
123-
batch_systems = get_batch_systems_from_config(config)
124-
if batch_systems and batch_systems != '""':
125-
attributes["OSG_BatchSystems"] = batch_systems
126-
127-
resource_catalog = get_resource_catalog_from_config(config)
128-
if resource_catalog and resource_catalog != "{}":
129-
attributes["OSG_ResourceCatalog"] = resource_catalog
130-
131-
return attributes
132-
133-
13451
def get_options(args):
13552
"""Parse, validate, and transform command-line options."""
13653
parser = ArgumentParser(prog="osg-ca-attrib-gen", description=__doc__)

0 commit comments

Comments
 (0)