summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qusb.py
blob: 6a004f05916e699044b012f1aeb6fc40e5172aab (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
import sh
import unittest
import re
from test.helpers.changedir import changedir


class Qusb(unittest.TestCase):
    params = None

    def __init__(self, testname, testfunc, varlist):
        self.params = varlist
        super(Qusb, self).__init__(testfunc)
        self._testMethodDoc = testname

    def execute(self):
        # Execute script usb.sh
        p = sh.bash('test/scripts/usb.sh')
        # Search in the stdout a pattern "/dev/sd + {letter} + {number}
        q = re.search("/dev/sd\w\d", p.stdout.decode('ascii'))
        # get the first device which matches the pattern
        device = q.group(0)
        # create a new folder where the pendrive is going to be mounted
        sh.mkdir("-p", "/mnt/pendrive")
        # mount the device
        p = sh.mount(device, "/mnt/pendrive")
        if p.exit_code == 0:
            # copy files
            p = sh.cp("/root/usbtest/usbdatatest.bin", "/root/usbtest/usbdatatest.md5", "/mnt/pendrive")
            if p.exit_code == 0:
                # check md5
                with changedir("/mnt/pendrive/"):
                    p = sh.md5sum("-c", "usbdatatest.md5")
                q = re.search("OK", p.stdout.decode('ascii'))
                # delete files
                sh.rm("-f", "/mnt/pendrive/usbdatatest.bin", "/mnt/pendrive/usbdatatest.md5")
                # umount
                sh.umount("/mnt/pendrive")
                # check result
                if q is None:
                    self.fail("failed: wrong md5 result.")
            else:
                # umount
                sh.umount("/mnt/pendrive")
                self.fail("failed: unable to copy files.")
        else:
            self.fail("failed: unable to mount the device.")