-
Notifications
You must be signed in to change notification settings - Fork 42
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
Introduction of broker config cli and much more! #317
Conversation
7290f31
to
032372a
Compare
|
||
def restore(self): | ||
"""Restore the configuration file from a backup if it exists.""" | ||
logger.debug( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm debating whether this should be info level or not. There is a stronger case for this being info level than the message in backup.
return curr_chunk | ||
if C_SEP in chunk: | ||
curr, chunk = chunk.split(C_SEP, 1) | ||
# curr = int(curr) if curr.isdigit() else curr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a remnant from when I allowed traversing lists, like how instances are currently stored. Could keep it in for some future use or just get rid of these lines.
global SETTINGS_VALIDATED # noqa: PLW0603 | ||
if not SETTINGS_VALIDATED: | ||
logger.debug("Validating ssh settings") | ||
settings.validators.validate(only="SSH") | ||
SETTINGS_VALIDATED = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delay validation until needed to avoid requiring the ssh config chunk.
this isn't currently important since every setting under ssh has a default value defined in its validator.
if click.confirm("Would you like to run the migrations now?"): | ||
cfg_manager.migrate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now this is a choice, but we could also just remove the choice and make it automatic.
b309886
to
9b17fed
Compare
The initial change of this was to introduce the broker config cli. However, to do this, a number of supporting and related changes needed to be made. The first of these is the new ConfigManager class that manages reading from and writing to the config file. Since so much logic was implemented for this, it made more sense to roll in the import/init functionality, that was originally in the settings module, into the new class. This also gave me the opportunity to separate the test config from the example config. This removal, and other changes in this were supported by ConfigManager's migration functionality. To simplify the nested chunk notation, I moved provider instances out from a list to just being a nested dictionary. This actually simplified the instance logic quite a bit. Related to config simlification was the separation of the host settings to a new ssh chunk of the config. This is because not all users use the host functionality Broker provides. A likely change with this release is going to be removing a default ssh backend from Broker's requirements. While I was at it, I also switched the CLI over to rich-click as part of a larger effort to improve the CLI experience.
Due to timing, I couldn't cleanly include this in the previous commit, but here it is. Now Broker actions, including checkins will reference this new setting when determining how many threads it should use.
9b17fed
to
37eb078
Compare
With this change, users can now specify a `--from` argument with a valid path or url to a valid broker settings file. This will still try to fallback on the current behavior of using a local repo or the main SatelliteQE/broker repo as the source.
922833e
to
f130b74
Compare
Broker has expanded a while ago with the types of hosts it can support, it's time we updated our terminology to match.
f787d37
to
45efe37
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a partial review, I went through a quarter of the patch and left some comments.
A number of changes were needed both functionally and stylistically to get this where we want it, but it's pretty good now. I don't know if I like the "Validation passed!" message, since it will likely print every time, but it can stay for now.
7bdbd02
to
bac3074
Compare
broker/settings.py
Outdated
BROKER_DIRECTORY = Path.home().joinpath(".broker") | ||
TEST_MODE = "pytest" in sys.modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test that pytest
is not in sys.modules
when broker is imported in robottelo or a similar project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it almost certainly should trigger test mode, so we wouldn't automatically migrate while in a pytest session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me rephrase, do we want to have TEST_MODE
set to True
when we run robottelo (Foreman) tests? If we don't, this logic needs to be changed.
pytest --setup-plan tests/foreman/api/test_ping.py -s
[74] > /home/ogajduse/repos/broker/broker/settings.py(28)<module>()
-> TEST_MODE = "pytest" in sys.modules
2 frames hidden (try 'help hidden_frames')
(Pdb++) l
23 from broker.exceptions import ConfigurationError
24
25 INTERACTIVE_MODE = ConfigManager.interactive_mode
26 BROKER_DIRECTORY = Path.home().joinpath(".broker")
27 breakpoint()
28 -> TEST_MODE = "pytest" in sys.modules
29
30 if TEST_MODE: # when in test mode, don't use the real broker directory
31 BROKER_DIRECTORY = Path("tests/data/")
32 elif "BROKER_DIRECTORY" in os.environ:
33 envar_location = Path(os.environ["BROKER_DIRECTORY"])
(Pdb++) "pytest" in sys.modules
True
047b887
to
107f7b3
Compare
107f7b3
to
c7b95e3
Compare
PyYaml is a good library, but had the unfortunate side-effect of stripping comments from yaml files on read/write. Switching to ruamel now let's us retain the comments, and arguably improves usage in some ways. There may be some issues with awxkit objects due to the way the representers are added, but I can't say for certain that is the case yet.
c7b95e3
to
23a7025
Compare
The initial change of this was to introduce the broker config cli. However, to do this, a number of supporting and related changes needed to be made.
The first of these is the new ConfigManager class that manages reading from and writing to the config file.
Since so much logic was implemented for this, it made more sense to roll in the import/init functionality, that was originally in the settings module, into the new class.
This also gave me the opportunity to separate the test config from the example config. This removal, and other changes in this were supported by ConfigManager's migration functionality.
To simplify the nested chunk notation, I moved provider instances out from a list to just being a nested dictionary. This actually simplified the instance logic quite a bit.
Related to config simlification was the separation of the host settings to a new ssh chunk of the config. This is because not all users use the host functionality Broker provides. A likely change with this release is going to be removing a default ssh backend from Broker's requirements.
While I was at it, I also switched the CLI over to rich-click as part of a larger effort to improve the CLI experience.