def close(self, que=None): line = "==magic-fail==" if que is None: que = self.queue try: glob_logger.info("putting ==magic-fail== in queue") que.put(line) except AssertionError: glob_logger.debug("queue got AssertionError") pass except Exception as ex: glob_logger.debug("queue got {}".format(ex)) glob_logger.info("closing queue") que.close() if self._process: glob_logger.debug("terminating watcher process") try: self._process.terminate() except ProcessLookupError: pass # Apparently, when the subprocess ends, the PIPE'd stdout # doesn't close. So we need to shut it down so that the # reader thread closes if not self._process.stdout.closed: self._process.stdout.close() if self._log: glob_logger.info("closing log file") self._log.close()
def get_keystone_init(**kwargs): """ Simple function to retrieve configuration information from the global environment. If no kwargs is passed in, the necessary information is retrieved from the environment (ie, as when you source keystonerc_admin) The valid (optional) kwargs are: username: -> "OS_USERNAME" password: -> " :rtype : dict :return: A dictionary that can be used for keystone client """ if not kwargs: config = load_config(__file__, "smog_config.yml", ["config"]) os.environ.update( {k: v for k, v in config["credentials"].items() if v is not None}) creds = { "username": os.environ.get("OS_USERNAME"), "password": os.environ.get("OS_PASSWORD"), "auth_url": os.environ.get("OS_AUTH_URL"), "tenant_name": os.environ.get("OS_TENANT_NAME") } # could have used short-cut evaluation, but this seemed more functional creds.update( {k: v for k, v in kwargs.items() if k in creds and v is not None}) glob_logger.debug("Using keystone creds: {}".format(creds)) valid_versions = ("/v2.0", "/v3") for v in valid_versions: if creds["auth_url"].endswith(v): creds["auth_url"] += "/v2.0/" return creds
def monitor(handler, que_r): """ This function will consume items from the queue. The handler callable will be called on each item pulled from the queue and do something accordingly. To break out of the loop, the handler function will raise a special exception of MonitoredException The handler is a callable that returns True if the monitor should continue or False if the monitor should stop. The callable takes a single arg, which is a line that will be examined to determine whether it returns True or False :param handler: a predicate that takes a single string as an argument :param que: a multiprocessing.Queue :return: """ keep_going = True while keep_going: try: empty = que_r.empty() except OSError: glob_logger.info("queue is closed") break if not empty: try: line = que_r.get() keep_going = handler(line) except OSError: glob_logger.debug("queue is closed") break except MonitoredException: break except Exception as ex: glob_logger.debug("queue error type: {}".format(ex)) break glob_logger.info("monitor loop is finished")
def get_keystone_init(**kwargs): """ Simple function to retrieve configuration information from the global environment. If no kwargs is passed in, the necessary information is retrieved from the environment (ie, as when you source keystonerc_admin) The valid (optional) kwargs are: username: -> "OS_USERNAME" password: -> " :rtype : dict :return: A dictionary that can be used for keystone client """ if not kwargs: config = load_config(__file__, "smog_config.yml", ["config"]) os.environ.update({k: v for k, v in config["credentials"].items() if v is not None}) creds = {"username": os.environ.get("OS_USERNAME"), "password": os.environ.get("OS_PASSWORD"), "auth_url": os.environ.get("OS_AUTH_URL"), "tenant_name": os.environ.get("OS_TENANT_NAME")} # could have used short-cut evaluation, but this seemed more functional creds.update({k: v for k, v in kwargs.items() if k in creds and v is not None}) glob_logger.debug("Using keystone creds: {}".format(creds)) valid_versions = ("/v2.0", "/v3") for v in valid_versions: if creds["auth_url"].endswith(v): creds["auth_url"] += "/v2.0/" return creds
def tearDown(self): self._base_setup(self.numa) if hasattr(self, "watcher"): glob_logger.debug("cleaning up watcher") self.watcher.close()