~ubuntu-branches/ubuntu/vivid/neutron/vivid-proposed

« back to all changes in this revision

Viewing changes to neutron/tests/unit/plugins/oneconvergence/test_nvsdlib.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-04-15 13:59:07 UTC
  • mfrom: (1.1.22)
  • Revision ID: package-import@ubuntu.com-20150415135907-z10fr18evag1ozq3
Tags: 1:2015.1~rc1-0ubuntu1
* New upstream milestone release:
  - debian/control: Update dependencies. 
  - debian/patches/disable-udev-tests.patch: Dropped no longer needed.
  - debian/patches/fixup-driver-test-execution.patch: Dropped no longer needed.
  - debian/patches/skip-iptest.patch: Skip failing test
  - debian/neutron-plugin-openvswitch-agent.install: Added neutron-ovsvapp-agent binary.
  - debian/neutron-plugin-cisco.install: Added neutron-cisco-apic-service-agent and 
    neutron-cisco-apic-host-agent

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 OneConvergence, Inc. All Rights Reserved.
 
2
#
 
3
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
#    not use this file except in compliance with the License. You may obtain
 
5
#    a copy of the License at
 
6
#
 
7
#         http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
#    Unless required by applicable law or agreed to in writing, software
 
10
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
#    License for the specific language governing permissions and limitations
 
13
#    under the License.
 
14
#
 
15
 
 
16
import mock
 
17
from oslo_serialization import jsonutils
 
18
 
 
19
from neutron.plugins.oneconvergence.lib import nvsdlib
 
20
from neutron.tests import base
 
21
 
 
22
NETWORKS_URI = "/pluginhandler/ocplugin/tenant/%s/lnetwork/"
 
23
NETWORK_URI = NETWORKS_URI + "%s"
 
24
GET_ALL_NETWORKS = "/pluginhandler/ocplugin/tenant/getallnetworks"
 
25
 
 
26
SUBNETS_URI = NETWORK_URI + "/lsubnet/"
 
27
SUBNET_URI = SUBNETS_URI + "%s"
 
28
GET_ALL_SUBNETS = "/pluginhandler/ocplugin/tenant/getallsubnets"
 
29
 
 
30
PORTS_URI = NETWORK_URI + "/lport/"
 
31
PORT_URI = PORTS_URI + "%s"
 
32
 
 
33
EXT_URI = "/pluginhandler/ocplugin/ext/tenant/%s"
 
34
FLOATING_IPS_URI = EXT_URI + "/floatingip/"
 
35
FLOATING_IP_URI = FLOATING_IPS_URI + "%s"
 
36
 
 
37
ROUTERS_URI = EXT_URI + "/lrouter/"
 
38
ROUTER_URI = ROUTERS_URI + "%s"
 
39
 
 
40
TEST_NET = 'test-network'
 
41
TEST_SUBNET = 'test-subnet'
 
42
TEST_PORT = 'test-port'
 
43
TEST_FIP = 'test-floatingip'
 
44
TEST_ROUTER = 'test-router'
 
45
TEST_TENANT = 'test-tenant'
 
46
 
 
47
 
 
48
class TestNVSDApi(base.BaseTestCase):
 
49
 
 
50
    def setUp(self):
 
51
        super(TestNVSDApi, self).setUp()
 
52
        self.nvsdlib = nvsdlib.NVSDApi()
 
53
 
 
54
    def test_create_network(self):
 
55
        network_obj = {
 
56
            "name": 'test-net',
 
57
            "tenant_id": TEST_TENANT,
 
58
            "shared": False,
 
59
            "admin_state_up": True,
 
60
            "router:external": False
 
61
        }
 
62
        resp = mock.Mock()
 
63
        resp.json.return_value = {'id': 'uuid'}
 
64
        with mock.patch.object(self.nvsdlib, 'send_request',
 
65
                               return_value=resp) as send_request:
 
66
            uri = NETWORKS_URI % TEST_TENANT
 
67
            net = self.nvsdlib.create_network(network_obj)
 
68
            send_request.assert_called_once_with(
 
69
                "POST", uri,
 
70
                body=jsonutils.dumps(network_obj),
 
71
                resource='network',
 
72
                tenant_id=TEST_TENANT)
 
73
            self.assertEqual(net, {'id': 'uuid'})
 
74
 
 
75
    def test_update_network(self):
 
76
        network = {'id': TEST_NET,
 
77
                   'tenant_id': TEST_TENANT}
 
78
        update_network = {'name': 'new_name'}
 
79
        uri = NETWORK_URI % (TEST_TENANT, TEST_NET)
 
80
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
81
            self.nvsdlib.update_network(network, update_network)
 
82
            send_request.assert_called_once_with(
 
83
                "PUT", uri, body=jsonutils.dumps(update_network),
 
84
                resource='network', tenant_id=TEST_TENANT,
 
85
                resource_id=TEST_NET)
 
86
 
 
87
    def test_delete_network(self):
 
88
        network = {'id': TEST_NET,
 
89
                   'tenant_id': TEST_TENANT}
 
90
 
 
91
        uri = NETWORK_URI % (TEST_TENANT, TEST_NET)
 
92
 
 
93
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
94
            with mock.patch.object(self.nvsdlib, '_get_ports'):
 
95
                self.nvsdlib.delete_network(network)
 
96
                send_request.assert_called_once_with(
 
97
                    "DELETE", uri, resource='network',
 
98
                    tenant_id=TEST_TENANT, resource_id=TEST_NET)
 
99
 
 
100
    def test_create_port(self):
 
101
        path = PORTS_URI % (TEST_TENANT, TEST_NET)
 
102
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
103
            fixed_ips = [{'ip_address': '10.0.0.2',
 
104
                          'subnet_id': TEST_SUBNET}]
 
105
 
 
106
            lport = {
 
107
                "id": TEST_PORT,
 
108
                "name": 'test',
 
109
                "device_id": "device_id",
 
110
                "device_owner": "device_owner",
 
111
                "mac_address": "mac_address",
 
112
                "fixed_ips": fixed_ips,
 
113
                "admin_state_up": True,
 
114
                "network_id": TEST_NET,
 
115
                "status": 'ACTIVE'
 
116
            }
 
117
            self.nvsdlib.create_port(TEST_TENANT, lport)
 
118
            expected = {"id": TEST_PORT, "name": 'test',
 
119
                        "device_id": "device_id",
 
120
                        "device_owner": "device_owner",
 
121
                        "mac_address": "mac_address",
 
122
                        "ip_address": '10.0.0.2',
 
123
                        "subnet_id": TEST_SUBNET,
 
124
                        "admin_state_up": True,
 
125
                        "network_id": TEST_NET,
 
126
                        "status": 'ACTIVE'}
 
127
            send_request.assert_called_once_with(
 
128
                "POST", path,
 
129
                body=jsonutils.dumps(expected),
 
130
                resource='port',
 
131
                tenant_id=TEST_TENANT)
 
132
 
 
133
    def test_update_port(self):
 
134
        port = {'id': TEST_PORT,
 
135
                'network_id': TEST_NET}
 
136
 
 
137
        port_update = {'name': 'new-name'}
 
138
        uri = PORT_URI % (TEST_TENANT, TEST_NET, TEST_PORT)
 
139
 
 
140
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
141
            self.nvsdlib.update_port(TEST_TENANT, port, port_update)
 
142
            send_request.assert_called_once_with(
 
143
                "PUT", uri,
 
144
                body=jsonutils.dumps(port_update),
 
145
                resource='port',
 
146
                resource_id='test-port',
 
147
                tenant_id=TEST_TENANT)
 
148
 
 
149
    def test_delete_port(self):
 
150
        port = {'network_id': TEST_NET,
 
151
                'tenant_id': TEST_TENANT}
 
152
        uri = PORT_URI % (TEST_TENANT, TEST_NET, TEST_PORT)
 
153
 
 
154
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
155
            self.nvsdlib.delete_port(TEST_PORT, port)
 
156
            send_request.assert_called_once_with("DELETE", uri,
 
157
                                                 resource='port',
 
158
                                                 tenant_id=TEST_TENANT,
 
159
                                                 resource_id=TEST_PORT)
 
160
 
 
161
    def test_create_subnet(self):
 
162
        subnet = {'id': TEST_SUBNET,
 
163
                  'tenant_id': TEST_TENANT,
 
164
                  'network_id': TEST_NET}
 
165
        uri = SUBNETS_URI % (TEST_TENANT, TEST_NET)
 
166
 
 
167
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
168
            self.nvsdlib.create_subnet(subnet)
 
169
            send_request.assert_called_once_with("POST", uri,
 
170
                                                 body=jsonutils.dumps(subnet),
 
171
                                                 resource='subnet',
 
172
                                                 tenant_id=TEST_TENANT)
 
173
 
 
174
    def test_update_subnet(self):
 
175
        subnet = {'id': TEST_SUBNET,
 
176
                  'tenant_id': TEST_TENANT,
 
177
                  'network_id': TEST_NET}
 
178
        subnet_update = {'name': 'new-name'}
 
179
        uri = SUBNET_URI % (TEST_TENANT, TEST_NET, TEST_SUBNET)
 
180
 
 
181
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
182
            self.nvsdlib.update_subnet(subnet, subnet_update)
 
183
            send_request.assert_called_once_with(
 
184
                "PUT", uri,
 
185
                body=jsonutils.dumps(subnet_update), resource='subnet',
 
186
                tenant_id=TEST_TENANT, resource_id=TEST_SUBNET)
 
187
 
 
188
    def test_delete_subnet(self):
 
189
        subnet = {'id': TEST_SUBNET,
 
190
                  'tenant_id': TEST_TENANT,
 
191
                  'network_id': TEST_NET}
 
192
        uri = SUBNET_URI % (TEST_TENANT, TEST_NET, TEST_SUBNET)
 
193
 
 
194
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
195
            self.nvsdlib.delete_subnet(subnet)
 
196
            send_request.assert_called_once_with("DELETE", uri,
 
197
                                                 resource='subnet',
 
198
                                                 tenant_id=TEST_TENANT,
 
199
                                                 resource_id=TEST_SUBNET)
 
200
 
 
201
    def test_create_floatingip(self):
 
202
        floatingip = {'id': TEST_FIP,
 
203
                      'tenant_id': TEST_TENANT}
 
204
        uri = FLOATING_IPS_URI % TEST_TENANT
 
205
 
 
206
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
207
            self.nvsdlib.create_floatingip(floatingip)
 
208
            send_request.assert_called_once_with(
 
209
                "POST", uri,
 
210
                body=jsonutils.dumps(floatingip),
 
211
                resource='floating_ip',
 
212
                tenant_id=TEST_TENANT)
 
213
 
 
214
    def test_update_floatingip(self):
 
215
        floatingip = {'id': TEST_FIP,
 
216
                      'tenant_id': TEST_TENANT}
 
217
        uri = FLOATING_IP_URI % (TEST_TENANT, TEST_FIP)
 
218
 
 
219
        floatingip_update = {'floatingip': {'router_id': TEST_ROUTER}}
 
220
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
221
            self.nvsdlib.update_floatingip(floatingip, floatingip_update)
 
222
            send_request.assert_called_once_with(
 
223
                "PUT", uri,
 
224
                body=jsonutils.dumps(floatingip_update['floatingip']),
 
225
                resource='floating_ip', tenant_id=TEST_TENANT,
 
226
                resource_id=TEST_FIP)
 
227
 
 
228
    def test_delete_floatingip(self):
 
229
        floatingip = {'id': TEST_FIP,
 
230
                      'tenant_id': TEST_TENANT}
 
231
        uri = FLOATING_IP_URI % (TEST_TENANT, TEST_FIP)
 
232
 
 
233
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
234
            self.nvsdlib.delete_floatingip(floatingip)
 
235
            send_request.assert_called_once_with(
 
236
                "DELETE", uri, resource='floating_ip', tenant_id=TEST_TENANT,
 
237
                resource_id=TEST_FIP)
 
238
 
 
239
    def test_create_router(self):
 
240
        router = {'id': TEST_ROUTER, 'tenant_id': TEST_TENANT}
 
241
        uri = ROUTERS_URI % TEST_TENANT
 
242
 
 
243
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
244
            self.nvsdlib.create_router(router)
 
245
            send_request.assert_called_once_with(
 
246
                "POST", uri, body=jsonutils.dumps(router), resource='router',
 
247
                tenant_id=TEST_TENANT)
 
248
 
 
249
    def test_update_router(self):
 
250
        router = {'id': TEST_ROUTER, 'tenant_id': TEST_TENANT}
 
251
        uri = ROUTER_URI % (TEST_TENANT, TEST_ROUTER)
 
252
 
 
253
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
254
            self.nvsdlib.update_router(router)
 
255
            send_request.assert_called_once_with(
 
256
                "PUT", uri, body=jsonutils.dumps(router),
 
257
                resource='router', tenant_id=TEST_TENANT,
 
258
                resource_id=TEST_ROUTER)
 
259
 
 
260
    def test_delete_router(self):
 
261
        uri = ROUTER_URI % (TEST_TENANT, TEST_ROUTER)
 
262
 
 
263
        with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
 
264
            self.nvsdlib.delete_router(TEST_TENANT, TEST_ROUTER)
 
265
            send_request.assert_called_once_with(
 
266
                "DELETE", uri, resource='router',
 
267
                tenant_id=TEST_TENANT, resource_id=TEST_ROUTER)