From 66cbd8c821bda168bc07ab3aaa1fe4d7717fc7ff Mon Sep 17 00:00:00 2001 From: Yosef Hoffman Date: Tue, 10 May 2016 18:38:42 -0400 Subject: [PATCH] Always expand Baymodel fields In baymodel (https://github.com/openstack/magnum/blob/master/magnum/ api/controllers/v1/baymodel.py), we have an unset exception list: baymodel.unset_fields_except(['uuid', 'name', 'image_id', 'apiserver_port', 'coe']) In order for the new "--fields" option [1] to work better, this patch will remove the expand option so that all fields are included by default. [1] https://review.openstack.org/#/c/286950/ Change-Id: I1adffca9a7c6e013bed38530036dfc0aed918fdc Closes-Bug: #1579236 --- magnum/api/controllers/v1/baymodel.py | 30 +++++++------------ .../unit/api/controllers/v1/test_baymodel.py | 12 ++------ 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/magnum/api/controllers/v1/baymodel.py b/magnum/api/controllers/v1/baymodel.py index decdddce56..89b09b7458 100644 --- a/magnum/api/controllers/v1/baymodel.py +++ b/magnum/api/controllers/v1/baymodel.py @@ -141,11 +141,7 @@ class BayModel(base.APIBase): setattr(self, field, kwargs.get(field, wtypes.Unset)) @staticmethod - def _convert_with_links(baymodel, url, expand=True): - if not expand: - baymodel.unset_fields_except(['uuid', 'name', 'image_id', - 'apiserver_port', 'coe']) - + def _convert_with_links(baymodel, url): baymodel.links = [link.Link.make_link('self', url, 'baymodels', baymodel.uuid), link.Link.make_link('bookmark', url, @@ -154,13 +150,12 @@ class BayModel(base.APIBase): return baymodel @classmethod - def convert_with_links(cls, rpc_baymodel, expand=True): + def convert_with_links(cls, rpc_baymodel): baymodel = BayModel(**rpc_baymodel.as_dict()) - return cls._convert_with_links(baymodel, pecan.request.host_url, - expand) + return cls._convert_with_links(baymodel, pecan.request.host_url) @classmethod - def sample(cls, expand=True): + def sample(cls): sample = cls( uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c', name='example', @@ -185,7 +180,7 @@ class BayModel(base.APIBase): created_at=timeutils.utcnow(), updated_at=timeutils.utcnow(), public=False), - return cls._convert_with_links(sample, 'http://localhost:9511', expand) + return cls._convert_with_links(sample, 'http://localhost:9511') class BayModelCollection(collection.Collection): @@ -198,10 +193,9 @@ class BayModelCollection(collection.Collection): self._type = 'baymodels' @staticmethod - def convert_with_links(rpc_baymodels, limit, url=None, expand=False, - **kwargs): + def convert_with_links(rpc_baymodels, limit, url=None, **kwargs): collection = BayModelCollection() - collection.baymodels = [BayModel.convert_with_links(p, expand) + collection.baymodels = [BayModel.convert_with_links(p) for p in rpc_baymodels] collection.next = collection.get_next(limit, url=url, **kwargs) return collection @@ -209,7 +203,7 @@ class BayModelCollection(collection.Collection): @classmethod def sample(cls): sample = cls() - sample.baymodels = [BayModel.sample(expand=False)] + sample.baymodels = [BayModel.sample()] return sample @@ -221,8 +215,7 @@ class BayModelsController(rest.RestController): } def _get_baymodels_collection(self, marker, limit, - sort_key, sort_dir, expand=False, - resource_url=None): + sort_key, sort_dir, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) @@ -238,7 +231,6 @@ class BayModelsController(rest.RestController): return BayModelCollection.convert_with_links(baymodels, limit, url=resource_url, - expand=expand, sort_key=sort_key, sort_dir=sort_dir) @@ -279,11 +271,9 @@ class BayModelsController(rest.RestController): if parent != "baymodels": raise exception.HTTPNotFound - expand = True resource_url = '/'.join(['baymodels', 'detail']) return self._get_baymodels_collection(marker, limit, - sort_key, sort_dir, expand, - resource_url) + sort_key, sort_dir, resource_url) @expose.expose(BayModel, types.uuid_or_name) def get_one(self, baymodel_ident): diff --git a/magnum/tests/unit/api/controllers/v1/test_baymodel.py b/magnum/tests/unit/api/controllers/v1/test_baymodel.py index 7219e31577..82848f2076 100644 --- a/magnum/tests/unit/api/controllers/v1/test_baymodel.py +++ b/magnum/tests/unit/api/controllers/v1/test_baymodel.py @@ -41,9 +41,6 @@ class TestBayModelObject(base.TestCase): class TestListBayModel(api_base.FunctionalTest): - _baymodel_attrs = ('apiserver_port', 'name', 'tls_disabled', - 'registry_enabled', 'image_id', 'coe', 'server_type', - 'public',) _expand_baymodel_attrs = ('name', 'apiserver_port', 'network_driver', 'coe', 'flavor_id', 'fixed_network', 'dns_nameserver', 'http_proxy', @@ -62,13 +59,8 @@ class TestListBayModel(api_base.FunctionalTest): baymodel = obj_utils.create_test_baymodel(self.context) response = self.get_json('/baymodels') self.assertEqual(baymodel.uuid, response['baymodels'][0]["uuid"]) - self._verify_attrs(self._baymodel_attrs, response['baymodels'][0]) - - # Verify attrs that should not appear from response - none_attrs = (set(self._expand_baymodel_attrs) - - set(self._baymodel_attrs)) - self._verify_attrs(none_attrs, response['baymodels'][0], - positive=False) + self._verify_attrs(self._expand_baymodel_attrs, + response['baymodels'][0]) def test_get_one(self): baymodel = obj_utils.create_test_baymodel(self.context)