Exemplo n.º 1
0
    def UpgradeRapiUsers(self):
        if (os.path.isfile(self.opts.RAPI_USERS_FILE_PRE24)
                and not os.path.islink(self.opts.RAPI_USERS_FILE_PRE24)):
            if os.path.exists(self.opts.RAPI_USERS_FILE):
                raise Error(
                    "Found pre-2.4 RAPI users file at %s, but another file"
                    " already exists at %s" % (self.opts.RAPI_USERS_FILE_PRE24,
                                               self.opts.RAPI_USERS_FILE))
            logging.info("Found pre-2.4 RAPI users file at %s, renaming to %s",
                         self.opts.RAPI_USERS_FILE_PRE24,
                         self.opts.RAPI_USERS_FILE)
            if not self.opts.dry_run:
                utils.RenameFile(self.opts.RAPI_USERS_FILE_PRE24,
                                 self.opts.RAPI_USERS_FILE,
                                 mkdir=True,
                                 mkdir_mode=0750)

        # Create a symlink for RAPI users file
        if (not (os.path.islink(self.opts.RAPI_USERS_FILE_PRE24)
                 or os.path.isfile(self.opts.RAPI_USERS_FILE_PRE24))
                and os.path.isfile(self.opts.RAPI_USERS_FILE)):
            logging.info("Creating symlink from %s to %s",
                         self.opts.RAPI_USERS_FILE_PRE24,
                         self.opts.RAPI_USERS_FILE)
            if not self.opts.dry_run:
                os.symlink(self.opts.RAPI_USERS_FILE,
                           self.opts.RAPI_USERS_FILE_PRE24)
Exemplo n.º 2
0
  def _StashConfigFile(self, instance_name):
    """Move the Xen config file to the log directory and return its new path.

    """
    old_filename = self._ConfigFileName(instance_name)
    base = ("%s-%s" %
            (instance_name, utils.TimestampForFilename()))
    new_filename = utils.PathJoin(pathutils.LOG_XEN_DIR, base)
    utils.RenameFile(old_filename, new_filename)
    return new_filename
Exemplo n.º 3
0
  def testRenameMkdir(self):
    """Rename with mkdir"""
    utils.RenameFile(self.tmpfile, os.path.join(self.tmpdir, "test/xyz"),
                     mkdir=True)
    self.assert_(os.path.isdir(os.path.join(self.tmpdir, "test")))
    self.assert_(os.path.isfile(os.path.join(self.tmpdir, "test/xyz")))

    self.assertRaises(EnvironmentError, utils.RenameFile,
                      os.path.join(self.tmpdir, "test/xyz"),
                      os.path.join(self.tmpdir, "test/foo/bar/baz"),
                      mkdir=True)

    self.assertTrue(os.path.exists(os.path.join(self.tmpdir, "test/xyz")))
    self.assertFalse(os.path.exists(os.path.join(self.tmpdir, "test/foo/bar")))
    self.assertFalse(os.path.exists(os.path.join(self.tmpdir,
                                                 "test/foo/bar/baz")))
Exemplo n.º 4
0
 def testSimpleRename2(self):
     """Simple rename 2"""
     utils.RenameFile(self.tmpfile,
                      os.path.join(self.tmpdir, "xyz"),
                      mkdir=True)
     self.assert_(os.path.isfile(os.path.join(self.tmpdir, "xyz")))
Exemplo n.º 5
0
 def testSimpleRename1(self):
     """Simple rename 1"""
     utils.RenameFile(self.tmpfile, os.path.join(self.tmpdir, "xyz"))
     self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, "xyz")))