]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
vstart_runner.py: add methods for negative testing a cmd
authorRishabh Dave <ridave@redhat.com>
Thu, 13 Feb 2020 13:12:02 +0000 (18:42 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 16 Apr 2020 18:58:20 +0000 (00:28 +0530)
Methods like run_shell effectively conduct positive test on the given
command. Add methods that runs given command expecting failure and then
verifies return value and error message with given one. Rewrite testcmd,
testcmd_as_user and testcmd_as_root to create these new methods for
negative testing since run_shell, run_as_user and run_as_root is
equivalent of running positive test.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
qa/tasks/cephfs/mount.py

index 03fb38cf60edf72f3fdf421672055e619b8ebe60..07dd82f9aeda2fafcf5cb5bf35d0c4570e1086eb 100644 (file)
@@ -238,6 +238,46 @@ class CephFSMount(object):
                                       stdout=BytesIO(), stderr=BytesIO(),
                                       check_status=check_status, cwd=cwd)
 
+    def _verify(self, proc, retval=None, errmsg=None):
+        if retval:
+            msg = ('expected return value: {}\nreceived return value: '
+                   '{}\n'.format(retval, proc.returncode))
+            assert proc.returncode == retval, msg
+
+        if errmsg:
+            stderr = proc.stderr.getvalue().lower()
+            msg = ('didn\'t find given string in stderr -\nexpected string: '
+                   '{}\nreceived error message: {}\nnote: received error '
+                   'message is converted to lowercase'.format(errmsg, stderr))
+            assert errmsg in stderr, msg
+
+    def negtestcmd(self, args, retval=None, errmsg=None, stdin=None,
+                   cwd=None, wait=True):
+        """
+        Conduct a negative test for the given command.
+
+        retval and errmsg are parameters to confirm the cause of command
+        failure.
+        """
+        proc = self.run_shell(args=args, wait=wait, stdin=stdin, cwd=cwd,
+                              check_status=False)
+        self._verify(proc, retval, errmsg)
+        return proc
+
+    def negtestcmd_as_user(self, args, user, retval=None, errmsg=None,
+                           stdin=None, cwd=None, wait=True):
+        proc = self.run_as_user(args=args, user=user, wait=wait, stdin=stdin,
+                                cwd=cwd, check_status=False)
+        self._verify(proc, retval, errmsg)
+        return proc
+
+    def negtestcmd_as_root(self, args, retval=None, errmsg=None, stdin=None,
+                           cwd=None, wait=True):
+        proc = self.run_as_root(args=args, wait=wait, stdin=stdin, cwd=cwd,
+                                check_status=False)
+        self._verify(proc, retval, errmsg)
+        return proc
+
     def open_no_data(self, basename):
         """
         A pure metadata operation