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:
parent
ccbffb2ef9
commit
7aa6e5e36c
openstackclient
common
compute/v2
network
tests
@ -111,9 +111,9 @@ class ListExtension(lister.Lister):
|
|||||||
if parsed_args.network or show_all:
|
if parsed_args.network or show_all:
|
||||||
network_client = self.app.client_manager.network
|
network_client = self.app.client_manager.network
|
||||||
try:
|
try:
|
||||||
data = network_client.list_extensions()['extensions']
|
data = network_client.extensions()
|
||||||
dict_tuples = (
|
dict_tuples = (
|
||||||
utils.get_dict_properties(
|
utils.get_item_properties(
|
||||||
s,
|
s,
|
||||||
columns,
|
columns,
|
||||||
formatters={},
|
formatters={},
|
||||||
|
@ -37,7 +37,6 @@ from openstackclient.common import parseractions
|
|||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
from openstackclient.i18n import _ # noqa
|
from openstackclient.i18n import _ # noqa
|
||||||
from openstackclient.identity import common as identity_common
|
from openstackclient.identity import common as identity_common
|
||||||
from openstackclient.network import common as network_common
|
|
||||||
|
|
||||||
|
|
||||||
def _format_servers_list_networks(networks):
|
def _format_servers_list_networks(networks):
|
||||||
@ -476,19 +475,13 @@ class CreateServer(show.ShowOne):
|
|||||||
if neutron_enabled:
|
if neutron_enabled:
|
||||||
network_client = self.app.client_manager.network
|
network_client = self.app.client_manager.network
|
||||||
if nic_info["net-id"]:
|
if nic_info["net-id"]:
|
||||||
nic_info["net-id"] = network_common.find(
|
net = network_client.find_network(
|
||||||
network_client,
|
nic_info["net-id"], ignore_missing=False)
|
||||||
'network',
|
nic_info["net-id"] = net.id
|
||||||
'networks',
|
|
||||||
nic_info["net-id"]
|
|
||||||
)
|
|
||||||
if nic_info["port-id"]:
|
if nic_info["port-id"]:
|
||||||
nic_info["port-id"] = network_common.find(
|
port = network_client.find_port(
|
||||||
network_client,
|
nic_info["port-id"], ignore_missing=False)
|
||||||
'port',
|
nic_info["port-id"] = port.id
|
||||||
'ports',
|
|
||||||
nic_info["port-id"]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
if nic_info["net-id"]:
|
if nic_info["net-id"]:
|
||||||
nic_info["net-id"] = utils.find_resource(
|
nic_info["net-id"] = utils.find_resource(
|
||||||
|
@ -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
|
|
@ -34,9 +34,9 @@ class TestExtension(utils.TestCommand):
|
|||||||
self.app.client_manager.identity.extensions)
|
self.app.client_manager.identity.extensions)
|
||||||
self.identity_extensions_mock.reset_mock()
|
self.identity_extensions_mock.reset_mock()
|
||||||
|
|
||||||
network = network_fakes.FakeNetworkV2Client()
|
network_client = network_fakes.FakeNetworkV2Client()
|
||||||
self.app.client_manager.network = network
|
self.app.client_manager.network = network_client
|
||||||
self.network_extensions_mock = network.list_extensions
|
self.network_extensions_mock = network_client.extensions
|
||||||
self.network_extensions_mock.reset_mock()
|
self.network_extensions_mock.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
|
@ -215,12 +215,17 @@ class TestServerCreate(TestServer):
|
|||||||
self.app.client_manager.auth_ref.service_catalog.get_endpoints = (
|
self.app.client_manager.auth_ref.service_catalog.get_endpoints = (
|
||||||
get_endpoints)
|
get_endpoints)
|
||||||
|
|
||||||
list_networks = mock.Mock()
|
find_network = mock.Mock()
|
||||||
list_ports = mock.Mock()
|
find_port = mock.Mock()
|
||||||
self.app.client_manager.network.list_networks = list_networks
|
network_client = self.app.client_manager.network
|
||||||
self.app.client_manager.network.list_ports = list_ports
|
network_client.find_network = find_network
|
||||||
list_networks.return_value = {'networks': [{'id': 'net1_uuid'}]}
|
network_client.find_port = find_port
|
||||||
list_ports.return_value = {'ports': [{'id': 'port1_uuid'}]}
|
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.
|
# Mock sdk APIs.
|
||||||
_network = mock.Mock()
|
_network = mock.Mock()
|
||||||
|
@ -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)
|
|
@ -27,19 +27,21 @@ extension_updated = '2013-07-09T12:00:0-00:00'
|
|||||||
extension_alias = 'Dystopian'
|
extension_alias = 'Dystopian'
|
||||||
extension_links = '[{"href":''"https://github.com/os/network", "type"}]'
|
extension_links = '[{"href":''"https://github.com/os/network", "type"}]'
|
||||||
|
|
||||||
NETEXT = {
|
|
||||||
'name': extension_name,
|
def create_extension():
|
||||||
'namespace': extension_namespace,
|
extension = mock.Mock()
|
||||||
'description': extension_description,
|
extension.name = extension_name
|
||||||
'updated': extension_updated,
|
extension.namespace = extension_namespace
|
||||||
'alias': extension_alias,
|
extension.description = extension_description
|
||||||
'links': extension_links,
|
extension.updated = extension_updated
|
||||||
}
|
extension.alias = extension_alias
|
||||||
|
extension.links = extension_links
|
||||||
|
return extension
|
||||||
|
|
||||||
|
|
||||||
class FakeNetworkV2Client(object):
|
class FakeNetworkV2Client(object):
|
||||||
def __init__(self, **kwargs):
|
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):
|
class TestNetworkV2(utils.TestCommand):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user