File: task.yaml

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (96 lines) | stat: -rw-r--r-- 4,755 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
summary: Check that timeserver interface works

details: |
    This test makes sure that a snap using the timeserver-control interface
    can access timeserver information and update it.

prepare: |
    # This test requires busctl but on 14.04 we don't have one.
    # Let's pick the one from the core snap in such case.
    if [ -z "$(command -v busctl 2>/dev/null)" ]; then
        ln -s /snap/core/current/usr/bin/busctl /usr/local/bin/busctl
        hash -r
        tests.cleanup defer rm -f /usr/local/bin/busctl
    fi

    # Technically the interface may be implemented by many things but in
    # practice systemd implementation has a working SetNTP while others do not.
    # On such systems, install systemd-timesyncd to get the implementation we
    # can test. On other systems remember the current setting of the NTP
    # property and restore it later.
    case "$(busctl get-property org.freedesktop.timedate1 /org/freedesktop/timedate1 org.freedesktop.timedate1 NTP)" in
        "b true")
            tests.cleanup defer busctl call org.freedesktop.timedate1 /org/freedesktop/timedate1 org.freedesktop.timedate1 SetNTP bb true false
            ;;
        "b false")
            tests.cleanup defer busctl call org.freedesktop.timedate1 /org/freedesktop/timedate1 org.freedesktop.timedate1 SetNTP bb false false
            ;;
        *)
            echo "Unexpected value of NTP property"
            exit 1
            ;;
    esac

    # Install a snap declaring a plug on timeserver-control.
    if systemctl is-enabled systemd-timesyncd.service ; then
        # Install the base core20 variant with timedatectl that supports systemd-timesyncd commands.
        "$TESTSTOOLS"/snaps-state install-local-variant test-snapd-timedate-control-consumer-core24 test-snapd-timedate-control-consumer
    else
        # Install the default version.
        "$TESTSTOOLS"/snaps-state install-local test-snapd-timedate-control-consumer
    fi
    tests.cleanup defer snap remove --purge test-snapd-timedate-control-consumer

execute: |
    # If we cannot use network time protocol then the test is meaningless.
    if [ "$(busctl get-property org.freedesktop.timedate1 /org/freedesktop/timedate1 org.freedesktop.timedate1 CanNTP)" != "b true" ]; then
        echo "This system cannot use NTP, test precondition failed"
        exit 1
    fi

    echo "The interface is disconnected by default"
    snap interfaces -i timeserver-control | MATCH -- '- +test-snapd-timedate-control-consumer:timeserver-control'

    echo "When the interface is connected"
    snap connect test-snapd-timedate-control-consumer:timeserver-control

    # Use timedatectl without a subcommand
    test-snapd-timedate-control-consumer.timedatectl-timeserver

    # Set NTP and check that the setting was propagated.
    for value in true false true; do
        test-snapd-timedate-control-consumer.timedatectl-timeserver set-ntp "$value"
        # Starting or stopping NTP takes non-zero time so give it some time to take effect.
        # shellcheck disable=SC2016
        retry --wait 5 sh -c 'test "$(busctl get-property org.freedesktop.timedate1 /org/freedesktop/timedate1 org.freedesktop.timedate1 NTP)" = "b '"$value"'"'
    done

    # We rely systemd-timesyncd to test timesyncd functionality.
    if systemctl list-unit-files | grep systemd-timesyncd | awk '{print $2}' | MATCH "enabled"; then
        # Test timesyncd functionality exposed via timedatectl.
        echo "Check dbus access to org.freedesktop.timesync1 properties"
        serverName=$(busctl get-property --system org.freedesktop.timesync1 /org/freedesktop/timesync1 org.freedesktop.timesync1.Manager ServerName | awk -F'"' '{print $2}')


        echo "Check that timedatectl timesync commands can be used"
        test-snapd-timedate-control-consumer.timedatectl-timeserver show-timesync --property=ServerName | cut -d= -f2 | MATCH "$serverName"
        test-snapd-timedate-control-consumer.timedatectl-timeserver timesync-status | grep 'Server:' | cut -d'(' -f2 | cut -d')' -f1 | MATCH "$serverName"
    elif os.query is-core-ge 20; then
        # We expect to cover at least core 20+.
        echo "Error: insufficient test coverage of timedatectl timesyncd commands"
        exit 1
    fi

    if [ "$(snap debug confinement)" = partial ] ; then
        exit 0
    fi

    echo "When the plug is disconnected"
    snap disconnect test-snapd-timedate-control-consumer:timeserver-control

    echo "The timedatectl status cannot be retrieved"
    if test-snapd-timedate-control-consumer.timedatectl-timeserver status 2> call.error; then
        echo "Expected permission error calling timedatectl status with disconnected plug"
        exit 1
    fi
    MATCH "Permission denied" < call.error