SDK integration extensions and server create networks

Finish up the SDK integration with server create network and port
find and extension list.

Change-Id: I18dbada784d8aa92a45a937f251023ddf899c53e
This commit is contained in:
Terry Howe 2015-12-09 11:38:31 -07:00
parent ccbffb2ef9
commit 7aa6e5e36c
7 changed files with 33 additions and 119 deletions

View File

@ -111,9 +111,9 @@ class ListExtension(lister.Lister):
if parsed_args.network or show_all:
network_client = self.app.client_manager.network
try:
data = network_client.list_extensions()['extensions']
data = network_client.extensions()
dict_tuples = (
utils.get_dict_properties(
utils.get_item_properties(
s,
columns,
formatters={},

View File

@ -37,7 +37,6 @@ from openstackclient.common import parseractions
from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
from openstackclient.identity import common as identity_common
from openstackclient.network import common as network_common
def _format_servers_list_networks(networks):
@ -476,19 +475,13 @@ class CreateServer(show.ShowOne):
if neutron_enabled:
network_client = self.app.client_manager.network
if nic_info["net-id"]:
nic_info["net-id"] = network_common.find(
network_client,
'network',
'networks',
nic_info["net-id"]
)
net = network_client.find_network(
nic_info["net-id"], ignore_missing=False)
nic_info["net-id"] = net.id
if nic_info["port-id"]:
nic_info["port-id"] = network_common.find(
network_client,
'port',
'ports',
nic_info["port-id"]
)
port = network_client.find_port(
nic_info["port-id"], ignore_missing=False)
nic_info["port-id"] = port.id
else:
if nic_info["net-id"]:
nic_info["net-id"] = utils.find_resource(

View File

@ -1,29 +0,0 @@
# 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.
#
def find(client, resource, resources, name_or_id, name_attr='name'):
"""Find a network resource
:param client: network client
:param resource: name of the resource
:param resources: plural name of resource
:param name_or_id: name or id of resource user is looking for
:param name_attr: key to the name attribute for the resource
For example:
n = find(netclient, 'network', 'networks', 'matrix')
"""
list_method = getattr(client, "find_%s" % resource)
data = list_method(name_or_id, ignore_missing=False)
return data.id

View File

@ -34,9 +34,9 @@ class TestExtension(utils.TestCommand):
self.app.client_manager.identity.extensions)
self.identity_extensions_mock.reset_mock()
network = network_fakes.FakeNetworkV2Client()
self.app.client_manager.network = network
self.network_extensions_mock = network.list_extensions
network_client = network_fakes.FakeNetworkV2Client()
self.app.client_manager.network = network_client
self.network_extensions_mock = network_client.extensions
self.network_extensions_mock.reset_mock()

View File

@ -215,12 +215,17 @@ class TestServerCreate(TestServer):
self.app.client_manager.auth_ref.service_catalog.get_endpoints = (
get_endpoints)
list_networks = mock.Mock()
list_ports = mock.Mock()
self.app.client_manager.network.list_networks = list_networks
self.app.client_manager.network.list_ports = list_ports
list_networks.return_value = {'networks': [{'id': 'net1_uuid'}]}
list_ports.return_value = {'ports': [{'id': 'port1_uuid'}]}
find_network = mock.Mock()
find_port = mock.Mock()
network_client = self.app.client_manager.network
network_client.find_network = find_network
network_client.find_port = find_port
netty = mock.Mock()
netty.id = 'net1_uuid'
porty = mock.Mock()
porty.id = 'port1_uuid'
find_network.return_value = netty
find_port.return_value = porty
# Mock sdk APIs.
_network = mock.Mock()

View File

@ -1,57 +0,0 @@
# 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 openstackclient.network import common
from openstackclient.tests import utils
RESOURCE = 'resource'
RESOURCES = 'resources'
NAME = 'matrix'
ID = 'Fishburne'
class TestFind(utils.TestCase):
def setUp(self):
super(TestFind, self).setUp()
self.mock_client = mock.Mock()
self.list_resources = mock.Mock()
self.mock_client.find_resource = self.list_resources
self.resource = mock.Mock()
self.resource.id = ID
def test_name(self):
self.list_resources.return_value = self.resource
result = common.find(self.mock_client, RESOURCE, RESOURCES, NAME)
self.assertEqual(ID, result)
self.list_resources.assert_called_with(NAME, ignore_missing=False)
def test_id(self):
self.list_resources.return_value = self.resource
result = common.find(self.mock_client, RESOURCE, RESOURCES, NAME)
self.assertEqual(ID, result)
self.list_resources.assert_called_with(NAME, ignore_missing=False)
def test_nameo(self):
self.list_resources.return_value = self.resource
result = common.find(self.mock_client, RESOURCE, RESOURCES, NAME,
name_attr='nameo')
self.assertEqual(ID, result)
self.list_resources.assert_called_with(NAME, ignore_missing=False)

View File

@ -27,19 +27,21 @@ extension_updated = '2013-07-09T12:00:0-00:00'
extension_alias = 'Dystopian'
extension_links = '[{"href":''"https://github.com/os/network", "type"}]'
NETEXT = {
'name': extension_name,
'namespace': extension_namespace,
'description': extension_description,
'updated': extension_updated,
'alias': extension_alias,
'links': extension_links,
}
def create_extension():
extension = mock.Mock()
extension.name = extension_name
extension.namespace = extension_namespace
extension.description = extension_description
extension.updated = extension_updated
extension.alias = extension_alias
extension.links = extension_links
return extension
class FakeNetworkV2Client(object):
def __init__(self, **kwargs):
self.list_extensions = mock.Mock(return_value={'extensions': [NETEXT]})
self.extensions = mock.Mock(return_value=[create_extension()])
class TestNetworkV2(utils.TestCommand):