Update OpenstackConfig.find_configs to return query object

OpenstackConfig.find_configs should return query, not list
since NalgunCollection.to_json expects iterable object and
has incorrect behaviour when trying to pass empty list
as an iterable parameter.

Closes-Bug: #1523477
Change-Id: I50aaaa9a20dbf55d83a418189f808cd3829a8002
This commit is contained in:
Alexander Saprykin 2015-12-08 11:50:19 +01:00
parent 218e8a2ab3
commit fe79f827f3
2 changed files with 21 additions and 15 deletions

View File

@ -89,8 +89,7 @@ class OpenstackConfig(NailgunObject):
Example:
OpenstackConfig.find_configs(cluster_id=10, node_id=12)
"""
query = cls._find_configs_query(filters)
return query.all()
return cls._find_configs_query(filters)
@classmethod
def find_configs_for_nodes(cls, cluster, nodes):

View File

@ -30,17 +30,20 @@ class TestOpenstackConfigHandlers(BaseIntegrationTest):
def setUp(self):
super(TestOpenstackConfigHandlers, self).setUp()
self.cluster = self.env.create_cluster(api=False)
self.env.create_cluster(api=False)
self.env.create_cluster(api=False)
self.clusters = self.env.clusters
self.nodes = self.env.create_nodes(3)
self.configs = []
self.create_openstack_config(
cluster_id=self.cluster.id, configuration={})
cluster_id=self.clusters[0].id, configuration={})
self.create_openstack_config(
cluster_id=self.cluster.id, node_id=self.nodes[1].id,
cluster_id=self.clusters[0].id, node_id=self.nodes[1].id,
configuration={})
self.create_openstack_config(
cluster_id=self.cluster.id, node_id=self.nodes[1].id,
cluster_id=self.clusters[0].id, node_id=self.nodes[1].id,
configuration={}, is_active=False)
def create_openstack_config(self, **kwargs):
@ -51,7 +54,7 @@ class TestOpenstackConfigHandlers(BaseIntegrationTest):
def test_openstack_config_upload_new(self):
data = {
'cluster_id': self.cluster.id,
'cluster_id': self.clusters[0].id,
'node_id': self.nodes[0].id,
'configuration': {}
}
@ -62,12 +65,12 @@ class TestOpenstackConfigHandlers(BaseIntegrationTest):
headers=self.default_headers)
self.assertEqual(resp.status_code, 201)
resp_data = resp.json_body
self.assertEqual(resp_data['cluster_id'], self.cluster.id)
self.assertEqual(resp_data['cluster_id'], self.clusters[0].id)
self.assertEqual(resp_data['node_id'], self.nodes[0].id)
def test_openstack_config_upload_override(self):
data = {
'cluster_id': self.cluster.id,
'cluster_id': self.clusters[0].id,
'node_id': self.nodes[1].id,
'configuration': {}
}
@ -77,7 +80,7 @@ class TestOpenstackConfigHandlers(BaseIntegrationTest):
headers=self.default_headers)
self.assertEqual(resp.status_code, 201)
resp_data = resp.json_body
self.assertEqual(resp_data['cluster_id'], self.cluster.id)
self.assertEqual(resp_data['cluster_id'], self.clusters[0].id)
self.assertEqual(resp_data['node_id'], self.nodes[1].id)
resp = self.app.get(
@ -88,27 +91,31 @@ class TestOpenstackConfigHandlers(BaseIntegrationTest):
self.assertEqual(resp.json_body['is_active'], False)
def test_openstack_config_list(self):
url = self._make_filter_url(cluster_id=self.cluster.id)
url = self._make_filter_url(cluster_id=self.clusters[0].id)
resp = self.app.get(url, headers=self.default_headers)
self.assertEqual(resp.status_code, 200)
self.assertEqual(len(resp.json_body), 2)
url = self._make_filter_url(
cluster_id=self.cluster.id, node_id=self.nodes[1].id)
cluster_id=self.clusters[0].id, node_id=self.nodes[1].id)
resp = self.app.get(url, headers=self.default_headers)
self.assertEqual(resp.status_code, 200)
self.assertEqual(len(resp.json_body), 1)
url = self._make_filter_url(
cluster_id=self.cluster.id, is_active=0)
cluster_id=self.clusters[0].id, is_active=0)
resp = self.app.get(url, headers=self.default_headers)
self.assertEqual(resp.status_code, 200)
self.assertEqual(len(resp.json_body), 1)
self.assertFalse(resp.json_body[0]['is_active'])
url = self._make_filter_url(cluster_id=self.clusters[1].id)
resp = self.app.get(url, headers=self.default_headers)
self.assertEqual(len(resp.json_body), 0)
def test_openstack_config_list_fail(self):
url = self._make_filter_url(
cluster_id=self.cluster.id, node_id=self.nodes[0].id,
cluster_id=self.clusters[0].id, node_id=self.nodes[0].id,
node_role='controller')
resp = self.app.get(url, headers=self.default_headers,
expect_errors=True)
@ -142,7 +149,7 @@ class TestOpenstackConfigHandlers(BaseIntegrationTest):
@mock.patch('nailgun.task.task.rpc.cast')
def test_openstack_config_execute(self, _):
data = {'cluster_id': self.cluster.id}
data = {'cluster_id': self.clusters[0].id}
resp = self.app.put(
reverse('OpenstackConfigExecuteHandler'),
jsonutils.dumps(data), headers=self.default_headers