Skip to content

Commit

Permalink
Merge pull request #173 from Mirantis/engine-whitelist
Browse files Browse the repository at this point in the history
Engine whitelist
  • Loading branch information
tomkukral authored Dec 19, 2017
2 parents aa697ec + ac83659 commit 878035f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/kqueen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion kqueen/blueprints/api/test_provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions kqueen/blueprints/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions kqueen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions kqueen/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 878035f

Please sign in to comment.