From fb7e2c11027dd52b895a377f64212baa9faa97fa Mon Sep 17 00:00:00 2001 From: Chang Bo Guo Date: Wed, 6 Nov 2013 05:05:05 -0800 Subject: [PATCH] Don't use deprecated module commands The commands module was deprecated since version 2.6 and it has been removed in Python 3. See http://docs.python.org/2/library/commands#module-commands Closes-Bug: #1248216 Change-Id: I0ae40c7683ca58ede75f493d020e5c80a6434fef --- nova/tests/db/test_migrations.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/nova/tests/db/test_migrations.py b/nova/tests/db/test_migrations.py index 1922e259062b..54fa3b0f6842 100644 --- a/nova/tests/db/test_migrations.py +++ b/nova/tests/db/test_migrations.py @@ -43,7 +43,6 @@ postgres=# create database openstack_baremetal_citest with owner """ -import commands import ConfigParser import datetime import glob @@ -58,6 +57,7 @@ import nova.db.sqlalchemy.migrate_repo from nova.db.sqlalchemy import utils as db_utils from nova.openstack.common.gettextutils import _ from nova.openstack.common import log as logging +from nova.openstack.common import processutils from nova.openstack.common import timeutils from nova.openstack.common import uuidutils from nova import test @@ -254,9 +254,10 @@ class BaseMigrationTestCase(test.NoDBTestCase): self._create_databases() def execute_cmd(self, cmd=None): - status, output = commands.getstatusoutput(cmd) + out, err = processutils.trycmd(cmd, shell=True, discard_warnings=True) + output = out or err LOG.debug(output) - self.assertEqual(0, status, + self.assertEqual('', err, "Failed to run: %s\n%s" % (cmd, output)) @utils.synchronized('pgadmin', external=True) @@ -336,11 +337,14 @@ class BaseMigrationTestCase(test.NoDBTestCase): sql = ("create database if not exists %s;") % database createtable = sqlcmd % {'user': user, 'host': host, 'sql': sql} - status, output = commands.getstatusoutput(createtable) - if status != 0 and status != 256: - # 0 means databases is created - # 256 means it already exists (which is fine) - # otherwise raise an error + # 0 means databases is created + # 256 means it already exists (which is fine) + # otherwise raise an error + out, err = processutils.trycmd(createtable, shell=True, + check_exit_code=[0, 256], + discard_warnings=True) + output = out or err + if err != '': self.fail("Failed to run: %s\n%s" % (createtable, output)) os.unsetenv('PGPASSWORD')