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

snapshots_serialized(props=["createtxg"], ...) misformats the data #227

Open
asomers opened this issue Feb 7, 2023 · 0 comments
Open

snapshots_serialized(props=["createtxg"], ...) misformats the data #227

asomers opened this issue Feb 7, 2023 · 0 comments
Assignees

Comments

@asomers
Copy link
Contributor

asomers commented Feb 7, 2023

If you use snapshots_serialized and the only property in the list is createtxg, py-libzfs will not fetch it correctly. Instead of the usual parsed, source, rawvalue, value dict, it will simply return 0. However, if there are any other properties in the list, then all will be fetched correctly. From my spot-checking, only createtxg exhibits this behavior.

Environment

FreeBSD 13.1-RELEASE amd64, py-libzfs-1.1.2023020200. The bug must've been introduced sometime in the revision range 077cf6d..1a99a45.

Steps to Reproduce

Ensure that there is a dataset named "tank" with at least one snapshot. Then run this script:

from pprint import pprint
import libzfs

zfs = libzfs.ZFS()
badsnaps = zfs.snapshots_serialized(
    props=["createtxg"],
    datasets=["tank"],
    recursive=False
)

goodsnaps = zfs.snapshots_serialized(
    props=["used", "createtxg"],
    datasets=["tank"],
    recursive=False
)

print("Bad version of the snapshot list:")
pprint(badsnaps[0])
print("\nGood version of the snapshot list:")
pprint(goodsnaps[0])

The output will look like this:

Bad version of the snapshot list:
{'createtxg': '0',                                                   <--- Incorrect value
 'dataset': 'tank',
 'id': 'tank@zrepl_20230119_070154_000',
 'name': 'tank@zrepl_20230119_070154_000',
 'pool': 'tank',
 'snapshot_name': 'zrepl_20230119_070154_000',
 'type': 'SNAPSHOT'}                                                 <--- Dict ends with no 'properties' section

Good version of the snapshot list:
{'createtxg': '53209141',                                            <--- Correct value
 'dataset': 'tank',
 'id': 'tank@zrepl_20230119_070154_000',
 'name': 'tank@zrepl_20230119_070154_000',
 'pool': 'tank',
 'properties': {'createtxg': {'parsed': '53209141',                  <--- Expected 'properties' section
                              'rawvalue': '53209141',
                              'source': 'NONE',
                              'value': '53209141'},
                'used': {'parsed': 0,
                         'rawvalue': '0',
                         'source': 'NONE',
                         'value': '0B'}},
 'snapshot_name': 'zrepl_20230119_070154_000',
 'type': 'SNAPSHOT'}
@sonicaj sonicaj self-assigned this Feb 9, 2023
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

No branches or pull requests

2 participants