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 plist serializer #56954

Merged
merged 17 commits into from
May 19, 2020
Merged

add a plist serializer #56954

merged 17 commits into from
May 19, 2020

Conversation

weswhet
Copy link
Contributor

@weswhet weswhet commented Apr 28, 2020

What does this PR do?

Adds a plist serializer, allowing you to manage plist files with file.serialize.

Previous Behavior

Before the only way to manage and manipulate plists, a common file type on macOS, was to use file.manage with a source file.

New Behavior

you can now use a formatter of plist in a file.serialize state to manage xml and binary plist files.

test_plist_serial:
  file.serialize:
    - name: /tmp/test_plist.plist
    - serializer_opts:
      - fmt: FMT_BINARY
    - formatter: plist
    - user: root
    - group: wheel
    - mode: 0644
    - makedirs: True
    - merge_if_exists: False
    - dataset:
        Label: com.saltstack.salt.master
        RunAtLoad: True
        KeepAlive: True
        ProgramArguments:
          - /opt/salt/bin/start-salt-master.sh
        SoftResourceLimits:
          NumberOfFiles: 100000
        HardResourceLimits:
          NumberOfFiles: 100000
        StandardOutPath: /tmp/salt-minion.out
        StandardErrorPath: /tmp/salt-minion.err

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

  • Docs
  • Changelog
  • Tests written/updated

Commits signed with GPG?

Yes

@weswhet weswhet requested a review from a team as a code owner April 28, 2020 22:22
@ghost ghost requested review from dwoz and removed request for a team April 28, 2020 22:22
@weswhet
Copy link
Contributor Author

weswhet commented Apr 28, 2020

cc @sheagcraig @garethgreenaway members of the macOS working group.

@@ -7805,7 +7805,8 @@ def serialize(
dataset, **serializer_options.get(serializer_name, {})
)

contents += "\n"
if isinstance(contents, str):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the previous implementation would attempt to add a new line to the end of a binary plist. which would cause sadness.

Copy link
Contributor

Choose a reason for hiding this comment

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

My guess is that was written using Py2, where binary == str == text. In Py3, binary == bytes and text == str. Definitely a good move here - unless we should have an

else:
   contents += b"\n"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@waynew Would it make sense to check to see if a new line already exists? I know plistlib automatically adds a newline.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with other tools out there, but I would assume we should do whatever the "correct" thing is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated with the recommendation as well as skipping new line concatenation on plists as this will create an invalid plist file.

@@ -7773,7 +7773,7 @@ def serialize(
"result": False,
}

with salt.utils.files.fopen(name, "r") as fhr:
with salt.utils.files.fopen(name, "rb") as fhr:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

trying to read a binary plist without the "b" would cause an exception. Also appears all the other implementations of salt.utils.files.fopen in this file use "rb" as arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this back to its previous behavior and only add a "b" if the formatter is a plist. this change was causing the integration.states.test_file.FileTest.test_serializer_deserializer_opts test to fail.

"""
salt.serializers.plist
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionadded:: TODO
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would this be 3001?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be, assuming all is 🥇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@sheagcraig
Copy link
Contributor

@wes and I wargamed this one and I think it looks ✨🤘🏻✨

Copy link
Contributor

@waynew waynew left a comment

Choose a reason for hiding this comment

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

The module at salt/serializers/plist.py does not have a sphinx stub at doc/ref/serializers/all/salt.serializers.plist.rst

Looks like you're missing some docs. I think you can autogen - just take a look at the other docs around there.

@weswhet
Copy link
Contributor Author

weswhet commented May 18, 2020

The module at salt/serializers/plist.py does not have a sphinx stub at doc/ref/serializers/all/salt.serializers.plist.rst

Looks like you're missing some docs. I think you can autogen - just take a look at the other docs around there.

Should be added. I think I did that right :)

@weswhet weswhet requested a review from waynew May 18, 2020 21:31
@dwoz dwoz merged commit 74a744a into saltstack:master May 19, 2020
@weswhet
Copy link
Contributor Author

weswhet commented May 19, 2020

wooo, thanks all!

@weswhet weswhet deleted the add_plist_serializer branch May 19, 2020 17:32
@sagetherage sagetherage added the ZRelease-Sodium retired label label May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ZRelease-Sodium retired label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants