Beispiel #1
0
 def __init__(
     self,
     checklists_loader: Optional[BaseChecklistsLoader] = None,
     configuration_loader: Optional[ConfigurationLoader[Dict[str,
                                                             Any]]] = None
 ) -> None:
     super().__init__()
     import_module('aiohttp')
 def test_import_module_raises_exception_if_this_is_non_extra_module(self):
     with self.assertRaises(RuntimeError):
         try:
             import_module('non_extra_module')
         except RuntimeError as e:
             self.assertEqual(
                 str(e),
                 'Module [non_extra_module] is not part of any extras, ' +
                 'please use standard import statement')
             raise
 def test_import_module_raises_exception_if_extra_module_is_missing(self):
     with self.assertRaises(RuntimeError), mock.patch(
             'checklisting.extras.has_module', return_value=False):
         try:
             import_module('aiohttp')
         except RuntimeError as e:
             self.assertEqual(
                 str(e), 'Please install [web] extras to use [aiohttp] ' +
                 f'(required by [{__name__}]): pip install checklisting[web]'
             )
             raise
Beispiel #4
0
from abc import ABC, abstractmethod
from enum import Enum
from typing import Any, Awaitable, Optional, Union

from checklisting.extras import import_module
from checklisting.result import BaseTaskResult, TaskResult
from checklisting.result.status import TaskResultStatus
from checklisting.task import BaseTask

aiohttp = import_module('aiohttp')
yarl = import_module('yarl')


class HttpMethod(Enum):

    CONNECT = aiohttp.hdrs.METH_CONNECT
    HEAD = aiohttp.hdrs.METH_HEAD
    GET = aiohttp.hdrs.METH_GET
    DELETE = aiohttp.hdrs.METH_DELETE
    OPTIONS = aiohttp.hdrs.METH_OPTIONS
    PATCH = aiohttp.hdrs.METH_PATCH
    POST = aiohttp.hdrs.METH_POST
    PUT = aiohttp.hdrs.METH_PUT
    TRACE = aiohttp.hdrs.METH_TRACE


class BaseHttpTaskResponseValidator(ABC):

    @abstractmethod
    async def validate(self, response: aiohttp.ClientResponse) -> Awaitable[BaseTaskResult]:
        pass
import argparse
from itertools import chain
from typing import Iterator

from checklisting.extras import import_module
from checklisting.provider import StaticChecklistsProvider
from checklisting.task import Checklist
from checklisting.tasks.external import ExternalChecklistTask

from . import BaseRunner, BaseRunnerFactory
from .cli import CliRunner

yarl = import_module('yarl')


def _fix_url(source: str) -> str:
    if not source.startswith('http'):
        return f'http://{source}'
    else:
        return source


class ExternalChecklistRunner(CliRunner):
    def __init__(self, sources: Iterator[yarl.URL]) -> None:
        super().__init__(
            StaticChecklistsProvider([
                Checklist('external', (ExternalChecklistTask(source)
                                       for source in sources))
            ]))

Beispiel #6
0
 def __init__(self, addr: str, port: int,
              checklists_provider: BaseChecklistsProvider) -> None:
     import_module('aiohttp')
 def test_import_module_returns_module_if_this_is_extra_module(self):
     for module_name in list_extra_modules():
         module = import_module(module_name)
         self.assertIsInstance(module, types.ModuleType)
         self.assertEqual(module.__name__, module_name)
Beispiel #8
0
import asyncio
import os
from typing import Iterable, Iterator, NamedTuple, Optional

from checklisting.extras import import_module
from checklisting.result import BaseTaskResult, MultiTaskResult, TaskResult
from checklisting.result.builder import MultiTaskResultBuilder
from checklisting.result.status import TaskResultStatus
from checklisting.task import BaseTask

psutil = import_module('psutil')

GIGABYTE = 1024**3

DiskInfoStruct = NamedTuple('DiskInfoStruct',
                            [('mountpoint', str), ('device', str),
                             ('fstype', str), ('total', int), ('used', int),
                             ('percent', float)])
CPUUsageStruct = NamedTuple('CPUUsageStruct', [('user', float),
                                               ('system', float),
                                               ('idle', float),
                                               ('iowait', float)])


async def _cpu_times_percent(interval: float) -> Iterable[CPUUsageStruct]:
    psutil.cpu_times_percent(interval=None, percpu=True)
    await asyncio.sleep(interval)
    cpu_times = psutil.cpu_times_percent(interval=None, percpu=True)
    assert isinstance(
        cpu_times,
        Iterable)  # always True since percpu=True; just making mypy happy