From fe79f827f35ae39c97f0a06ef16d45dc51b7773a Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Tue, 8 Dec 2015 11:50:19 +0100 Subject: [PATCH] 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 --- nailgun/nailgun/objects/openstack_config.py | 3 +- .../unit/test_openstack_config_handler.py | 33 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/nailgun/nailgun/objects/openstack_config.py b/nailgun/nailgun/objects/openstack_config.py index 00b7c24798..cb50b0a4d9 100644 --- a/nailgun/nailgun/objects/openstack_config.py +++ b/nailgun/nailgun/objects/openstack_config.py @@ -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): diff --git a/nailgun/nailgun/test/unit/test_openstack_config_handler.py b/nailgun/nailgun/test/unit/test_openstack_config_handler.py index bdca7d4f67..40fd3e2339 100644 --- a/nailgun/nailgun/test/unit/test_openstack_config_handler.py +++ b/nailgun/nailgun/test/unit/test_openstack_config_handler.py @@ -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