Skip to content

Commit fe02162

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Implement "address scope set" command"
2 parents 94de0d3 + cc78d48 commit fe02162

6 files changed

Lines changed: 201 additions & 1 deletion

File tree

doc/source/command-objects/address-scope.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Create new address scope
4545
.. _address_scope_create-name:
4646
.. describe:: <name>
4747
48-
New address scope name
48+
New address scope name
4949
5050
address scope delete
5151
--------------------
@@ -73,6 +73,36 @@ List address scopes
7373
7474
os address scope list
7575
76+
address scope set
77+
-----------------
78+
79+
Set address scope properties
80+
81+
.. program:: address scope set
82+
.. code:: bash
83+
84+
os address scope set
85+
[--name <name>]
86+
[--share | --no-share]
87+
<address-scope>
88+
89+
.. option:: --name <name>
90+
91+
Set address scope name
92+
93+
.. option:: --share
94+
95+
Share the address scope between projects
96+
97+
.. option:: --no-share
98+
99+
Do not share the address scope between projects
100+
101+
.. _address_scope_set-address-scope:
102+
.. describe:: <address-scope>
103+
104+
Address scope to modify (name or ID)
105+
76106
address scope show
77107
------------------
78108
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import uuid
14+
15+
from functional.common import test
16+
17+
18+
class AddressScopeTests(test.TestCase):
19+
"""Functional tests for address scope. """
20+
NAME = uuid.uuid4().hex
21+
HEADERS = ['Name']
22+
FIELDS = ['name']
23+
24+
@classmethod
25+
def setUpClass(cls):
26+
opts = cls.get_show_opts(cls.FIELDS)
27+
raw_output = cls.openstack('address scope create ' + cls.NAME + opts)
28+
cls.assertOutput(cls.NAME + "\n", raw_output)
29+
30+
@classmethod
31+
def tearDownClass(cls):
32+
raw_output = cls.openstack('address scope delete ' + cls.NAME)
33+
cls.assertOutput('', raw_output)
34+
35+
def test_address_scope_list(self):
36+
opts = self.get_list_opts(self.HEADERS)
37+
raw_output = self.openstack('address scope list' + opts)
38+
self.assertIn(self.NAME, raw_output)
39+
40+
def test_address_scope_show(self):
41+
opts = self.get_show_opts(self.FIELDS)
42+
raw_output = self.openstack('address scope show ' + self.NAME + opts)
43+
self.assertEqual(self.NAME + "\n", raw_output)
44+
45+
def test_address_scope_set(self):
46+
self.openstack('address scope set --share ' + self.NAME)
47+
opts = self.get_show_opts(['shared'])
48+
raw_output = self.openstack('address scope show ' + self.NAME + opts)
49+
self.assertEqual("True\n", raw_output)

openstackclient/network/v2/address_scope.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Address scope action implementations"""
1515

1616
from openstackclient.common import command
17+
from openstackclient.common import exceptions
1718
from openstackclient.common import utils
1819
from openstackclient.i18n import _
1920
from openstackclient.identity import common as identity_common
@@ -142,6 +143,53 @@ def take_action(self, parsed_args):
142143
) for s in data))
143144

144145

146+
class SetAddressScope(command.Command):
147+
"""Set address scope properties"""
148+
149+
def get_parser(self, prog_name):
150+
parser = super(SetAddressScope, self).get_parser(prog_name)
151+
parser.add_argument(
152+
'address_scope',
153+
metavar="<address-scope>",
154+
help=_("Address scope to modify (name or ID)")
155+
)
156+
parser.add_argument(
157+
'--name',
158+
metavar="<name>",
159+
help=_('Set address scope name')
160+
)
161+
share_group = parser.add_mutually_exclusive_group()
162+
share_group.add_argument(
163+
'--share',
164+
action='store_true',
165+
help=_('Share the address scope between projects')
166+
)
167+
share_group.add_argument(
168+
'--no-share',
169+
action='store_true',
170+
help=_('Do not share the address scope between projects')
171+
)
172+
173+
return parser
174+
175+
def take_action(self, parsed_args):
176+
client = self.app.client_manager.network
177+
obj = client.find_address_scope(
178+
parsed_args.address_scope,
179+
ignore_missing=False)
180+
attrs = {}
181+
if parsed_args.name is not None:
182+
attrs['name'] = parsed_args.name
183+
if parsed_args.share:
184+
attrs['shared'] = True
185+
if parsed_args.no_share:
186+
attrs['shared'] = False
187+
if attrs == {}:
188+
msg = "Nothing specified to be set."
189+
raise exceptions.CommandError(msg)
190+
client.update_address_scope(obj, **attrs)
191+
192+
145193
class ShowAddressScope(command.ShowOne):
146194
"""Display address scope details"""
147195

openstackclient/tests/network/v2/test_address_scope.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import copy
1515
import mock
1616

17+
from openstackclient.common import exceptions
1718
from openstackclient.network.v2 import address_scope
1819
from openstackclient.tests import fakes
1920
from openstackclient.tests.identity.v3 import fakes as identity_fakes_v3
@@ -237,6 +238,72 @@ def test_address_scope_list(self):
237238
self.assertEqual(self.data, list(data))
238239

239240

241+
class TestSetAddressScope(TestAddressScope):
242+
243+
# The address scope to set.
244+
_address_scope = network_fakes.FakeAddressScope.create_one_address_scope()
245+
246+
def setUp(self):
247+
super(TestSetAddressScope, self).setUp()
248+
self.network.update_address_scope = mock.Mock(return_value=None)
249+
self.network.find_address_scope = mock.Mock(
250+
return_value=self._address_scope)
251+
252+
# Get the command object to test
253+
self.cmd = address_scope.SetAddressScope(self.app, self.namespace)
254+
255+
def test_set_nothing(self):
256+
arglist = [self._address_scope.name, ]
257+
verifylist = [
258+
('address_scope', self._address_scope.name),
259+
]
260+
261+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
262+
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
263+
parsed_args)
264+
265+
def test_set_name_and_share(self):
266+
arglist = [
267+
'--name', 'new_address_scope',
268+
'--share',
269+
self._address_scope.name,
270+
]
271+
verifylist = [
272+
('name', 'new_address_scope'),
273+
('share', True),
274+
('address_scope', self._address_scope.name),
275+
]
276+
277+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
278+
result = self.cmd.take_action(parsed_args)
279+
attrs = {
280+
'name': "new_address_scope",
281+
'shared': True,
282+
}
283+
self.network.update_address_scope.assert_called_with(
284+
self._address_scope, **attrs)
285+
self.assertIsNone(result)
286+
287+
def test_set_no_share(self):
288+
arglist = [
289+
'--no-share',
290+
self._address_scope.name,
291+
]
292+
verifylist = [
293+
('no_share', True),
294+
('address_scope', self._address_scope.name),
295+
]
296+
297+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
298+
result = self.cmd.take_action(parsed_args)
299+
attrs = {
300+
'shared': False,
301+
}
302+
self.network.update_address_scope.assert_called_with(
303+
self._address_scope, **attrs)
304+
self.assertIsNone(result)
305+
306+
240307
class TestShowAddressScope(TestAddressScope):
241308

242309
# The address scope to show.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- Add ``address scope create``,``address scope delete``,``address scope list``,
4+
``address scope set`` and ``address scope show`` commands.
5+
[Bug `1566269 <https://bugs.launchpad.net/python-openstackclient/+bug/1566269>`_]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ openstack.network.v2 =
327327
address_scope_create = openstackclient.network.v2.address_scope:CreateAddressScope
328328
address_scope_delete = openstackclient.network.v2.address_scope:DeleteAddressScope
329329
address_scope_list = openstackclient.network.v2.address_scope:ListAddressScope
330+
address_scope_set = openstackclient.network.v2.address_scope:SetAddressScope
330331
address_scope_show = openstackclient.network.v2.address_scope:ShowAddressScope
331332

332333
ip_floating_create = openstackclient.network.v2.floating_ip:CreateFloatingIP

0 commit comments

Comments
 (0)