def setUp(self): """Update postgres timezone and create a deployment.""" super(TimezoneTest, self).setUp() postgres_conf = get_postgres_conf() run_query( self.env.container_id, "ALTER USER {} SET TIME ZONE '{}'" .format(postgres_conf.username, self.TIMEZONE) )
def setUpClass(cls): """Configure database timezone.""" super(EventsAlternativeTimezoneTest, cls).setUpClass() # Container is launched once per unittest.TestCase class. # Timezone configuration just needs to updated at the class level. # Between tests cases tables are re-created, # but timezone configuration is preserved. postgres_conf = get_postgres_conf() run_query("ALTER USER {} SET TIME ZONE '{}'".format( postgres_conf.username, cls.TIMEZONE))
def setUpClass(cls): """Configure database timezone.""" super(EventsAlternativeTimezoneTest, cls).setUpClass() # Container is launched once per unittest.TestCase class. # Timezone configuration just needs to updated at the class level. # Between tests cases tables are re-created, # but timezone configuration is preserved. postgres_conf = get_postgres_conf() run_query( "ALTER USER {} SET TIME ZONE '{}'" .format(postgres_conf.username, cls.TIMEZONE) )
def setUpClass(cls): """Configure database timezone.""" super(EventsAlternativeTimezoneTest, cls).setUpClass() # Container is launched once per unittest.TestCase class. # Timezone configuration just needs to updated at the class level. # Between tests cases tables are re-created, # but timezone configuration is preserved. postgres_conf = get_postgres_conf() run_query("ALTER USER {} SET TIME ZONE '{}'".format( postgres_conf.username, cls.TIMEZONE)) # restart all users of the db so that they get a new session which # uses the just-set timezone docl.execute( "systemctl restart cloudify-amqp-postgres cloudify-restservice")
def run_query(container_id, query, db_name=None, fetch_results=True): conf = get_postgres_conf() manager_ip = docker.get_manager_ip(container_id) db_name = db_name or conf.db_name with psycopg2.connect(database=db_name, user=conf.username, password=conf.password, host=manager_ip) as con: con.autocommit = True logger.info('Trying to execute SQL query: ' + query) with closing(con.cursor()) as cur: try: cur.execute(query) fetchall = cur.fetchall() if fetch_results else None status_message = 'ok' except Exception as e: fetchall = None status_message = str(e) return {'status': status_message, 'all': fetchall}
def run_query(query, db_name=None): conf = get_postgres_conf() manager_ip = utils.get_manager_ip() db_name = db_name or conf.db_name with psycopg2.connect(database=db_name, user=conf.username, password=conf.password, host=manager_ip) as con: con.autocommit = True logger.info('Trying to execute SQL query: ' + query) with closing(con.cursor()) as cur: try: cur.execute(query) fetchall = cur.fetchall() status_message = 'ok' except Exception, e: fetchall = None status_message = str(e) return {'status': status_message, 'all': fetchall}
def run_query(query, db_name=None): conf = get_postgres_conf() manager_ip = utils.get_manager_ip() db_name = db_name or conf.db_name with closing(pg8000.connect(database=db_name, user=conf.username, password=conf.password, host=manager_ip)) as con: con.autocommit = True logger.info('Trying to execute SQL query: ' + query) with closing(con.cursor()) as cur: try: cur.execute(query) fetchall = cur.fetchall() status_message = 'ok' except Exception, e: fetchall = None status_message = str(e) return {'status': status_message, 'all': fetchall}