Merge "Remove node object from magnumclient"

This commit is contained in:
Jenkins 2016-02-18 03:21:21 +00:00 committed by Gerrit Code Review
commit 9eb9de4bcc
7 changed files with 0 additions and 321 deletions

View File

@ -122,7 +122,6 @@ class ShellTest(utils.TestCase):
stdout, stderr = self.shell('bash-completion')
# just check we have some output
required = [
'.*--type',
'.*--json',
'.*help',
'.*bay-show',

View File

@ -1,135 +0,0 @@
# Copyright 2015 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import testtools
from testtools import matchers
from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import nodes
NODE1 = {'id': 123,
'uuid': '66666666-7777-8888-9999-000000000001',
'type': 'virt',
'image_id': 'ubuntu',
'ironic_node_id': '5d12f6fd-a196-4bf0-ae4c-1f639a523a51',
}
NODE2 = {'id': 124,
'uuid': '66666666-7777-8888-9999-000000000002',
'type': 'ironic',
'image_id': 'rhel7',
'ironic_node_id': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
}
CREATE_NODE = copy.deepcopy(NODE1)
del CREATE_NODE['id']
del CREATE_NODE['uuid']
del CREATE_NODE['ironic_node_id']
UPDATED_NODE = copy.deepcopy(NODE1)
NEW_IMAGE_ID = 'centos7'
UPDATED_NODE['image_id'] = NEW_IMAGE_ID
fake_responses = {
'/v1/nodes':
{
'GET': (
{},
{'nodes': [NODE1, NODE2]},
),
'POST': (
{},
CREATE_NODE,
),
},
'/v1/nodes/%s' % NODE1['id']:
{
'GET': (
{},
NODE1
),
'DELETE': (
{},
None,
),
'PATCH': (
{},
UPDATED_NODE,
),
},
}
class NodeManagerTest(testtools.TestCase):
def setUp(self):
super(NodeManagerTest, self).setUp()
self.api = utils.FakeAPI(fake_responses)
self.mgr = nodes.NodeManager(self.api)
def test_node_list(self):
nodes = self.mgr.list()
expect = [
('GET', '/v1/nodes', {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertThat(nodes, matchers.HasLength(2))
def test_node_show(self):
node = self.mgr.get(NODE1['id'])
expect = [
('GET', '/v1/nodes/%s' % NODE1['id'], {}, None)
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(NODE1['type'], node.type)
self.assertEqual(NODE1['image_id'], node.image_id)
def test_node_create(self):
node = self.mgr.create(**CREATE_NODE)
expect = [
('POST', '/v1/nodes', {}, CREATE_NODE),
]
self.assertEqual(expect, self.api.calls)
self.assertTrue(node)
def test_node_create_fail(self):
CREATE_NODE_FAIL = copy.deepcopy(CREATE_NODE)
CREATE_NODE_FAIL["wrong_key"] = "wrong"
self.assertRaisesRegexp(exceptions.InvalidAttribute,
("Key must be in %s" %
','.join(nodes.CREATION_ATTRIBUTES)),
self.mgr.create, **CREATE_NODE_FAIL)
self.assertEqual([], self.api.calls)
def test_node_delete(self):
node = self.mgr.delete(NODE1['id'])
expect = [
('DELETE', '/v1/nodes/%s' % NODE1['id'], {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertIsNone(node)
def test_node_update(self):
patch = {'op': 'replace',
'value': NEW_IMAGE_ID,
'path': '/image_id'}
node = self.mgr.update(id=NODE1['id'], patch=patch)
expect = [
('PATCH', '/v1/nodes/%s' % NODE1['id'], {}, patch),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(NEW_IMAGE_ID, node.image_id)

View File

@ -1,38 +0,0 @@
# Copyright 2015 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from magnumclient.tests.v1 import shell_test_base
class ShellTest(shell_test_base.TestCommandLineArgument):
@mock.patch('magnumclient.v1.nodes.NodeManager.list')
def test_node_list_success(self, mock_list):
self._test_arg_success('node-list')
self.assertTrue(mock_list.called)
@mock.patch('magnumclient.v1.nodes.NodeManager.list')
def test_node_list_failure(self, mock_list):
self._test_arg_failure('node-list --wrong',
self._unrecognized_arg_error)
self.assertFalse(mock_list.called)
@mock.patch('magnumclient.v1.nodes.NodeManager.create')
def test_node_create_success(self, mock_create):
self._test_arg_success('node-create '
'--type test '
'--image-id test')
self.assertTrue(mock_create.called)

View File

@ -22,7 +22,6 @@ from magnumclient.v1 import bays
from magnumclient.v1 import certificates
from magnumclient.v1 import containers
from magnumclient.v1 import mservices
from magnumclient.v1 import nodes
from magnumclient.v1 import pods
from magnumclient.v1 import replicationcontrollers as rcs
from magnumclient.v1 import services
@ -112,7 +111,6 @@ class Client(object):
self.certificates = certificates.CertificateManager(self.http_client)
self.baymodels = baymodels.BayModelManager(self.http_client)
self.containers = containers.ContainerManager(self.http_client)
self.nodes = nodes.NodeManager(self.http_client)
self.pods = pods.PodManager(self.http_client)
self.rcs = rcs.ReplicationControllerManager(self.http_client)
self.services = services.ServiceManager(self.http_client)

View File

@ -1,99 +0,0 @@
# Copyright 2014 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from magnumclient.common import base
from magnumclient.common import utils
from magnumclient import exceptions
CREATION_ATTRIBUTES = ['name', 'type', 'image_id']
class Node(base.Resource):
def __repr__(self):
return "<Node %s>" % self._info
class NodeManager(base.Manager):
resource_class = Node
@staticmethod
def _path(id=None):
return '/v1/nodes/%s' % id if id else '/v1/nodes'
def list(self, limit=None, marker=None, sort_key=None,
sort_dir=None, detail=False):
"""Retrieve a list of nodes.
:param marker: Optional, the UUID of a node, eg the last
node from a previous result set. Return
the next result set.
:param limit: The maximum number of results to return per
request, if:
1) limit > 0, the maximum number of nodes to return.
2) limit == 0, return the entire list of nodes.
3) limit param is NOT specified (None), the number of items
returned respect the maximum imposed by the Magnum API
(see Magnum's api.max_limit option).
:param sort_key: Optional, field used for sorting.
:param sort_dir: Optional, direction of sorting, either 'asc' (the
default) or 'desc'.
:param detail: Optional, boolean whether to return detailed information
about nodes.
:returns: A list of nodes.
"""
if limit is not None:
limit = int(limit)
filters = utils.common_filters(marker, limit, sort_key, sort_dir)
path = ''
if detail:
path += 'detail'
if filters:
path += '?' + '&'.join(filters)
if limit is None:
return self._list(self._path(path), "nodes")
else:
return self._list_pagination(self._path(path), "nodes",
limit=limit)
def get(self, id):
try:
return self._list(self._path(id))[0]
except IndexError:
return None
def create(self, **kwargs):
new = {}
for (key, value) in kwargs.items():
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exceptions.InvalidAttribute(
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, id):
return self._delete(self._path(id))
def update(self, id, patch):
return self._update(self._path(id), patch)

View File

@ -1,44 +0,0 @@
# Copyright 2015 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from magnumclient.common import utils as magnum_utils
from magnumclient.openstack.common import cliutils as utils
def _show_node(node):
utils.print_dict(node._info)
def do_node_list(cs, args):
"""Print a list of configured nodes."""
nodes = cs.nodes.list()
columns = ('uuid', 'type', 'image_id')
utils.print_list(nodes, columns,
{'versions': magnum_utils.print_list_field('versions')})
@utils.arg('--type',
metavar='<type>',
help='Type of node to create (virt or bare).')
@utils.arg('--image-id',
metavar='<image-id>',
help='The name or UUID of the base image to use for the node.')
def do_node_create(cs, args):
"""Create a node."""
opts = {}
opts['type'] = args.type
opts['image_id'] = args.image_id
node = cs.nodes.create(**opts)
_show_node(node)

View File

@ -18,7 +18,6 @@ from magnumclient.v1 import bays_shell
from magnumclient.v1 import certificates_shell
from magnumclient.v1 import containers_shell
from magnumclient.v1 import mservices_shell
from magnumclient.v1 import nodes_shell
from magnumclient.v1 import pods_shell
from magnumclient.v1 import replicationcontrollers_shell
from magnumclient.v1 import services_shell
@ -29,7 +28,6 @@ COMMAND_MODULES = [
certificates_shell,
containers_shell,
mservices_shell,
nodes_shell,
pods_shell,
replicationcontrollers_shell,
services_shell,