コード例 #1
0
    def __createWorkArea(self,
                         jobDesc=None,
                         log=None,
                         logLevel="INFO",
                         proxy=None):
        """Creates a directory for the container and populates it with the
        template directories, scripts & proxy.
        """
        if not jobDesc:
            jobDesc = {}
        if not log:
            log = gLogger

        # Create the directory for our container area
        try:
            os.mkdir(self.__workdir)
        except OSError:
            if not os.path.isdir(self.__workdir):
                result = S_ERROR(
                    "Failed to create container base directory '%s'" %
                    self.__workdir)
                result["ReschedulePayload"] = True
                return result
            # Otherwise, directory probably just already exists...
        baseDir = None
        try:
            baseDir = tempfile.mkdtemp(prefix="job%s_" %
                                       jobDesc.get("jobID", 0),
                                       dir=self.__workdir)
        except OSError:
            result = S_ERROR(
                "Failed to create container work directory in '%s'" %
                self.__workdir)
            result["ReschedulePayload"] = True
            return result

        self.log.debug("Use singularity workarea: %s" % baseDir)
        for subdir in ["home", "tmp", "var_tmp"]:
            os.mkdir(os.path.join(baseDir, subdir))
        tmpDir = os.path.join(baseDir, "tmp")

        # Now we have a directory, we can stage in the proxy and scripts
        # Proxy
        if proxy:
            proxyLoc = os.path.join(tmpDir, "proxy")
            rawfd = os.open(proxyLoc, os.O_WRONLY | os.O_CREAT, 0o600)
            fd = os.fdopen(rawfd, "wb")
            fd.write(proxy)
            fd.close()
        else:
            self.log.warn("No user proxy")

        # Job Wrapper (Standard-ish DIRAC wrapper)
        result = createRelocatedJobWrapper(
            wrapperPath=tmpDir,
            rootLocation=self.__innerdir,
            jobID=jobDesc.get("jobID", 0),
            jobParams=jobDesc.get("jobParams", {}),
            resourceParams=jobDesc.get("resourceParams", {}),
            optimizerParams=jobDesc.get("optimizerParams", {}),
            log=log,
            logLevel=logLevel,
            extraOptions=""
            if self.__installDIRACInContainer else "/tmp/pilot.cfg",
        )
        if not result["OK"]:
            result["ReschedulePayload"] = True
            return result
        wrapperPath = result["Value"]

        if self.__installDIRACInContainer:
            if six.PY2:
                result = S_ERROR(
                    "InstallDIRACInContainer is not supported with Python 2")
                result["ReschedulePayload"] = True
                return result

            infoDict = None
            if os.path.isfile(
                    "pilot.json"
            ):  # if this is a pilot 3 this file should be found
                with io.open("pilot.json") as pj:
                    infoDict = json.load(pj)

            # Extra Wrapper (Container DIRAC installer)
            installFlags = self.__getInstallFlags(infoDict)
            wrapSubs = {
                "next_wrapper": wrapperPath,
                "dirac_project": installFlags[0],
                "version": installFlags[1],
                "config_args": self.__getConfigFlags(infoDict),
            }
            CONTAINER_WRAPPER = CONTAINER_WRAPPER_INSTALL

        else:  # In case we don't (re)install DIRAC
            wrapSubs = {
                "next_wrapper": wrapperPath,
                "dirac_env_var": os.environ.get("DIRAC", ""),
                "diracos_env_var": os.environ.get("DIRACOS", ""),
            }
            if six.PY2:
                shutil.copyfile(
                    os.path.join(self.__findInstallBaseDir(), "bashrc"),
                    os.path.join(tmpDir, "bashrc"),
                )
                wrapSubs["rc_script"] = "bashrc"
            else:
                wrapSubs["rc_script"] = os.path.join(
                    self.__findInstallBaseDir(), "diracosrc")
            shutil.copyfile("pilot.cfg", os.path.join(tmpDir, "pilot.cfg"))
            CONTAINER_WRAPPER = CONTAINER_WRAPPER_NO_INSTALL

        wrapLoc = os.path.join(tmpDir, "dirac_container.sh")
        rawfd = os.open(wrapLoc, os.O_WRONLY | os.O_CREAT, 0o700)
        fd = os.fdopen(rawfd, "w")
        fd.write(CONTAINER_WRAPPER % wrapSubs)
        fd.close()

        ret = S_OK()
        ret["baseDir"] = baseDir
        ret["tmpDir"] = tmpDir
        if proxy:
            ret["proxyLocation"] = proxyLoc
        return ret
コード例 #2
0
  def __createWorkArea(self, proxy, jobDesc, log, logLevel):
    """ Creates a directory for the container and populates it with the
        template directories, scripts & proxy.
    """

    # Create the directory for our continer area
    try:
      os.mkdir(self.__workdir)
    except OSError:
      if not os.path.isdir(self.__workdir):
        result = S_ERROR("Failed to create container base directory '%s'" % self.__workdir)
        result['ReschedulePayload'] = True
        return result
      # Otherwise, directory probably just already exists...
    baseDir = None
    try:
      baseDir = tempfile.mkdtemp(prefix="job%s_" % jobDesc["jobID"], dir=self.__workdir)
    except OSError:
      result = S_ERROR("Failed to create container work directory in '%s'" % self.__workdir)
      result['ReschedulePayload'] = True
      return result

    self.log.debug('Use singularity workarea: %s' % baseDir)
    for subdir in ["home", "tmp", "var_tmp"]:
      os.mkdir(os.path.join(baseDir, subdir))
    tmpDir = os.path.join(baseDir, "tmp")

    # Now we have a directory, we can stage in the proxy and scripts
    # Proxy
    proxyLoc = os.path.join(tmpDir, "proxy")
    rawfd = os.open(proxyLoc, os.O_WRONLY | os.O_CREAT, 0o600)
    fd = os.fdopen(rawfd, "w")
    fd.write(proxy)
    fd.close()

    # dirac-install.py
    install_loc = os.path.join(tmpDir, "dirac-install.py")
    shutil.copyfile(DIRAC_INSTALL, install_loc)
    os.chmod(install_loc, 0o755)

    # Job Wrapper (Standard DIRAC wrapper)
    result = createRelocatedJobWrapper(tmpDir, self.__innerdir,
                                       log=log, logLevel=logLevel, **jobDesc)
    if not result['OK']:
      result['ReschedulePayload'] = True
      return result
    wrapperPath = result['Value']

    # Extra Wrapper (Container DIRAC installer)
    wrapSubs = {'next_wrapper': wrapperPath,
                'install_args': self.__getInstallFlags(),
                'config_args': self.__getConfigFlags(),
                }
    wrapLoc = os.path.join(tmpDir, "dirac_container.sh")
    rawfd = os.open(wrapLoc, os.O_WRONLY | os.O_CREAT, 0o700)
    fd = os.fdopen(rawfd, "w")
    fd.write(CONTAINER_WRAPPER % wrapSubs)
    fd.close()

    ret = S_OK()
    ret['baseDir'] = baseDir
    ret['tmpDir'] = tmpDir
    ret['proxyLocation'] = proxyLoc
    return ret
コード例 #3
0
    def __createWorkArea(self, proxy, jobDesc, log, logLevel):
        """ Creates a directory for the container and populates it with the
        template directories, scripts & proxy.
    """

        # Create the directory for our continer area
        try:
            os.mkdir(self.__workdir)
        except OSError:
            if not os.path.isdir(self.__workdir):
                result = S_ERROR(
                    "Failed to create container base directory '%s'" %
                    self.__workdir)
                result['ReschedulePayload'] = True
                return result
            # Otherwise, directory probably just already exists...
        baseDir = None
        try:
            baseDir = tempfile.mkdtemp(prefix="job%s_" % jobDesc["jobID"],
                                       dir=self.__workdir)
        except OSError:
            result = S_ERROR(
                "Failed to create container work directory in '%s'" %
                self.__workdir)
            result['ReschedulePayload'] = True
            return result

        self.log.debug('Use singularity workarea: %s' % baseDir)
        for subdir in ["home", "tmp", "var_tmp"]:
            os.mkdir(os.path.join(baseDir, subdir))
        tmpDir = os.path.join(baseDir, "tmp")

        # Now we have a directory, we can stage in the proxy and scripts
        # Proxy
        proxyLoc = os.path.join(tmpDir, "proxy")
        rawfd = os.open(proxyLoc, os.O_WRONLY | os.O_CREAT, 0o600)
        fd = os.fdopen(rawfd, "w")
        fd.write(proxy)
        fd.close()

        # dirac-install.py
        install_loc = os.path.join(tmpDir, "dirac-install.py")
        shutil.copyfile(DIRAC_INSTALL, install_loc)
        os.chmod(install_loc, 0o755)

        # Job Wrapper (Standard DIRAC wrapper)
        result = createRelocatedJobWrapper(tmpDir,
                                           self.__innerdir,
                                           log=log,
                                           logLevel=logLevel,
                                           **jobDesc)
        if not result['OK']:
            result['ReschedulePayload'] = True
            return result
        wrapperPath = result['Value']

        # Extra Wrapper (Container DIRAC installer)
        wrapSubs = {
            'next_wrapper': wrapperPath,
            'install_args': self.__getInstallFlags(),
            'config_args': self.__getConfigFlags(),
        }
        wrapLoc = os.path.join(tmpDir, "dirac_container.sh")
        rawfd = os.open(wrapLoc, os.O_WRONLY | os.O_CREAT, 0o700)
        fd = os.fdopen(rawfd, "w")
        fd.write(CONTAINER_WRAPPER % wrapSubs)
        fd.close()

        ret = S_OK()
        ret['baseDir'] = baseDir
        ret['tmpDir'] = tmpDir
        ret['proxyLocation'] = proxyLoc
        return ret
コード例 #4
0
    def __createWorkArea(self,
                         jobDesc=None,
                         log=None,
                         logLevel='INFO',
                         proxy=None):
        """ Creates a directory for the container and populates it with the
        template directories, scripts & proxy.
    """
        if not jobDesc:
            jobDesc = {}
        if not log:
            log = gLogger

        # Create the directory for our container area
        try:
            os.mkdir(self.__workdir)
        except OSError:
            if not os.path.isdir(self.__workdir):
                result = S_ERROR(
                    "Failed to create container base directory '%s'" %
                    self.__workdir)
                result['ReschedulePayload'] = True
                return result
            # Otherwise, directory probably just already exists...
        baseDir = None
        try:
            baseDir = tempfile.mkdtemp(prefix="job%s_" %
                                       jobDesc.get('jobID', 0),
                                       dir=self.__workdir)
        except OSError:
            result = S_ERROR(
                "Failed to create container work directory in '%s'" %
                self.__workdir)
            result['ReschedulePayload'] = True
            return result

        self.log.debug('Use singularity workarea: %s' % baseDir)
        for subdir in ["home", "tmp", "var_tmp"]:
            os.mkdir(os.path.join(baseDir, subdir))
        tmpDir = os.path.join(baseDir, "tmp")

        # Now we have a directory, we can stage in the proxy and scripts
        # Proxy
        if proxy:
            proxyLoc = os.path.join(tmpDir, "proxy")
            rawfd = os.open(proxyLoc, os.O_WRONLY | os.O_CREAT, 0o600)
            fd = os.fdopen(rawfd, "w")
            fd.write(proxy)
            fd.close()
        else:
            self.log.warn("No user proxy")

        # dirac-install.py
        install_loc = os.path.join(tmpDir, "dirac-install.py")
        shutil.copyfile(DIRAC_INSTALL, install_loc)
        os.chmod(install_loc, 0o755)

        # Job Wrapper (Standard-ish DIRAC wrapper)
        result = createRelocatedJobWrapper(
            wrapperPath=tmpDir,
            rootLocation=self.__innerdir,
            jobID=jobDesc.get('jobID', 0),
            jobParams=jobDesc.get('jobParams', {}),
            resourceParams=jobDesc.get('resourceParams', {}),
            optimizerParams=jobDesc.get('optimizerParams', {}),
            log=log,
            logLevel=logLevel)
        if not result['OK']:
            result['ReschedulePayload'] = True
            return result
        wrapperPath = result['Value']

        if self.__installDIRACInContainer:
            # dirac-install.py
            install_loc = os.path.join(tmpDir, "dirac-install.py")
            shutil.copyfile(DIRAC_INSTALL, install_loc)
            os.chmod(install_loc, 0o755)

            infoDict = None
            if os.path.isfile(
                    'pilot.json'
            ):  # if this is a pilot 3 this file should be found
                with io.open('pilot.json') as pj:
                    infoDict = json.load(pj)

            # Extra Wrapper (Container DIRAC installer)
            wrapSubs = {
                'next_wrapper': wrapperPath,
                'install_args': self.__getInstallFlags(infoDict),
                'config_args': self.__getConfigFlags(infoDict),
            }
            CONTAINER_WRAPPER = CONTAINER_WRAPPER_INSTALL

        else:  # In case we don't (re)install DIRAC
            shutil.copyfile(
                os.path.join(self.__findInstallBaseDir(), 'bashrc'),
                os.path.join(tmpDir, 'bashrc'),
            )
            shutil.copyfile('pilot.cfg', os.path.join(tmpDir, 'pilot.cfg'))
            wrapSubs = {'next_wrapper': wrapperPath}
            CONTAINER_WRAPPER = CONTAINER_WRAPPER_NO_INSTALL

        wrapLoc = os.path.join(tmpDir, "dirac_container.sh")
        rawfd = os.open(wrapLoc, os.O_WRONLY | os.O_CREAT, 0o700)
        fd = os.fdopen(rawfd, "w")
        fd.write(CONTAINER_WRAPPER % wrapSubs)
        fd.close()

        ret = S_OK()
        ret['baseDir'] = baseDir
        ret['tmpDir'] = tmpDir
        if proxy:
            ret['proxyLocation'] = proxyLoc
        return ret