def test_keep_warnings(self):
     self.useFixture(
         fixtures.MonkeyPatch('oslo_concurrency.processutils.execute',
                              fake_execute))
     o, e = processutils.trycmd('this is a command'.split(' '))
     self.assertNotEqual('', o)
     self.assertNotEqual('', e)
Exemplo n.º 2
0
 def test_discard_warnings(self):
     self.useFixture(fixtures.MonkeyPatch(
         'oslo_concurrency.processutils.execute', fake_execute))
     o, e = processutils.trycmd('this is a command'.split(' '),
                                discard_warnings=True)
     self.assertIsNotNone(o)
     self.assertEqual('', e)
Exemplo n.º 3
0
 def test_discard_warnings(self):
     self.useFixture(fixtures.MonkeyPatch(
         'oslo_concurrency.processutils.execute', fake_execute))
     o, e = processutils.trycmd('this is a command'.split(' '),
                                discard_warnings=True)
     self.assertIsNotNone(o)
     self.assertEqual('', e)
Exemplo n.º 4
0
    def _create_database(self, key):
        """Create database if it doesn't exist."""
        conn_string = self.test_databases[key]
        conn_pieces = urlparse.urlparse(conn_string)

        if conn_string.startswith('mysql'):
            (user, password, database, host) = \
                get_mysql_connection_info(conn_pieces)
            sql = "create database if not exists %s;" % database
            cmd = ("mysql -u \"%(user)s\" %(password)s -h %(host)s "
                   "-e \"%(sql)s\"" % {
                       'user': user,
                       'password': password,
                       'host': host,
                       'sql': sql
                   })
            self.execute_cmd(cmd)
        elif conn_string.startswith('postgresql'):
            (user, password, database, host) = \
                get_pgsql_connection_info(conn_pieces)
            os.environ['PGPASSWORD'] = password
            os.environ['PGUSER'] = user

            sqlcmd = ("psql -w -U %(user)s -h %(host)s -c"
                      " '%(sql)s' -d postgres")

            sql = ("create database if not exists %s;") % database
            createtable = sqlcmd % {'user': user, 'host': host, 'sql': sql}
            # 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')
            os.unsetenv('PGUSER')
Exemplo n.º 5
0
    def _create_database(self, key):
        """Create database if it doesn't exist."""
        conn_string = self.test_databases[key]
        conn_pieces = urlparse.urlparse(conn_string)

        if conn_string.startswith('mysql'):
            (user, password, database, host) = \
                get_mysql_connection_info(conn_pieces)
            sql = "create database if not exists %s;" % database
            cmd = ("mysql -u \"%(user)s\" %(password)s -h %(host)s "
                   "-e \"%(sql)s\"" % {'user': user, 'password': password,
                                       'host': host, 'sql': sql})
            self.execute_cmd(cmd)
        elif conn_string.startswith('postgresql'):
            (user, password, database, host) = \
                get_pgsql_connection_info(conn_pieces)
            os.environ['PGPASSWORD'] = password
            os.environ['PGUSER'] = user

            sqlcmd = ("psql -w -U %(user)s -h %(host)s -c"
                      " '%(sql)s' -d postgres")

            sql = ("create database if not exists %s;") % database
            createtable = sqlcmd % {'user': user, 'host': host, 'sql': sql}
            # 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')
            os.unsetenv('PGUSER')
Exemplo n.º 6
0
 def execute_cmd(self, cmd=None):
     out, err = processutils.trycmd(cmd, shell=True, discard_warnings=True)
     output = out or err
     LOG.debug(output)
     self.assertEqual('', err,
                      "Failed to run: %s\n%s" % (cmd, output))
Exemplo n.º 7
0
def trycmd(*args, **kwargs):
    """Convenience wrapper around oslo's trycmd() method."""
    if kwargs.get('run_as_root') and 'root_helper' not in kwargs:
        kwargs['root_helper'] = _get_root_helper()
    return processutils.trycmd(*args, **kwargs)
Exemplo n.º 8
0
def trycmd(*args, **kwargs):
    """Convenience wrapper around oslo's trycmd() method."""
    if 'run_as_root' in kwargs and 'root_helper' not in kwargs:
        kwargs['root_helper'] = _get_root_helper()
    return processutils.trycmd(*args, **kwargs)
Exemplo n.º 9
0
 def test_keep_warnings(self):
     self.useFixture(fixtures.MonkeyPatch(
         'oslo_concurrency.processutils.execute', fake_execute))
     o, e = processutils.trycmd('this is a command'.split(' '))
     self.assertNotEqual('', o)
     self.assertNotEqual('', e)
Exemplo n.º 10
0
 def execute_cmd(self, cmd=None):
     out, err = processutils.trycmd(cmd, shell=True, discard_warnings=True)
     output = out or err
     LOG.debug(output)
     self.assertEqual('', err, "Failed to run: %s\n%s" % (cmd, output))
Exemplo n.º 11
0
def trycmd(*args, **kwargs):
    """Convenience wrapper around oslo's trycmd() method."""
    return processutils.trycmd(*args, **kwargs)