Merge "Fix to enable negative test image_invalid_metadata"
diff --git a/cli/__init__.py b/cli/__init__.py
index 7a92260..a3038d2 100644
--- a/cli/__init__.py
+++ b/cli/__init__.py
@@ -87,6 +87,15 @@
         flags = creds + ' ' + flags
         return self.cmd(cmd, action, flags, params, fail_ok)
 
+    def check_output(self, cmd, **kwargs):
+        # substitutes subprocess.check_output which is not in python2.6
+        kwargs['stdout'] = subprocess.PIPE
+        proc = subprocess.Popen(cmd, **kwargs)
+        output = proc.communicate()[0]
+        if proc.returncode != 0:
+            raise CommandFailed(proc.returncode, cmd, output)
+        return output
+
     def cmd(self, cmd, action, flags='', params='', fail_ok=False,
             merge_stderr=False):
         """Executes specified command for the given action."""
@@ -96,10 +105,10 @@
         cmd = shlex.split(cmd)
         try:
             if merge_stderr:
-                result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+                result = self.check_output(cmd, stderr=subprocess.STDOUT)
             else:
-                devnull = open('/dev/null', 'w')
-                result = subprocess.check_output(cmd, stderr=devnull)
+                with open('/dev/null', 'w') as devnull:
+                    result = self.check_output(cmd, stderr=devnull)
         except subprocess.CalledProcessError, e:
             LOG.error("command output:\n%s" % e.output)
             raise
@@ -110,3 +119,10 @@
         for item in items:
             for field in field_names:
                 self.assertIn(field, item)
+
+
+class CommandFailed(subprocess.CalledProcessError):
+    # adds output attribute for python2.6
+    def __init__(self, returncode, cmd, output):
+        super(CommandFailed, self).__init__(returncode, cmd)
+        self.output = output
diff --git a/tempest/test.py b/tempest/test.py
index ccb2251..b0038e0 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -56,6 +56,11 @@
         #NOTE(afazekas): inspection workaround
         BaseTestCase.config = config.TempestConfig()
 
+    @classmethod
+    def setUpClass(cls):
+        if hasattr(super(BaseTestCase, cls), 'setUpClass'):
+            super(BaseTestCase, cls).setUpClass()
+
 
 class TestCase(BaseTestCase):
     """Base test case class for all Tempest tests