Added overwrite warning for db_export_metadefs.

The bug in [1] proposed to always require a directory option for
glance-manage db_export_metadefs command. The rationale being that
silently overwriting the default path /etc/glance/metadefs can
be undesired. However, the feedback was that this command should
stay silent in case it's called from cron jobs or automated tasks,
and that it's better to simply log a warning and proceed, as well
as update the documentation with a cautionary note. This patch
addresses that request.

[1] https://bugs.launchpad.net/glance/+bug/1367011

Change-Id: Ie8cc4bb3769a6347fd25e2235a72c6358af70d42
Closes-Bug: #1367011
This commit is contained in:
Alexander Bashmakov 2016-09-09 13:44:36 -07:00
parent b50cd90f65
commit 9968b0993f
2 changed files with 6 additions and 2 deletions

View File

@ -57,11 +57,13 @@ COMMANDS
Place a database under migration control and upgrade, creating
it first if necessary.
**db_export_metadefs**
**db_export_metadefs [PATH | PREFIX]**
Export the metadata definitions into json format. By default the
definitions are exported to /etc/glance/metadefs directory.
**Note: this command will overwrite existing files in the supplied or
default path.**
**db_load_metadefs**
**db_load_metadefs [PATH]**
Load the metadata definitions into glance database. By default the
definitions are imported from /etc/glance/metadefs directory.

View File

@ -464,6 +464,8 @@ def _export_data_to_file(meta, path):
try:
file_name = ''.join([path, namespace_file_name, '.json'])
if isfile(file_name):
LOG.info(_LI("Overwriting: %s"), file_name)
with open(file_name, 'w') as json_file:
json_file.write(json.dumps(values))
except Exception as e: