From 36b28a22a8be96d22be30c27358b725ab905d15a Mon Sep 17 00:00:00 2001 From: tengqm Date: Tue, 29 Dec 2015 19:52:44 -0500 Subject: [PATCH] Make cluster CRUD calls invoke SDK Switching cluster CRUD operations to call SDK interfaces directly. Change-Id: Iba5ce951be0577b21c1b11dbea05b7f8d69041a2 --- senlinclient/tests/unit/v1/test_shell.py | 33 ++++++++++++------------ senlinclient/v1/shell.py | 12 ++++----- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/senlinclient/tests/unit/v1/test_shell.py b/senlinclient/tests/unit/v1/test_shell.py index 156c4aa4..3d230b8d 100644 --- a/senlinclient/tests/unit/v1/test_shell.py +++ b/senlinclient/tests/unit/v1/test_shell.py @@ -606,11 +606,11 @@ class ShellTest(testtools.TestCase): queries['status'] = 'ACTIVE' args = self._make_args(args) clusters = mock.Mock() - client.clusters.return_value = clusters + client.conn.cluster.clusters.return_value = clusters args.full_id = True formatters = {} sh.do_cluster_list(client, args) - client.clusters.assert_called_once_with(**queries) + client.conn.cluster.clusters.assert_called_once_with(**queries) mock_print.assert_called_once_with(clusters, fields, formatters=formatters, sortby_index=None) @@ -627,7 +627,7 @@ class ShellTest(testtools.TestCase): cluster_id = 'cluster_id' cluster = mock.Mock() cluster.id = cluster_id - client.get_cluster.return_value = cluster + client.conn.cluster.get_cluster.return_value = cluster formatters = { 'metadata': utils.json_formatter, 'nodes': utils.list_formatter, @@ -656,26 +656,26 @@ class ShellTest(testtools.TestCase): del attrs['profile'] attrs['metadata'] = {'user': 'demo'} cluster = mock.Mock() - client.create_cluster.return_value = cluster + client.conn.cluster.create_cluster.return_value = cluster cluster.id = 'cluster_id' sh.do_cluster_create(client, args) - client.create_cluster.assert_called_once_with(**attrs) + client.conn.cluster.create_cluster.assert_called_once_with(**attrs) mock_show.assert_called_once_with(client, 'cluster_id') def test_do_cluster_delete(self): client = mock.Mock() - args = {'id': ['cluster_id']} + args = {'id': ['CID']} args = self._make_args(args) - client.delete_cluster = mock.Mock() + client.conn.cluster.delete_cluster = mock.Mock() sh.do_cluster_delete(client, args) - client.delete_cluster.assert_called_once_with('cluster_id') + client.conn.cluster.delete_cluster.assert_called_once_with('CID') def test_do_cluster_delete_not_found(self): client = mock.Mock() args = {'id': ['cluster_id']} args = self._make_args(args) ex = exc.HTTPNotFound - client.delete_cluster.side_effect = ex + client.conn.cluster.delete_cluster.side_effect = ex ex = self.assertRaises(exc.CommandError, sh.do_cluster_delete, client, args) msg = _('Failed to delete some of the specified clusters.') @@ -696,15 +696,16 @@ class ShellTest(testtools.TestCase): attrs['profile_id'] = 'test_profile' del attrs['profile'] args = self._make_args(args) - args.id = 'cluster_id' + args.id = 'CID' cluster = mock.Mock() - cluster.id = 'cluster_id' - client.get_cluster.return_value = cluster - client.update_cluster = mock.Mock() + cluster.id = 'CID' + client.conn.cluster.get_cluster.return_value = cluster + client.conn.cluster.update_cluster = mock.Mock() sh.do_cluster_update(client, args) - client.get_cluster.assert_called_once_with('cluster_id') - client.update_cluster.assert_called_once_with('cluster_id', **attrs) - mock_show.assert_called_once_with(client, 'cluster_id') + client.conn.cluster.get_cluster.assert_called_once_with('CID') + client.conn.cluster.update_cluster.assert_called_once_with('CID', + **attrs) + mock_show.assert_called_once_with(client, 'CID') @mock.patch.object(sh, '_show_cluster') def test_do_cluster_show(self, mock_show): diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 39c1faa5..f4276eda 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -412,7 +412,7 @@ def do_cluster_list(sc, args=None): else: sortby_index = 3 - clusters = sc.clusters(**queries) + clusters = sc.conn.cluster.clusters(**queries) formatters = {} if not args.full_id: formatters = { @@ -424,7 +424,7 @@ def do_cluster_list(sc, args=None): def _show_cluster(sc, cluster_id): try: - cluster = sc.get_cluster(cluster_id) + cluster = sc.conn.cluster.get_cluster(cluster_id) except exc.HTTPNotFound: raise exc.CommandError(_('Cluster %s is not found') % cluster_id) @@ -470,7 +470,7 @@ def do_cluster_create(sc, args): 'timeout': args.timeout } - cluster = sc.create_cluster(**attrs) + cluster = sc.conn.cluster.create_cluster(**attrs) _show_cluster(sc, cluster.id) @@ -482,7 +482,7 @@ def do_cluster_delete(sc, args): for cid in args.id: try: - sc.delete_cluster(cid) + sc.conn.cluster.delete_cluster(cid) except exc.HTTPNotFound as ex: failure_count += 1 print(ex) @@ -510,7 +510,7 @@ def do_cluster_delete(sc, args): help=_('Name or ID of cluster to be updated.')) def do_cluster_update(sc, args): """Update the cluster.""" - cluster = sc.get_cluster(args.id) + cluster = sc.conn.cluster.get_cluster(args.id) attrs = { 'name': args.name, 'profile_id': args.profile, @@ -519,7 +519,7 @@ def do_cluster_update(sc, args): 'timeout': args.timeout, } - sc.update_cluster(cluster.id, **attrs) + sc.conn.cluster.update_cluster(cluster.id, **attrs) _show_cluster(sc, cluster.id)