Example #1
0
    def __init__(self, **kwvals):
        for p in self.init_needed_keywords:
            if p not in kwvals.keys():
                raise PIDanticUsageException(
                    "The driver %s must have the parameter %s." %
                    (self.driver_name, p))
        for p in kwvals.keys():
            if p not in self.init_needed_keywords and p not in self.init_optional_keywords:
                raise PIDanticUsageException(
                    "The driver %s does not know the parameter %s." %
                    (self.driver_name, p))

        self._next_poll_time = datetime.datetime.now()
        self._poll_interval = 0.5
        self._working_dir = kwvals['directory']
        self._name = kwvals['name']
        self._log = _set_param_or_default(kwvals, "log", logging)
        supd_exe = _set_param_or_default(kwvals, "supdexe",
                                         "%s/bin/supervisord" % sys.prefix)
        if not os.path.exists(supd_exe):
            raise PIDanticUsageException("No supervisord executable found")
        self._watched_processes = {}

        db_url = "sqlite:///%s/supd.db" % (self._working_dir)
        self._db = SupDDB(db_url)

        supd_db_a = self._db.get_all_supds()
        if len(supd_db_a) > 1:
            raise PIDanticUsageException(
                "The driver %s should have at most 1 supervisord process in its table."
                % (self.driver_name))

        if not supd_db_a:
            template = os.path.join(self._working_dir, "supd.template")
            if not os.path.exists(template):
                template = None
            self._supd = SupD(self._db,
                              name=self._name,
                              template=template,
                              log=self._log,
                              executable=supd_exe,
                              dirpath=self._working_dir)
        else:
            if supd_db_a[0].name != self._name:
                raise PIDanticUsageException(
                    "The requested supd name %s is not in the db" %
                    (self._name))
            self._supd = SupD(self._db, data_object=supd_db_a[0])

        self._is_alive()
Example #2
0
 def setUp(self):
     self.name = "test_something-" + str(uuid.uuid4())
     if system() == "Darwin":
         # The standard mac tmp path is too long
         # for a socket
         self.dirpath = tempfile.mkdtemp(dir="/tmp")
     else:
         self.dirpath = tempfile.mkdtemp()
     self.supd_db_path = "sqlite:///" + os.path.join(self.dirpath, "sup.db")
     self.supd_db = SupDDB(self.supd_db_path)
     supd_path = "%s/bin/supervisord" % (sys.prefix)
     self.supd = SupD(self.supd_db,
                      self.name,
                      dirpath=self.dirpath,
                      executable=supd_path)
 def setUp(self):
     self.name = "test_something-" + str(uuid.uuid4())
     self.dirpath = tempfile.mkdtemp()
     self.supd_db_path = "sqlite:///" + os.path.join(self.dirpath, "sup.db")
     self.supd_db = SupDDB(self.supd_db_path)