Beispiel #1
0
 def test_with_exists_and_not_exists(self, m_subp):
     """with exists=file where file does not exist should invoke subp."""
     mydev = self.tmp_path("mydev")
     util.udevadm_settle(exists=mydev)
     m_subp.called_once_with(
         ['udevadm', 'settle',
          '--exit-if-exists=%s' % mydev])
Beispiel #2
0
 def test_with_timeout_int(self, m_subp):
     """timeout can be an integer."""
     timeout = 9
     util.udevadm_settle(timeout=timeout)
     m_subp.called_once_with(
         ['udevadm', 'settle',
          '--timeout=%s' % timeout])
Beispiel #3
0
 def test_with_timeout_string(self, m_subp):
     """timeout can be a string."""
     timeout = "555"
     util.udevadm_settle(timeout=timeout)
     m_subp.assert_called_once_with(
         ['udevadm', 'settle',
          '--timeout=%s' % timeout])
Beispiel #4
0
 def test_with_exists_and_timeout(self, m_subp):
     """test call with both exists and timeout."""
     mydev = self.tmp_path("mydev")
     timeout = "3"
     util.udevadm_settle(exists=mydev)
     m_subp.called_once_with(
         ['udevadm', 'settle', '--exit-if-exists=%s' % mydev,
          '--timeout=%s' % timeout])
Beispiel #5
0
 def test_with_exists_and_timeout(self, m_subp):
     """test call with both exists and timeout."""
     mydev = self.tmp_path("mydev")
     timeout = "3"
     util.udevadm_settle(exists=mydev)
     m_subp.called_once_with(
         ['udevadm', 'settle', '--exit-if-exists=%s' % mydev,
          '--timeout=%s' % timeout])
Beispiel #6
0
    def user_data_rhevm(self):
        """
        RHEVM specific userdata read

         If on RHEV-M the user data will be contained on the
         floppy device in file <user_data_file>
         To access it:
           modprobe floppy

           Leverage util.mount_cb to:
               mkdir <tmp mount dir>
               mount /dev/fd0 <tmp mount dir>
               The call back passed to util.mount_cb will do:
                   read <tmp mount dir>/<user_data_file>
        """

        return_str = None

        # modprobe floppy
        try:
            modprobe_floppy()
        except subp.ProcessExecutionError as e:
            util.logexc(LOG, "Failed modprobe: %s", e)
            return False

        floppy_dev = "/dev/fd0"

        # udevadm settle for floppy device
        try:
            util.udevadm_settle(exists=floppy_dev, timeout=5)
        except (subp.ProcessExecutionError, OSError) as e:
            util.logexc(LOG, "Failed udevadm_settle: %s\n", e)
            return False

        try:
            return_str = util.mount_cb(floppy_dev, read_user_data_callback)
        except OSError as err:
            if err.errno != errno.ENOENT:
                raise
        except util.MountFailedError:
            util.logexc(
                LOG,
                "Failed to mount %s when looking for user data",
                floppy_dev,
            )

        self.userdata_raw = return_str
        self.metadata = META_DATA_NOT_SUPPORTED

        if return_str:
            return True
        else:
            return False
Beispiel #7
0
def assert_and_settle_device(device):
    """Assert that device exists and settle so it is fully recognized."""
    if not os.path.exists(device):
        util.udevadm_settle()
        if not os.path.exists(device):
            raise RuntimeError("Device %s did not exist and was not created "
                               "with a udevadm settle." % device)

    # Whether or not the device existed above, it is possible that udev
    # events that would populate udev database (for reading by lsdname) have
    # not yet finished. So settle again.
    util.udevadm_settle()
Beispiel #8
0
def assert_and_settle_device(device):
    """Assert that device exists and settle so it is fully recognized."""
    if not os.path.exists(device):
        util.udevadm_settle()
        if not os.path.exists(device):
            raise RuntimeError("Device %s did not exist and was not created "
                               "with a udevadm settle." % device)

    # Whether or not the device existed above, it is possible that udev
    # events that would populate udev database (for reading by lsdname) have
    # not yet finished. So settle again.
    util.udevadm_settle()
Beispiel #9
0
def read_parttbl(device):
    """
    Use partprobe instead of 'udevadm'. Partprobe is the only
    reliable way to probe the partition table.
    """
    blkdev_cmd = [BLKDEV_CMD, '--rereadpt', device]
    util.udevadm_settle()
    try:
        util.subp(blkdev_cmd)
    except Exception as e:
        util.logexc(LOG, "Failed reading the partition table %s" % e)

    util.udevadm_settle()
Beispiel #10
0
def read_parttbl(device):
    """
    Use partprobe instead of 'udevadm'. Partprobe is the only
    reliable way to probe the partition table.
    """
    blkdev_cmd = [BLKDEV_CMD, '--rereadpt', device]
    util.udevadm_settle()
    try:
        util.subp(blkdev_cmd)
    except Exception as e:
        util.logexc(LOG, "Failed reading the partition table %s" % e)

    util.udevadm_settle()
Beispiel #11
0
def read_parttbl(device):
    """
    `Partprobe` is preferred over `blkdev` since it is more reliably
    able to probe the partition table.
    """
    if PARTPROBE_CMD is not None:
        probe_cmd = [PARTPROBE_CMD, device]
    else:
        probe_cmd = [BLKDEV_CMD, '--rereadpt', device]
    util.udevadm_settle()
    try:
        subp.subp(probe_cmd)
    except Exception as e:
        util.logexc(LOG, "Failed reading the partition table %s" % e)

    util.udevadm_settle()
    def user_data_rhevm(self):
        '''
        RHEVM specific userdata read

         If on RHEV-M the user data will be contained on the
         floppy device in file <user_data_file>
         To access it:
           modprobe floppy

           Leverage util.mount_cb to:
               mkdir <tmp mount dir>
               mount /dev/fd0 <tmp mount dir>
               The call back passed to util.mount_cb will do:
                   read <tmp mount dir>/<user_data_file>
        '''

        return_str = None

        # modprobe floppy
        try:
            cmd = CMD_PROBE_FLOPPY
            (cmd_out, _err) = util.subp(cmd)
            LOG.debug('Command: %s\nOutput%s', ' '.join(cmd), cmd_out)
        except ProcessExecutionError as _err:
            util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err)
            return False
        except OSError as _err:
            util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err)
            return False

        floppy_dev = '/dev/fd0'

        # udevadm settle for floppy device
        try:
            (cmd_out, _err) = util.udevadm_settle(exists=floppy_dev, timeout=5)
            LOG.debug('Command: %s\nOutput%s', ' '.join(cmd), cmd_out)
        except ProcessExecutionError as _err:
            util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err)
            return False
        except OSError as _err:
            util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err)
            return False

        try:
            return_str = util.mount_cb(floppy_dev, read_user_data_callback)
        except OSError as err:
            if err.errno != errno.ENOENT:
                raise
        except util.MountFailedError:
            util.logexc(LOG, "Failed to mount %s when looking for user data",
                        floppy_dev)

        self.userdata_raw = return_str
        self.metadata = META_DATA_NOT_SUPPORTED

        if return_str:
            return True
        else:
            return False
Beispiel #13
0
 def test_with_exists_and_not_exists(self, m_subp):
     """with exists=file where file does not exist should invoke subp."""
     mydev = self.tmp_path("mydev")
     util.udevadm_settle(exists=mydev)
     m_subp.called_once_with(
         ['udevadm', 'settle', '--exit-if-exists=%s' % mydev])
Beispiel #14
0
 def test_with_exists_and_file_exists(self, m_subp):
     """with exists=file where file does exist should not invoke subp."""
     mydev = self.tmp_path("mydev")
     util.write_file(mydev, "foo\n")
     util.udevadm_settle(exists=mydev)
     self.assertIsNone(m_subp.call_args)
Beispiel #15
0
 def test_with_exists_and_file_exists(self, m_subp):
     """with exists=file where file does exist should not invoke subp."""
     mydev = self.tmp_path("mydev")
     util.write_file(mydev, "foo\n")
     util.udevadm_settle(exists=mydev)
     self.assertIsNone(m_subp.call_args)
Beispiel #16
0
 def test_with_no_params(self, m_subp):
     """called with no parameters."""
     util.udevadm_settle()
     m_subp.called_once_with(mock.call(['udevadm', 'settle']))
Beispiel #17
0
 def test_with_timeout_int(self, m_subp):
     """timeout can be an integer."""
     timeout = 9
     util.udevadm_settle(timeout=timeout)
     m_subp.called_once_with(
         ['udevadm', 'settle', '--timeout=%s' % timeout])
Beispiel #18
0
 def settle(self, *, exists=None) -> None:
     if exists is not None:
         exists = net.sys_dev_path(exists)
     util.udevadm_settle(exists=exists)
Beispiel #19
0
 def test_with_no_params(self, m_subp):
     """called with no parameters."""
     util.udevadm_settle()
     m_subp.called_once_with(mock.call(['udevadm', 'settle']))
Beispiel #20
0
 def test_with_timeout_string(self, m_subp):
     """timeout can be a string."""
     timeout = "555"
     util.udevadm_settle(timeout=timeout)
     m_subp.assert_called_once_with(
         ['udevadm', 'settle', '--timeout=%s' % timeout])