Skip to content

Commit

Permalink
Merge c148738 into 536d6f8
Browse files Browse the repository at this point in the history
  • Loading branch information
katyafervent committed Jul 2, 2018
2 parents 536d6f8 + c148738 commit 1c30d08
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 21 deletions.
5 changes: 3 additions & 2 deletions kqueen/blueprints/api/generic_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ class GetView(GenericView):
methods = ['GET']
action = 'get'

def get_content(self, *args, **kwargs):
self.obj = self.hide_secure_data(self.obj)
def get_content(self, *args, hide_secure_data=True, **kwargs):
if hide_secure_data:
self.obj = self.hide_secure_data(self.obj)
return self.obj


Expand Down
12 changes: 6 additions & 6 deletions kqueen/blueprints/api/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_crud_list(self):
self.namespace,
self.obj.id
)
obj.get_state()
obj.update_state()

assert isinstance(data, list)
assert len(data) == len(self.obj.__class__.list(
Expand Down Expand Up @@ -280,21 +280,21 @@ def test_error_codes(self, data, code, content_type):

assert response.status_code == code

def test_cluster_list_run_get_state(self, monkeypatch):
def test_cluster_list_run_update_state(self, monkeypatch):
clusters_to_remove = []
for _ in range(10):
test_cluster = ClusterFixture()
clusters_to_remove.append(test_cluster)
c = test_cluster.obj
c.save()

def fake_get_state(self):
def fake_update_state(self):
self.metadata = {'executed': True}
self.save()

return config.get('CLUSTER_UNKNOWN_STATE')

monkeypatch.setattr(self.obj.__class__, 'get_state', fake_get_state)
monkeypatch.setattr(self.obj.__class__, 'update_state', fake_update_state)

response = self.client.get(
url_for('api.cluster_list'),
Expand All @@ -306,8 +306,8 @@ def fake_get_state(self):

obj = self.obj.__class__.load(self.namespace, self.obj.id)

assert obj.metadata, 'get_state wasn\'t executed for cluster {}'.format(obj)
assert obj.metadata['executed'], 'get_state wasn\'t executed'
assert obj.metadata, 'update_state wasn\'t executed for cluster {}'.format(obj)
assert obj.metadata['executed'], 'update_state wasn\'t executed'

for c in clusters_to_remove:
c.destroy()
12 changes: 6 additions & 6 deletions kqueen/blueprints/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def _update_clusters(self, clusters, loop):
futures = [
loop.run_in_executor(
None,
cluster.get_state
cluster.update_state
)
for cluster in clusters
]
Expand All @@ -102,7 +102,7 @@ def get_content(self, *args, **kwargs):
logger.exception('Asyncio loop is NOT available, fallback to simple looping: ')

for c in clusters:
c.get_state()
c.update_state()
self.obj = clusters

return super().get_content(self, *args, **kwargs)
Expand Down Expand Up @@ -161,9 +161,9 @@ def dispatch_request(self, *args, **kwargs):
self.check_authentication()
self.set_object(*args, **kwargs)
self.check_authorization()
cluster = self.get_content(*args, **kwargs)
cluster.get_state()

cluster = self.get_content(*args, hide_secure_data=False, **kwargs)
cluster.update_state()
cluster = self.hide_secure_data(self.obj)
return jsonify(cluster)


Expand Down Expand Up @@ -217,7 +217,7 @@ def cluster_progress(pk):
progress = {
'response': 501,
'progress': 0,
'result': obj.get_state()
'result': obj.update_state()
}
except Exception:
progress = {
Expand Down
4 changes: 2 additions & 2 deletions kqueen/engines/aks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AksEngine(BaseEngine):
'provisioner': {
'client_id': {
'type': 'text',
'label': 'Client ID',
'label': 'Application ID',
'order': 0,
'validators': {
'required': True,
Expand All @@ -51,7 +51,7 @@ class AksEngine(BaseEngine):
},
'tenant': {
'type': 'text',
'label': 'Tenant ID',
'label': 'Directory ID',
'order': 2,
'validators': {
'required': True,
Expand Down
2 changes: 1 addition & 1 deletion kqueen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Cluster(Model, metaclass=ModelMeta):
created_at = DatetimeField(default=datetime.utcnow)
owner = RelationField(required=True, remote_class_name='User')

def get_state(self):
def update_state(self):
try:
remote_cluster = self.engine.cluster_get()
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions kqueen/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def fake_cluster_get(self):
self.cluster = cluster

def test_stale_cluster(self):
cluster_state = self.cluster.get_state()
print(self.cluster.get_state())
cluster_state = self.cluster.update_state()
print(self.cluster.update_state())

assert cluster_state == config.get('CLUSTER_ERROR_STATE')
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
'google-api-python-client==1.6.4',
'google-auth==1.2.1',
'google-auth-httplib2==0.0.3',
'azure==2.0.0',
'azure-mgmt-containerservice==3.0.1',
'azure-common==1.1.9',
'azure-mgmt-containerservice==3.0.0',
'msrestazure==0.4.25',
'urllib3==1.22'
],
setup_requires=[
Expand Down

0 comments on commit 1c30d08

Please sign in to comment.