def get_worker_path(task_obj): home_path = task.get_home_directory(task_obj, logger) djm_path = os.path.join(home_path, "djm") virtualenv_worker = os.path.join(djm_path, "python/bin/djm-worker") if task.check_for_path(task_obj, virtualenv_worker, logger=logger): worker_path = virtualenv_worker else: worker_path = task.find_exe(task_obj, "djm-worker", logger) if not worker_path: raise TaskError("Could not find worker script djm-worker on node %s. Checked at %s and in path" % (task_obj.worker_node["name"], virtualenv_worker)) return worker_path
def __call__(self, status_update_callback, completion_callback): uc = status_update_callback try: home_path = task.get_home_directory(self, logger) djm_path = os.path.join(home_path, "djm") python_ve_path = os.path.join(djm_path, "python") virtualenv_worker = os.path.join(python_ve_path, "bin/djm-worker") # we go through a bunch of stuff to see if we can reuse the # existing worker can_use_existing_worker = False if task.check_for_path(self, virtualenv_worker, logger=logger): existing_worker_path = virtualenv_worker else: existing_worker_path = task.find_exe(self, "djm-worker", logger) if existing_worker_path: # a worker already exists on this node. See if it has a new enough # version. We upgrade if the version is older than this one. result = task.run_command(self, [existing_worker_path, "version"], logger=logger) version_str = result[len(result)-1] if len(result)>0 else "" if not version_pattern.match(version_str): raise TaskError("Unable to determine version of worker running on node %s. Version string obtained was '%s'" % (self.worker_node["node"], version_str)) if utils.compare_versions(VERSION, version_str)>=0: can_use_existing_worker = True else: virtualenv_exe = task.find_exe(self, "virtualenv", logger) if not virtualenv_exe: raise TaskError("Unable to bootstrap node %s: cannot find virtualenv executable" % self.worker_node["name"]) logger.debug("making sure old DJM on %s is stopped" % self.worker_node["name"]) task.run_command(self, [existing_worker_path, "stop"], logger) if task.check_for_path(self, python_ve_path): logger.debug("Remove old DJM install from %s" % self.worker_node["name"]) task.run_command(self, ["/bin/rm", "-rf", python_ve_path], logger) else: # no existing worker path virtualenv_exe = task.find_exe(self, "virtualenv", logger) if not virtualenv_exe: raise TaskError("Unable to bootstrap node %s: cannot find virtualenv executable" % self.worker_node["name"]) if can_use_existing_worker: logger.info("Using existing DJM worker on node %s" % self.worker_node["name"]) else: # setup a virtualenv task.run_command(self, ["/bin/mkdir", "-p", python_ve_path], shell=True) result = task.run_command(self, [virtualenv_exe, "--version"]) virtualenv_version = result[len(result)-1] logger.debug("Virtualenv version on %s is %s" % (self.worker_node["name"], virtualenv_version)) if utils.compare_versions("1.7", virtualenv_version)>=0: # F'ing virtualenv options changed in 1.7! task.run_command(self, [virtualenv_exe, "--system-site-packages", python_ve_path], shell=True, logger=logger) else: task.run_command(self, [virtualenv_exe, python_ve_path], shell=True, logger=logger) # get the package to the node if necessary djm_package = self.server_config["djm_package"] if (not djm_package.startswith("http://")) and \ (not djm_package.startswith("https://")): target_djm_package_path = os.path.join(djm_path, os.path.basename(djm_package)) if (not task.local_node(self.worker_node)) or \ (djm_package != target_djm_package_path): task.copy(self.worker_node, djm_package, target_djm_package_path, log_tag=self.get_log_tag()) else: target_djm_package_path = djm_package pip_exe = os.path.join(python_ve_path, "bin/pip") task.run_command(self, [pip_exe, "install", target_djm_package_path], shell=True, logger=logger) except TaskError, e: logger.exception("Task %s failed due to error: %s" % (self.get_log_tag(), e)) completion_callback(self, TaskStatus.TASK_FAILED, reason="Got error: %s" % e) return 1