You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/02/24 18:22:49 UTC

[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5564: Python 2.7 support for Python postinstall script

zrhoffman commented on a change in pull request #5564:
URL: https://github.com/apache/trafficcontrol/pull/5564#discussion_r582195938



##########
File path: traffic_ops/install/bin/postinstall.py
##########
@@ -1167,34 +1338,41 @@ def main(
 			logging.critical("psql is not installed, please install it to continue with database setup")
 			return 1
 
-		try:
-			setup_database_data(conn_str, admin_conf, paramconf, root_dir)
-		except (OSError, subprocess.SubprocessError)as e:
+		def db_connect_failed():
 			logging.error("Failed to set up database: %s", e)
 			logging.error(
-				"Can't connect to the database.  " \
-				"Use the script `/opt/traffic_ops/install/bin/todb_bootstrap.sh` " \
+				"Can't connect to the database.  "
+				"Use the script `/opt/traffic_ops/install/bin/todb_bootstrap.sh` "
 				"on the db server to create it and run `postinstall` again."
 			)
+
+		try:
+			setup_database_data(conn_str, admin_conf, paramconf, root_dir)
+		except (OSError, subprocess.CalledProcessError)as e:
+			db_connect_failed()
+			return -1
+		except subprocess.SubprocessError as e:

Review comment:
       `subprocess.SubprocessError` is not defined in Python 2. Separating them like that prevent
   ```
   AttributeError: 'module' object has no attribute 'SubprocessError'
   ```
   in Python 2




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org