~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/tests/unit/ml2/drivers/test_l2population.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    under the License.
15
15
 
16
16
import contextlib
 
17
import testtools
17
18
 
18
19
import mock
19
 
from oslo.utils import timeutils
 
20
from oslo_utils import timeutils
20
21
 
21
22
from neutron.agent import l2population_rpc
22
23
from neutron.common import constants
26
27
from neutron.extensions import portbindings
27
28
from neutron.extensions import providernet as pnet
28
29
from neutron import manager
 
30
from neutron.plugins.ml2.common import exceptions as ml2_exc
 
31
from neutron.plugins.ml2 import driver_context
29
32
from neutron.plugins.ml2.drivers.l2pop import db as l2pop_db
30
33
from neutron.plugins.ml2.drivers.l2pop import mech_driver as l2pop_mech_driver
31
34
from neutron.plugins.ml2.drivers.l2pop import rpc as l2pop_rpc
80
83
}
81
84
 
82
85
L2_AGENT_5 = {
83
 
    'binary': 'neutron-ofagent-agent',
 
86
    'binary': 'neutron-fake-agent',
84
87
    'host': HOST + '_5',
85
88
    'topic': constants.L2_AGENT_TOPIC,
86
89
    'configurations': {'tunneling_ip': '20.0.0.5',
87
90
                       'tunnel_types': [],
88
91
                       'interface_mappings': {'physnet1': 'eth9'},
89
92
                       'l2pop_network_types': ['vlan']},
 
93
    # NOTE(yamamoto): mech_fake_agent has a comment to explain why
 
94
    # OFA is used here.
90
95
    'agent_type': constants.AGENT_TYPE_OFA,
91
96
    'tunnel_type': [],
92
97
    'start_flag': True
97
102
 
98
103
 
99
104
class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
100
 
    _mechanism_drivers = ['openvswitch', 'ofagent', 'l2population']
 
105
    _mechanism_drivers = ['openvswitch', 'fake_agent', 'l2population']
101
106
 
102
107
    def setUp(self):
103
108
        super(TestL2PopulationRpcTestCase, self).setUp()
303
308
                    self.mock_fanout.assert_called_with(
304
309
                        mock.ANY, 'add_fdb_entries', expected)
305
310
 
 
311
    def test_fdb_called_for_active_ports(self):
 
312
        self._register_ml2_agents()
 
313
 
 
314
        with self.subnet(network=self._network) as subnet:
 
315
            host_arg = {portbindings.HOST_ID: HOST}
 
316
            with self.port(subnet=subnet,
 
317
                           device_owner=DEVICE_OWNER_COMPUTE,
 
318
                           arg_list=(portbindings.HOST_ID,),
 
319
                           **host_arg) as port1:
 
320
                host_arg = {portbindings.HOST_ID: HOST + '_2'}
 
321
                with self.port(subnet=subnet,
 
322
                               device_owner=DEVICE_OWNER_COMPUTE,
 
323
                               arg_list=(portbindings.HOST_ID,),
 
324
                               **host_arg):
 
325
                    p1 = port1['port']
 
326
 
 
327
                    device1 = 'tap' + p1['id']
 
328
 
 
329
                    self.mock_cast.reset_mock()
 
330
                    self.mock_fanout.reset_mock()
 
331
                    self.callbacks.update_device_up(self.adminContext,
 
332
                                                    agent_id=HOST,
 
333
                                                    device=device1)
 
334
 
 
335
                    p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
 
336
 
 
337
                    self.assertFalse(self.mock_cast.called)
 
338
 
 
339
                    expected2 = {p1['network_id']:
 
340
                                 {'ports':
 
341
                                  {'20.0.0.1': [constants.FLOODING_ENTRY,
 
342
                                                l2pop_rpc.PortInfo(
 
343
                                                    p1['mac_address'],
 
344
                                                    p1_ips[0])]},
 
345
                                  'network_type': 'vxlan',
 
346
                                  'segment_id': 1}}
 
347
 
 
348
                    self.mock_fanout.assert_called_with(
 
349
                        mock.ANY, 'add_fdb_entries', expected2)
 
350
 
306
351
    def test_fdb_add_two_agents(self):
307
352
        self._register_ml2_agents()
308
353
 
323
368
                    p1 = port1['port']
324
369
                    p2 = port2['port']
325
370
 
326
 
                    device = 'tap' + p1['id']
 
371
                    device1 = 'tap' + p1['id']
 
372
                    device2 = 'tap' + p2['id']
327
373
 
328
374
                    self.mock_cast.reset_mock()
329
375
                    self.mock_fanout.reset_mock()
330
376
                    self.callbacks.update_device_up(self.adminContext,
 
377
                                                    agent_id=HOST + '_2',
 
378
                                                    device=device2)
 
379
                    self.callbacks.update_device_up(self.adminContext,
331
380
                                                    agent_id=HOST,
332
 
                                                    device=device)
 
381
                                                    device=device1)
333
382
 
334
383
                    p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
335
384
                    p2_ips = [p['ip_address'] for p in p2['fixed_ips']]
381
430
                            p1 = port1['port']
382
431
                            p3 = port3['port']
383
432
 
384
 
                            device = 'tap' + p3['id']
 
433
                            device1 = 'tap' + p1['id']
 
434
                            device3 = 'tap' + p3['id']
385
435
 
386
436
                            self.mock_cast.reset_mock()
387
437
                            self.mock_fanout.reset_mock()
388
438
                            self.callbacks.update_device_up(
 
439
                                self.adminContext, agent_id=HOST + '_2',
 
440
                                device=device1)
 
441
                            self.callbacks.update_device_up(
389
442
                                self.adminContext, agent_id=HOST,
390
 
                                device=device)
 
443
                                device=device3)
391
444
 
392
445
                            p1_ips = [p['ip_address']
393
446
                                      for p in p1['fixed_ips']]
886
939
                                  'get_agent_ip',
887
940
                                  side_effect=agent_ip_side_effect),
888
941
                mock.patch.object(l2pop_db.L2populationDbMixin,
889
 
                                  'get_nondvr_network_ports',
 
942
                                  'get_nondvr_active_network_ports',
890
943
                                  new=fdb_network_ports_query),
891
944
                mock.patch.object(l2pop_db.L2populationDbMixin,
892
 
                                  'get_dvr_network_ports',
 
945
                                  'get_dvr_active_network_ports',
893
946
                                  new=tunnel_network_ports_query)):
894
947
            session = mock.Mock()
895
948
            agent = mock.Mock()
946
999
                           {'10.0.0.1':
947
1000
                            [constants.FLOODING_ENTRY]}}
948
1001
        self.assertEqual(expected_result, result)
 
1002
 
 
1003
    def test_update_port_postcommit_mac_address_changed_raises(self):
 
1004
        port = {'status': u'ACTIVE',
 
1005
                'device_owner': u'compute:None',
 
1006
                'mac_address': u'12:34:56:78:4b:0e',
 
1007
                'id': u'1'}
 
1008
 
 
1009
        original_port = port.copy()
 
1010
        original_port['mac_address'] = u'12:34:56:78:4b:0f'
 
1011
 
 
1012
        with mock.patch.object(driver_context.db, 'get_network_segments'):
 
1013
            ctx = driver_context.PortContext(mock.Mock(),
 
1014
                                             mock.Mock(),
 
1015
                                             port,
 
1016
                                             mock.MagicMock(),
 
1017
                                             mock.Mock(),
 
1018
                                             None,
 
1019
                                             original_port=original_port)
 
1020
 
 
1021
        mech_driver = l2pop_mech_driver.L2populationMechanismDriver()
 
1022
        with testtools.ExpectedException(ml2_exc.MechanismDriverError):
 
1023
            mech_driver.update_port_postcommit(ctx)