Migrate "network show" command to use SDK.
This patch makes "network show" command use sdk. Since we have to keep the other commands runnable with the old network client, we use a temporary method to create sdk network client. And as a result, the tests need to patch a method to fake the temporary method, which will be removed at last. There are two same test cases in the unit tests. This patch will remove one. And since the output has changed, we also need to fix function test cases. Change-Id: I4c06b4efad2db430767bbaa882b0876df3ab483a Implements: blueprint neutron-client Co-Authored-By: Terry Howe <terrylhowe@gmail.com> Co-Authored-By: Tang Chen <tangchen@cn.fujitsu.com>
This commit is contained in:
parent
45c644d428
commit
2a2cb4f75d
@ -40,9 +40,9 @@ class NetworkTests(test.TestCase):
|
||||
|
||||
def test_network_set(self):
|
||||
raw_output = self.openstack('network set --disable ' + self.NAME)
|
||||
opts = self.get_show_opts(['name', 'state'])
|
||||
opts = self.get_show_opts(['name', 'admin_state_up'])
|
||||
raw_output = self.openstack('network show ' + self.NAME + opts)
|
||||
self.assertEqual(self.NAME + "\nDOWN\n", raw_output)
|
||||
self.assertEqual("DOWN\n" + self.NAME + "\n", raw_output)
|
||||
|
||||
def test_network_show(self):
|
||||
opts = self.get_show_opts(self.FIELDS)
|
||||
|
@ -14,7 +14,6 @@
|
||||
"""Network action implementations"""
|
||||
|
||||
import logging
|
||||
import six
|
||||
|
||||
from cliff import command
|
||||
from cliff import lister
|
||||
@ -48,22 +47,6 @@ def _make_client_sdk(instance):
|
||||
return conn.network
|
||||
|
||||
|
||||
def _prep_network_detail(net):
|
||||
"""Prepare network object for output"""
|
||||
if 'subnets' in net:
|
||||
net['subnets'] = utils.format_list(net['subnets'])
|
||||
if 'admin_state_up' in net:
|
||||
net['state'] = 'UP' if net['admin_state_up'] else 'DOWN'
|
||||
net.pop('admin_state_up')
|
||||
if 'router:external' in net:
|
||||
net['router_type'] = 'External' if net['router:external'] \
|
||||
else 'Internal'
|
||||
net.pop('router:external')
|
||||
if 'tenant_id' in net:
|
||||
net['project_id'] = net.pop('tenant_id')
|
||||
return net
|
||||
|
||||
|
||||
class CreateNetwork(show.ShowOne):
|
||||
"""Create new network"""
|
||||
|
||||
@ -323,10 +306,10 @@ class ShowNetwork(show.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug('take_action(%s)' % parsed_args)
|
||||
self.app.client_manager.network = \
|
||||
_make_client_sdk(self.app.client_manager)
|
||||
client = self.app.client_manager.network
|
||||
net = client.api.find_attr(
|
||||
'networks',
|
||||
parsed_args.identifier,
|
||||
)
|
||||
data = _prep_network_detail(net)
|
||||
return zip(*sorted(six.iteritems(data)))
|
||||
obj = client.find_network(parsed_args.identifier, ignore_missing=False)
|
||||
columns = sorted(obj.keys())
|
||||
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
||||
return (tuple(columns), data)
|
||||
|
@ -21,6 +21,7 @@ from openstackclient.tests import fakes
|
||||
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes_v2
|
||||
from openstackclient.tests.identity.v3 import fakes as identity_fakes_v3
|
||||
from openstackclient.tests.network.v2 import fakes as network_fakes
|
||||
from openstackclient.tests import utils as tests_utils
|
||||
|
||||
RESOURCE = 'network'
|
||||
RESOURCES = 'networks'
|
||||
@ -533,39 +534,67 @@ class TestSetNetwork(TestNetwork):
|
||||
parsed_args)
|
||||
|
||||
|
||||
@mock.patch(
|
||||
'openstackclient.api.network_v2.APIv2.find_attr'
|
||||
)
|
||||
@mock.patch('openstackclient.network.v2.network._make_client_sdk')
|
||||
class TestShowNetwork(TestNetwork):
|
||||
|
||||
# The network to set.
|
||||
_network = network_fakes.FakeNetwork.create_one_network()
|
||||
|
||||
columns = (
|
||||
'admin_state_up',
|
||||
'id',
|
||||
'name',
|
||||
'router_external',
|
||||
'status',
|
||||
'subnets',
|
||||
'tenant_id',
|
||||
)
|
||||
|
||||
data = (
|
||||
network._format_admin_state(_network.admin_state_up),
|
||||
_network.id,
|
||||
_network.name,
|
||||
network._format_router_external(_network.router_external),
|
||||
_network.status,
|
||||
utils.format_list(_network.subnets),
|
||||
_network.tenant_id,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestShowNetwork, self).setUp()
|
||||
|
||||
self.network.find_network = mock.Mock(return_value=self._network)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = network.ShowNetwork(self.app, self.namespace)
|
||||
|
||||
def test_show_no_options(self, find_attr):
|
||||
def test_show_no_options(self, _make_client_sdk):
|
||||
_make_client_sdk.return_value = self.app.client_manager.network
|
||||
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
try:
|
||||
# Missing required args should bail here
|
||||
self.check_parser(self.cmd, arglist, verifylist)
|
||||
except tests_utils.ParserException:
|
||||
pass
|
||||
|
||||
def test_show_all_options(self, _make_client_sdk):
|
||||
_make_client_sdk.return_value = self.app.client_manager.network
|
||||
|
||||
arglist = [
|
||||
FAKE_NAME,
|
||||
self._network.name,
|
||||
]
|
||||
verifylist = [
|
||||
('identifier', FAKE_NAME),
|
||||
('identifier', self._network.name),
|
||||
]
|
||||
find_attr.return_value = copy.deepcopy(RECORD)
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = list(self.cmd.take_action(parsed_args))
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
find_attr.assert_called_with('networks', FAKE_NAME)
|
||||
self.assertEqual(FILTERED, result)
|
||||
self.network.find_network.assert_called_with(self._network.name,
|
||||
ignore_missing=False)
|
||||
|
||||
def test_show_all_options(self, find_attr):
|
||||
arglist = [FAKE_NAME]
|
||||
verifylist = [('identifier', FAKE_NAME)]
|
||||
find_attr.return_value = copy.deepcopy(RECORD)
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = list(self.cmd.take_action(parsed_args))
|
||||
|
||||
find_attr.assert_called_with('networks', FAKE_NAME)
|
||||
self.assertEqual(FILTERED, result)
|
||||
self.assertEqual(tuple(self.columns), columns)
|
||||
self.assertEqual(list(self.data), list(data))
|
||||
|
Loading…
Reference in New Issue
Block a user