Skip to content

Commit 6595271

Browse files
committed
Use Keystone properties to load VO mapping.
Mark as deprecated the usage of mapping file, and load from Keystone properties the VO mapping, removing the need of maintaining a different file. Sem-Ver: deprecation Sem-Ver: feature
1 parent 920b791 commit 6595271

File tree

5 files changed

+69
-13
lines changed

5 files changed

+69
-13
lines changed

caso/extract/base.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
"mapping_file",
4747
default="/etc/caso/voms.json",
4848
deprecated_group="extractor",
49-
help="File containing the VO <-> project mapping as used " "in Keystone-VOMS.",
49+
deprecated_for_removal=True,
50+
deprecated_reason="This option is marked for removal in the next release. "
51+
"Please see the release notes, and migrate your current configuration "
52+
"to use the project_mapping file as soon as possible.",
53+
help="File containing the VO <-> project mapping as used in Keystone-VOMS.",
5054
),
5155
]
5256

@@ -144,14 +148,17 @@ def __init__(self, project):
144148
"""Initialize extractor, loading the VO map."""
145149
self.project = project
146150

151+
@property
152+
def voms_map(self):
153+
"""Get the VO map."""
147154
# FIXME(remove this)
148155
try:
149156
mapping = json.loads(open(CONF.mapping_file).read())
150157
except ValueError:
151158
# FIXME(aloga): raise a proper exception here
152159
raise
153160
else:
154-
self.voms_map = {}
161+
voms_map = {}
155162
for vo, vomap in six.iteritems(mapping):
156163
tenant = vomap.get("tenant", None)
157164
tenants = vomap.get("tenants", [])
@@ -172,7 +179,8 @@ def __init__(self, project):
172179
if not projects:
173180
LOG.warning(f"No project mapping found for VO {vo}")
174181
for project in projects:
175-
self.voms_map[project] = vo
182+
voms_map[project] = vo
183+
return voms_map
176184

177185
def vm_status(self, status):
178186
"""Return the status corresponding to the OpenStack status.

caso/extract/openstack/base.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
"extract records from a specific OpenStack Region, if "
3636
"there are several defined in the OpenStack site. "
3737
"Defaults to None.",
38-
)
38+
),
39+
cfg.StrOpt(
40+
"vo_property",
41+
default="accounting:VO",
42+
help="Property key used to get the VO name from the project properties. ",
43+
),
3944
]
4045

4146
CONF.register_opts(opts)
@@ -50,11 +55,11 @@ def __init__(self, project):
5055
"""Initialize the OpenStack extractor for a given project."""
5156
super(BaseOpenStackExtractor, self).__init__(project)
5257

53-
self.vo = self._get_vo()
54-
5558
self.keystone = self._get_keystone_client()
5659
self.project_id = self._get_project_id()
5760

61+
self.vo = self._get_vo()
62+
5863
class Users:
5964
def __init__(self, parent):
6065
self._users = {}
@@ -111,11 +116,29 @@ def _get_keystone_user(self, uuid):
111116

112117
def _get_vo(self):
113118
"""Get the VO where the project should be mapped."""
114-
vo = self.voms_map.get(self.project)
119+
project = self.keystone.projects.get(self.project)
120+
project.get()
121+
vo = project.to_dict().get(CONF.vo_property, None)
115122
if vo is None:
116123
LOG.warning(
117-
"No mapping could be found for project "
118-
f"'{self.project}', please check mapping file!"
124+
f"No mapping could be found for project '{self.project}' in the "
125+
"Keystone project metadata, please check cASO documentation."
126+
)
127+
vo = self.voms_map.get(self.project, None)
128+
if vo is None:
129+
LOG.warning(
130+
"No mapping could be found for project "
131+
f"'{self.project}', please check mapping file!"
132+
)
133+
else:
134+
LOG.warning(
135+
"Using deprecated mapping file, please check cASO documentation "
136+
"and migrate to Keystone properties as soon as possible."
137+
)
138+
else:
139+
LOG.debug(
140+
f"Found VO mapping ({vo}) in Keystone project '{self.project}' "
141+
"metadata."
119142
)
120143
return vo
121144

doc/source/configuration.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ result from the merge of both methods, so thay are not mutually exclusive.
8686
* Using the ``projects`` list in the ``[DEFAULT]`` section of your configuration file
8787
(see below).
8888

89+
Setting VO mapping
90+
------------------
91+
92+
In order to publish correct accounting records, ``cASO`` needs to know the VO that
93+
should be used to publish the records from a given project. In order to do so, you need
94+
to specify the correct mapping in each of the projects properties. The name of the
95+
property that will be used is defined in the ``vo_property`` configuration option, and
96+
defaults to ``accounting:VO``, therefore you can configure it as follows::
97+
98+
openstack project set --property acconting:VO=<VO FQAN> <project id>
99+
89100
cASO configuration
90101
==================
91102

@@ -128,8 +139,8 @@ of every option. You should check at least the following options:
128139

129140
Note that there might be other messengers available in the system if they are
130141
registered into the ``caso.messenger`` entry point namespace.
131-
* ``mapping_file`` (default: ``/etc/caso/voms.json``). File containing the
132-
mapping from VOs to local projects as configured in Keystone-VOMS, in the
142+
* **DEPRECATED** ``mapping_file`` (default: ``/etc/caso/voms.json``). File containing
143+
the mapping from VOs to local projects as configured in Keystone-VOMS, in the
133144
following form::
134145

135146
{

etc/caso/caso.conf.sample

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@
3737
# Tag used to mark a project in Keystone to be extracted by cASO (string value)
3838
#caso_tag = caso
3939

40-
# File containing the VO <-> project mapping as used in Keystone-VOMS. (string
41-
# value)
40+
# DEPRECATED: File containing the VO <-> project mapping as used in Keystone-
41+
# VOMS. (string value)
42+
# This option is deprecated for removal.
43+
# Its value may be silently ignored in the future.
44+
# Reason: This option is marked for removal in the next release. Please see the
45+
# release notes, and migrate your current configuration to use the
46+
# project_mapping file as soon as possible.
4247
#mapping_file = /etc/caso/voms.json
4348

4449
# Extract record changes until this date. If it is not set, we use now. If a
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- |
4+
Allow loading VO mapping directly from Keystone. Instead of mainitaining a
5+
separate file, we now allow users to load the VO directly from a configurable
6+
project property.
7+
deprecations:
8+
- |
9+
The VO mapping file is now deprecated, in favour of project properties.

0 commit comments

Comments
 (0)