From c381fefc494415768eb186ef0dd432dc3d02ff2c Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 30 Jan 2017 16:27:49 -0500 Subject: [PATCH] Give a friendlier message on restore of redact DB A redacted dump will not have a keys.json file, which is natural. Replace 'file not found' with a message indicating the possibility of a redacted dump. --- confluent_server/confluent/config/configmanager.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index 2876b9d0..10805ea7 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -1466,10 +1466,15 @@ def _dump_keys(password): def restore_db_from_directory(location, password): - with open(os.path.join(location, 'keys.json'), 'r') as cfgfile: - keydata = cfgfile.read() - json.loads(keydata) - _restore_keys(keydata, password) + try: + with open(os.path.join(location, 'keys.json'), 'r') as cfgfile: + keydata = cfgfile.read() + json.loads(keydata) + _restore_keys(keydata, password) + except IOError as e: + if e.errno == 2: + raise Exception("Cannot restore without keys, this may be a " + "redacted dump") with open(os.path.join(location, 'main.json'), 'r') as cfgfile: cfgdata = cfgfile.read() ConfigManager(tenant=None)._load_from_json(cfgdata)