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

chore: Document and validate settable status values in _ModelBackend.set_status #1354

Merged

Commits on Sep 3, 2024

  1. Fix broken test of registering StatusBase subclass

    Previously was catching AttributeError, which must have been raised
    historically for missing `name` attribute on StatusBase subclasses.
    This, combined with a `type: ignore` directive concealed that the
    `register_status` method does not exist -- the attempt to access it
    raises an AttributeError. The correct method is `register`, which
    raises a TypeError.
    james-garner-canonical committed Sep 3, 2024
    Configuration menu
    Copy the full SHA
    de6cede View commit details
    Browse the repository at this point in the history
  2. Fix broken status_set test

    A `type: ignore` directive hid that `status_set` was being called with
    the wrong argument types. The intention was to test that an error is
    raised on calling with a non-bool argument for `is_app`, however the
    status argument should be a string, and was instead a `StatusBase`
    class. The test would have still correctly errored out on the `is_app`
    argument before this error had an effect at testing time.
    james-garner-canonical committed Sep 3, 2024
    Configuration menu
    Copy the full SHA
    b586027 View commit details
    Browse the repository at this point in the history
  3. Expose settable statuses in type hint of set_status

    _ModelBackend.status_set's status argument was previously type hinted
    only as str. However, this argument can really only be one of four valid
    statuses that juju's set-status will accept. This commit documents this,
    and adjusts the definition of StatusBase to also type hint the six
    acceptable status names, as well as using these type hints across code
    that interacts with StatusBase and status_set.
    james-garner-canonical committed Sep 3, 2024
    Configuration menu
    Copy the full SHA
    c50dd47 View commit details
    Browse the repository at this point in the history
  4. Validate status in status_set before calling status-set

    Since we know the valid arguments for status, and expose them in type
    hints, and since ops already validates arguments here to some extent
    (is_app being a bool in status_set, status and message being strings in
    Application.status and Unit.status), let's check that status is valid
    in status_set and raise a ModelError immediately if not, rather than
    catching status-set's exit code and only then raising a ModelError.
    james-garner-canonical committed Sep 3, 2024
    Configuration menu
    Copy the full SHA
    f8e1596 View commit details
    Browse the repository at this point in the history
  5. Validate type of message in set_status

    Since _ModelBackend.set_status validates its status and is_app
    arguments, let's also validate the type of message, removing redundant
    checks from Application.status and cleaning up a fixme in Unit.status.
    Also add a test to cover this, analogous to the existing test for the
    type of is_app.
    james-garner-canonical committed Sep 3, 2024
    Configuration menu
    Copy the full SHA
    f9423de View commit details
    Browse the repository at this point in the history
  6. Revert change to signature of StatusBase.from_name

    Since StatusBase.from_name is part of the public API, and is currently
    used in several charms, changing the type of the name argument from str
    to _StatusName will break users' tests. Furthermore, satisfying the type
    checker as to the contents of the strings used may be painful for users,
    leading to a proliferation of casts or `type: ignore`s. Therefore, the
    type or the name argument has been reverted to str.
    james-garner-canonical committed Sep 3, 2024
    Configuration menu
    Copy the full SHA
    424b74d View commit details
    Browse the repository at this point in the history

Commits on Sep 4, 2024

  1. Remove TODOs

    Unclear how to narrow type of value given that type checking doesn't
    excellently support properties with differing types for getter and
    setter, so sticking with a simple `cast` for now.
    james-garner-canonical committed Sep 4, 2024
    Configuration menu
    Copy the full SHA
    c295028 View commit details
    Browse the repository at this point in the history
  2. Change object to object() in test cases

    Either work, as we're just testing that the type not being bool or str
    raises an error, but bare object may raise eyebrows for readers.
    james-garner-canonical committed Sep 4, 2024
    Configuration menu
    Copy the full SHA
    ebe61a1 View commit details
    Browse the repository at this point in the history
  3. Raise InvalidStatusError instead of ModelError in status_set

    InvalidStatusError is a subclass of ModelError, so it shouldn't break
    any user code, and anyway it doesn't look like people were setting
    invalid statuses since Juju would give them an error at runtime
    currently.
    james-garner-canonical committed Sep 4, 2024
    Configuration menu
    Copy the full SHA
    3ad8459 View commit details
    Browse the repository at this point in the history

Commits on Sep 9, 2024

  1. Configuration menu
    Copy the full SHA
    0132af5 View commit details
    Browse the repository at this point in the history

Commits on Sep 17, 2024

  1. Document InvalidStatusError cases in add_status

    Calling add_status with an ErrorStatus *will* eventually result in
    an InvalidStatusError. Calling add_status with an UnknownStatus *may*
    eventually result in an InvalidStatusError.
    james-garner-canonical committed Sep 17, 2024
    Configuration menu
    Copy the full SHA
    a92737e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8e17020 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    aabb970 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    435e539 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    f126853 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f2f57ee View commit details
    Browse the repository at this point in the history

Commits on Sep 18, 2024

  1. Revert changes to docstring for CollectStatusEvent

    The plan is to make using ErrorStatus and UnknownStatus here an error
    james-garner-canonical committed Sep 18, 2024
    Configuration menu
    Copy the full SHA
    fb95f48 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2fe3bbd View commit details
    Browse the repository at this point in the history