Example #1
0
def sdb_exist():
    help_url = 'https://github.com/dhs-shine/litmus#prerequisite'
    try:
        check_output(['sdb', 'version'], timeout=10)
    except FileNotFoundError:
        raise Exception('Please install sdb. Refer to {}'.format(help_url))
    return
Example #2
0
 def get_items():
     """docstring for splitter"""
     out = check_output('ls /dev | egrep "(ttyUSB|ttyS0)"', shell=True)
     if out:
         return out.split()
     else:
         raise Exception('There\'s no /dev/ttyUSB for duts.')
Example #3
0
 def _find_device_id(self):
     """docstring for _find_device_id"""
     self.start_sdb_server()
     outs = check_output(['sdb', 'devices'], timeout=10)
     pattern = '.*List of devices attached \n([a-zA-Z0-9]*).*device.*'
     found = find_pattern(pattern, outs, groupindex=1)
     if found:
         return found
Example #4
0
 def find_cleware4_names():
     """docstring for find_cleware4s"""
     p = '.*Switch1.*version:.(29|512),.*serial number:.([0-9]{6,7})'
     cleware4s = [find_pattern(p, s, groupindex=2)
                  for s in check_output('clewarecontrol -l',
                                        shell=True).split('\n')
                  if find_pattern(p, s)]
     logging.debug('cleware4 cutters : {0}'.format(cleware4s))
     return cleware4s
Example #5
0
    def is_on(self):
        """docstring for is_on"""
        super(cuttercleware4, self).is_on()
        c = self._getstatuscmd.format(cport=self._cport, cindex=self._cindex)
        out = check_output(c, shell=True, timeout=10)

        if find_pattern(pattern=r'On', data=out):
            return True
        else:
            return False
Example #6
0
    def _find_usb_bus_and_device_address(self):
        """docstring for _find_usb_bus_and_device_address"""
        pattern = 'usb (.*):.*idVendor={0}, idProduct={1}'.format(
            self._vid, self._pid)
        kernlog = 'dmesg | grep usb | tail -n 20'
        outs = check_output(kernlog, shell=True, timeout=10)
        result = find_all_pattern(pattern=pattern, data=outs)
        if result:
            bid = result[-1]
            busaddr_cmd = 'cat /sys/bus/usb/devices/{0}/busnum'.format(bid)
            busaddr = check_output(busaddr_cmd, shell=True).rstrip().zfill(3)
            logging.debug('usb_bus_addr : {}'.format(busaddr))
            devaddr_cmd = 'cat /sys/bus/usb/devices/{0}/devnum'.format(bid)
            devaddr = check_output(devaddr_cmd, shell=True).rstrip().zfill(3)
            logging.debug('usb_dev_addr : {}'.format(devaddr))
        else:
            raise Exception('Can\'t find usb bus and dev addr')

        return (busaddr, devaddr)
Example #7
0
 def find_smartpower_names():
     """docstring for find_smartpowers"""
     p = '.*Microchip Technology.*'
     try:
         smartpower_names = ['/dev/{}'.format(s)
                             for s in check_output('ls /dev '
                                                   '| grep hidraw',
                                                   shell=True).split()
                             if find_pattern(p, check_output(['cat',
                                                              '/sys/'
                                                              'class/'
                                                              'hidraw/'
                                                              '{}/'
                                                              'device/'
                                                              'uevent'
                                                              .format(s)
                                                              ]))]
     except AttributeError:
         smartpower_names = []
     logging.debug('smart powers : {0}'.format(smartpower_names))
     return smartpower_names
Example #8
0
    def is_on(self):
        """docstring for is_on"""
        super(cuttersmartpower, self).is_on()
        c = self._getstatuscmd.format(cport=self._cport)
        out = check_output(c,
                           shell=True,
                           stderr=subprocess.DEVNULL,
                           timeout=10)

        if find_pattern(pattern=r'[0-9].[0-9]{3}W', data=out):
            return True
        else:
            return False
Example #9
0
    def _find_usb_busid(self):
        """docstring for find_usb_busid"""
        pattern = 'usb (.*):.*idVendor={0}, idProduct={1}'.format(
            self._vid, self._pid)
        kernlog = 'dmesg | grep usb | tail -n 20'
        outs = check_output(kernlog, shell=True, timeout=10)
        result = find_all_pattern(pattern=pattern, data=outs)
        if result:
            busid = result[-1]
            logging.debug('usb busid : {}'.format(busid))
        else:
            raise Exception('Can\'t find usb busid')

        return busid
Example #10
0
    def _attach_sdb(self):
        """docstring for _attach_sdb"""
        # start sdb server if it is not started.
        call('sdb start-server'.split(), timeout=10)

        retry_attempt = 0
        pattern = r'{}.*device.*\t.*'.format(self.get_id())

        while retry_attempt < self._max_attempt_attach_sdb:
            for l in range(self._retrycnt_at_a_time_sdb):
                outs = check_output('sdb devices'.split(), timeout=10)
                logging.debug(outs)
                if find_pattern(pattern, outs):
                    logging.debug('found {}.'.format(self.get_id()))
                    return
                time.sleep(0.2)
            retry_attempt += 1
        else:
            raise Exception('Can\'t find device.')
Example #11
0
    def is_on(self):
        """
        Return whether device is turned on or not.

        Example:
            >>> dut.on()
            >>> dut.is_on()
            True
            >>> dut.off()
            >>> dut.is_on()
            False

        :returns boolean: true if device is turned on, false otherwise.
        """
        pattern = '.*{}'.format(self.get_id())
        outs = check_output('sdb devices'.split(), timeout=10)
        if find_pattern(pattern, outs):
            return True
        else:
            return False
Example #12
0
    def pull_file(self, src, dest, timeout=None):
        """
        Pull a file from device to destination path of host.

        :param str src: file path from device
        :param str dest: destination path of host pc
        :param float timeout: timeout

        Example:
            >>> dut.pull_file('/tmp/test.png','.')

        :returns str: stdout of sdb push command
        """
        logging.debug(
            '==============Pull a file from device {}============'.format(
                self.get_name()))
        logging.debug('src from dut : {}'.format(src))
        logging.debug('dest on host: {}'.format(dest))
        c = ['sdb', '-s', self.get_id(), 'pull', src, dest]
        result = check_output(c, timeout=timeout)
        return result
Example #13
0
    def run_cmd(self, command, timeout=None):
        """
        Run a command on device.

        :param str command: command to run on device
        :param float timeout: timeout

        Example:
            >>> dut.on()
            >>> dut.run_cmd('ls -alF / | grep usr')
            \'drwxr-xr-x  15 root root     4096 Apr 29  2016 usr/\\r\\n\'

        :returns str: stdout of sdb shell command

        """
        logging.debug(
            '==============Run a command on device {}============'.format(
                self.get_name()))
        c = ['sdb', '-s', self.get_id(), 'shell']
        c.extend(convert_single_item_to_list(command))
        logging.debug(c)
        result = check_output(c, timeout=timeout)
        return result