Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--version and --help broken #846

Closed
themattman opened this issue Feb 23, 2022 · 1 comment
Closed

--version and --help broken #846

themattman opened this issue Feb 23, 2022 · 1 comment
Labels

Comments

@themattman
Copy link

themattman commented Feb 23, 2022

The argparse behavior requires mongod to be installed in PATH, otherwise the tool barfs.

Prior to parsing arguments, the MLaunchTool constructor requires getMongoDVersion() to return a valid value.

This exposes an underlying circular dependency between construction and argument parsing.

allowed arguments -> mongod version number -> binarypath argument

Expected behavior

The MLaunchTool should be capable of successfully running a few meta commands regardless of the existence of mongod in PATH.
e.g. The mtools version string gets printed or the help output of the script is printed

$ mlaunch --version
mtools version 1.7.0-dev || Python 3.9.2 (default, Jan 25 2022, 16:35:56) [GCC 7.5.0]
$ mlaunch --help
usage: mlaunch [-h] [--version] [--no-progressbar] {init,start,stop,restart,list,kill} ...

script to launch MongoDB stand-alone servers, replica sets and shards.

commands:
  init is the default command and can be omitted. To get help on individual commands, run mlaunch <command> --help. Command line arguments which are not handled by mlaunch will be passed
  through to mongod/mongos if those options are listed in the --help output for the current binary. For example: --storageEngine, --logappend, or --config.

  {init,start,stop,restart,list,kill}
    init                initialize a new MongoDB environment and start stand-alone instances, replica sets, or sharded clusters.
    start               starts existing MongoDB instances. Example: "mlaunch start config" will start all config servers.
    stop                stops running MongoDB instances. Example: "mlaunch stop shard 2 secondary" will stop all secondary nodes of shard 2.
    restart             stops, then restarts MongoDB instances.
    list                list MongoDB instances of this environment.
    kill                kills (or sends another signal to) MongoDB instances of this environment.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --no-progressbar      disables progress bar

Actual/current behavior

$ mlaunch --version
Failed to launch mongod
Traceback (most recent call last):
  File "/home/ubuntu/mongo/python3-venv/bin/mlaunch", line 33, in <module>
    sys.exit(load_entry_point('mtools==1.7.0.dev0', 'console_scripts', 'mlaunch')())
  File ".../mtools-1.7.0.dev0-py3.9.egg/mtools/mlaunch/mlaunch.py", line 2214, in main
    tool = MLaunchTool()
  File "/home/ubuntu/mongo/python3-venv/lib/python3.9/site-packages/mtools-1.7.0.dev0-py3.9.egg/mtools/mlaunch/mlaunch.py", line 198, in __init__
    self.current_version = self.getMongoDVersion()
  File ".../mtools-1.7.0.dev0-py3.9.egg/mtools/mlaunch/mlaunch.py", line 913, in getMongoDVersion
    out = check_mongo_server_output(binary, '--version')
  File "/home/ubuntu/mongo/python3-venv/lib/python3.9/site-packages/mtools-1.7.0.dev0-py3.9.egg/mtools/mlaunch/mlaunch.py", line 149, in check_mongo_server_output
    raise exc
  File ".../mtools-1.7.0.dev0-py3.9.egg/mtools/mlaunch/mlaunch.py", line 144, in check_mongo_server_output
    proc = subprocess.Popen(['%s' % binary, argument],
  File ".../stow/python3-v3.bmk/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File ".../stow/python3-v3.bmk/lib/python3.9/subprocess.py", line 1823, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'mongod'

Steps to reproduce the actual/current behavior

  1. Ensure mongod not in PATH
  2. Install mtools
  3. mlaunch --version or mlaunch --help

Environment

mtools version 1.7.0-dev || Python 3.9.2 (default, Jan 25 2022, 16:35:56) [GCC 7.5.0]

Software Version
mtools tip b96568cf
Python 3.9.2
MongoDB server local install / tip
Operating system Ubuntu 5.4.0-1059-aws
@themattman themattman changed the title Support prefixed installations --version and --help broken Feb 23, 2022
@stennie stennie added bug and removed question labels Feb 24, 2022
@stennie
Copy link
Collaborator

stennie commented Feb 24, 2022

Thanks for the bug report @themattman ! It has clearly been awhile since someone using mtools didn't have MongoDB in their path :P

Cheers,
Stennie

stennie added a commit to stennie/mtools that referenced this issue Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants