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

Add a way of creating and executing "config switch" operations #86

Merged
merged 4 commits into from
Jan 8, 2024

Conversation

barthisrael
Copy link
Contributor

@barthisrael barthisrael commented Nov 16, 2023

Through this PR we expose an operation in the REST API for performing barman config-switch command remotely. The following changes have been applied:

  • Create a ConfigSwitchOperation class, which takes care of validating the arguments for a config switch operation, and also of running such operation;
  • Modify servers_operations_post Flask end point so it is able to receive POST requests both for creating a recovery operation or a config switch operation;
  • Create a new command pg-backup-api config-switch, which is used by the API in order to run the config switch on Barman;
  • Create a function config_switch_operation, which is used by pg-backup-api config-switch command;
  • Create a helper function _run_operation, which is used both by recovery_operation and config_switch_operation functions. They both have a very similar logic, so that helper function executes the common code paths.

The new API endpoint is able to handle both an "apply model" or a "reset model" through barman config-switch command.

References: BAR-125.

@barthisrael barthisrael self-assigned this Nov 16, 2023
@barthisrael barthisrael marked this pull request as draft November 16, 2023 18:43
Copy link

@gcalacoci gcalacoci left a comment

Choose a reason for hiding this comment

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

this looks good to me for now

@barthisrael
Copy link
Contributor Author

this looks good to me for now

Thanks for checking :)

Once #87 is merged, I'll rebase this branch on top of that.

@barthisrael barthisrael force-pushed the dev/BAR-125-config-switch-endpoint branch 2 times, most recently from 07fdc0d to abf19e3 Compare November 23, 2023 14:09
@barthisrael
Copy link
Contributor Author

Rebased on top of main to include changes from #87 . Based on that:

  • Adjusted unit tests of test_server_operation.py to use pytest and split complex tests
  • Included missing unit tests for test_main.py, test_utility_controller.py, and test_run.py -- modules which were introduced by Improve unit tests suite #87 .

I plan to rebase this branch on top of main again in the future, once #88 is merged into main, because that PR also touches some unit tests and the changes are relevant here (in regards to patching terminal size).

@barthisrael barthisrael force-pushed the dev/BAR-125-config-switch-endpoint branch from abf19e3 to 809f870 Compare November 24, 2023 11:21
This commit is a WIP -- the final implementation in the ``pg-backup-api``
depends on the final implementation of the ``barman config switch``
command in Barman.

Through this commit we create a draft for the future change in
``pg-backup-api``. Currently it is composed by the following changes:

* Create a ``ConfigSwitchOperation`` class, which takes care of
validating the arguments for a config switch operation, and also
of running such operation;
* Modify `servers_operations_post` Flask end point so it is able
to receive POST requests both for creating a recovery operation
or a config switch operation;
* Create a new command ``pg-backup-api config-switch``, which is
used by the API in order to run the config swith on Barman;
* Create a function ``config_switch_operation``, which is used by
``pg-backup-api config-switch`` command;
* Create a helper function ``_run_operation``, which is used both
by ``recovery_operation`` and ``config_switch_operation`` functions.
They both have a very similar logic, so that helper function executes
the common code paths.

References: BAR-125.

Signed-off-by: Israel Barth Rubio <[email protected]>
This commit adds unit tests for the recently implemented
``ConfigSwitchOperation``.

This is still a WIP because we need to know how the final implementation
of ``barman config switch`` comand in Barman so we can then adjust
the code and tests in pg-backup-api.

References: BAR-125.

Signed-off-by: Israel Barth Rubio <[email protected]>
@barthisrael barthisrael force-pushed the dev/BAR-125-config-switch-endpoint branch from 809f870 to bd0d1da Compare November 24, 2023 11:34
@barthisrael
Copy link
Contributor Author

Rebased on top of main after #88 has been merged, and adjusted the code/unit tests accordingly.

After #87 has been merged into `main`, this dev branch for BAR-125
has been rebased on top of `main`.

Given the improvements made to the unit test suite through #87,
we are now adjusting the unit tests of this dev branch:

* `test_server_operation.py` for `ConfigSwitchOperation` is now
  following the new design, which uses `pytest` and splits complex
  tests into several smaller ones;
* add tests for "config switch operation" on unit test modules that
  where introduced by #87 (`test_main.py`, `test_run.py`, and
  `test_utility_controller.py`)

Note: we are still missing the final design of the `barman config switch`
implementation in Barman, so we keep this branch as a WIP.

References: BAR-125.

Signed-off-by: Israel Barth Rubio <[email protected]>
@barthisrael barthisrael force-pushed the dev/BAR-125-config-switch-endpoint branch from bd0d1da to 39bed62 Compare November 24, 2023 11:43
…fig-switch`

Previous to this commit we had draft code and unit tests as we were still
working on the implementation of `barman config-switch` command.

Now that the design of `barman config-switch` is mature, we are adjusting
this branch so it gets compliant with the expected implementation of that
command.

References: BAR-125.

Signed-off-by: Israel Barth Rubio <[email protected]>
@barthisrael barthisrael changed the title WIP: Add a way of creating and executing "config switch" operations Add a way of creating and executing "config switch" operations Dec 6, 2023
@barthisrael barthisrael marked this pull request as ready for review December 6, 2023 16:12
@barthisrael barthisrael merged commit 896957b into main Jan 8, 2024
14 checks passed
@barthisrael barthisrael deleted the dev/BAR-125-config-switch-endpoint branch January 8, 2024 17:50
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