summaryrefslogtreecommitdiffstats
path: root/lib/oeqa/selftest/updater.py
blob: 4cdd1a2749ec6904bf160a6f462858909c7ae7b5 (plain)
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
import unittest
import os
import logging

from oeqa.selftest.base import oeSelfTest
from oeqa.utils.commands import runCmd, bitbake, get_bb_var
import subprocess
from oeqa.selftest.qemucommand import QemuCommand
import time

class UpdaterTests(oeSelfTest):

    @classmethod
    def setUpClass(cls):
        logger = logging.getLogger("selftest")
        logger.info('Running bitbake to build aktualizr-native tools and garage-sign-native')
        bitbake('aktualizr-native garage-sign-native')

    def test_help(self):
        image_dir = get_bb_var("D", "aktualizr-native")
        bin_dir = get_bb_var("bindir", "aktualizr-native")
        gp_path = os.path.join(image_dir, bin_dir[1:], 'garage-push')
        result = runCmd('%s --help' % gp_path, ignore_status=True)
        self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)

    def test_java(self):
        result = runCmd('which java', ignore_status=True)
        self.assertEqual(result.status, 0, "Java not found.")

    def test_sign(self):
        image_dir = get_bb_var("D", "garage-sign-native")
        bin_dir = get_bb_var("bindir", "garage-sign-native")
        gs_path = os.path.join(image_dir, bin_dir[1:], 'garage-sign')
        result = runCmd('%s --help' % gs_path, ignore_status=True)
        self.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)

    def test_push(self):
        bitbake('core-image-minimal')
        self.write_config('IMAGE_INSTALL_append = " man "')
        bitbake('core-image-minimal')

    def test_hsm(self):
        self.write_config('SOTA_CLIENT_FEATURES="hsm hsm-test"')
        bitbake('core-image-minimal')

    def test_qemu(self):
        print('')
        # Create empty object.
        args = type('', (), {})()
        args.imagename = 'core-image-minimal'
        args.mac = None
        args.dir = 'tmp/deploy/images'
        args.efi = False
        args.machine = None
        args.no_kvm = False
        args.no_gui = True
        args.gdb = False
        args.pcap = None
        args.overlay = None
        args.dry_run = False

        qemu_command = QemuCommand(args)
        cmdline = qemu_command.command_line()
        print('Booting image with run-qemu-ota...')
        s = subprocess.Popen(cmdline)
        time.sleep(10)
        print('Machine name (hostname) of device is:')
        ssh_cmd = ['ssh', '-q', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@localhost', '-p', str(qemu_command.ssh_port), 'hostname']
        s2 = subprocess.Popen(ssh_cmd)
        time.sleep(5)
        try:
            s.terminate()
        except KeyboardInterrupt:
            pass