Added TIMESPAN flags to match archive in various commands (Borg2 feature) #661

Merged
witten merged 12 commits from :borg2-archive-flags into main 2023-05-23 21:26:18 +00:00
Contributor

Fixes #659

Also adds --first and --last flags support to mount option.

Subcommands support

  • info

  • transfer

  • prune

  • mount

  • rlist

Tasks:

  • Adjust tests

  • Rewrite help text for args if needed

  • Cleanup debug messages and formatting

Signed-off-by: jetchirag thechiragaggarwal@gmail.com

Fixes #659 Also adds `--first` and `--last` flags support to mount option. Subcommands support - [x] info - [x] transfer - [x] prune - [x] mount - [x] rlist Tasks: - [ ] Adjust tests - [ ] Rewrite help text for args if needed - [ ] Cleanup debug messages and formatting Signed-off-by: jetchirag <thechiragaggarwal@gmail.com>
jetchirag added 1 commit 2023-03-25 20:36:15 +00:00
jetchirag added 1 commit 2023-03-25 20:37:02 +00:00
witten requested changes 2023-03-26 21:35:39 +00:00
witten left a comment
Owner

Nice! This approach seems like it'll work just great.

Nice! This approach seems like it'll work just great.
@@ -35,6 +35,7 @@ def run_mount(
mount_arguments.paths,
mount_arguments.foreground,
mount_arguments.options,
mount_arguments,
Owner

I would recommend either exploding out mount_arguments into individual parameters (probably not the best idea given the number of new arguments) or removing the individual mount_arguments.mount_point, etc. parameters and passing in mount_arguments only.

I would recommend _either_ exploding out `mount_arguments` into individual parameters (probably not the best idea given the number of new arguments) *or* removing the individual `mount_arguments.mount_point`, etc. parameters and passing in `mount_arguments` only.
jetchirag marked this conversation as resolved
@@ -38,0 +41,4 @@
+ (flags.make_flags('newest', mount_arguments.newest) if mount_arguments.newest else ())
+ (flags.make_flags('oldest', mount_arguments.oldest) if mount_arguments.oldest else ())
+ (flags.make_flags('older', mount_arguments.older) if mount_arguments.older else ())
+ (flags.make_flags('newer', mount_arguments.newer) if mount_arguments.newer else ())
Owner

As you discovered, you can maybe use borgmatic.borg.flags.make_flags_from_arguments() here to make this a little more succinct. That might take care of some of the other arguments too.

As you discovered, you can maybe use `borgmatic.borg.flags.make_flags_from_arguments()` here to make this a little more succinct. That might take care of some of the other arguments too.
jetchirag marked this conversation as resolved
@@ -322,2 +322,4 @@
'--last', metavar='N', help='Only transfer last N archives after other filters are applied'
)
transfer_group.add_argument(
'--oldest', metavar='TIMESPAN', help='Transfer archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]'
Owner

If you're going to use square brackets for the Borg 2 only part (which seems fine), it might be worth scrubbing through the rest of the arguments to standardize.

If you're going to use square brackets for the Borg 2 only part (which seems fine), it might be worth scrubbing through the rest of the arguments to standardize.
jetchirag marked this conversation as resolved
@@ -324,0 +325,4 @@
'--oldest', metavar='TIMESPAN', help='Transfer archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]'
)
transfer_group.add_argument(
'--newest', metavar='TIMESPAN', help='Transfer archives within a time range that ends at newest archive\'s timestamp and starts a specified time range ago (e.g. 7d or 12m) [Borg 2.x+ only]'
Owner

Minor nit: I think PEP 8 says to vary outer quotes instead of backslashing quotes in strings. So for instance: "I won't" instead of I won\'t. There might even be a flake8 rule for this.

Minor nit: I think [PEP 8](https://pep8.org/) says to vary outer quotes instead of backslashing quotes in strings. So for instance: `"I won't"` instead of ``I won\'t``. There might even be a flake8 rule for this.
Author
Contributor

Is length of help text a problem?

'--newest', metavar='TIMESPAN', help='Mount archives within a time range that ends at timestamp of the newest archive and starts a specified time range ago (e.g. 7d or 12m) [Borg 2.x+ only]'
Is length of help text a problem? ``` '--newest', metavar='TIMESPAN', help='Mount archives within a time range that ends at timestamp of the newest archive and starts a specified time range ago (e.g. 7d or 12m) [Borg 2.x+ only]' ```
jetchirag marked this conversation as resolved
jetchirag added 2 commits 2023-03-28 12:40:56 +00:00
jetchirag added 1 commit 2023-03-28 12:45:55 +00:00
Owner

Also, please let me know when this one is ready for review again. Thanks!

Also, please let me know when this one is ready for review again. Thanks!
jetchirag requested review from witten 2023-03-31 18:55:30 +00:00
witten reviewed 2023-04-02 21:48:43 +00:00
witten left a comment
Owner

This is looking good! Note that there's unfortunately been some work in master that will pose minor conflicts with this branch. Hopefully it won't be a big deal to merge those in.

What's next? Test updates?

This is looking good! Note that there's unfortunately been some work in master that will pose minor conflicts with this branch. Hopefully it won't be a big deal to merge those in. What's next? Test updates?
@@ -39,0 +34,4 @@
+ flags.make_flags_from_arguments(
mount_arguments,
excludes=('repository', 'archive', 'mount_point', 'path', 'options'),
Owner

I think path should be paths here...?

I think `path` should be `paths` here...?
Author
Contributor

Yes it should be paths

Yes it should be paths
@@ -74,0 +73,4 @@
+ flags.make_flags_from_arguments(
prune_arguments,
excludes=('repository', 'stats'),
)
Owner

Nice way to cut down on many of the explicit arguments.

Nice way to cut down on many of the explicit arguments.
witten reviewed 2023-04-02 21:50:33 +00:00
@@ -324,0 +325,4 @@
'--oldest', metavar='TIMESPAN', help='Transfer archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]'
)
transfer_group.add_argument(
'--newest', metavar='TIMESPAN', help='Transfer archives within a time range that ends at timestamp of the newest archive and starts a specified time range ago (e.g. 7d or 12m) [Borg 2.x+ only]'
Owner

FYI I'm fine leaving the wording in these descriptions if you want to. It's accurate even if it's a little hard to parse (for me).

FYI I'm fine leaving the wording in these descriptions if you want to. It's accurate even if it's a little hard to parse (for me).
Author
Contributor

I couldn't find a way to simplify it further which can also be read easily. This definitely requires one or two re-reads for first time. I'll check back on this again after tests.

I couldn't find a way to simplify it further which can also be read easily. This definitely requires one or two re-reads for first time. I'll check back on this again after tests.
Owner

Sounds good. Maybe the Borg project already did the heavy lifting simplifying it as far as it could reasonably go.

Sounds good. Maybe the Borg project already did the heavy lifting simplifying it as far as it could reasonably go.
Author
Contributor

Note that there's unfortunately been some work in master that will pose minor conflicts with this branch. Hopefully it won't be a big deal to merge those in.

No worries, I'll resolve them.

What's next? Test updates?

Yes, I got a little occupied with my exams. I'll write tests as soon as possible.

> Note that there's unfortunately been some work in master that will pose minor conflicts with this branch. Hopefully it won't be a big deal to merge those in. No worries, I'll resolve them. > What's next? Test updates? Yes, I got a little occupied with my exams. I'll write tests as soon as possible.
Owner

No worries. Exams are definitely more important. 😄

No worries. Exams are definitely more important. 😄
jetchirag added 1 commit 2023-04-15 12:00:38 +00:00
Author
Contributor

@witten I did not encounter any merge issue.

Can you give me pointers on testing? I suppose we can add a date-based matching test for each subcommand under /tests/unit/borg. Is there anything else?

@witten I did not encounter any merge issue. Can you give me pointers on testing? I suppose we can add a date-based matching test for each subcommand under `/tests/unit/borg`. Is there anything else?
Owner

Can you give me pointers on testing? I suppose we can add a date-based matching test for each subcommand under /tests/unit/borg.

Yeah, that sounds good to me.. just to make sure the new arguments get constructed correctly. There are plenty of existing tests to look at in that directory for examples, but I'd be happy to help out if something's not clear. Given that both borgmatic/borg/prune.py and borgmatic/borg/mount.py build up their flags to Borg in a main function rather than a separate flags-building function, a certain amount of mocking will be required.

Is there anything else?

There's one other candidate for testing I can think of: In tests/integration/borg/test_commands.py, there are integration tests for several borgmatic actions (subcommands) that use make_flags_from_arguments(). The idea is that incorrect use of make_flags_from_arguments() can result in duplicated arguments passed to Borg, so those tests check for that. Given that you've introduced make_flags_from_arguments() to prune and mount, you could potentially also add tests for them to test_commands.py.

I don't think your arguments.py changes need tests, because there's no real logic there. There are some argument integration tests in tests/integration/commands/test_arguments.py, but that's mostly for testing logic and interactions between arguments and actions.

Thank you! Please let me know if you have any questions on this.

> Can you give me pointers on testing? I suppose we can add a date-based matching test for each subcommand under /tests/unit/borg. Yeah, that sounds good to me.. just to make sure the new arguments get constructed correctly. There are plenty of existing tests to look at in that directory for examples, but I'd be happy to help out if something's not clear. Given that both `borgmatic/borg/prune.py` and `borgmatic/borg/mount.py` build up their flags to Borg in a main function rather than a separate flags-building function, a certain amount of mocking will be required. > Is there anything else? There's one other candidate for testing I can think of: In `tests/integration/borg/test_commands.py`, there are integration tests for several borgmatic actions (subcommands) that use `make_flags_from_arguments()`. The idea is that incorrect use of `make_flags_from_arguments()` can result in duplicated arguments passed to Borg, so those tests check for that. Given that you've introduced `make_flags_from_arguments()` to `prune` and `mount`, you could potentially also add tests for them to `test_commands.py`. I don't think your `arguments.py` changes need tests, because there's no real logic there. There *are* some argument integration tests in `tests/integration/commands/test_arguments.py`, but that's mostly for testing logic and interactions between arguments and actions. Thank you! Please let me know if you have any questions on this.
jetchirag added 1 commit 2023-04-24 14:54:27 +00:00
jetchirag added 1 commit 2023-04-24 15:13:19 +00:00
jetchirag added 1 commit 2023-04-24 15:19:24 +00:00
Author
Contributor

@witten Sorry for the delay. Exams still going on 😅.

I've updated/fixed existing tests and added a test to prune for your review. Can you please take a quick look and I'll push new commits and add tests for rest of subcommands?

@witten Sorry for the delay. Exams still going on 😅. I've updated/fixed existing tests and added a test to prune for your review. Can you please take a quick look and I'll push new commits and add tests for rest of subcommands?
witten reviewed 2023-04-25 17:19:16 +00:00
@@ -109,0 +119,4 @@
borgmatic.borg.prune.prune_archives(
False, 'repo', {}, {}, '2.3.4', fuzz_argument(arguments, argument_name)
)
Owner

This looks good to me! Thank you for adding it.

This looks good to me! Thank you for adding it.
@@ -294,1 +335,4 @@
retention_config=flexmock(),
local_borg_version='1.2.3',
prune_arguments=prune_arguments,
)
Owner

This test looks great!

This test looks great!
jetchirag added 1 commit 2023-04-27 16:56:58 +00:00
jetchirag added 1 commit 2023-04-27 16:57:30 +00:00
jetchirag changed title from WIP: Added TIMESPAN flags to match archive in various commands (Borg2 feature) to Added TIMESPAN flags to match archive in various commands (Borg2 feature) 2023-05-02 15:28:25 +00:00
witten requested changes 2023-05-04 18:54:54 +00:00
witten left a comment
Owner

Almost done! Just a couple more mocks (noted in comments) and I think that's it. I appreciate you sticking with this.

Almost done! Just a couple more mocks (noted in comments) and I think that's it. I appreciate you sticking with this.
@@ -233,0 +221,4 @@
)
def test_mount_archive_with_date_based_matching_calls_borg_with_date_based_flags():
Owner

Given that this is a unit test instead of integration test, I think this should probably also mock out make_flags_from_arguments like you did in some your other tests.

Given that this is a unit test instead of integration test, I think this should probably also mock out `make_flags_from_arguments` like you did in some your other tests.
@@ -294,0 +314,4 @@
)
def test_prune_archives_with_date_based_matching_calls_borg_with_date_based_flags():
Owner

I didn't catch the first time around, but: I also think this test should mock out make_flags_from_arguments.

I didn't catch the first time around, but: I also think this test should mock out `make_flags_from_arguments`.
@@ -509,0 +547,4 @@
'--oldest',
'1w',
'repo',
)
Owner

Nice!

Nice!
jetchirag added 1 commit 2023-05-20 13:23:23 +00:00
jetchirag requested review from witten 2023-05-20 13:23:33 +00:00
Author
Contributor

@witten I mostly merge with Github and seem to have messed up conflict resolving with merge as it's assigning other commits to this pull. Can you help?

@witten I mostly merge with Github and seem to have messed up conflict resolving with merge as it's assigning other commits to this pull. Can you help?
Owner

Can you point me at where things are messed up and/or have conflicts? Looking at your branch, it appears to be up-to-date with master and only has your own commits as part of the PR!

Can you point me at where things are messed up and/or have conflicts? Looking at your branch, it appears to be up-to-date with master and only has your own commits as part of the PR!
Author
Contributor

Last time I checked I thought I was getting other commits in my files changed. It looks fine right now though.

Last time I checked I thought I was getting other commits in my files changed. It looks fine right now though.
witten approved these changes 2023-05-23 21:24:49 +00:00
witten left a comment
Owner

This looks great to me!

This looks great to me!
@@ -127,0 +144,4 @@
'2.3.4',
fuzz_argument(arguments, argument_name),
argparse.Namespace(log_json=False),
)
Owner

Given the changes you've made to the mount action, it looks like it should also be represented with a mount-specific test in this integration test file. However, so as to avoid another round of back and forth, I can just add it myself after merging!

Given the changes you've made to the mount action, it looks like it should also be represented with a mount-specific test in this integration test file. However, so as to avoid another round of back and forth, I can just add it myself after merging!
Owner

Thank you so much for continuing to push on this through all the revisions. I really appreciate it!

Thank you so much for continuing to push on this through all the revisions. I really appreciate it!
witten merged commit 35b5c62ca6 into main 2023-05-23 21:26:18 +00:00
jetchirag deleted branch borg2-archive-flags 2023-06-04 07:07:43 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#661