def testDirErrors(self):
        self.assertRaises(errors.GenericError,
                          utils.MakeDirWithPerm,
                          "/ganeti-qa-non-test",
                          0o700,
                          0,
                          0,
                          _lstat_fn=_MockStatResult(None, 0, 0, 0))
        self.assertRaises(IndexError, self._mkdir_calls.pop)

        other_stat_raise = _MockStatResult(_OtherStatRaise, stat.S_IFDIR, 0, 0)
        self.assertRaises(errors.GenericError,
                          utils.MakeDirWithPerm,
                          "/ganeti-qa-non-test",
                          0o700,
                          0,
                          0,
                          _lstat_fn=other_stat_raise)
        self.assertRaises(IndexError, self._mkdir_calls.pop)

        non_exist_stat = _MockStatResult(_RaiseNoEntError, stat.S_IFDIR, 0, 0)
        utils.MakeDirWithPerm("/ganeti-qa-non-test",
                              0o700,
                              self.UID_A,
                              self.GID_A,
                              _lstat_fn=non_exist_stat,
                              _mkdir_fn=self._FakeMkdir,
                              _perm_fn=self._VerifyPerm)
        self.assertEqual(self._mkdir_calls.pop(0), "/ganeti-qa-non-test")
 def testMakeDirWithPerm(self):
     is_dir_stat = _MockStatResult(None, stat.S_IFDIR, 0, 0)
     utils.MakeDirWithPerm("/ganeti-qa-non-test",
                           0o700,
                           self.UID_A,
                           self.GID_A,
                           _lstat_fn=is_dir_stat,
                           _perm_fn=self._VerifyPerm)
Exemple #3
0
def ProcessPath(path):
  """Processes a path component.

  @param path: A tuple of the path component to process

  """
  (pathname, pathtype, mode, uid, gid) = path[0:5]

  assert pathtype in ALL_TYPES

  if pathtype in (DIR, QUEUE_DIR):
    # No additional parameters
    assert len(path) == 5
    if pathtype == DIR:
      utils.MakeDirWithPerm(pathname, mode, uid, gid)
    elif pathtype == QUEUE_DIR:
      EnsureQueueDir(pathname, mode, uid, gid)
  elif pathtype == FILE:
    (must_exist, ) = path[5:]
    utils.EnforcePermission(pathname, mode, uid=uid, gid=gid,
                            must_exist=must_exist)