コード例 #1
0
ファイル: test_config.py プロジェクト: votdev/aquarium
def test_custom_registry(fs: fake_filesystem.FakeFilesystem) -> None:
    os.environ["AQUARIUM_REGISTRY_URL"] = "foobar"
    os.environ["AQUARIUM_REGISTRY_IMAGE"] = "bar"
    os.environ["AQUARIUM_REGISTRY_SECURE"] = "false"

    config = Config()
    config.init()
    assert config.options.containers.registry == "foobar"
    assert config.options.containers.image == "bar"
    assert not config.options.containers.secure
コード例 #2
0
ファイル: test_config.py プロジェクト: votdev/aquarium
def test_config_path(fs: fake_filesystem.FakeFilesystem):
    config = Config()
    config.init()
    assert config.confpath == Path("/etc/aquarium/config.json")

    config = Config(path="foo")
    config.init()
    assert config.confpath == Path("foo/config.json")
コード例 #3
0
ファイル: test_config.py プロジェクト: ml8mr/aquarium
def test_config_path(fs):
    config = Config()
    assert config.confpath == Path('/etc/aquarium/config.json')
    assert (config.options.service_state_path ==
            Path('/etc/aquarium/storage.json'))

    config = Config(path='foo')
    assert config.confpath == Path('foo/config.json')
    assert config.options.service_state_path == Path('foo/storage.json')

    # dirname(config.json) != dirname(storage.json)
    config = Config(path='bar')
    config.options.service_state_path = Path('baz')
    config._saveConfig(config.config)
    config = Config(path='bar')
    assert config.options.service_state_path == Path('baz')
コード例 #4
0
async def aquarium_startup(_: FastAPI, aquarium_api: FastAPI):
    lvl = "INFO" if not os.getenv("AQUARIUM_DEBUG") else "DEBUG"
    setup_logging(lvl)
    logger.info("Aquarium startup!")

    deployment = DeploymentMgr()

    try:
        await deployment.preinit()
    except DeploymentError as e:
        logger.error(f"Unable to pre-init the node: {e.message}")
        sys.exit(1)

    config: Config = Config()
    kvstore: KV = KV()
    gstate: GlobalState = GlobalState(config, kvstore)
    nodemgr: NodeMgr = NodeMgr(gstate)

    gstate_preinit(gstate)

    global _main_task
    _main_task = asyncio.create_task(
        aquarium_main_task(
            aquarium_api, config, kvstore, gstate, nodemgr, deployment
        )
    )
コード例 #5
0
ファイル: test_config.py プロジェクト: ml8mr/aquarium
def test_config_version(fs):
    config = Config()
    assert config.config.version == 1
コード例 #6
0
ファイル: test_config.py プロジェクト: ml8mr/aquarium
def test_config_options(fs):
    opts = Config().options
    assert opts.inventory.probe_interval == 60
    assert opts.storage.probe_interval == 30.0
コード例 #7
0
ファイル: test_config.py プロジェクト: jhesketh/aquarium
    def test_config_path(self):
        config = Config()
        assert config.confpath == Path('/etc/aquarium/config.json')

        config = Config(path='foo')
        assert config.confpath == Path('foo/config.json')
コード例 #8
0
ファイル: test_config.py プロジェクト: jhesketh/aquarium
 def test_deployment_state(self):
     ds = Config().deployment_state
     assert ds.stage == DeploymentStage.none
     assert ds.last_modified < datetime.now()
コード例 #9
0
ファイル: test_config.py プロジェクト: jhesketh/aquarium
 def test_config_version(self):
     config = Config()
     assert config.config.version == 2
コード例 #10
0
ファイル: test_config.py プロジェクト: votdev/aquarium
def test_config_options(fs: fake_filesystem.FakeFilesystem):
    config = Config()
    config.init()
    opts = config.options
    assert opts.inventory.probe_interval == 60
    assert opts.storage.probe_interval == 30.0
コード例 #11
0
ファイル: test_config.py プロジェクト: votdev/aquarium
def test_config_version(fs: fake_filesystem.FakeFilesystem):
    config = Config()
    config.init()
    assert config.config.version == 1
コード例 #12
0
ファイル: gstate.py プロジェクト: sebastian-philipp/aquarium
 def __init__(self):
     self.executor = ThreadPoolExecutor()
     self.counter = 0
     self.config = Config()
     self.is_shutting_down = False
     self.tickers = {}
コード例 #13
0
ファイル: gstate.py プロジェクト: tserong/aquarium
 def __init__(self, kv_class: Type[KV] = KV):
     self._config = Config()
     self._is_shutting_down = False
     self._tickers = {}
     self._kvstore = kv_class()
コード例 #14
0
ファイル: conftest.py プロジェクト: votdev/aquarium
    async def startup(aquarium_app: FastAPI, aquarium_api: FastAPI):
        from fastapi.logger import logger as fastapi_logger

        from gravel.cephadm.cephadm import Cephadm
        from gravel.controllers.ceph.ceph import Ceph, Mgr, Mon
        from gravel.controllers.config import Config
        from gravel.controllers.inventory.inventory import Inventory
        from gravel.controllers.nodes.mgr import NodeInitStage, NodeMgr
        from gravel.controllers.resources.devices import Devices
        from gravel.controllers.resources.network import Network
        from gravel.controllers.resources.status import Status
        from gravel.controllers.resources.storage import Storage

        logger: logging.Logger = fastapi_logger

        class FakeNodeMgr(NodeMgr):
            def __init__(self, gstate: GlobalState):
                super().__init__(gstate)

            async def start(self) -> None:
                assert self._state
                logger.debug(f"start > {self._state}")

                assert self._init_stage == NodeInitStage.INITED
                self._init_stage = NodeInitStage.AVAILABLE

            async def _obtain_images(self) -> bool:
                return True

        class FakeCephadm(Cephadm):
            def __init__(self):
                super().__init__()

            async def call(
                self,
                cmd: List[str],
                noimage: bool = False,
                outcb: Optional[Callable[[str], None]] = None,
            ) -> Tuple[str, str, int]:
                # Implement expected calls to cephadm with testable responses
                if cmd[0] == "pull":
                    return "", "", 0
                elif cmd[0] == "gather-facts":
                    return (
                        get_data_contents(DATA_DIR, "gather_facts_real.json"),
                        "",
                        0,
                    )
                elif cmd == ["ceph-volume", "inventory", "--format", "json"]:
                    return (
                        get_data_contents(DATA_DIR, "inventory_real.json"),
                        "",
                        0,
                    )
                else:
                    print(cmd)
                    print(outcb)
                    raise Exception("Tests should not get here")

        class FakeCeph(Ceph):
            def __init__(self, conf_file: str = "/etc/ceph/ceph.conf"):
                self.conf_file = conf_file
                self._is_connected = False

            def connect(self):
                if not self.is_connected():
                    self.cluster = mocker.Mock()
                    self._is_connected = True

        class FakeStorage(Storage):  # type: ignore
            available = 2000  # type: ignore
            total = 2000  # type: ignore

        config = Config()
        kvstore = FakeKV()
        gstate: GlobalState = GlobalState(config, kvstore)
        config.init()
        kvstore.init()

        # init node mgr
        nodemgr: NodeMgr = FakeNodeMgr(gstate)
        nodemgr.init()

        # Prep cephadm
        cephadm: Cephadm = FakeCephadm()
        gstate.add_cephadm(cephadm)
        cephadm.set_config(gstate.config.options.containers)

        # Set up Ceph connections
        ceph: Ceph = FakeCeph()
        ceph_mgr: Mgr = Mgr(ceph)
        gstate.add_ceph_mgr(ceph_mgr)
        ceph_mon: Mon = Mon(ceph)
        gstate.add_ceph_mon(ceph_mon)

        # Set up all of the tickers
        devices: Devices = Devices(
            gstate.config.options.devices.probe_interval,
            nodemgr,
            ceph_mgr,
            ceph_mon,
        )
        gstate.add_devices(devices)

        status: Status = Status(gstate.config.options.status.probe_interval,
                                gstate, nodemgr)
        gstate.add_status(status)

        inventory: Inventory = Inventory(
            gstate.config.options.inventory.probe_interval, nodemgr, gstate)
        gstate.add_inventory(inventory)

        storage: Storage = FakeStorage(
            gstate.config.options.storage.probe_interval, nodemgr, ceph_mon)
        gstate.add_storage(storage)

        network: Network = Network(
            gstate.config.options.network.probe_interval)
        gstate.add_network(network)

        await nodemgr.start()
        await gstate.start()

        # Add instances into FastAPI's state:
        aquarium_api.state.gstate = gstate
        aquarium_api.state.nodemgr = nodemgr