Repository: anchore/anchore-cli

Issue:
Deleting an image reports success even if the image can't be deleted
Starting anchore-engine v0.8.0 image deletion is an async op and the response has changed to reflect this. The API always responds with 200 HTTP status unless the service is unable to respond. Status and details of the delete op are in the body of the response. anchore-cli does not currently parse the body, it simply keys off of the HTTP status to indicate whether the deletion attempt was successful

Discussion:

Patch:
diff --git a/anchorecli/cli/image.py b/anchorecli/cli/image.py
index 2b6ba61..7607869 100644
--- a/anchorecli/cli/image.py
+++ b/anchorecli/cli/image.py
@@ -376,7 +376,7 @@ def delete(input_image, force, all):
                     ret = anchorecli.clients.apiexternal.delete_image(config, imageDigest=image['imageDigest'], force=force)
                     if ret['success']:
                         payload = ret.get('payload')
-                        if payload and payload.get('status') != 'deleting':
+                        if isinstance(payload, dict) and payload.get('status') != 'deleting':  # >= v.0.8.8
                             raise Exception(payload.get('detail'))
 
                         for image_detail in image['image_detail']:
@@ -406,7 +406,7 @@ def delete(input_image, force, all):
             if ret:
                 if ret['success']:
                     payload = ret.get('payload')
-                    if payload and payload.get('status') != 'deleting':
+                    if isinstance(payload, dict) and payload.get('status') != 'deleting':  # >= v.0.8.8
                         ecode = 1  # backwards compatibility with pre v0.8.0 error
                         raise Exception(payload.get('detail', 'cannot delete image'))
                     else:


Test patch:
diff --git a/tests/unit/cli/test_image.py b/tests/unit/cli/test_image.py
index 00fc7e5..b6ef091 100644
--- a/tests/unit/cli/test_image.py
+++ b/tests/unit/cli/test_image.py
@@ -127,7 +127,7 @@ class TestDeleteImage:
         monkeypatch.setattr(image.anchorecli.clients.apiexternal, 'delete_image', lambda *a, **kw: {
             'success': True,
             'httpcode': 200,
-            'payload': {},
+            'payload': True,
             'error': {}
         })
         runner = CliRunner()