apache / trafficcontrol

Apache Traffic Control is an Open Source implementation of a Content Delivery Network
https://trafficcontrol.apache.org/
Apache License 2.0
1.02k stars 339 forks source link

TO Postinstall: NameError: name 'Pg' is not defined #6394

Open zrhoffman opened 2 years ago

zrhoffman commented 2 years ago

This Bug Report affects these Traffic Control components:

Current behavior:

Running the Postinstall script using terminal (instead of input.json) input under Python 2 fails:

[user@host trafficcontrol]$ cd traffic_ops/install/bin
[user@host bin]$ <<<Pg sudo python2 _postinstall.py
INFO:root:Starting postinstall
INFO:root:Debug is on
INFO:root:No input file given - using defaults
INFO:root:===========/opt/traffic_ops/app/conf/production/database.conf===========
Database type [Pg]: Traceback (most recent call last):
  File "_postinstall.py", line 1528, in <module>
    ARGS.no_database
  File "_postinstall.py", line 1293, in main
    dbconf = generate_db_conf(user_input[DATABASE_CONF_FILE], DATABASE_CONF_FILE, automatic, root_dir)
  File "_postinstall.py", line 330, in generate_db_conf
    db_conf = get_config(qstns, fname, automatic)
  File "_postinstall.py", line 318, in get_config
    answer = question.default if automatic else question.ask()
  File "_postinstall.py", line 146, in ask
    ipt = input(self)
  File "<string>", line 1, in <module>
NameError: name 'Pg' is not defined

Expected behavior:

Running the Postinstall script using terminal (instead of input.json) input under Python 2 should succeed and have test coverage.

ocket8888 commented 2 years ago

This is because in The Dead Language, input is compiling and running the received input as though it were a Python script. So, equivalently eval("Pg"). The Dead Language's equivalent of input is raw_input, but that returns a str not a unicode which is what str is redefined to, so there also needs to be a cast there. Probably needs a shim like

if language_is_dead:
    def input(*args):
        if len(args) > 1:
            raise TypeError("input expected at most 1 argument, got " + str(len(args)))
        return unicode(raw_input(*args))