diff --git a/docs/kqueen.rst b/docs/kqueen.rst index be3ff3fe..25ac3133 100644 --- a/docs/kqueen.rst +++ b/docs/kqueen.rst @@ -142,6 +142,9 @@ Example configuration files are located in `config/` directory. Default configur * - PROVISIONER_UNKNOWN_STATE - Not Reachable - Caption for unknown provisioner. + * - PROVISIONER_ENGINE_WHITELIST + - None + - Enable only engines in list. * - PROMETHEUS_WHITELIST - 127.0.0.0/8 diff --git a/kqueen/blueprints/api/test_provisioner.py b/kqueen/blueprints/api/test_provisioner.py index 82905986..d7f4e9d2 100644 --- a/kqueen/blueprints/api/test_provisioner.py +++ b/kqueen/blueprints/api/test_provisioner.py @@ -22,11 +22,12 @@ def get_create_data(self): return data - def test_provision_engines(self): + def test_provisioner_engines(self): url = url_for('api.provisioner_engine_list') response = self.client.get(url, headers=self.auth_header) print(response.json) + assert response.status_code == 200 assert isinstance(response.json, list) assert len(response.json) == len(all_engines) diff --git a/kqueen/blueprints/api/views.py b/kqueen/blueprints/api/views.py index d5fa2ee1..c3999e9b 100644 --- a/kqueen/blueprints/api/views.py +++ b/kqueen/blueprints/api/views.py @@ -208,10 +208,10 @@ class DeleteProvisioner(DeleteView): @api.route('/provisioners/engines', methods=['GET']) @jwt_required() def provisioner_engine_list(): - from kqueen.engines import __all__ as ENGINES engine_cls = [] module_path = 'kqueen.engines' - for engine in ENGINES: + + for engine in Provisioner.list_engines(): try: module = import_module(module_path) _class = getattr(module, engine) diff --git a/kqueen/models.py b/kqueen/models.py index 9b1aafab..7bd3078d 100644 --- a/kqueen/models.py +++ b/kqueen/models.py @@ -301,6 +301,18 @@ class Provisioner(Model, metaclass=ModelMeta): created_at = DatetimeField() owner = RelationField(required=True) + @classmethod + def list_engines(self): + """Read engines and filter them according to whitelist""" + + engines = config.get('PROVISIONER_ENGINE_WHITELIST') + + if engines is None: + from kqueen.engines import __all__ as engines_available + engines = engines_available + + return engines + def get_engine_cls(self): """Return engine class""" try: diff --git a/kqueen/tests/test_models.py b/kqueen/tests/test_models.py index 7c20235b..7ecf28df 100644 --- a/kqueen/tests/test_models.py +++ b/kqueen/tests/test_models.py @@ -1,11 +1,12 @@ +from kqueen.engines import __all__ as all_engines from kqueen.models import Cluster +from kqueen.models import Provisioner from kqueen.storages.etcd import Field from kqueen.storages.etcd import Model -from kqueen.engines.__init__ import __all__ as all_engines import pytest -import yaml import subprocess +import yaml class TestModelMethods: @@ -172,3 +173,8 @@ def test_get_engine_cls(self, provisioner, engine): engine_class = provisioner.get_engine_cls() assert engine_class is not None + + def test_list_engines(self): + engines = Provisioner.list_engines() + + assert engines == all_engines