This file is indexed.

/usr/lib/python3/dist-packages/maasserver/components.py is in python3-django-maas 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2012-2016 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""MAAS components notifications.

This is a legacy compatibility shim, to use the new notifications feature to
display the old components messages. In time this will go away, but it's
simple enough that there's no rush until it doesn't actually do what we want
it to do.
"""

__all__ = [
    "discard_persistent_error",
    "get_persistent_error",
    "get_persistent_errors",
    "register_persistent_error",
]

from maasserver.enum import COMPONENT
from maasserver.models import Notification
from maasserver.utils.orm import transactional
from provisioningserver.utils.enum import map_enum


@transactional
def discard_persistent_error(component):
    """Drop the persistent error for `component`.

    :param component: An enum value of :class:`COMPONENT`.
    """
    Notification.objects.filter(ident=component).delete()


@transactional
def register_persistent_error(component, error_message):
    """Register a persistent error for `component`.

    :param component: An enum value of :class:`COMPONENT`.
    :param error_message: Human-readable error text.
    """
    try:
        notification = Notification.objects.get(ident=component)
    except Notification.DoesNotExist:
        notification = Notification.objects.create_error_for_admins(
            error_message, ident=component)
    else:
        if notification.message != error_message:
            notification.message = error_message
            notification.save()


def get_persistent_error(component):
    """Return persistent error for `component`, or None."""
    try:
        notification = Notification.objects.get(ident=component)
    except Notification.DoesNotExist:
        return None
    else:
        return notification.render()


def get_persistent_errors():
    """Return list of current persistent error messages."""
    components = map_enum(COMPONENT).values()
    return sorted(
        notification.render() for notification in
        Notification.objects.filter(ident__in=components)
    )