Skip to content

Commit d6e058f

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add network service provider list to OSC"
2 parents 155114e + ac7d27a commit d6e058f

8 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
========================
2+
network service provider
3+
========================
4+
5+
A **network service provider** is a particular driver that implements a
6+
networking service
7+
8+
Network v2
9+
10+
network service provider list
11+
-----------------------------
12+
13+
List service providers
14+
15+
.. program:: network service provider list
16+
.. code:: bash
17+
18+
os network service provider list

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ referring to both Compute and Volume quotas.
114114
* ``network rbac``: (**Network**) - an RBAC policy for network resources
115115
* ``network qos policy``: (**Network**) - a QoS policy for network resources
116116
* ``network segment``: (**Network**) - a segment of a virtual network
117+
* ``network service provider``: (**Network**) - a driver providing a network service
117118
* ``object``: (**Object Storage**) a single file in the Object Storage
118119
* ``object store account``: (**Object Storage**) owns a group of Object Storage resources
119120
* ``policy``: (**Identity**) determines authorization
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
14+
"""Network Service Providers Implementation"""
15+
16+
from osc_lib.command import command
17+
from osc_lib import utils
18+
19+
20+
class ListNetworkServiceProvider(command.Lister):
21+
"""List Service Providers"""
22+
23+
def take_action(self, parsed_args):
24+
client = self.app.client_manager.network
25+
26+
columns = (
27+
'service_type',
28+
'name',
29+
'is_default',
30+
)
31+
column_headers = (
32+
'Service Type',
33+
'Name',
34+
'Default',
35+
)
36+
37+
data = client.service_providers()
38+
return(column_headers,
39+
(utils.get_item_properties(
40+
s, columns,
41+
) for s in data))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2016, Intel Corporation.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
from openstackclient.tests.functional import base
17+
18+
19+
class TestNetworkServiceProvider(base.TestCase):
20+
"""Functional tests for network service provider"""
21+
22+
SERVICE_TYPE = ['L3_ROUTER_NAT']
23+
24+
def test_network_service_provider_list(self):
25+
raw_output = self.openstack('network service provider list')
26+
self.assertIn(self.SERVICE_TYPE, raw_output)

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,3 +1269,38 @@ def get_subnet_pools(subnet_pools=None, count=2):
12691269
if subnet_pools is None:
12701270
subnet_pools = FakeSubnetPool.create_subnet_pools(count)
12711271
return mock.Mock(side_effect=subnet_pools)
1272+
1273+
1274+
class FakeNetworkServiceProvider(object):
1275+
"""Fake Network Service Providers"""
1276+
1277+
@staticmethod
1278+
def create_one_network_service_provider(attrs=None):
1279+
"""Create service provider"""
1280+
attrs = attrs or {}
1281+
1282+
service_provider = {
1283+
'name': 'provider-name-' + uuid.uuid4().hex,
1284+
'service_type': 'service-type-' + uuid.uuid4().hex,
1285+
'default': False,
1286+
}
1287+
1288+
service_provider.update(attrs)
1289+
1290+
provider = fakes.FakeResource(
1291+
info=copy.deepcopy(service_provider),
1292+
loaded=True)
1293+
provider.is_default = service_provider['default']
1294+
1295+
return provider
1296+
1297+
@staticmethod
1298+
def create_network_service_providers(attrs=None, count=2):
1299+
"""Create multiple service providers"""
1300+
1301+
service_providers = []
1302+
for i in range(0, count):
1303+
service_providers.append(FakeNetworkServiceProvider.
1304+
create_one_network_service_provider(
1305+
attrs))
1306+
return service_providers
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (c) 2016, Intel Corporation.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
import mock
17+
18+
from openstackclient.network.v2 import network_service_provider \
19+
as service_provider
20+
from openstackclient.tests.unit.network.v2 import fakes
21+
22+
23+
class TestNetworkServiceProvider(fakes.TestNetworkV2):
24+
25+
def setUp(self):
26+
super(TestNetworkServiceProvider, self).setUp()
27+
self.network = self.app.client_manager.network
28+
29+
30+
class TestListNetworkServiceProvider(TestNetworkServiceProvider):
31+
provider_list = \
32+
fakes.FakeNetworkServiceProvider.create_network_service_providers(
33+
count=2
34+
)
35+
36+
columns = (
37+
'Service Type',
38+
'Name',
39+
'Default',
40+
)
41+
42+
data = []
43+
44+
for provider in provider_list:
45+
data.append((
46+
provider.service_type,
47+
provider.name,
48+
provider.is_default,
49+
))
50+
51+
def setUp(self):
52+
super(TestListNetworkServiceProvider, self).setUp()
53+
self.network.service_providers = mock.Mock(
54+
return_value=self.provider_list
55+
)
56+
57+
self.cmd = \
58+
service_provider.ListNetworkServiceProvider(self.app,
59+
self.namespace)
60+
61+
def test_network_service_provider_list(self):
62+
arglist = []
63+
verifylist = []
64+
65+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
66+
67+
columns, data = self.cmd.take_action(parsed_args)
68+
69+
self.network.service_providers.assert_called_with()
70+
self.assertEqual(self.columns, columns)
71+
self.assertEqual(self.data, list(data))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
Add support for the ``network service provider`` command.

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ openstack.network.v2 =
384384
network_segment_set = openstackclient.network.v2.network_segment:SetNetworkSegment
385385
network_segment_show = openstackclient.network.v2.network_segment:ShowNetworkSegment
386386

387+
network_service_provider_list = openstackclient.network.v2.network_service_provider:ListNetworkServiceProvider
388+
387389
port_create = openstackclient.network.v2.port:CreatePort
388390
port_delete = openstackclient.network.v2.port:DeletePort
389391
port_list = openstackclient.network.v2.port:ListPort

0 commit comments

Comments
 (0)