From cd8f35afd7c289a62de498a7a56d9ccec707462b Mon Sep 17 00:00:00 2001 From: Iwona Kotlarska Date: Wed, 19 Jul 2017 15:47:13 +0200 Subject: [PATCH] Add export of node group templates Partially-Implements: bp portable-node-group-and-cluster-templates Depends-On: I7a2ef7e5cff70e6034c1222252fbf7c5c35a7e1c This change adds functions to saharaclient to enable export of ngt to JSON. Change-Id: I33c3b6daa5b9e2be218a84efdb6113a4ce9a86df --- saharaclient/api/node_group_templates.py | 4 ++++ saharaclient/tests/unit/base.py | 5 +++++ saharaclient/tests/unit/test_node_group_templates.py | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/saharaclient/api/node_group_templates.py b/saharaclient/api/node_group_templates.py index 90c1b4da..0eaf80bb 100644 --- a/saharaclient/api/node_group_templates.py +++ b/saharaclient/api/node_group_templates.py @@ -127,3 +127,7 @@ class NodeGroupTemplateManager(base.ResourceManager): def delete(self, ng_template_id): """Delete a Node Group Template.""" self._delete('/node-group-templates/%s' % ng_template_id) + + def export(self, ng_template_id): + """Export a Node Group Template.""" + return self._get('/node-group-templates/%s/export' % ng_template_id) diff --git a/saharaclient/tests/unit/base.py b/saharaclient/tests/unit/base.py index c2cd255e..6d95f6a4 100644 --- a/saharaclient/tests/unit/base.py +++ b/saharaclient/tests/unit/base.py @@ -35,6 +35,11 @@ class BaseTestCase(testtools.TestCase): for key, value in body.items(): self.assertEqual(value, getattr(obj, key)) + def assertDictsEqual(self, dict1, dict2): + self.assertEqual(len(dict1), len(dict2)) + for key in dict1: + self.assertEqual(dict1[key], dict2[key]) + class TestResource(base.Resource): resource_name = 'Test Resource' diff --git a/saharaclient/tests/unit/test_node_group_templates.py b/saharaclient/tests/unit/test_node_group_templates.py index 99ef5a0d..13a75514 100644 --- a/saharaclient/tests/unit/test_node_group_templates.py +++ b/saharaclient/tests/unit/test_node_group_templates.py @@ -145,3 +145,12 @@ class NodeGroupTemplateTest(base.BaseTestCase): self.assertEqual(update_url, self.responses.last_request.url) self.assertEqual(unset_json, json.loads(self.responses.last_request.body)) + + def test_node_group_template_export(self): + url = self.URL + '/node-group-templates/id/export' + self.responses.get(url, json={'node_group_template': self.body}) + resp = self.client.node_group_templates.export('id') + + self.assertEqual(url, self.responses.last_request.url) + self.assertIsInstance(resp, ng.NodeGroupTemplate) + self.assertDictsEqual(self.body, resp.__dict__[u'node_group_template'])