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

« back to all changes in this revision

Viewing changes to neutron/agent/l3/ha.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:
22
22
 
23
23
from neutron.agent.linux import keepalived
24
24
from neutron.agent.linux import utils as agent_utils
25
 
from neutron.common import constants as l3_constants
26
 
from neutron.i18n import _LE, _LI
 
25
from neutron.i18n import _LI
 
26
from neutron.notifiers import batch_notifier
27
27
 
28
28
LOG = logging.getLogger(__name__)
29
29
 
91
91
    def __init__(self, host):
92
92
        self._init_ha_conf_path()
93
93
        super(AgentMixin, self).__init__(host)
 
94
        self.state_change_notifier = batch_notifier.BatchNotifier(
 
95
            self._calculate_batch_duration(), self.notify_server)
94
96
        eventlet.spawn(self._start_keepalived_notifications_server)
95
97
 
96
98
    def _start_keepalived_notifications_server(self):
98
100
            L3AgentKeepalivedStateChangeServer(self, self.conf))
99
101
        state_change_server.run()
100
102
 
 
103
    def _calculate_batch_duration(self):
 
104
        # Slave becomes the master after not hearing from it 3 times
 
105
        detection_time = self.conf.ha_vrrp_advert_int * 3
 
106
 
 
107
        # Keepalived takes a couple of seconds to configure the VIPs
 
108
        configuration_time = 2
 
109
 
 
110
        # Give it enough slack to batch all events due to the same failure
 
111
        return (detection_time + configuration_time) * 2
 
112
 
101
113
    def enqueue_state_change(self, router_id, state):
102
114
        LOG.info(_LI('Router %(router_id)s transitioned to %(state)s'),
103
115
                 {'router_id': router_id,
104
116
                  'state': state})
105
117
        self._update_metadata_proxy(router_id, state)
 
118
        self.state_change_notifier.queue_event((router_id, state))
106
119
 
107
120
    def _update_metadata_proxy(self, router_id, state):
108
121
        try:
122
135
            self.metadata_driver.destroy_monitored_metadata_proxy(
123
136
                self.process_monitor, ri.router_id, ri.ns_name, self.conf)
124
137
 
 
138
    def notify_server(self, batched_events):
 
139
        translation_map = {'master': 'active',
 
140
                           'backup': 'standby',
 
141
                           'fault': 'standby'}
 
142
        translated_states = dict((router_id, translation_map[state]) for
 
143
                                 router_id, state in batched_events)
 
144
        LOG.debug('Updating server with HA routers states %s',
 
145
                  translated_states)
 
146
        self.plugin_rpc.update_ha_routers_states(
 
147
            self.context, translated_states)
 
148
 
125
149
    def _init_ha_conf_path(self):
126
150
        ha_full_path = os.path.dirname("/%s/" % self.conf.ha_confs_path)
127
151
        agent_utils.ensure_dir(ha_full_path)
128
 
 
129
 
    def process_ha_router_added(self, ri):
130
 
        ha_port = ri.router.get(l3_constants.HA_INTERFACE_KEY)
131
 
        if not ha_port:
132
 
            LOG.error(_LE('Unable to process HA router %s without ha port'),
133
 
                      ri.router_id)
134
 
            return
135
 
 
136
 
        ri._set_subnet_info(ha_port)
137
 
        ri.ha_port = ha_port
138
 
        ri._init_keepalived_manager(self.process_monitor)
139
 
        ri.ha_network_added(ha_port['network_id'],
140
 
                            ha_port['id'],
141
 
                            ha_port['ip_cidr'],
142
 
                            ha_port['mac_address'])
143
 
 
144
 
        ri.update_initial_state(self.enqueue_state_change)
145
 
        ri.spawn_state_change_monitor(self.process_monitor)
146
 
 
147
 
    def process_ha_router_removed(self, ri):
148
 
        ri.destroy_state_change_monitor(self.process_monitor)
149
 
        ri.ha_network_removed()