File: test_analyze.py

package info (click to toggle)
cloud-init 25.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,412 kB
  • sloc: python: 135,894; sh: 3,883; makefile: 141; javascript: 30; xml: 22
file content (36 lines) | stat: -rw-r--r-- 1,558 bytes parent folder | download
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
# This file is part of cloud-init. See LICENSE file for license information.
"""Tests for `cloud-init analyze`"""
import pytest

from cloudinit.distros import uses_systemd
from tests.integration_tests.integration_settings import PLATFORM
from tests.integration_tests.util import get_datetime_from_string


class TestAnalyzeCommand:
    @pytest.mark.skipif(not uses_systemd(), reason="Relies on systemd output")
    @pytest.mark.skipif(
        PLATFORM != "lxd_container",
        reason="Testing lxdcontainer-specific behavior",
    )
    def test_analyze_boot_ordered_timestamps(self, module_client):
        """
        Confirm that analyze boot is working correctly in lxd containers
        and that the correct zero-point is used for the monotonic clock used
        to determine when cloud-init was activated by systemd
        """
        assert module_client.execute("cloud-init status --wait --long").ok
        result = module_client.execute("cloud-init analyze boot")
        assert result.stderr == "container"

        container_start_time = get_datetime_from_string(
            result.stdout, "^\\s*Container started at: (.+?)$"
        )
        cloudinit_activation_time = get_datetime_from_string(
            result.stdout, "^\\s*Cloud-init activated by systemd at: (.+?)$"
        )
        cloudinit_start_time = get_datetime_from_string(
            result.stdout, "^\\s*Cloud-init start: (.+?)$"
        )
        assert container_start_time < cloudinit_activation_time
        assert cloudinit_activation_time < cloudinit_start_time