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

« back to all changes in this revision

Viewing changes to neutron/tests/unit/openvswitch/test_ovs_neutron_agent.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:
18
18
 
19
19
import mock
20
20
import netaddr
21
 
from oslo.config import cfg
 
21
from oslo_config import cfg
 
22
from oslo_log import log
22
23
import testtools
23
24
 
24
25
from neutron.agent.linux import async_process
26
27
from neutron.agent.linux import ovs_lib
27
28
from neutron.agent.linux import utils
28
29
from neutron.common import constants as n_const
29
 
from neutron.openstack.common import log
30
30
from neutron.plugins.common import constants as p_const
31
31
from neutron.plugins.ml2.drivers.l2pop import rpc as l2pop_rpc
32
32
from neutron.plugins.openvswitch.agent import ovs_neutron_agent
111
111
 
112
112
        with contextlib.nested(
113
113
            mock.patch('neutron.plugins.openvswitch.agent.ovs_neutron_agent.'
114
 
                       'OVSNeutronAgent.setup_integration_br',
115
 
                       return_value=mock.Mock()),
 
114
                       'OVSNeutronAgent.setup_integration_br'),
116
115
            mock.patch('neutron.plugins.openvswitch.agent.ovs_neutron_agent.'
117
116
                       'OVSNeutronAgent.setup_ancillary_bridges',
118
117
                       return_value=[]),
267
266
        self.assertEqual(expected, actual)
268
267
 
269
268
    def test_update_ports_returns_changed_vlan(self):
270
 
        br = ovs_lib.OVSBridge('br-int', 'sudo')
 
269
        br = ovs_lib.OVSBridge('br-int')
271
270
        mac = "ca:fe:de:ad:be:ef"
272
271
        port = ovs_lib.VifPort(1, 1, 1, mac, br)
273
272
        lvm = ovs_neutron_agent.LocalVLANMapping(
498
497
                               physical_network="physnet")
499
498
        self.assertEqual(set(['123']), self.agent.updated_ports)
500
499
 
 
500
    def test_port_delete(self):
 
501
        port_id = "123"
 
502
        port_name = "foo"
 
503
        with contextlib.nested(
 
504
            mock.patch.object(self.agent.int_br, 'get_vif_port_by_id',
 
505
                              return_value=mock.MagicMock(
 
506
                                      port_name=port_name)),
 
507
            mock.patch.object(self.agent.int_br, "delete_port")
 
508
        ) as (get_vif_func, del_port_func):
 
509
            self.agent.port_delete("unused_context",
 
510
                                   port_id=port_id)
 
511
            self.assertTrue(get_vif_func.called)
 
512
            del_port_func.assert_called_once_with(port_name)
 
513
 
501
514
    def test_setup_physical_bridges(self):
502
515
        with contextlib.nested(
503
516
            mock.patch.object(ip_lib, "device_exists"),
577
590
            parent.attach_mock(addveth_fn, 'add_veth')
578
591
            addveth_fn.return_value = (ip_lib.IPDevice("int-br-eth1"),
579
592
                                       ip_lib.IPDevice("phy-br-eth1"))
580
 
            ovs_addport_fn.return_value = "int_ofport"
581
 
            br_addport_fn.return_value = "phys_veth"
 
593
            ovs_addport_fn.return_value = "phys_veth_ofport"
 
594
            br_addport_fn.return_value = "int_veth_ofport"
582
595
            get_br_fn.return_value = ["br-eth"]
583
596
            self.agent.setup_physical_bridges({"physnet1": "br-eth"})
584
597
            expected_calls = [mock.call.link_delete(),
589
602
                                                 'phy-br-eth')]
590
603
            parent.assert_has_calls(expected_calls, any_order=False)
591
604
            self.assertEqual(self.agent.int_ofports["physnet1"],
592
 
                             "phys_veth")
 
605
                             "int_veth_ofport")
593
606
            self.assertEqual(self.agent.phys_ofports["physnet1"],
594
 
                             "int_ofport")
 
607
                             "phys_veth_ofport")
595
608
 
596
609
    def test_get_peer_name(self):
597
610
            bridge1 = "A_REALLY_LONG_BRIDGE_NAME1"
863
876
            self.assertEqual(len(expected_calls),
864
877
                             len(do_action_flows_fn.mock_calls))
865
878
 
 
879
    def test_del_fdb_flow_idempotency(self):
 
880
        lvm = mock.Mock()
 
881
        lvm.network_type = 'gre'
 
882
        lvm.vlan = 'vlan1'
 
883
        lvm.segmentation_id = 'seg1'
 
884
        lvm.tun_ofports = set(['1', '2'])
 
885
        with contextlib.nested(
 
886
            mock.patch.object(self.agent.tun_br, 'mod_flow'),
 
887
            mock.patch.object(self.agent.tun_br, 'delete_flows')
 
888
        ) as (mod_flow_fn, delete_flows_fn):
 
889
            self.agent.del_fdb_flow(self.agent.tun_br, n_const.FLOODING_ENTRY,
 
890
                                    '1.1.1.1', lvm, '3')
 
891
            self.assertFalse(mod_flow_fn.called)
 
892
            self.assertFalse(delete_flows_fn.called)
 
893
 
866
894
    def test_recl_lv_port_to_preserve(self):
867
895
        self._prepare_l2_pop_ofports()
868
896
        self.agent.l2_pop = True
889
917
            'neutron.agent.linux.polling.get_polling_manager') as mock_get_pm:
890
918
            with mock.patch.object(self.agent, 'rpc_loop') as mock_loop:
891
919
                self.agent.daemon_loop()
892
 
        mock_get_pm.assert_called_with(True, 'sudo',
 
920
        mock_get_pm.assert_called_with(True,
893
921
                                       constants.DEFAULT_OVSDBMON_RESPAWN)
894
922
        mock_loop.assert_called_once_with(polling_manager=mock.ANY)
895
923
 
966
994
            mock.call(self.agent.tun_br, 'gre-0a0a0a0a', '10.10.10.10', 'gre')]
967
995
        self.agent._setup_tunnel_port.assert_has_calls(expected_calls)
968
996
 
 
997
    def test_tunnel_delete(self):
 
998
        kwargs = {'tunnel_ip': '10.10.10.10',
 
999
                  'tunnel_type': 'gre'}
 
1000
        self.agent.enable_tunneling = True
 
1001
        self.agent.tunnel_types = ['gre']
 
1002
        self.agent.tun_br_ofports = {'gre': {'10.10.10.10': '1'}}
 
1003
        with mock.patch.object(
 
1004
            self.agent, 'cleanup_tunnel_port'
 
1005
        ) as clean_tun_fn:
 
1006
            self.agent.tunnel_delete(context=None, **kwargs)
 
1007
            self.assertTrue(clean_tun_fn.called)
 
1008
 
969
1009
    def test_ovs_status(self):
970
1010
        reply2 = {'current': set(['tap0']),
971
1011
                  'added': set(['tap2']),
977
1017
 
978
1018
        with contextlib.nested(
979
1019
            mock.patch.object(async_process.AsyncProcess, "_spawn"),
980
 
            mock.patch.object(log.ContextAdapter, 'exception'),
 
1020
            mock.patch.object(log.KeywordArgumentAdapter, 'exception'),
981
1021
            mock.patch.object(ovs_neutron_agent.OVSNeutronAgent,
982
1022
                              'scan_ports'),
983
1023
            mock.patch.object(ovs_neutron_agent.OVSNeutronAgent,
1067
1107
 
1068
1108
        with contextlib.nested(
1069
1109
            mock.patch('neutron.plugins.openvswitch.agent.ovs_neutron_agent.'
1070
 
                       'OVSNeutronAgent.setup_integration_br',
1071
 
                       return_value=mock.Mock()),
 
1110
                       'OVSNeutronAgent.setup_integration_br'),
1072
1111
            mock.patch('neutron.agent.linux.utils.get_interface_mac',
1073
1112
                       return_value='00:00:00:00:00:01'),
1074
1113
            mock.patch('neutron.agent.linux.ovs_lib.OVSBridge.'