18224 pkg verify can traceback on unmatched or invalid package names
authorShawn Walker <shawn.walker@oracle.com>
Fri, 29 Apr 2011 11:48:22 -0700
changeset 2318 42b68ea03c9e
parent 2317 5f86408f56d1
child 2319 247375ff5e19
18224 pkg verify can traceback on unmatched or invalid package names
src/client.py
src/tests/cli/t_pkg_verify.py
--- a/src/client.py	Thu Apr 28 16:11:08 2011 -0700
+++ b/src/client.py	Fri Apr 29 11:48:22 2011 -0700
@@ -834,8 +834,6 @@
                 if e.illegal:
                         for i in e.illegal:
                                 error(i)
-                        api_inst.log_operation_end(
-                            result=history.RESULT_FAILED_BAD_REQUEST)
                         return EXIT_OOPS
                 notfound = e.notfound
         except api_errors.ImageFormatUpdateNeeded, e:
--- a/src/tests/cli/t_pkg_verify.py	Thu Apr 28 16:11:08 2011 -0700
+++ b/src/tests/cli/t_pkg_verify.py	Fri Apr 29 11:48:22 2011 -0700
@@ -20,7 +20,7 @@
 # CDDL HEADER END
 #
 
-# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
 
 import testutils
 if __name__ == "__main__":
@@ -68,22 +68,13 @@
                 self.make_misc_files(self.misc_files)
                 self.pkgsend_bulk(self.rurl, self.foo10)
 
-        def test_pkg_verify_bad_opts(self):
+        def test_00_bad_opts(self):
                 """ test pkg verify with bad options """
 
                 self.image_create(self.rurl)
                 self.pkg("verify -vq", exit=2)
 
-        def test_bug_1463(self):
-                """When multiple FMRIs are given to pkg verify,
-                if any of them aren't installed it should fail."""
-
-                self.image_create(self.rurl)
-                self.pkg("install foo")
-                self.pkg("verify foo nonexistent", exit=1)
-                self.pkg("uninstall foo")
-
-        def test_0_verify(self):
+        def test_01_basics(self):
                 """Ensure that verify returns failure as expected when packages
                 are not correctly installed."""
 
@@ -163,6 +154,31 @@
                 # ...but it should not be treated as a fatal error.
                 self.pkg("verify foo")
 
+        def test_02_installed(self):
+                """When multiple FMRIs are given to pkg verify, if any of them
+                aren't installed it should fail."""
+
+                self.image_create(self.rurl)
+                self.pkg("install foo")
+                self.pkg("verify foo nonexistent", exit=1)
+                self.pkg("uninstall foo")
+
+        def test_03_invalid(self):
+                """Test that pkg verify handles invalid input gracefully."""
+
+                self.image_create(self.rurl)
+
+                # Verify invalid package causes graceful exit.
+                self.pkg("verify _not_valid", exit=1)
+
+                # Verify unmatched input fails gracefully.
+                self.pkg("verify no/such/package", exit=1)
+
+                # Verify invalid package name and unmatched input combined with
+                # installed package name results in graceful failure.
+                self.pkg("install foo")
+                self.pkg("verify _not_valid no/such/package foo", exit=1)
+
 
 if __name__ == "__main__":
         unittest.main()