Merge "Add network segment create, delete and set support"
This commit is contained in:
commit
5dc8151b58
@ -9,6 +9,75 @@ within a network may not be guaranteed.
|
||||
|
||||
Network v2
|
||||
|
||||
network segment create
|
||||
----------------------
|
||||
|
||||
Create new network segment
|
||||
|
||||
.. caution:: This is a beta command and subject to change.
|
||||
Use global option ``--os-beta-command`` to
|
||||
enable this command.
|
||||
|
||||
.. program:: network segment create
|
||||
.. code:: bash
|
||||
|
||||
os network segment create
|
||||
[--description <description>]
|
||||
[--physical-network <physical-network>]
|
||||
[--segment <segment>]
|
||||
--network <network>
|
||||
--network-type <network-type>
|
||||
<name>
|
||||
|
||||
.. option:: --description <description>
|
||||
|
||||
Network segment description
|
||||
|
||||
.. option:: --physical-network <physical-network>
|
||||
|
||||
Physical network name of this network segment
|
||||
|
||||
.. option:: --segment <segment>
|
||||
|
||||
Segment identifier for this network segment which is
|
||||
based on the network type, VLAN ID for vlan network
|
||||
type and tunnel ID for geneve, gre and vxlan network
|
||||
types
|
||||
|
||||
.. option:: --network <network>
|
||||
|
||||
Network this network segment belongs to (name or ID)
|
||||
|
||||
.. option:: --network-type <network-type>
|
||||
|
||||
Network type of this network segment
|
||||
(flat, geneve, gre, local, vlan or vxlan)
|
||||
|
||||
.. _network_segment_create-name:
|
||||
.. describe:: <name>
|
||||
|
||||
New network segment name
|
||||
|
||||
network segment delete
|
||||
----------------------
|
||||
|
||||
Delete network segment(s)
|
||||
|
||||
.. caution:: This is a beta command and subject to change.
|
||||
Use global option ``--os-beta-command`` to
|
||||
enable this command.
|
||||
|
||||
.. program:: network segment delete
|
||||
.. code:: bash
|
||||
|
||||
os network segment delete
|
||||
<network-segment> [<network-segment> ...]
|
||||
|
||||
.. _network_segment_delete-segment:
|
||||
.. describe:: <network-segment>
|
||||
|
||||
Network segment(s) to delete (name or ID)
|
||||
|
||||
network segment list
|
||||
--------------------
|
||||
|
||||
@ -33,6 +102,36 @@ List network segments
|
||||
|
||||
List network segments that belong to this network (name or ID)
|
||||
|
||||
network segment set
|
||||
-------------------
|
||||
|
||||
Set network segment properties
|
||||
|
||||
.. caution:: This is a beta command and subject to change.
|
||||
Use global option ``--os-beta-command`` to
|
||||
enable this command.
|
||||
|
||||
.. program:: network segment set
|
||||
.. code:: bash
|
||||
|
||||
os network segment set
|
||||
[--description <description>]
|
||||
[--name <name>]
|
||||
<network-segment>
|
||||
|
||||
.. option:: --description <description>
|
||||
|
||||
Set network segment description
|
||||
|
||||
.. option:: --name <name>
|
||||
|
||||
Set network segment name
|
||||
|
||||
.. _network_segment_set-segment:
|
||||
.. describe:: <network-segment>
|
||||
|
||||
Network segment to modify (name or ID)
|
||||
|
||||
network segment show
|
||||
--------------------
|
||||
|
||||
@ -51,4 +150,4 @@ Display network segment details
|
||||
.. _network_segment_show-segment:
|
||||
.. describe:: <network-segment>
|
||||
|
||||
Network segment to display (ID only)
|
||||
Network segment to display (name or ID)
|
||||
|
@ -13,14 +13,129 @@
|
||||
|
||||
"""Network segment action implementations"""
|
||||
|
||||
# TODO(rtheis): Add description and name properties when support is available.
|
||||
import logging
|
||||
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CreateNetworkSegment(command.ShowOne):
|
||||
"""Create new network segment
|
||||
|
||||
(Caution: This is a beta command and subject to change.
|
||||
Use global option --os-beta-command to enable
|
||||
this command)
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateNetworkSegment, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'name',
|
||||
metavar='<name>',
|
||||
help=_('New network segment name')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_('Network segment description'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--physical-network',
|
||||
metavar='<physical-network>',
|
||||
help=_('Physical network name of this network segment'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--segment',
|
||||
metavar='<segment>',
|
||||
type=int,
|
||||
help=_('Segment identifier for this network segment which is '
|
||||
'based on the network type, VLAN ID for vlan network '
|
||||
'type and tunnel ID for geneve, gre and vxlan network '
|
||||
'types'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--network',
|
||||
metavar='<network>',
|
||||
required=True,
|
||||
help=_('Network this network segment belongs to (name or ID)'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--network-type',
|
||||
metavar='<network-type>',
|
||||
choices=['flat', 'geneve', 'gre', 'local', 'vlan', 'vxlan'],
|
||||
required=True,
|
||||
help=_('Network type of this network segment '
|
||||
'(flat, geneve, gre, local, vlan or vxlan)'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.validate_os_beta_command_enabled()
|
||||
client = self.app.client_manager.network
|
||||
attrs = {}
|
||||
attrs['name'] = parsed_args.name
|
||||
attrs['network_id'] = client.find_network(parsed_args.network,
|
||||
ignore_missing=False).id
|
||||
attrs['network_type'] = parsed_args.network_type
|
||||
if parsed_args.description is not None:
|
||||
attrs['description'] = parsed_args.description
|
||||
if parsed_args.physical_network is not None:
|
||||
attrs['physical_network'] = parsed_args.physical_network
|
||||
if parsed_args.segment is not None:
|
||||
attrs['segmentation_id'] = parsed_args.segment
|
||||
obj = client.create_segment(**attrs)
|
||||
columns = tuple(sorted(obj.keys()))
|
||||
data = utils.get_item_properties(obj, columns)
|
||||
return (columns, data)
|
||||
|
||||
|
||||
class DeleteNetworkSegment(command.Command):
|
||||
"""Delete network segment(s)
|
||||
|
||||
(Caution: This is a beta command and subject to change.
|
||||
Use global option --os-beta-command to enable
|
||||
this command)
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(DeleteNetworkSegment, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'network_segment',
|
||||
metavar='<network-segment>',
|
||||
nargs='+',
|
||||
help=_('Network segment(s) to delete (name or ID)'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.validate_os_beta_command_enabled()
|
||||
client = self.app.client_manager.network
|
||||
|
||||
result = 0
|
||||
for network_segment in parsed_args.network_segment:
|
||||
try:
|
||||
obj = client.find_segment(network_segment,
|
||||
ignore_missing=False)
|
||||
client.delete_segment(obj)
|
||||
except Exception as e:
|
||||
result += 1
|
||||
LOG.error(_("Failed to delete network segment with "
|
||||
"ID '%(network_segment)s': %(e)s")
|
||||
% {'network_segment': network_segment, 'e': e})
|
||||
|
||||
if result > 0:
|
||||
total = len(parsed_args.network_segment)
|
||||
msg = (_("%(result)s of %(total)s network segments failed "
|
||||
"to delete.") % {'result': result, 'total': total})
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
class ListNetworkSegment(command.Lister):
|
||||
"""List network segments
|
||||
|
||||
@ -61,12 +176,14 @@ class ListNetworkSegment(command.Lister):
|
||||
|
||||
headers = (
|
||||
'ID',
|
||||
'Name',
|
||||
'Network',
|
||||
'Network Type',
|
||||
'Segment',
|
||||
)
|
||||
columns = (
|
||||
'id',
|
||||
'name',
|
||||
'network_id',
|
||||
'network_type',
|
||||
'segmentation_id',
|
||||
@ -86,6 +203,46 @@ class ListNetworkSegment(command.Lister):
|
||||
) for s in data))
|
||||
|
||||
|
||||
class SetNetworkSegment(command.Command):
|
||||
"""Set network segment properties
|
||||
|
||||
(Caution: This is a beta command and subject to change.
|
||||
Use global option --os-beta-command to enable
|
||||
this command)
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SetNetworkSegment, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'network_segment',
|
||||
metavar='<network-segment>',
|
||||
help=_('Network segment to modify (name or ID)'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_('Set network segment description'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<name>',
|
||||
help=_('Set network segment name'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.validate_os_beta_command_enabled()
|
||||
client = self.app.client_manager.network
|
||||
obj = client.find_segment(parsed_args.network_segment,
|
||||
ignore_missing=False)
|
||||
attrs = {}
|
||||
if parsed_args.description is not None:
|
||||
attrs['description'] = parsed_args.description
|
||||
if parsed_args.name is not None:
|
||||
attrs['name'] = parsed_args.name
|
||||
client.update_segment(obj, **attrs)
|
||||
|
||||
|
||||
class ShowNetworkSegment(command.ShowOne):
|
||||
"""Display network segment details
|
||||
|
||||
@ -99,7 +256,7 @@ class ShowNetworkSegment(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'network_segment',
|
||||
metavar='<network-segment>',
|
||||
help=_('Network segment to display (ID only)'),
|
||||
help=_('Network segment to display (name or ID)'),
|
||||
)
|
||||
return parser
|
||||
|
||||
|
@ -57,6 +57,11 @@ class TestCase(testtools.TestCase):
|
||||
opts = cls.get_opts([configuration])
|
||||
return cls.openstack('configuration show ' + opts)
|
||||
|
||||
@classmethod
|
||||
def get_openstack_extention_names(cls):
|
||||
opts = cls.get_opts(['Name'])
|
||||
return cls.openstack('extension list ' + opts)
|
||||
|
||||
@classmethod
|
||||
def get_opts(cls, fields, format='value'):
|
||||
return ' -f {0} {1}'.format(format,
|
||||
|
@ -10,20 +10,18 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import testtools
|
||||
import uuid
|
||||
|
||||
from openstackclient.tests.functional import base
|
||||
|
||||
|
||||
# NOTE(rtheis): Routed networks is still a WIP and not enabled by default.
|
||||
@testtools.skip("bp/routed-networks")
|
||||
class NetworkSegmentTests(base.TestCase):
|
||||
"""Functional tests for network segment. """
|
||||
NETWORK_NAME = uuid.uuid4().hex
|
||||
PHYSICAL_NETWORK_NAME = uuid.uuid4().hex
|
||||
NETWORK_SEGMENT_ID = None
|
||||
NETWORK_ID = None
|
||||
NETWORK_SEGMENT_EXTENSION = None
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@ -32,29 +30,75 @@ class NetworkSegmentTests(base.TestCase):
|
||||
raw_output = cls.openstack('network create ' + cls.NETWORK_NAME + opts)
|
||||
cls.NETWORK_ID = raw_output.strip('\n')
|
||||
|
||||
# Get the segment for the network.
|
||||
opts = cls.get_opts(['ID', 'Network'])
|
||||
raw_output = cls.openstack('--os-beta-command '
|
||||
'network segment list '
|
||||
' --network ' + cls.NETWORK_NAME +
|
||||
' ' + opts)
|
||||
raw_output_row = raw_output.split('\n')[0]
|
||||
cls.NETWORK_SEGMENT_ID = raw_output_row.split(' ')[0]
|
||||
# NOTE(rtheis): The segment extension is not yet enabled by default.
|
||||
# Skip the tests if not enabled.
|
||||
extensions = cls.get_openstack_extention_names()
|
||||
if 'Segment' in extensions:
|
||||
cls.NETWORK_SEGMENT_EXTENSION = 'Segment'
|
||||
|
||||
if cls.NETWORK_SEGMENT_EXTENSION:
|
||||
# Get the segment for the network.
|
||||
opts = cls.get_opts(['ID', 'Network'])
|
||||
raw_output = cls.openstack('--os-beta-command '
|
||||
'network segment list '
|
||||
' --network ' + cls.NETWORK_NAME +
|
||||
' ' + opts)
|
||||
raw_output_row = raw_output.split('\n')[0]
|
||||
cls.NETWORK_SEGMENT_ID = raw_output_row.split(' ')[0]
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME)
|
||||
cls.assertOutput('', raw_output)
|
||||
|
||||
def test_network_segment_create_delete(self):
|
||||
if self.NETWORK_SEGMENT_EXTENSION:
|
||||
opts = self.get_opts(['id'])
|
||||
raw_output = self.openstack(
|
||||
'--os-beta-command' +
|
||||
' network segment create --network ' + self.NETWORK_ID +
|
||||
' --network-type geneve ' +
|
||||
' --segment 2055 test_segment ' + opts
|
||||
)
|
||||
network_segment_id = raw_output.strip('\n')
|
||||
raw_output = self.openstack('--os-beta-command ' +
|
||||
'network segment delete ' +
|
||||
network_segment_id)
|
||||
self.assertOutput('', raw_output)
|
||||
else:
|
||||
self.skipTest('Segment extension disabled')
|
||||
|
||||
def test_network_segment_list(self):
|
||||
opts = self.get_opts(['ID'])
|
||||
raw_output = self.openstack('--os-beta-command '
|
||||
'network segment list' + opts)
|
||||
self.assertIn(self.NETWORK_SEGMENT_ID, raw_output)
|
||||
if self.NETWORK_SEGMENT_EXTENSION:
|
||||
opts = self.get_opts(['ID'])
|
||||
raw_output = self.openstack('--os-beta-command '
|
||||
'network segment list' + opts)
|
||||
self.assertIn(self.NETWORK_SEGMENT_ID, raw_output)
|
||||
else:
|
||||
self.skipTest('Segment extension disabled')
|
||||
|
||||
def test_network_segment_set(self):
|
||||
if self.NETWORK_SEGMENT_EXTENSION:
|
||||
new_description = 'new_description'
|
||||
raw_output = self.openstack('--os-beta-command '
|
||||
'network segment set ' +
|
||||
'--description ' + new_description +
|
||||
' ' + self.NETWORK_SEGMENT_ID)
|
||||
self.assertOutput('', raw_output)
|
||||
opts = self.get_opts(['description'])
|
||||
raw_output = self.openstack('--os-beta-command '
|
||||
'network segment show ' +
|
||||
self.NETWORK_SEGMENT_ID + opts)
|
||||
self.assertEqual(new_description + "\n", raw_output)
|
||||
else:
|
||||
self.skipTest('Segment extension disabled')
|
||||
|
||||
def test_network_segment_show(self):
|
||||
opts = self.get_opts(['network_id'])
|
||||
raw_output = self.openstack('--os-beta-command '
|
||||
'network segment show ' +
|
||||
self.NETWORK_SEGMENT_ID + opts)
|
||||
self.assertEqual(self.NETWORK_ID + "\n", raw_output)
|
||||
if self.NETWORK_SEGMENT_EXTENSION:
|
||||
opts = self.get_opts(['network_id'])
|
||||
raw_output = self.openstack('--os-beta-command '
|
||||
'network segment show ' +
|
||||
self.NETWORK_SEGMENT_ID + opts)
|
||||
self.assertEqual(self.NETWORK_ID + "\n", raw_output)
|
||||
else:
|
||||
self.skipTest('Segment extension disabled')
|
||||
|
@ -364,11 +364,14 @@ class FakeNetworkSegment(object):
|
||||
attrs = attrs or {}
|
||||
|
||||
# Set default attributes.
|
||||
fake_uuid = uuid.uuid4().hex
|
||||
network_segment_attrs = {
|
||||
'id': 'network-segment-id-' + uuid.uuid4().hex,
|
||||
'network_id': 'network-id-' + uuid.uuid4().hex,
|
||||
'description': 'network-segment-description-' + fake_uuid,
|
||||
'id': 'network-segment-id-' + fake_uuid,
|
||||
'name': 'network-segment-name-' + fake_uuid,
|
||||
'network_id': 'network-id-' + fake_uuid,
|
||||
'network_type': 'vlan',
|
||||
'physical_network': 'physical-network-name-' + uuid.uuid4().hex,
|
||||
'physical_network': 'physical-network-name-' + fake_uuid,
|
||||
'segmentation_id': 1024,
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#
|
||||
|
||||
import mock
|
||||
from mock import call
|
||||
|
||||
from osc_lib import exceptions
|
||||
|
||||
@ -32,6 +33,243 @@ class TestNetworkSegment(network_fakes.TestNetworkV2):
|
||||
self.network = self.app.client_manager.network
|
||||
|
||||
|
||||
class TestCreateNetworkSegment(TestNetworkSegment):
|
||||
|
||||
# The network segment to create along with associated network.
|
||||
_network_segment = \
|
||||
network_fakes.FakeNetworkSegment.create_one_network_segment()
|
||||
_network = network_fakes.FakeNetwork.create_one_network({
|
||||
'id': _network_segment.network_id,
|
||||
})
|
||||
|
||||
columns = (
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'network_id',
|
||||
'network_type',
|
||||
'physical_network',
|
||||
'segmentation_id',
|
||||
)
|
||||
|
||||
data = (
|
||||
_network_segment.description,
|
||||
_network_segment.id,
|
||||
_network_segment.name,
|
||||
_network_segment.network_id,
|
||||
_network_segment.network_type,
|
||||
_network_segment.physical_network,
|
||||
_network_segment.segmentation_id,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestCreateNetworkSegment, self).setUp()
|
||||
|
||||
self.network.create_segment = mock.Mock(
|
||||
return_value=self._network_segment
|
||||
)
|
||||
self.network.find_network = mock.Mock(return_value=self._network)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = network_segment.CreateNetworkSegment(
|
||||
self.app,
|
||||
self.namespace
|
||||
)
|
||||
|
||||
def test_create_no_options(self):
|
||||
# Missing required args should bail here
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, [], [])
|
||||
|
||||
def test_create_no_beta_commands(self):
|
||||
arglist = [
|
||||
'--network', self._network_segment.network_id,
|
||||
'--network-type', self._network_segment.network_type,
|
||||
self._network_segment.name,
|
||||
]
|
||||
verifylist = [
|
||||
('network', self._network_segment.network_id),
|
||||
('network_type', self._network_segment.network_type),
|
||||
('name', self._network_segment.name),
|
||||
]
|
||||
self.app.options.os_beta_command = False
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
||||
def test_create_invalid_network_type(self):
|
||||
arglist = [
|
||||
'--network', self._network_segment.network_id,
|
||||
'--network-type', 'foo',
|
||||
self._network_segment.name,
|
||||
]
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, [])
|
||||
|
||||
def test_create_minimum_options(self):
|
||||
arglist = [
|
||||
'--network', self._network_segment.network_id,
|
||||
'--network-type', self._network_segment.network_type,
|
||||
self._network_segment.name,
|
||||
]
|
||||
verifylist = [
|
||||
('network', self._network_segment.network_id),
|
||||
('network_type', self._network_segment.network_type),
|
||||
('name', self._network_segment.name),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.find_network.assert_called_once_with(
|
||||
self._network_segment.network_id,
|
||||
ignore_missing=False
|
||||
)
|
||||
self.network.create_segment.assert_called_once_with(**{
|
||||
'network_id': self._network_segment.network_id,
|
||||
'network_type': self._network_segment.network_type,
|
||||
'name': self._network_segment.name,
|
||||
})
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
def test_create_all_options(self):
|
||||
arglist = [
|
||||
'--description', self._network_segment.description,
|
||||
'--network', self._network_segment.network_id,
|
||||
'--network-type', self._network_segment.network_type,
|
||||
'--physical-network', self._network_segment.physical_network,
|
||||
'--segment', str(self._network_segment.segmentation_id),
|
||||
self._network_segment.name,
|
||||
]
|
||||
verifylist = [
|
||||
('description', self._network_segment.description),
|
||||
('network', self._network_segment.network_id),
|
||||
('network_type', self._network_segment.network_type),
|
||||
('physical_network', self._network_segment.physical_network),
|
||||
('segment', self._network_segment.segmentation_id),
|
||||
('name', self._network_segment.name),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.find_network.assert_called_once_with(
|
||||
self._network_segment.network_id,
|
||||
ignore_missing=False
|
||||
)
|
||||
self.network.create_segment.assert_called_once_with(**{
|
||||
'description': self._network_segment.description,
|
||||
'network_id': self._network_segment.network_id,
|
||||
'network_type': self._network_segment.network_type,
|
||||
'physical_network': self._network_segment.physical_network,
|
||||
'segmentation_id': self._network_segment.segmentation_id,
|
||||
'name': self._network_segment.name,
|
||||
})
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
|
||||
class TestDeleteNetworkSegment(TestNetworkSegment):
|
||||
|
||||
# The network segments to delete.
|
||||
_network_segments = \
|
||||
network_fakes.FakeNetworkSegment.create_network_segments()
|
||||
|
||||
def setUp(self):
|
||||
super(TestDeleteNetworkSegment, self).setUp()
|
||||
|
||||
self.network.delete_segment = mock.Mock(return_value=None)
|
||||
self.network.find_segment = mock.MagicMock(
|
||||
side_effect=self._network_segments
|
||||
)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = network_segment.DeleteNetworkSegment(
|
||||
self.app,
|
||||
self.namespace
|
||||
)
|
||||
|
||||
def test_delete_no_beta_commands(self):
|
||||
arglist = [
|
||||
self._network_segments[0].id,
|
||||
]
|
||||
verifylist = [
|
||||
('network_segment', [self._network_segments[0].id]),
|
||||
]
|
||||
self.app.options.os_beta_command = False
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
||||
def test_delete(self):
|
||||
arglist = [
|
||||
self._network_segments[0].id,
|
||||
]
|
||||
verifylist = [
|
||||
('network_segment', [self._network_segments[0].id]),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.delete_segment.assert_called_once_with(
|
||||
self._network_segments[0]
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_delete_multiple(self):
|
||||
arglist = []
|
||||
for _network_segment in self._network_segments:
|
||||
arglist.append(_network_segment.id)
|
||||
verifylist = [
|
||||
('network_segment', arglist),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
calls = []
|
||||
for _network_segment in self._network_segments:
|
||||
calls.append(call(_network_segment))
|
||||
self.network.delete_segment.assert_has_calls(calls)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_delete_multiple_with_exception(self):
|
||||
arglist = [
|
||||
self._network_segments[0].id,
|
||||
'doesnotexist'
|
||||
]
|
||||
verifylist = [
|
||||
('network_segment', [self._network_segments[0].id,
|
||||
'doesnotexist']),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
find_mock_result = [self._network_segments[0],
|
||||
exceptions.CommandError]
|
||||
self.network.find_segment = (
|
||||
mock.MagicMock(side_effect=find_mock_result)
|
||||
)
|
||||
|
||||
try:
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.fail('CommandError should be raised.')
|
||||
except exceptions.CommandError as e:
|
||||
self.assertEqual('1 of 2 network segments failed to delete.',
|
||||
str(e))
|
||||
|
||||
self.network.find_segment.assert_any_call(
|
||||
self._network_segments[0].id, ignore_missing=False)
|
||||
self.network.find_segment.assert_any_call(
|
||||
'doesnotexist', ignore_missing=False)
|
||||
self.network.delete_segment.assert_called_once_with(
|
||||
self._network_segments[0]
|
||||
)
|
||||
|
||||
|
||||
class TestListNetworkSegment(TestNetworkSegment):
|
||||
_network = network_fakes.FakeNetwork.create_one_network()
|
||||
_network_segments = \
|
||||
@ -39,6 +277,7 @@ class TestListNetworkSegment(TestNetworkSegment):
|
||||
|
||||
columns = (
|
||||
'ID',
|
||||
'Name',
|
||||
'Network',
|
||||
'Network Type',
|
||||
'Segment',
|
||||
@ -51,6 +290,7 @@ class TestListNetworkSegment(TestNetworkSegment):
|
||||
for _network_segment in _network_segments:
|
||||
data.append((
|
||||
_network_segment.id,
|
||||
_network_segment.name,
|
||||
_network_segment.network_id,
|
||||
_network_segment.network_type,
|
||||
_network_segment.segmentation_id,
|
||||
@ -60,6 +300,7 @@ class TestListNetworkSegment(TestNetworkSegment):
|
||||
for _network_segment in _network_segments:
|
||||
data_long.append((
|
||||
_network_segment.id,
|
||||
_network_segment.name,
|
||||
_network_segment.network_id,
|
||||
_network_segment.network_type,
|
||||
_network_segment.segmentation_id,
|
||||
@ -131,6 +372,78 @@ class TestListNetworkSegment(TestNetworkSegment):
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
|
||||
class TestSetNetworkSegment(TestNetworkSegment):
|
||||
|
||||
# The network segment to show.
|
||||
_network_segment = \
|
||||
network_fakes.FakeNetworkSegment.create_one_network_segment()
|
||||
|
||||
def setUp(self):
|
||||
super(TestSetNetworkSegment, self).setUp()
|
||||
|
||||
self.network.find_segment = mock.Mock(
|
||||
return_value=self._network_segment
|
||||
)
|
||||
self.network.update_segment = mock.Mock(
|
||||
return_value=self._network_segment
|
||||
)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = network_segment.SetNetworkSegment(self.app, self.namespace)
|
||||
|
||||
def test_set_no_beta_commands(self):
|
||||
arglist = [
|
||||
self._network_segment.id,
|
||||
]
|
||||
verifylist = [
|
||||
('network_segment', self._network_segment.id),
|
||||
]
|
||||
self.app.options.os_beta_command = False
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
||||
def test_set_no_options(self):
|
||||
arglist = [
|
||||
self._network_segment.id,
|
||||
]
|
||||
verifylist = [
|
||||
('network_segment', self._network_segment.id),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.update_segment.assert_called_once_with(
|
||||
self._network_segment, **{}
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_set_all_options(self):
|
||||
arglist = [
|
||||
'--description', 'new description',
|
||||
'--name', 'new name',
|
||||
self._network_segment.id,
|
||||
]
|
||||
verifylist = [
|
||||
('description', 'new description'),
|
||||
('name', 'new name'),
|
||||
('network_segment', self._network_segment.id),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
attrs = {
|
||||
'description': 'new description',
|
||||
'name': 'new name',
|
||||
}
|
||||
self.network.update_segment.assert_called_once_with(
|
||||
self._network_segment, **attrs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestShowNetworkSegment(TestNetworkSegment):
|
||||
|
||||
# The network segment to show.
|
||||
@ -138,7 +451,9 @@ class TestShowNetworkSegment(TestNetworkSegment):
|
||||
network_fakes.FakeNetworkSegment.create_one_network_segment()
|
||||
|
||||
columns = (
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'network_id',
|
||||
'network_type',
|
||||
'physical_network',
|
||||
@ -146,7 +461,9 @@ class TestShowNetworkSegment(TestNetworkSegment):
|
||||
)
|
||||
|
||||
data = (
|
||||
_network_segment.description,
|
||||
_network_segment.id,
|
||||
_network_segment.name,
|
||||
_network_segment.network_id,
|
||||
_network_segment.network_type,
|
||||
_network_segment.physical_network,
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- Add ``network segment create``, ``network segment delete`` and
|
||||
``network segment set`` commands. These are beta commands and subject to
|
||||
change. Use global option ``--os-beta-command`` to enable these commands.
|
||||
[Blueprint `routed-networks <https://blueprints.launchpad.net/neutron/+spec/routed-networks>`_]
|
@ -372,7 +372,10 @@ openstack.network.v2 =
|
||||
network_rbac_set = openstackclient.network.v2.network_rbac:SetNetworkRBAC
|
||||
network_rbac_show = openstackclient.network.v2.network_rbac:ShowNetworkRBAC
|
||||
|
||||
network_segment_create = openstackclient.network.v2.network_segment:CreateNetworkSegment
|
||||
network_segment_delete = openstackclient.network.v2.network_segment:DeleteNetworkSegment
|
||||
network_segment_list = openstackclient.network.v2.network_segment:ListNetworkSegment
|
||||
network_segment_set = openstackclient.network.v2.network_segment:SetNetworkSegment
|
||||
network_segment_show = openstackclient.network.v2.network_segment:ShowNetworkSegment
|
||||
|
||||
port_create = openstackclient.network.v2.port:CreatePort
|
||||
|
Loading…
x
Reference in New Issue
Block a user