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

« back to all changes in this revision

Viewing changes to neutron/tests/unit/db/test_l3_hamode_db.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Corey Byrant
  • Date: 2015-10-15 08:56:04 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20151015085604-zmf42dhshxz2qjad
Tags: 1:2015.1.2-0ubuntu1
[ Chuck Short ]
* Resynchronize with stable/kilo (7dbaa12) (LP: #1506058):
  - [7dbaa12] Changed filter field to router_id
  - [6c55f58] Do not log an error when deleting a linuxbridge does not exist
  - [118a76f] metadata: don't crash proxy on non-unicode user data
  - [eec8c50] Only get host data for floating ips on DVR routers
  - [9950ce2] Update dhcp host portbinding on failover
  - [1c87d72] func: Don't use private method of AsyncProcess
  - [834279c] Allow setting Agents description to None
  - [2f85b22] Process user iptables rules before INVALID
  - [f232475] Execute ipset command using check_exit_code
  - [d78899d] Don't write DHCP opts for SLAAC entries
  - [cb0554f] Check idl.run() return value before blocking
  - [2224851] Stop sending gratuitous arp when ip version is 6
  - [96276d5] Fix _ensure_default_security_group logic
  - [66a5116] Remove hack for sending gratuitous arp from fip ns
  - [2394418] populate port security default into network
  - [fc1c812] Remove early yields in _iter_hosts in dhcp agent
  - [2ead51a] Enable servicing lbaasV2 vip by DVR
  - [9498ea2] Descheduling DVR routers when ports are unbound from VM
  - [c74b05e] Bug-Fix for unexpected DHCP agent redundant
  - [e6a0e7d] Switch to dictionary for iptables find
  - [c377330] Add configurable options for HA networks
  - [114949b] Fix ipset can't be destroyed when last rule is deleted
  - [aba5e82] Updated NSXv plugin parameter descriptions
  - [d1a48f7] ovs: don't use ARP responder for IPv6 addresses
  - [4d15b6f] Configure gw_iface for RAs only in Master HA Router
  - [6975b2b] Register extraroute extension
  - [19d5ba4] Broadcast service port's arp in DVR
  - [767cea2] Stop device_owner from being set to 'network:*'
  - [2a6b34e] Fix a wrong condition for the _purge_metering_info function
  - [bf28c72] Add ARP spoofing protection for LinuxBridge agent
  - [635d5cf] Correct neutron-ns-metadata-proxy command when watch_log is
              False
  - [cc791b0] Fix usage of netaddr '.broadcast'
  - [f57a90a] Switch to using os-testr's copy of subunit2html
  - [c1201a2] Add optional file permission argument to replace_file()
  - [533900c] Adding loadbalanacerv2 device owner constant to neutron
              constants
  - [2a00016] Don't fatal error during initialization for missing service
              providers
  - [7c2727c] Update port bindings for master router
  - [6298a90] Setup reference service providers for API test runs
  - [6167d44] Move away nested transaction from _ensure_default_security_group
  - [c129bfa] Reject router-interface-add with a port which doesn't have any
              addresses
  - [770a105] SR-IOV: Fix SR-IOV agent to run ip link commands as root
  - [a0632d7] Catch ObjectDeletedError and skip port or subnet removal
  - [c4c8686] Cleanup stale metadata processes on l3 agent sync
  - [0c22d15] Bump stable/kilo next version to 2015.1.2
  - [4f9409d] lb-agent: ensure tap mtu is the same as physical device
  - [5d38dc5] Adds garp_master_repeat and garp_master_refresh to
              keepalived.conf
  - [e759c1c] Lower log level of errors caused by user requests to INFO
  - [1a1cc3d] Fix race condition by using lock on enable_radvd
  - [5827664] Remove bridge cleanup call
  - [23f5134] Added networking-plumgrid in plugin requirements

[ Corey Byrant ]
* d/rules: Prevent dh_python2 from guessing dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
import mock
16
16
from oslo_config import cfg
17
17
 
 
18
from neutron.api.rpc.handlers import l3_rpc
18
19
from neutron.api.v2 import attributes
19
20
from neutron.common import constants
20
21
from neutron import context
24
25
from neutron.db import l3_hamode_db
25
26
from neutron.extensions import l3
26
27
from neutron.extensions import l3_ext_ha_mode
 
28
from neutron.extensions import portbindings
 
29
from neutron.extensions import providernet
27
30
from neutron import manager
28
31
from neutron.openstack.common import uuidutils
29
32
from neutron.scheduler import l3_agent_scheduler
179
182
        router = self._create_router(ha=False)
180
183
        self.assertFalse(router['ha'])
181
184
 
 
185
    def test_add_ha_network_settings(self):
 
186
        cfg.CONF.set_override('l3_ha_network_type', 'abc')
 
187
        cfg.CONF.set_override('l3_ha_network_physical_name', 'def')
 
188
 
 
189
        network = {}
 
190
        self.plugin._add_ha_network_settings(network)
 
191
 
 
192
        self.assertEqual('abc', network[providernet.NETWORK_TYPE])
 
193
        self.assertEqual('def', network[providernet.PHYSICAL_NETWORK])
 
194
 
182
195
    def test_router_create_with_ha_conf_enabled(self):
183
196
        cfg.CONF.set_override('l3_ha', True)
184
197
 
420
433
        routers_after = self.plugin.get_routers(self.admin_ctx)
421
434
        self.assertEqual(routers_before, routers_after)
422
435
 
 
436
    def test_get_active_host_for_ha_router(self):
 
437
        router = self._create_router()
 
438
        self._bind_router(router['id'])
 
439
        self.assertEqual(
 
440
            None,
 
441
            self.plugin.get_active_host_for_ha_router(
 
442
                self.admin_ctx, router['id']))
 
443
        self.plugin.update_routers_states(
 
444
            self.admin_ctx, {router['id']: 'active'}, self.agent2['host'])
 
445
        self.assertEqual(
 
446
            self.agent2['host'],
 
447
            self.plugin.get_active_host_for_ha_router(
 
448
                self.admin_ctx, router['id']))
 
449
 
423
450
    def test_update_routers_states(self):
424
451
        router1 = self._create_router()
425
452
        self._bind_router(router1['id'])
520
547
            self.admin_ctx, [router['id']])
521
548
        self.assertEqual(2, len(bindings))
522
549
 
 
550
    def test_update_router_port_bindings_no_ports(self):
 
551
        self.plugin._update_router_port_bindings(
 
552
            self.admin_ctx, {}, self.agent1['host'])
 
553
 
 
554
    def _get_first_interface(self, router_id):
 
555
        device_filter = {'device_id': [router_id],
 
556
                         'device_owner':
 
557
                         [constants.DEVICE_OWNER_ROUTER_INTF]}
 
558
        return self.core_plugin.get_ports(
 
559
            self.admin_ctx,
 
560
            filters=device_filter)[0]
 
561
 
 
562
    def test_update_router_port_bindings_updates_host(self):
 
563
        network_id = self._create_network(self.core_plugin, self.admin_ctx)
 
564
        subnet = self._create_subnet(self.core_plugin, self.admin_ctx,
 
565
                                     network_id)
 
566
        interface_info = {'subnet_id': subnet['id']}
 
567
 
 
568
        router = self._create_router()
 
569
        self._bind_router(router['id'])
 
570
        self.plugin.add_router_interface(self.admin_ctx,
 
571
                                         router['id'],
 
572
                                         interface_info)
 
573
        self.plugin._update_router_port_bindings(
 
574
            self.admin_ctx, {router['id']: 'active'}, self.agent1['host'])
 
575
 
 
576
        port = self._get_first_interface(router['id'])
 
577
        self.assertEqual(self.agent1['host'], port[portbindings.HOST_ID])
 
578
 
 
579
        self.plugin._update_router_port_bindings(
 
580
            self.admin_ctx, {router['id']: 'active'}, self.agent2['host'])
 
581
        port = self._get_first_interface(router['id'])
 
582
        self.assertEqual(self.agent2['host'], port[portbindings.HOST_ID])
 
583
 
 
584
    def test_ensure_host_set_on_ports_binds_correctly(self):
 
585
        network_id = self._create_network(self.core_plugin, self.admin_ctx)
 
586
        subnet = self._create_subnet(self.core_plugin, self.admin_ctx,
 
587
                                     network_id)
 
588
        interface_info = {'subnet_id': subnet['id']}
 
589
 
 
590
        router = self._create_router()
 
591
        self._bind_router(router['id'])
 
592
        self.plugin.add_router_interface(self.admin_ctx,
 
593
                                         router['id'],
 
594
                                         interface_info)
 
595
        port = self._get_first_interface(router['id'])
 
596
        self.assertEqual('', port[portbindings.HOST_ID])
 
597
 
 
598
        # Update the router object to include the first interface
 
599
        router = (
 
600
            self.plugin.list_active_sync_routers_on_active_l3_agent(
 
601
                self.admin_ctx, self.agent1['host'], [router['id']]))[0]
 
602
 
 
603
        # ensure_host_set_on_ports binds an unbound port
 
604
        callback = l3_rpc.L3RpcCallback()
 
605
        callback._l3plugin = self.plugin
 
606
        callback._ensure_host_set_on_ports(
 
607
            self.admin_ctx, self.agent1['host'], [router])
 
608
        port = self._get_first_interface(router['id'])
 
609
        self.assertEqual(self.agent1['host'], port[portbindings.HOST_ID])
 
610
 
 
611
        # ensure_host_set_on_ports does not rebind a bound port
 
612
        router = (
 
613
            self.plugin.list_active_sync_routers_on_active_l3_agent(
 
614
                self.admin_ctx, self.agent1['host'], [router['id']]))[0]
 
615
        callback._ensure_host_set_on_ports(
 
616
            self.admin_ctx, self.agent2['host'], [router])
 
617
        port = self._get_first_interface(router['id'])
 
618
        self.assertEqual(self.agent1['host'], port[portbindings.HOST_ID])
 
619
 
523
620
 
524
621
class L3HAUserTestCase(L3HATestFramework):
525
622