| 1047 | self._conn.cancel() |
| 1048 | |
| 1049 | def _connect(self): |
| 1050 | try: |
| 1051 | import psycopg2 |
| 1052 | except ImportError as e: |
| 1053 | if "No module named psycopg2" not in str(e): |
| 1054 | raise e |
| 1055 | import os |
| 1056 | import subprocess |
| 1057 | from tests.util.shell_util import shell |
| 1058 | LOG.info("psycopg2 module not found; attempting to install it...") |
| 1059 | pip_path = os.path.join(os.environ["IMPALA_HOME"], "infra", "python", "env", |
| 1060 | "bin", "pip") |
| 1061 | try: |
| 1062 | shell(pip_path + " install psycopg2", stdout=subprocess.PIPE, |
| 1063 | stderr=subprocess.STDOUT) |
| 1064 | LOG.info("psycopg2 installation complete.") |
| 1065 | except Exception as e: |
| 1066 | LOG.error("psycopg2 installation failed. Try installing python-dev and" |
| 1067 | " libpq-dev then try again.") |
| 1068 | raise e |
| 1069 | import psycopg2 |
| 1070 | self._conn = psycopg2.connect( |
| 1071 | host=self._host_name, |
| 1072 | port=self._port, |
| 1073 | user=self._user_name, |
| 1074 | password=self._password, |
| 1075 | database=self.db_name) |
| 1076 | self._conn.autocommit = True |
| 1077 | |
| 1078 | |
| 1079 | class MySQLConnection(DbConnection): |