Python logzero.logger.debug() Examples

The following are 30 code examples of logzero.logger.debug(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module logzero.logger , or try the search function .
Example #1
Source File: actions.py    From chaostoolkit-kubernetes with Apache License 2.0 7 votes vote down vote up
def delete_pods(name: str, ns: str = "default",
                label_selector: str = "name in ({name})",
                secrets: Secrets = None):
    """
    Delete pods by `name` in the namespace `ns`.

    The pods are deleted without a graceful period to trigger an abrupt
    termination.

    The selected resources are matched by the given `label_selector`.
    """
    label_selector = label_selector.format(name=name)
    api = create_k8s_api_client(secrets)
    v1 = client.CoreV1Api(api)
    if label_selector:
        ret = v1.list_namespaced_pod(ns, label_selector=label_selector)
    else:
        ret = v1.list_namespaced_pod(ns)

    logger.debug("Found {d} pods named '{n}'".format(
        d=len(ret.items), n=name))

    body = client.V1DeleteOptions()
    for p in ret.items:
        v1.delete_namespaced_pod(p.metadata.name, ns, body=body) 
Example #2
Source File: probes.py    From chaostoolkit-kubernetes with Apache License 2.0 7 votes vote down vote up
def service_is_initialized(name: str, ns: str = "default",
                           label_selector: str = "name in ({name})",
                           secrets: Secrets = None):
    """
    Lookup a service endpoint by its name and raises :exc:`FailedProbe` when
    the service was not found or not initialized.
    """
    label_selector = label_selector.format(name=name)
    api = create_k8s_api_client(secrets)

    v1 = client.CoreV1Api(api)
    if label_selector:
        ret = v1.list_namespaced_service(ns, label_selector=label_selector)
    else:
        ret = v1.list_namespaced_service(ns)

    logger.debug("Found {d} service(s) named '{n}' ins ns '{s}'".format(
        d=len(ret.items), n=name, s=ns))

    if not ret.items:
        raise ActivityFailed(
            "service '{name}' is not initialized".format(name=name))

    return True 
Example #3
Source File: init.py    From uiautomator2 with MIT License 6 votes vote down vote up
def mirror_download(url: str, filename=None, logger: logging.Logger = logger):
    """
    Download from mirror, then fallback to origin url
    """
    storepath = gen_cachepath(url)
    if not filename:
        filename = os.path.basename(url)
    github_host = "https://github.com"
    if url.startswith(github_host):
        mirror_url = "https://tool.appetizer.io" + url[len(
            github_host):]  # mirror of github
        try:
            return cache_download(mirror_url,
                                  filename,
                                  timeout=60,
                                  storepath=storepath,
                                  logger=logger)
        except (requests.RequestException, FileNotFoundError,
                AssertionError) as e:
            logger.debug("download error from mirror(%s), use origin source", e)

    return cache_download(url, filename, storepath=storepath, logger=logger) 
Example #4
Source File: device.py    From atxserver2-android-provider with MIT License 6 votes vote down vote up
def _push_stf(self,
                  path: str,
                  dest: str,
                  zipfile_path: str,
                  mode=0o755):
        """ push minicap and minitouch from zip """
        with zipfile.ZipFile(zipfile_path) as z:
            if path not in z.namelist():
                logger.warning("stf stuff %s not found", path)
                return
            src_info = z.getinfo(path)
            dest_info = self._device.sync.stat(dest)
            if dest_info.size == src_info.file_size and dest_info.mode & mode == mode:
                logger.debug("%s already pushed %s", self, path)
                return
            with z.open(path) as f:
                self._device.sync.push(f, dest, mode) 
Example #5
Source File: main.py    From atxserver2-ios-provider with MIT License 6 votes vote down vote up
def device_watch(wda_directory: str):
    """
    When iOS device plugin, launch WDA
    """
    lock = locks.Lock()  # WDA launch one by one

    async for event in idb.track_devices():
        if event.udid.startswith("ffffffffffffffffff"):
            logger.debug("Invalid event: %s", event)
            continue
        logger.debug("Event: %s", event)
        if event.present:
            d = idb.WDADevice(event.udid, lock=lock, callback=_device_callback)
            d.wda_directory = wda_directory
            idevices[event.udid] = d
            d.start()
        else:  # offline
            await idevices[event.udid].stop()
            idevices.pop(event.udid) 
Example #6
Source File: heartbeat.py    From atxserver2-android-provider with MIT License 6 votes vote down vote up
def _drain_queue(self):
        """
        Logic:
            - send message to server when server is alive
            - update local db
        """
        while True:
            message = await self._queue.get()
            if message is None:
                logger.info("Resent messages: %s", self._db)
                for _, v in self._db.items():
                    await self._ws.write_message(v)
                continue

            if 'udid' in message:  # ping消息不包含在裡面
                udid = message['udid']
                update_recursive(self._db, {udid: message})
            self._queue.task_done()

            if self._ws:
                try:
                    await self._ws.write_message(message)
                    logger.debug("websocket send: %s", message)
                except TypeError as e:
                    logger.info("websocket write_message error: %s", e) 
Example #7
Source File: cli.py    From chaostoolkit with Apache License 2.0 6 votes vote down vote up
def discover(ctx: click.Context, package: str,
             discovery_path: str = "./discovery.json",
             no_system_info: bool = False,
             no_install: bool = False) -> Discovery:
    """Discover capabilities and experiments."""
    settings = load_settings(ctx.obj["settings_path"])
    try:
        notify(settings, DiscoverFlowEvent.DiscoverStarted, package)
        discovery = disco(
            package_name=package, discover_system=not no_system_info,
            download_and_install=not no_install)
    except DiscoveryFailed as err:
        notify(settings, DiscoverFlowEvent.DiscoverFailed, package, err)
        logger.debug("Failed to discover {}".format(package), exc_info=err)
        logger.fatal(str(err))
        return

    with open(discovery_path, "w") as d:
        d.write(json.dumps(discovery, indent=2, default=encoder))
    logger.info("Discovery outcome saved in {p}".format(
        p=discovery_path))

    notify(settings, DiscoverFlowEvent.DiscoverCompleted, discovery)
    return discovery 
Example #8
Source File: cli.py    From chaostoolkit with Apache License 2.0 6 votes vote down vote up
def validate(ctx: click.Context, source: str,
             no_verify_tls: bool = False) -> Experiment:
    """Validate the experiment at SOURCE."""
    settings = load_settings(ctx.obj["settings_path"])

    try:
        experiment = load_experiment(
            source, settings, verify_tls=not no_verify_tls)
    except InvalidSource as x:
        logger.error(str(x))
        logger.debug(x)
        ctx.exit(1)

    try:
        notify(settings, ValidateFlowEvent.ValidateStarted, experiment)
        ensure_experiment_is_valid(experiment)
        notify(settings, ValidateFlowEvent.ValidateCompleted, experiment)
        logger.info("experiment syntax and semantic look valid")
    except ChaosException as x:
        notify(settings, ValidateFlowEvent.ValidateFailed, experiment, x)
        logger.error(str(x))
        logger.debug(x)
        ctx.exit(1)

    return experiment 
Example #9
Source File: fetching.py    From atxserver2-android-provider with MIT License 6 votes vote down vote up
def mirror_download(url: str, target: str) -> str:
    """
    Returns:
        target path
    """
    if os.path.exists(target):
        return target
    github_host = "https://github.com"
    if url.startswith(github_host):
        mirror_url = "http://tool.appetizer.io" + url[len(
            github_host):]  # mirror of github
        try:
            return download(mirror_url, target)
        except (requests.RequestException, ValueError) as e:
            logger.debug("download from mirror error, use origin source")

    return download(url, target) 
Example #10
Source File: idb.py    From atxserver2-ios-provider with MIT License 6 votes vote down vote up
def wda_status(self):
        """
        Returns:
            dict or None
        """
        try:
            request = httpclient.HTTPRequest(self.wda_device_url + "/status",
                                             connect_timeout=3,
                                             request_timeout=15)
            client = httpclient.AsyncHTTPClient()
            resp = await client.fetch(request)
            info = json.loads(resp.body)
            self.__wda_info = info
            return info
        except httpclient.HTTPError as e:
            logger.debug("%s request wda/status error: %s", self, e)
            return None
        except (ConnectionResetError, ConnectionRefusedError):
            logger.debug("%s waiting for wda", self)
            return None
        except Exception as e:
            logger.warning("%s ping wda unknown error: %s %s", self, type(e),
                           e)
            return None 
Example #11
Source File: xpath.py    From uiautomator2 with MIT License 6 votes vote down vote up
def send_click(self, x, y):
        if self._click_before_delay:
            self.logger.debug("click before delay %.1f seconds",
                              self._click_after_delay)
            time.sleep(self._click_before_delay)

        # TODO(ssx): should use a better way
        # event callbacks for report generate
        for callback_func in self._event_callbacks['send_click']:
            callback_func(x, y)

        self._d.click(x, y)

        if self._click_after_delay:
            self.logger.debug("click after delay %.1f seconds",
                              self._click_after_delay)
            time.sleep(self._click_after_delay) 
Example #12
Source File: heartbeat.py    From atxserver2-ios-provider with MIT License 6 votes vote down vote up
def _drain_queue(self):
        """
        Logic:
            - send message to server when server is alive
            - update local db
        """
        while True:
            message = await self._queue.get()
            if message is None:
                logger.info("Resent messages: %s", self._db)
                for _, v in self._db.items():
                    await self._ws.write_message(v)
                continue

            if 'udid' in message:  # ping消息不包含在裡面
                udid = message['udid']
                update_recursive(self._db, {udid: message})
            self._queue.task_done()

            if self._ws:
                try:
                    await self._ws.write_message(message)
                    logger.debug("websocket send: %s", message)
                except TypeError as e:
                    logger.info("websocket write_message error: %s", e) 
Example #13
Source File: actions.py    From chaostoolkit-aws with Apache License 2.0 6 votes vote down vote up
def deregister_target(tg_name: str,
                      configuration: Configuration = None,
                      secrets: Secrets = None) -> AWSResponse:
    """Deregisters one random target from target group"""
    client = aws_client('elbv2', configuration, secrets)
    tg_arn = get_target_group_arns(tg_names=[tg_name], client=client)
    tg_health = get_targets_health_description(tg_arns=tg_arn, client=client)
    random_target = random.choice(
        tg_health[tg_name]['TargetHealthDescriptions'])

    logger.debug("Deregistering target {} from target group {}".format(
        random_target['Target']['Id'], tg_name))

    try:
        return client.deregister_targets(
            TargetGroupArn=tg_arn[tg_name],
            Targets=[{
                'Id': random_target['Target']['Id'],
                'Port': random_target['Target']['Port']
            }]
        )
    except ClientError as e:
        raise FailedActivity('Exception detaching %s: %s' % (
            tg_name, e.response['Error']['Message'])) 
Example #14
Source File: actions.py    From chaostoolkit-aws with Apache License 2.0 6 votes vote down vote up
def delete_load_balancer(load_balancer_names: List[str],
                         configuration: Configuration = None,
                         secrets: Secrets = None):
    """
    Deletes the provided load balancer(s).

    Parameters:
        - load_balancer_names: a list of load balancer names
    """
    client = aws_client('elbv2', configuration, secrets)
    load_balancers = get_load_balancer_arns(load_balancer_names, client)

    for k, v in load_balancers.items():
        if k not in ('application', 'network'):
            continue

        for l in v:
            logger.debug('Deleting load balancer %s' % l)
            client.delete_load_balancer(LoadBalancerArn=l)


###############################################################################
# Private functions
############################################################################### 
Example #15
Source File: actions.py    From chaostoolkit-aws with Apache License 2.0 6 votes vote down vote up
def get_target_group_arns(tg_names: List[str],
                          client: boto3.client) -> Dict:
    """
    Return list of target group ARNs based on list of target group names

    return structure:
    {
        "TargetGroupName": "TargetGroupArn",
        ....
    }
    """
    logger.debug("Target group name(s): {} Looking for ARN"
                 .format(str(tg_names)))
    res = client.describe_target_groups(Names=tg_names)
    tg_arns = {}

    for tg in res['TargetGroups']:
        tg_arns[tg['TargetGroupName']] = tg['TargetGroupArn']
    logger.debug("Target groups ARN: {}".format(str(tg_arns)))

    return tg_arns 
Example #16
Source File: init.py    From uiautomator2 with MIT License 6 votes vote down vote up
def is_atx_agent_outdated(self):
        """
        Returns:
            bool
        """
        agent_version = self._device.shell(self.atx_agent_path +
                                           " version").strip()
        if agent_version == "dev":
            self.logger.info("skip version check for atx-agent dev")
            return False

        # semver major.minor.patch
        try:
            real_ver = list(map(int, agent_version.split(".")))
            want_ver = list(map(int, __atx_agent_version__.split(".")))
        except ValueError:
            return True

        self.logger.debug("Real version: %s, Expect version: %s", real_ver,
                          want_ver)

        if real_ver[:2] != want_ver[:2]:
            return True

        return real_ver[2] < want_ver[2] 
Example #17
Source File: probes.py    From chaostoolkit-aws with Apache License 2.0 6 votes vote down vote up
def get_target_group_arns(tg_names: List[str],
                          client: boto3.client) -> Dict:
    """
    Return list of target group ARNs based on list of target group names

    return structure:
    {
        "TargetGroupName": "TargetGroupArn",
        ....
    }
    """
    logger.debug("Target group name(s): {} Looking for ARN"
                 .format(str(tg_names)))
    res = client.describe_target_groups(Names=tg_names)
    tg_arns = {}

    for tg in res['TargetGroups']:
        tg_arns[tg['TargetGroupName']] = tg['TargetGroupArn']
    logger.debug("Target groups ARNs: {}".format(str(tg_arns)))

    return tg_arns 
Example #18
Source File: actions.py    From chaostoolkit-kubernetes with Apache License 2.0 6 votes vote down vote up
def delete_replica_set(name: str, ns: str = "default",
                       label_selector: str = "name in ({name})",
                       secrets: Secrets = None):
    """
    Delete a replica set by `name` in the namespace `ns`.

    The replica set is deleted without a graceful period to trigger an abrupt
    termination.

    The selected resources are matched by the given `label_selector`.
    """
    label_selector = label_selector.format(name=name)
    api = create_k8s_api_client(secrets)
    v1 = client.ExtensionsV1beta1Api(api)
    if label_selector:
        ret = v1.list_namespaced_replica_set(ns, label_selector=label_selector)
    else:
        ret = v1.list_namespaced_replica_set(ns)

    logger.debug("Found {d} replica sets named '{n}'".format(
        d=len(ret.items), n=name))

    body = client.V1DeleteOptions()
    for r in ret.items:
        v1.delete_namespaced_replica_set(r.metadata.name, ns, body=body) 
Example #19
Source File: init.py    From uiautomator2 with MIT License 6 votes vote down vote up
def push_url(self, url, dest=None, mode=0o755, tgz=False, extract_name=None):  # yapf: disable
        path = mirror_download(url,
                               filename=os.path.basename(url),
                               logger=self.logger)
        if tgz:
            tar = tarfile.open(path, 'r:gz')
            path = os.path.join(os.path.dirname(path), extract_name)
            tar.extract(extract_name,
                        os.path.dirname(path))  # zlib.error may raise

        if not dest:
            dest = "/data/local/tmp/" + os.path.basename(path)

        self.logger.debug("Push to %s:0%o", dest, mode)
        self._device.sync.push(path, dest, mode=mode)
        return dest 
Example #20
Source File: idb.py    From atxserver2-ios-provider with MIT License 5 votes vote down vote up
def is_wda_alive(self):
        logger.debug("%s check /status", self)
        if not await self.wda_session_ok():
            return False

        logger.debug("%s check /screenshot", self)
        if not await self.wda_screenshot_ok():
            return False

        return True 
Example #21
Source File: webview.py    From uiautomator2 with MIT License 5 votes vote down vote up
def get_active_tab_list(self):
        tabs = []
        for tab in self.browser.list_tab():
            logger.debug("tab: %s", tab)
            tab.start()
            t = BrowserTab(tab)
            if t.is_activate():
                tabs.append(t)
            else:
                tab.stop()
        return tabs 
Example #22
Source File: probes.py    From chaostoolkit-aws with Apache License 2.0 5 votes vote down vote up
def all_targets_healthy(tg_names: List[str],
                        configuration: Configuration = None,
                        secrets: Secrets = None) -> AWSResponse:
    """
    Return true/false based on if all targets for listed
    target groups are healthy
    """

    if not tg_names:
        raise FailedActivity(
            "Non-empty list of target groups is required")

    client = aws_client('elbv2', configuration, secrets)
    logger.debug("Checking if all targets are healthy for targets: {}"
                 .format(str(tg_names)))
    tg_arns = get_target_group_arns(tg_names=tg_names, client=client)
    tg_health = get_targets_health_description(tg_arns=tg_arns, client=client)
    result = True

    for tg in tg_health:
        time_to_break = False

        for health_descr in tg_health[tg]['TargetHealthDescriptions']:
            if health_descr['TargetHealth']['State'] != 'healthy':
                result = False
                time_to_break = True

                break

        if time_to_break:
            break

    return result


###############################################################################
# Private functions
############################################################################### 
Example #23
Source File: actions.py    From chaostoolkit-aws with Apache License 2.0 5 votes vote down vote up
def _remove_rule_targets(rule_name: str, target_ids: str,
                         client: boto3.client):
    """
    Removes provided CloudWatch rule targets.
    """
    logger.debug(
        "Removing {} targets from rule {}: {}".format(
            len(target_ids), rule_name, target_ids)
    )
    return client.remove_targets(Rule=rule_name, Ids=target_ids) 
Example #24
Source File: heartbeat.py    From atxserver2-ios-provider with MIT License 5 votes vote down vote up
def _drain_ws_message(self):
        while True:
            message = await self._ws.read_message()
            logger.debug("WS read message: %s", message)
            if message is None:
                self._ws = None
                logger.warning("WS closed")
                self._ws = await self.connect()
                await self._queue.put(None)
            logger.info("WS receive message: %s", message) 
Example #25
Source File: probes.py    From chaostoolkit-aws with Apache License 2.0 5 votes vote down vote up
def get_targets_health_description(tg_arns: Dict,
                                   client: boto3.client) -> Dict:
    """
    Return TargetHealthDescriptions by targetgroups
    Structure:
    {
        "TargetGroupName": {
            "TargetGroupArn": value,
            "TargetHealthDescriptions": TargetHealthDescriptions[]
        },
        ....
    }
    """
    logger.debug("Target group ARN: {} Getting health descriptions"
                 .format(str(tg_arns)))
    tg_health_descr = {}

    for tg in tg_arns:
        tg_health_descr[tg] = {}
        tg_health_descr[tg]['TargetGroupArn'] = tg_arns[tg]
        tg_health_descr[tg]['TargetHealthDescriptions'] = \
            client.describe_target_health(TargetGroupArn=tg_arns[tg])[
            'TargetHealthDescriptions']
    logger.debug("Health descriptions for target group(s) are: {}"
                 .format(str(tg_health_descr)))

    return tg_health_descr 
Example #26
Source File: __init__.py    From logzero with MIT License 5 votes vote down vote up
def log_function_call(func):
    @functools.wraps(func)
    def wrap(*args, **kwargs):
        args_str = ", ".join([str(arg) for arg in args])
        kwargs_str = ", ".join(["%s=%s" % (key, kwargs[key]) for key in kwargs])
        if args_str and kwargs_str:
            all_args_str = ", ".join([args_str, kwargs_str])
        else:
            all_args_str = args_str or kwargs_str
        logger.debug("%s(%s)", func.__name__, all_args_str)
        return func(*args, **kwargs)
    return wrap 
Example #27
Source File: idb.py    From atxserver2-ios-provider with MIT License 5 votes vote down vote up
def stop(self):
        """ stop wda process """
        if self._stop.is_set():
            raise RuntimeError(self, "WDADevice is already stopped")
        self._stop.set()  # no need await
        logger.debug("%s waiting for wda stopped ...", self)
        await self._finished.wait()
        logger.debug("%s wda stopped!", self)
        self._finished.clear() 
Example #28
Source File: cli.py    From chaostoolkit with Apache License 2.0 5 votes vote down vote up
def cli(ctx: click.Context, verbose: bool = False,
        no_version_check: bool = False, change_dir: str = None,
        no_log_file: bool = False, log_file: str = "chaostoolkit.log",
        log_format: str = "string", settings: str = CHAOSTOOLKIT_CONFIG_PATH):

    if no_log_file:
        configure_logger(
            verbose=verbose, log_format=log_format,
            context_id=str(uuid.uuid4()))
    else:
        configure_logger(
            verbose=verbose, log_file=log_file, log_format=log_format,
            context_id=str(uuid.uuid4()))

    subcommand = ctx.invoked_subcommand

    # make it nicer for going through the log file
    logger.debug("#" * 79)
    logger.debug("Running command '{}'".format(subcommand))

    ctx.obj = {}
    ctx.obj["settings_path"] = click.format_filename(settings)
    logger.debug("Using settings file '{}'".format(ctx.obj["settings_path"]))

    if not no_version_check:
        check_newer_version(command=subcommand)

    if change_dir:
        logger.warning("Moving to {d}".format(d=change_dir))
        os.chdir(change_dir) 
Example #29
Source File: run.py    From uiautomator2 with MIT License 5 votes vote down vote up
def run_conf(d, conf_filename: str):
    d.healthcheck()
    d.xpath.when("允许").click()
    d.xpath.watch_background(2.0)

    cf = yaml.load(read_file_content(conf_filename), Loader=yaml.SafeLoader)
    default = {
        "output_directory": "output",
        "action_before_delay": 0,
        "action_after_delay": 0,
        "skip_cleanup": False,
    }
    for k, v in default.items():
        cf.setdefault(k, v)
    cf = bunch.Bunch(cf)

    print("Author:", cf.author)
    print("Description:", cf.description)
    print("Package:", cf.package)
    logger.debug("action_delay: %.1f / %.1f", cf.action_before_delay, cf.action_after_delay)

    app = d.session(cf.package)
    for step in cf.steps:
        time.sleep(cf.action_before_delay)
        run_step(cf, app, step)
        time.sleep(cf.action_after_delay)

    if not cf.skip_cleanup:
        app.close() 
Example #30
Source File: init.py    From uiautomator2 with MIT License 5 votes vote down vote up
def check_atx_agent_version(self):
        port = self._device.forward_port(7912)
        self.logger.debug("Forward: local:tcp:%d -> remote:tcp:%d", port, 7912)
        version = requests.get("http://127.0.0.1:%d/version" %
                               port).text.strip()
        self.logger.debug("atx-agent version %s", version)
        return version