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

feat: implement basic "install" command #1

Merged
merged 7 commits into from
Nov 27, 2024
Merged

Conversation

infinitewarp
Copy link
Member

@infinitewarp infinitewarp commented Nov 20, 2024

This PR demonstrates a prototype for how we might build out commands for installing, maintaining, and troubleshooting a quipucords server through this quipucordsctl package/program. The overall design is intended to enable more commands to be added easily over time or to add specific commands only in certain environments. Commands are dynamically loaded from the commands package; so, a user could install additional custom commands there, or maybe we would add a setting to load additional commands from another path. Maybe discovery-ci could benefit from this, but I doubt many of our "real" customer users would be interested in writing custom commands. Maybe SEAP or SAs would having some unique ideas for commands? If they did, we'd probably ask to incorporate them into the project properly.

This program is not intended to replace qpc which is a client for the quipucords service. This program does not interact with the quipucords APIs; this program manages the installation itself like the old quipucords-installer does.

This PR uses only standard library functionality from Python. It uses Poetry to install development dependencies (ruff, pytest), but the actual runtime has no dependencies outside Python 3.12 itself. This is a deliberate design choice because this tool will eventually be downstreamed and packaged and shipped to RHEL repos, and we do not have a great variety of useful modern third-party Python libraries available there. This project may eventually vendor some small third-party dependencies, but that is a discussion for a future day.

This PR currently includes only a partially-working install command. Effectively, it just creates directories, copies files, and invokes two systemctl commands. The code does include several placeholders and TODO comments where I intend to continue expanding this work. Next steps, assuming we agree on this approach, would be to implement setting the server password and Django secret, applying the "overrides" templates, and adding an uninstall command. We would build a proper setup.py and spec file to make everything RPM-installable. At that point, we would have feature parity with the old quipucords-installer, and we could start implementing new commands for checking container status/health, getting logs, dumping the database, etc.

Also, unlike quipucords-installer, high unit test coverage. Finally. 🎉

Currently, you can invoke the program like this:

$ python3.12 -m quipucordsctl
usage: quipucordsctl [-h] [-v] [-q] [-c OVERRIDE_CONF_DIR] {install} ...

positional arguments:
  {install}
    install             Install the Quipucords server.

options:
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbose output
  -q, --quiet           Quiet output (overrides `-v`/`--verbose`)
  -c OVERRIDE_CONF_DIR, --override-conf-dir OVERRIDE_CONF_DIR
                        Override configuration directory
$ python3.12 -m quipucordsctl install
WARNING: quipucordsctl.commands.reset_server_password is not yet implemented.
WARNING: quipucordsctl.commands.reset_django_secret is not yet implemented.

Using multiple verbose flags drives the log level down (i.e. more output).

$ python3.12 -m quipucordsctl -vv install
INFO: Starting install command
WARNING: quipucordsctl.commands.reset_server_password is not yet implemented.
WARNING: quipucordsctl.commands.reset_django_secret is not yet implemented.
INFO: Generating config files
DEBUG: Ensuring data directory exists: /home/brasmith/.local/share/quipucords/data
DEBUG: Ensuring data directory exists: /home/brasmith/.local/share/quipucords/db
DEBUG: Ensuring data directory exists: /home/brasmith/.local/share/quipucords/log
DEBUG: Ensuring data directory exists: /home/brasmith/.local/share/quipucords/sshkeys
DEBUG: Ensuring config directory exists: /home/brasmith/.config/quipucords/env
DEBUG: Ensuring config directory exists: /home/brasmith/.config/containers/systemd
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/config/quipucords.network to /home/brasmith/.config/containers/systemd/quipucords.network
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/config/quipucords-db.container to /home/brasmith/.config/containers/systemd/quipucords-db.container
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/config/quipucords-celery-worker.container to /home/brasmith/.config/containers/systemd/quipucords-celery-worker.container
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/config/quipucords-app.container to /home/brasmith/.config/containers/systemd/quipucords-app.container
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/config/quipucords-redis.container to /home/brasmith/.config/containers/systemd/quipucords-redis.container
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/config/quipucords-server.container to /home/brasmith/.config/containers/systemd/quipucords-server.container
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/env/env-redis.env to /home/brasmith/.config/quipucords/env/env-redis.env
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/env/env-server.env to /home/brasmith/.config/quipucords/env/env-server.env
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/env/env-ansible.env to /home/brasmith/.config/quipucords/env/env-ansible.env
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/env/env-db.env to /home/brasmith/.config/quipucords/env/env-db.env
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/env/env-app.env to /home/brasmith/.config/quipucords/env/env-app.env
DEBUG: Copying /home/brasmith/projects/quipucordsctl/templates/env/env-celery-worker.env to /home/brasmith/.config/quipucords/env/env-celery-worker.env

Once we build setup.py and the spec file, the program would be invoked simply as quipucordsctl.

@infinitewarp infinitewarp changed the title feat: prototype "install" command feat: implement basic "install" command Nov 20, 2024
@infinitewarp infinitewarp force-pushed the 852-prototype branch 4 times, most recently from 0ad9a11 to b53226d Compare November 21, 2024 18:39
Copy link

codecov bot commented Nov 21, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

At this point, the "install" command simply copies the template files to the right places in the user's XDG directory tree and invokes the `systemctl` commands to reload the daemon to recognize the new/updated units. This basic functionality does not include any support for the "override" files. That will come later.

This commit also includes placeholder code for commands "reset_django_secret" and "reset_server_password" that currently do nothing. They will come later.
@infinitewarp infinitewarp force-pushed the 852-prototype branch 3 times, most recently from 6eea67c to 0bd58d5 Compare November 25, 2024 21:07
@infinitewarp infinitewarp marked this pull request as ready for review November 25, 2024 21:58
Copy link
Contributor

@bruno-fs bruno-fs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love what I see here!

I only left one comment but feel free to ignore it.

Thanks to @bruno-fs for suggesting this change!

Co-authored-by: Bruno FS Ciconelle <[email protected]>
@infinitewarp infinitewarp merged commit fcbe491 into main Nov 27, 2024
5 checks passed
@infinitewarp infinitewarp deleted the 852-prototype branch November 27, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants