Ejemplo n.º 1
0
 def resize_fs(self):
     """Resize the filesystem on the specified device"""
     self._check_device_exists()
     try:
         utils.execute("sudo", "resize2fs", self.device_path)
     except ProcessExecutionError as err:
         LOG.error(err)
         raise GuestError("Error resizing the filesystem: %s" %
                          self.device_path)
Ejemplo n.º 2
0
 def test_resize_volume_unmount_exception(self, mock_logging):
     self.instance.guest.unmount_volume = Mock(
         side_effect=GuestError("test exception"))
     self.assertRaises(GuestError,
                       self.action._unmount_volume,
                       recover_func=self.action._recover_restart)
     self.assertEqual(1, self.instance.restart.call_count)
     self.instance.guest.unmount_volume.side_effect = None
     self.instance.reset_mock()
Ejemplo n.º 3
0
    def mount_points(self, device_path):
        """Returns a list of mount points on the specified device."""
        try:
            cmd = "grep %s /etc/mtab | awk '{print $2}'" % device_path
            stdout, stderr = utils.execute(cmd, shell=True)
            return stdout.strip().split('\n')

        except ProcessExecutionError:
            LOG.exception(_("Error retrieving mount points"))
            raise GuestError(_("Could not obtain a list of mount points for "
                               "device: %s") % device_path)
Ejemplo n.º 4
0
 def resize_fs(self, mount_point):
     """Resize the filesystem on the specified device."""
     self._check_device_exists()
     try:
         utils.execute("e2fsck", "-f", "-p", self.device_path,
                       run_as_root=True, root_helper="sudo")
         utils.execute("resize2fs", self.device_path,
                       run_as_root=True, root_helper="sudo")
     except ProcessExecutionError:
         LOG.exception(_("Error resizing file system."))
         raise GuestError(_("Error resizing the filesystem: %s") %
                          self.device_path)
Ejemplo n.º 5
0
 def resize_fs(self, mount_point):
     """Resize the filesystem on the specified device"""
     self._check_device_exists()
     try:
         # check if the device is mounted at mount_point before e2fsck
         if not os.path.ismount(mount_point):
             utils.execute("sudo", "e2fsck", "-f", "-n", self.device_path)
         utils.execute("sudo", "resize2fs", self.device_path)
     except ProcessExecutionError as err:
         LOG.error(err)
         raise GuestError("Error resizing the filesystem: %s" %
                          self.device_path)
Ejemplo n.º 6
0
 def set_readahead_size(self, readahead_size,
                        execute_function=utils.execute):
     """Set the readahead size of disk."""
     self._check_device_exists()
     try:
         execute_function("sudo", "blockdev", "--setra",
                          readahead_size, self.device_path)
     except ProcessExecutionError:
         LOG.exception(_("Error setting readhead size to %(size)s "
                         "for device %(device)s.") %
                       {'size': readahead_size, 'device': self.device_path})
         raise GuestError(_("Error setting readhead size: %s.") %
                          self.device_path)
Ejemplo n.º 7
0
    def _check_device_exists(self):
        """Check that the device path exists.

        Verify that the device path has actually been created and can report
        it's size, only then can it be available for formatting, retry
        num_tries to account for the time lag.
        """
        try:
            num_tries = CONF.num_tries
            utils.execute('sudo', 'blockdev', '--getsize64', self.device_path,
                          attempts=num_tries)
        except ProcessExecutionError:
            raise GuestError("InvalidDevicePath(path=%s)" % self.device_path)
Ejemplo n.º 8
0
 def test_create_cluster_fail(self, mock_logging, mock_dv, mock_ds,
                              mock_find_all, mock_load, mock_ready, mock_ip,
                              mock_reset_task, mock_update_status):
     mock_find_all.return_value.all.return_value = [self.dbinst1]
     mock_load.return_value = BaseInstance(
         Mock(), self.dbinst1, Mock(),
         InstanceServiceStatus(ServiceStatuses.NEW))
     mock_ip.return_value = "10.0.0.2"
     guest_client = Mock()
     guest_client.install_cluster = Mock(side_effect=GuestError("Error"))
     with patch.object(ClusterTasks, 'get_guest',
                       return_value=guest_client):
         self.clustertasks.create_cluster(Mock(), self.cluster_id)
         mock_update_status.assert_called_with('1232')
         mock_reset_task.assert_called_with()
Ejemplo n.º 9
0
    def _check_device_exists(self):
        """Check that the device path exists.

        Verify that the device path has actually been created and can report
        its size, only then can it be available for formatting, retry
        num_tries to account for the time lag.
        """
        try:
            num_tries = CONF.num_tries
            LOG.debug("Checking if %s exists." % self.device_path)

            utils.execute('sudo',
                          'blockdev',
                          '--getsize64',
                          self.device_path,
                          attempts=num_tries)
        except ProcessExecutionError:
            LOG.exception(_("Error getting device status"))
            raise GuestError(original_message=_("InvalidDevicePath(path=%s)") %
                             self.device_path)
Ejemplo n.º 10
0
 def resize_fs(self, mount_point):
     """Resize the filesystem on the specified device."""
     self._check_device_exists()
     try:
         # check if the device is mounted at mount_point before e2fsck
         if not os.path.ismount(mount_point):
             utils.execute("e2fsck",
                           "-f",
                           "-p",
                           self.device_path,
                           run_as_root=True,
                           root_helper="sudo")
         utils.execute("resize2fs",
                       self.device_path,
                       run_as_root=True,
                       root_helper="sudo")
     except ProcessExecutionError:
         LOG.exception(_("Error resizing file system."))
         raise GuestError(
             original_message=_("Error resizing the filesystem: %s") %
             self.device_path)