Skip to content

Commit e482b4b

Browse files
committed
Add migrate command to ease migration
1 parent cbef12a commit e482b4b

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

caso/_cmd/projects.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,57 @@
2222
import caso.config
2323
import caso.manager
2424

25+
cli_opts = [
26+
cfg.BoolOpt(
27+
"migrate-projects",
28+
default=False,
29+
help="Migrate also the project list to Keystone tags (i.e. stop using the "
30+
"'projects' option in the configuration file).",
31+
),
32+
]
33+
2534
CONF = cfg.CONF
35+
CONF.register_cli_opts(cli_opts)
36+
37+
38+
def migrate():
39+
"""Migrate cASO VO file mapping to Keystone-based configuration."""
40+
caso.config.parse_args(sys.argv)
41+
log.setup(cfg.CONF, "caso")
42+
43+
CONF.set_default("dry_run", True)
44+
manager = caso.manager.Manager()
45+
if CONF.dry_run:
46+
print(
47+
"WARNING: Running in 'dry-run' mode, no actions will be peformed. If you "
48+
"want to apply the changes, run with '--nodry-run'. Be aware that in "
49+
"that case the cASO user will need write access to Keystone. If unsure "
50+
"run the following commands as admin."
51+
)
52+
53+
manager._load_managers()
54+
for prj, vo in manager.extractor_manager.voms_map.items():
55+
if CONF.dry_run:
56+
print(f"openstack project set --property {CONF.vo_property}={vo} {prj}")
57+
else:
58+
try:
59+
kw = {CONF.vo_property: vo}
60+
manager.extractor_manager.keystone.projects.update(prj, **kw)
61+
except Exception as e:
62+
print(f"ERROR: could not add property for project {prj}.")
63+
print(f"ERROR: {e}")
64+
65+
if CONF.migrate_projects:
66+
for prj in CONF.projects:
67+
if CONF.dry_run:
68+
print(f"openstack project set --tag {CONF.caso_tag} {prj}")
69+
else:
70+
try:
71+
project = manager.extractor_manager.keystone.projects.get(prj)
72+
project.add_tag(CONF.caso_tag)
73+
except Exception as e:
74+
print(f"ERROR: could not add tag for project {prj}.")
75+
print(f"ERROR: {e}")
2676

2777

2878
def main():

caso/extract/manager.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
deprecated_for_removal=True,
5858
deprecated_reason="This option is marked for removal in the next release. "
5959
"Please see the release notes, and migrate your current configuration "
60-
"to use the project_mapping file as soon as possible.",
60+
"to use the new project mapping as soon as possible. If you already migrated "
61+
"your configuration, please remove the JSON file to get rid of this message.",
6162
help="File containing the VO <-> project mapping as used in Keystone-VOMS.",
6263
),
6364
cfg.StrOpt(
@@ -162,6 +163,9 @@ def voms_map(self):
162163
if self._voms_map:
163164
return self._voms_map
164165

166+
if not os.path.exists(CONF.mapping_file):
167+
return {}
168+
165169
try:
166170
mapping = json.loads(open(CONF.mapping_file).read())
167171
except ValueError:

etc/caso/caso.conf.sample

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
# This option is deprecated for removal.
4747
# Its value may be silently ignored in the future.
4848
# Reason: This option is marked for removal in the next release. Please see the
49-
# release notes, and migrate your current configuration to use the
50-
# project_mapping file as soon as possible.
49+
# release notes, and migrate your current configuration to use the new project
50+
# mapping as soon as possible. If you already migrated your configuration,
51+
# please remove the JSON file to get rid of this message.
5152
#mapping_file = /etc/caso/voms.json
5253

5354
# Extract record changes until this date. If it is not set, we use now. If a

releasenotes/notes/deprecate-voms-mapping-80cfda2246ec43e9.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ features:
77
deprecations:
88
- |
99
The VO mapping file is now deprecated, in favour of project properties.
10+
upgrade:
11+
- |
12+
It is reccomended that you stop using the Keystone voms mapping file as
13+
soon as possible, please migrate your old JSON mapping to the new method
14+
using Keystone project's properties. In order to do so, you can use the
15+
``caso-mapping-migrate`` command line option, that will provide you with
16+
the correct commands to run to perform the migration.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ oslo.config.opts =
4747
console_scripts =
4848
caso-extract = caso._cmd.extract:main
4949
caso-projects = caso._cmd.projects:main
50+
caso-mapping-migrate = caso._cmd.projects:migrate
5051

5152
caso.extractors =
5253
nova = caso.extract.openstack.nova:NovaExtractor

0 commit comments

Comments
 (0)