← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~j.kylmala/cloud-init:exceptions into cloud-init:master

 

Joonas Kylmälä has proposed merging ~j.kylmala/cloud-init:exceptions into cloud-init:master.

Commit message:
tools: Fix exception handling.

We should be expecting IndexError instead of KeyError because we are
using a list (key_ids) and not a dictionary. Also, thanks to Emmanuel
Kasper for pointing out the wrong response code.

LP: #1701527

Requested reviews:
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1701527 in cloud-init: "Exceptions in meta-mock.py need more care"
  https://bugs.launchpad.net/cloud-init/+bug/1701527

For more details, see:
https://code.launchpad.net/~j.kylmala/cloud-init/+git/cloud-init/+merge/327284
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~j.kylmala/cloud-init:exceptions into cloud-init:master.
diff --git a/tools/mock-meta.py b/tools/mock-meta.py
index f185dbf..a5d14ab 100755
--- a/tools/mock-meta.py
+++ b/tools/mock-meta.py
@@ -262,8 +262,8 @@ class MetaDataHandler(object):
                 except ValueError:
                     raise WebException(hclient.BAD_REQUEST,
                                        "%s: not an integer" % mybe_key)
-                except KeyError:
-                    raise WebException(hclient.BAD_REQUEST,
+                except IndexError:
+                    raise WebException(hclient.NOT_FOUND,
                                        "Unknown key id %r" % mybe_key)
                 # Extract the possible sub-params
                 result = traverse(nparams[1:], {

Follow ups