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

smb: improve smb module test coverage #57394

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

phlogistonjohn
Copy link
Contributor

@phlogistonjohn phlogistonjohn commented May 10, 2024

Depends on #57339

After adding a bunch of features and changing this we lacked test coverage in some areas. While it's not anywhere near 100% a bunch more things, esp with regards to error handling, are now covered.

In addition, I moved some stuff into a utils.py because it was easier to add/move tests for these utils to a new file. Stuff like proto.py and enums.py do not need test functions otherwise (they're largely mypy or import-time things).

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

There's no need for order_resources to be a method. Make order_resources
a proper function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
There's no need for these to be methods as they're largely
self-contained. Functions should be easier to unit-test independently in
the future too.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Split the ConfigStore protocol into a new base protocol that covers the
methods needed to list keys in a store, called ConfigStoreListing.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This in-memory staging area for new resources being applied to the
config helps simplify validation.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
The linked_to_cluster field will be used for resources that must be
life-cycled along side the cluster using them. This is mainly intended
for use with `cluster create` command line commands.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This will be used later to create resources that are not directly named
by a user.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The new squash method works similarly to `one` but permits multiple
resources to be reported on by moving them into the report for the
"parent" resource. This is meant for upcoming changes to `cluster
create` when it starts using linked join auths and linked
users-and-groups.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Convert the smb mgr module cli to use linked join auth and
users-and-groups resources when created on the `cluster create` command
line. These linked resources with have semi-ranodmized names and be
linked to the cluster that we're creating on the CLI.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Drop the embedded versions of the join source and usrers and groups
configs from the cluster resource type. This means that potentially
sensitive information is *always* stored in a separate resource
from the less-sensitive general cluster config. Future changes can
then make security related choices about those specific resources
without worrying about having embedded variants inside the cluster.

For convenience I added a new "emtpy" users and groups source type that
can be used for testing. It defines *no* users and groups (an empty set
basically). This wouldn't be useful in a production scenario today as it
would deploy an smbd that you couldn't log into. But for unit testing
it's extremely handy, and maybe it can be used for integration testing
too.

This is a large change because lots of unit tests relied on embedded
join auths or users-and-groups. I tried to handle all the breaking
changes in one go for bisect-ability.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Update the documentation to match the code, removing references to
source_types 'inline' and 'password' and uris. Adding documentation
of the new linked_to_cluster field.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
We would like a quick way of determining what is new. Add methods to the
staging area class to make it possible to do so using (cached) keys.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add a create_only argument to the handler class apply function. This
flag is used to prevent modification of existing resources. This flag
will be use by 'cluster create' and 'share create' commands to make
them true to their names and not sneaky modify-or-create commands.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Prior to this change the create commands could be used counter to the
term 'create' as a create-or-update command. IMO this violates the
principle of least surprise so make them create-only.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add a method to supply the Resource instances with a callback that
can handle errors that occur during object construction from simplified
data. If the callback is not set, the exceptions are handled as usual.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Use error hook function to wrap plain ValueError instances to an
InvalidResourcError. This error retains the simplified data being
(re)constructed into an object and thus will be used later to generate
proper error results.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This error type can not take a real resource object because the resource
object could not be constructed from the data. Use the raw data for
reporting the error result.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Can save a line of code later.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
The result classes are not based in handler.py (any more) but the
module.py code was not updated to reflect that. Update it now.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Convert failures to create a valid resource into error results that can
be reported back to the caller like the other error result types
generated by actually attempting to apply the resources.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Custom parameter dictionaries will be used to pass options to samba
config without much filtering and control by the smb mgr module. Because
the risks that it entails the user must "agree" that using these options
can break their setup with a "magic" key-value pair.
This pair will be filtered out of the eventual data passed to samba.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Allow devs/testers/experimenters to add custom smb config params to our
managed shares or clusters. Use at your own risk.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Pass the custom share and/or global option key-value pairs to the
generated configurations.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Document the options, the risk of using it, and the "magic key-value"
pair needed to enable it.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add enums that will be used to create a share login control attribute.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add a validation function that will be used for a future share login
control attribute.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
The login_control attribute contains a list of LoginAccessEntry objects.
These will be mapped to samba share access parameters.
The restrict_access attribute is a boolean that makes access to the
share contingent on being listed in the login_control list, as
either a listed user or member of a listed group, for any access
level other than 'none' (as that always denies access).

Signed-off-by: John Mulligan <jmulligan@redhat.com>
The login_control list (modified by restrict_access) defines the
smb.conf params 'read list', 'write list', 'admin users', 'invalid
users', and 'valid users'.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Includes updating the files that were using them and even
a few test functions.
Amusingly, the `one` function was being tested as part of
test_handler.py demonstrating the confusion that not having
a utils.py and corresponding test file brought.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
The load_text function was a bit buggy but mainly worked until I started
to try and write a proper test for it. The error handling here is a bit
of a hack, but we can refine it later if people notice/complain.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
At one point the comment was true but I ended doing a workaround
enabling a wrapper in proto.py of typing_extensions.Self and using it
here turning the comment untrue.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Make InvalidResourceError based on ErrorResponseBase as well as
ValueError for consistency with the InvalidInputError class and in the
case it ever fails to be wrapped by a Response type.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Copy link

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant