예제 #1
0
 def test_check_dir_ok(self, mock_free_space, mock_dir_writable, mock_exists):
     mock_exists.return_value = True
     self.config(tempdir="/fake/path")
     utils.check_dir()
     mock_exists.assert_called_once_with(CONF.tempdir)
     mock_dir_writable.assert_called_once_with(CONF.tempdir)
     mock_free_space.assert_called_once_with(CONF.tempdir, 1)
예제 #2
0
 def test_check_dir_with_pass_in(self, mock_free_space, mock_dir_writable, mock_exists):
     mock_exists.return_value = True
     # test passing in a directory and size
     utils.check_dir(directory_to_check="/fake/path", required_space=5)
     mock_exists.assert_called_once_with("/fake/path")
     mock_dir_writable.assert_called_once_with("/fake/path")
     mock_free_space.assert_called_once_with("/fake/path", 5)
예제 #3
0
 def test_check_dir_with_pass_in(self, mock_free_space, mock_dir_writable,
                                 mock_exists):
     mock_exists.return_value = True
     # test passing in a directory and size
     utils.check_dir(directory_to_check='/fake/path', required_space=5)
     mock_exists.assert_called_once_with('/fake/path')
     mock_dir_writable.assert_called_once_with('/fake/path')
     mock_free_space.assert_called_once_with('/fake/path', 5)
예제 #4
0
 def test_check_dir_ok(self, mock_free_space, mock_dir_writable,
                       mock_exists):
     mock_exists.return_value = True
     self.config(tempdir='/fake/path')
     utils.check_dir()
     mock_exists.assert_called_once_with(CONF.tempdir)
     mock_dir_writable.assert_called_once_with(CONF.tempdir)
     mock_free_space.assert_called_once_with(CONF.tempdir, 1)
예제 #5
0
파일: test_utils.py 프로젝트: yzping/ironic
 def test_check_dir_with_pass_in(self, mock_gettempdir, mock_free_space,
                                 mock_dir_writable, mock_exists):
     mock_exists.return_value = True
     # test passing in a directory and size
     utils.check_dir(directory_to_check='/fake/path', required_space=5)
     self.assertFalse(mock_gettempdir.called)
     mock_free_space.assert_called_once_with('/fake/path', 5)
     mock_exists.assert_called_once_with('/fake/path')
예제 #6
0
파일: test_utils.py 프로젝트: yzping/ironic
    def test_check_dir_ok(self, mock_gettempdir, mock_dir_writable,
                          mock_free_space, mock_exists):
        mock_gettempdir.return_value = "/fake/path"
        mock_exists.return_value = True

        utils.check_dir()
        mock_gettempdir.assert_called_once_with()
        mock_free_space.assert_called_once_with(mock_gettempdir.return_value)
        mock_exists.assert_called_once_with(mock_gettempdir.return_value)
예제 #7
0
파일: test_utils.py 프로젝트: yzping/ironic
    def test_check_dir_with_conf(self, mock_gettempdir, mock_free_space,
                                 mock_dir_writable, mock_exists):
        self.config(tempdir='/fake/path')
        mock_exists.return_value = True

        utils.check_dir()
        self.assertFalse(mock_gettempdir.called)
        mock_free_space.assert_called_once_with(CONF.tempdir, 1)
        mock_exists.assert_called_once_with(CONF.tempdir)
예제 #8
0
 def test_check_dir_ok(self, mock_free_space, mock_dir_writable):
     self.config(tempdir='/fake/path')
     # NOTE(dtantsur): self.config uses os.path.exists, so we cannot mock
     # on the method level.
     with mock.patch.object(os.path, 'exists',
                            autospec=True) as mock_exists:
         mock_exists.return_value = True
         utils.check_dir()
         mock_exists.assert_called_once_with(CONF.tempdir)
     mock_dir_writable.assert_called_once_with(CONF.tempdir)
     mock_free_space.assert_called_once_with(CONF.tempdir, 1)
예제 #9
0
 def test_check_dir_ok(self, mock_free_space, mock_dir_writable):
     self.config(tempdir='/fake/path')
     # NOTE(dtantsur): self.config uses os.path.exists, so we cannot mock
     # on the method level.
     with mock.patch.object(os.path, 'exists',
                            autospec=True) as mock_exists:
         mock_exists.return_value = True
         utils.check_dir()
         mock_exists.assert_called_once_with(CONF.tempdir)
     mock_dir_writable.assert_called_once_with(CONF.tempdir)
     mock_free_space.assert_called_once_with(CONF.tempdir, 1)
예제 #10
0
def _check_temp_dir():
    """Check for Valid temp directory."""
    global TMP_DIR_CHECKED
    # because a temporary file is used to pass the password to ipmitool,
    # we should check the directory
    if TMP_DIR_CHECKED is None:
        try:
            utils.check_dir()
        except (exception.PathNotFound, exception.DirectoryNotWritable,
                exception.InsufficientDiskSpace) as e:
            with excutils.save_and_reraise_exception():
                TMP_DIR_CHECKED = False
                err_msg = (_("Ipmitool drivers need to be able to create "
                             "temporary files to pass password to ipmitool. "
                             "Encountered error: %s") % e)
                e.message = err_msg
                LOG.error(err_msg)
        else:
            TMP_DIR_CHECKED = True
예제 #11
0
def _check_temp_dir():
    """Check for Valid temp directory."""
    global TMP_DIR_CHECKED
    # because a temporary file is used to pass the password to ipmitool,
    # we should check the directory
    if TMP_DIR_CHECKED is None:
        try:
            utils.check_dir()
        except (exception.PathNotFound,
                exception.DirectoryNotWritable,
                exception.InsufficientDiskSpace) as e:
            with excutils.save_and_reraise_exception():
                TMP_DIR_CHECKED = False
                err_msg = (_("Ipmitool drivers need to be able to create "
                             "temporary files to pass password to ipmitool. "
                             "Encountered error: %s") % e)
                e.message = err_msg
                LOG.error(err_msg)
        else:
            TMP_DIR_CHECKED = True