~aleteoryx/muditaos

ref: 2e6899a4923ef53e5f02e9a018aec1967e7eed82 muditaos/test/pytest/service-desktop/test_backup.py -rw-r--r-- 2.3 KiB
2e6899a4 — Marek Niepieklo [CP-2] I don't want to see data from Pure in Center when Pure is locked 4 years ago
                                                                                
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 (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
import pytest
import time
import os
from harness import log
from harness.interface.defs import status


@pytest.mark.service_desktop_test
@pytest.mark.rt1051
@pytest.mark.usefixtures("usb_unlocked")
@pytest.mark.backup
def test_backup(harness):
    body = { "request": True }
    log.debug("backup testing");
    
    # this requests a backup start
    response = harness.endpoint_request("backup", "get", body)
    assert response["body"] != ""
    assert response["body"]["task"] != ""
    task = response["body"]["task"]
    assert response["status"] == status["OK"]
    
    # in response we get a task ID and status 200
    log.debug("backup started, waiting for results")
    
    # start polling for backup status and wait for it to end
    i = 0
    while True:
        i = i+1
        time.sleep(1)  # wait for the endpoint to be ready

        # now that we know the task ID we can poll for it's status
        body = { "request": True, "task": task }
        response = harness.endpoint_request("backup", "get", body)
        
        # backup is still running
        if response["body"]["state"] == "running":
            assert response["status"] == 200
            log.debug("backup is running...")
            
        # backup has stopped, should be OK and finished, status is 303
        # and redirects to a location as per the documentation
        if response["body"]["state"] == "stopped":
            log.debug("backup ended, check results")
            assert response["status"] == 303
            assert response["body"]["location"] != ""
            
            # see if the location is a valid backup path, extensions is .tar
            # and starts with a /
            p = response["body"]["location"]
            p_split = os.path.splitext(p)
            assert p_split[1] == ".tar"
            assert p_split[0][0] == "/"
            
            break
            
        # wait for a moment
        log.debug("sleeping for 1 second")
        time.sleep(1)
        
        # max 30 second timeout
        if i > 30:
            # this is bas, and the test fails here
            log.error("backup timeout reached")
            assert False
            break