Esempio n. 1
0
def log_deprecations(logger=None):
    """Log active deprecations."""
    if logger is None:
        logger = LegacyLogger()

    for d in get_deprecations():
        logger.msg("Deprecation {id} ({url}): {description}".format(**d))
Esempio n. 2
0
    def test_log_deprecations(self):
        self.patch(deprecations, "get_deprecations").return_value = [
            Deprecation(id="MD123",
                        since="2.9",
                        description="something is deprecated")
        ]

        events = []
        logger = LegacyLogger(observer=events.append)
        log_deprecations(logger=logger)
        [event] = events
        self.assertEqual(
            event["_message_0"],
            "Deprecation MD123 (https://maas.io/deprecations/MD123): "
            "something is deprecated",
        )
Esempio n. 3
0
    def test_log_deprecations(self):
        self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current"))
        snap_common_path = Path(self.make_dir())
        self.useFixture(
            EnvironmentVariable("SNAP_COMMON", str(snap_common_path)))
        snap_common_path.joinpath("snap_mode").write_text("all", "utf-8")

        events = []
        logger = LegacyLogger(observer=events.append)
        log_deprecations(logger=logger)
        [event] = events
        self.assertEqual(
            event["_message_0"],
            "Deprecation MD1 (https://maas.io/deprecations/MD1): "
            "MAAS is currently running the PostgreSQL database inside the snap. "
            "It should be migrated outside of the snap.",
        )
Esempio n. 4
0
    def test_log_deprecations(self):
        self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current"))
        snap_common_path = Path(self.make_dir())
        self.useFixture(
            EnvironmentVariable("SNAP_COMMON", str(snap_common_path))
        )
        snap_common_path.joinpath("snap_mode").write_text("all", "utf-8")

        events = []
        logger = LegacyLogger(observer=events.append)
        log_deprecations(logger=logger)
        [event] = events
        self.assertEqual(
            event["_message_0"],
            "Deprecation MD1 (https://maas.io/deprecations/MD1): "
            "The setup for this MAAS is deprecated and not suitable for production "
            "environments, as the database is running inside the snap.",
        )
Esempio n. 5
0
    Fabric,
    Machine,
    Node,
    Pod,
    Space,
    StaticIPAddress,
    Subnet,
    VLAN,
)
from maasserver.utils import get_maas_user_agent
from maasserver.utils.orm import transactional
from maasserver.utils.threads import deferToDatabase
from provisioningserver.logger import LegacyLogger
from provisioningserver.utils.network import IPRangeStatistics

log = LegacyLogger()


def NotNullSum(column):
    """Like Sum, but returns 0 if the aggregate is None."""
    return Coalesce(Sum(column), Value(0))


def get_machine_stats():
    # Rather overall amount of stats for machines.
    return Machine.objects.aggregate(
        total_cpu=NotNullSum("cpu_count"),
        total_mem=NotNullSum("memory"),
        total_storage=NotNullSum("blockdevice__size"),
    )
Esempio n. 6
0
def log_deprecations(logger=None):
    """Log active deprecations."""
    if logger is None:
        logger = LegacyLogger()
    for d in get_deprecations():
        logger.msg(d.message)