Duplicated image id return 409 instead of 500 in API v2

Based on current code, in API v2 duplicated image id will
return HTTP 500 error instead of 409. This patch fix this
issue and add an unit test case for that.

Closes-Bug: 1366503

Change-Id: Ia6c27f9edffd63619d63013e456072d811daf127
Merge "Duplicated image id return 409 instead of 500 in API v2"