)]}'
{"/COMMIT_MSG":[{"author":{"_account_id":8873,"name":"Assaf Muller","email":"amuller@redhat.com","username":"amuller"},"change_message_id":"9919b7d2e5004319b080a8ddbda713ed5da4691d","unresolved":false,"context_lines":[{"line_number":20,"context_line":"scheduled (even if it has been scheduled already to some of the agents"},{"line_number":21,"context_line":"on their own), and makes sure no duplicate binding is created."},{"line_number":22,"context_line":""},{"line_number":23,"context_line":"Closes-Bug: #1499647"},{"line_number":24,"context_line":"Change-Id: If684326f213685e406415f42f84d94d2c2af344f"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":1,"id":"bae84128_8917a853","line":23,"updated":"2016-02-25 15:07:15.000000000","message":"Let\u0027s file a new bug, it\u0027s very hard to understand what\u0027s going in the existing bug.","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"1c660856317e9131634238936910d9e03938cc6a","unresolved":false,"context_lines":[{"line_number":20,"context_line":"scheduled (even if it has been scheduled already to some of the agents"},{"line_number":21,"context_line":"on their own), and makes sure no duplicate binding is created."},{"line_number":22,"context_line":""},{"line_number":23,"context_line":"Closes-Bug: #1499647"},{"line_number":24,"context_line":"Change-Id: If684326f213685e406415f42f84d94d2c2af344f"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":1,"id":"9aed3d3a_bfd9c185","line":23,"in_reply_to":"bae84128_588445b0","updated":"2016-02-28 08:44:42.000000000","message":"Done","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"f0d63d6e924b5131bf103281e1346ec1c2753ec8","unresolved":false,"context_lines":[{"line_number":20,"context_line":"scheduled (even if it has been scheduled already to some of the agents"},{"line_number":21,"context_line":"on their own), and makes sure no duplicate binding is created."},{"line_number":22,"context_line":""},{"line_number":23,"context_line":"Closes-Bug: #1499647"},{"line_number":24,"context_line":"Change-Id: If684326f213685e406415f42f84d94d2c2af344f"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":1,"id":"bae84128_588445b0","line":23,"in_reply_to":"bae84128_8917a853","updated":"2016-02-25 15:37:13.000000000","message":"++","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"b00174a84ae1bc5d15653186bf2ae7d7e5570848","unresolved":false,"context_lines":[{"line_number":10,"context_line":"(including the HA network and ports if it\u0027s the first one), the server"},{"line_number":11,"context_line":"continues on the schedule the router to (some of) the available agents."},{"line_number":12,"context_line":""},{"line_number":13,"context_line":"The race is achieved when an L3 agent router issues a sync_router"},{"line_number":14,"context_line":"request, which later down the line ends up in an auto_schedule_routers()"},{"line_number":15,"context_line":"call. If this happens before the above schedule (of the create_router())"},{"line_number":16,"context_line":"is complete, the server will refuse to schedule the router to the other"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":7,"id":"7af24918_bd9d5f5b","line":13,"range":{"start_line":13,"start_character":54,"end_line":13,"end_character":65},"updated":"2016-03-02 14:59:23.000000000","message":"should here be get_router_ids invoked by fetch_and_sync_all_routers as we discussed in IRC?","commit_id":"bff362ebc636da504efda1533601aa89d30b3047"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"5efa9e19bf80d418f6edf10842d5d9e7fae74e70","unresolved":false,"context_lines":[{"line_number":10,"context_line":"(including the HA network and ports if it\u0027s the first one), the server"},{"line_number":11,"context_line":"continues on the schedule the router to (some of) the available agents."},{"line_number":12,"context_line":""},{"line_number":13,"context_line":"The race is achieved when an L3 agent router issues a sync_router"},{"line_number":14,"context_line":"request, which later down the line ends up in an auto_schedule_routers()"},{"line_number":15,"context_line":"call. If this happens before the above schedule (of the create_router())"},{"line_number":16,"context_line":"is complete, the server will refuse to schedule the router to the other"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":7,"id":"7af24918_bd16ff52","line":13,"range":{"start_line":13,"start_character":54,"end_line":13,"end_character":65},"in_reply_to":"7af24918_bd9d5f5b","updated":"2016-03-02 15:03:40.000000000","message":"Done","commit_id":"bff362ebc636da504efda1533601aa89d30b3047"}],"neutron/db/l3_hascheduler_db.py":[{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"3b25cb82014401a32aeaaa66fd6d1420986518b1","unresolved":false,"context_lines":[{"line_number":49,"context_line":"        return [(self._make_router_dict(router), agent_count)"},{"line_number":50,"context_line":"                for router, agent_count in query]"},{"line_number":51,"context_line":""},{"line_number":52,"context_line":"    def is_router_scheduled_to_agent(self, context, router_id, agent_id):"},{"line_number":53,"context_line":"        with context.session.begin(subtransactions\u003dTrue):"},{"line_number":54,"context_line":"            query \u003d (context.session.query(l3_sch_db.RouterL3AgentBinding)."},{"line_number":55,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.router_id"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_51039a0d","line":52,"range":{"start_line":52,"start_character":8,"end_line":52,"end_character":36},"updated":"2016-02-25 09:36:26.000000000","message":"nothing HA specific here so better place in l3_agentschedulers_db","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"66930eb7b52db16ddf1f7d56840f86e6d27267ce","unresolved":false,"context_lines":[{"line_number":49,"context_line":"        return [(self._make_router_dict(router), agent_count)"},{"line_number":50,"context_line":"                for router, agent_count in query]"},{"line_number":51,"context_line":""},{"line_number":52,"context_line":"    def is_router_scheduled_to_agent(self, context, router_id, agent_id):"},{"line_number":53,"context_line":"        with context.session.begin(subtransactions\u003dTrue):"},{"line_number":54,"context_line":"            query \u003d (context.session.query(l3_sch_db.RouterL3AgentBinding)."},{"line_number":55,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.router_id"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_c60b6f2a","line":52,"range":{"start_line":52,"start_character":8,"end_line":52,"end_character":36},"in_reply_to":"bae84128_51039a0d","updated":"2016-02-25 11:25:16.000000000","message":"Done","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"3b25cb82014401a32aeaaa66fd6d1420986518b1","unresolved":false,"context_lines":[{"line_number":52,"context_line":"    def is_router_scheduled_to_agent(self, context, router_id, agent_id):"},{"line_number":53,"context_line":"        with context.session.begin(subtransactions\u003dTrue):"},{"line_number":54,"context_line":"            query \u003d (context.session.query(l3_sch_db.RouterL3AgentBinding)."},{"line_number":55,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.router_id"},{"line_number":56,"context_line":"                            \u003d\u003d router_id)."},{"line_number":57,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.l3_agent_id"},{"line_number":58,"context_line":"                            \u003d\u003d agent_id))"},{"line_number":59,"context_line":"            return query.count() \u003d\u003d 1"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_b6b5bc7f","line":56,"range":{"start_line":55,"start_character":21,"end_line":56,"end_character":41},"updated":"2016-02-25 09:36:26.000000000","message":"filter_by(router_id\u003drouter_id)","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"66930eb7b52db16ddf1f7d56840f86e6d27267ce","unresolved":false,"context_lines":[{"line_number":52,"context_line":"    def is_router_scheduled_to_agent(self, context, router_id, agent_id):"},{"line_number":53,"context_line":"        with context.session.begin(subtransactions\u003dTrue):"},{"line_number":54,"context_line":"            query \u003d (context.session.query(l3_sch_db.RouterL3AgentBinding)."},{"line_number":55,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.router_id"},{"line_number":56,"context_line":"                            \u003d\u003d router_id)."},{"line_number":57,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.l3_agent_id"},{"line_number":58,"context_line":"                            \u003d\u003d agent_id))"},{"line_number":59,"context_line":"            return query.count() \u003d\u003d 1"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_a608eb2e","line":56,"range":{"start_line":55,"start_character":21,"end_line":56,"end_character":41},"in_reply_to":"bae84128_b6b5bc7f","updated":"2016-02-25 11:25:16.000000000","message":"Done","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"3b25cb82014401a32aeaaa66fd6d1420986518b1","unresolved":false,"context_lines":[{"line_number":54,"context_line":"            query \u003d (context.session.query(l3_sch_db.RouterL3AgentBinding)."},{"line_number":55,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.router_id"},{"line_number":56,"context_line":"                            \u003d\u003d router_id)."},{"line_number":57,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.l3_agent_id"},{"line_number":58,"context_line":"                            \u003d\u003d agent_id))"},{"line_number":59,"context_line":"            return query.count() \u003d\u003d 1"},{"line_number":60,"context_line":""}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_d6acc037","line":57,"range":{"start_line":57,"start_character":21,"end_line":57,"end_character":27},"updated":"2016-02-25 09:36:26.000000000","message":"ditto","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"66930eb7b52db16ddf1f7d56840f86e6d27267ce","unresolved":false,"context_lines":[{"line_number":54,"context_line":"            query \u003d (context.session.query(l3_sch_db.RouterL3AgentBinding)."},{"line_number":55,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.router_id"},{"line_number":56,"context_line":"                            \u003d\u003d router_id)."},{"line_number":57,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.l3_agent_id"},{"line_number":58,"context_line":"                            \u003d\u003d agent_id))"},{"line_number":59,"context_line":"            return query.count() \u003d\u003d 1"},{"line_number":60,"context_line":""}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_0606f71f","line":57,"range":{"start_line":57,"start_character":21,"end_line":57,"end_character":27},"in_reply_to":"bae84128_d6acc037","updated":"2016-02-25 11:25:16.000000000","message":"Done","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"3b25cb82014401a32aeaaa66fd6d1420986518b1","unresolved":false,"context_lines":[{"line_number":56,"context_line":"                            \u003d\u003d router_id)."},{"line_number":57,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.l3_agent_id"},{"line_number":58,"context_line":"                            \u003d\u003d agent_id))"},{"line_number":59,"context_line":"            return query.count() \u003d\u003d 1"},{"line_number":60,"context_line":""},{"line_number":61,"context_line":"    def get_l3_agents_ordered_by_num_routers(self, context, agent_ids):"},{"line_number":62,"context_line":"        if not agent_ids:"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_b66c9c09","line":59,"range":{"start_line":59,"start_character":19,"end_line":59,"end_character":37},"updated":"2016-02-25 09:36:26.000000000","message":"query.first() !\u003d None","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"1c660856317e9131634238936910d9e03938cc6a","unresolved":false,"context_lines":[{"line_number":56,"context_line":"                            \u003d\u003d router_id)."},{"line_number":57,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.l3_agent_id"},{"line_number":58,"context_line":"                            \u003d\u003d agent_id))"},{"line_number":59,"context_line":"            return query.count() \u003d\u003d 1"},{"line_number":60,"context_line":""},{"line_number":61,"context_line":"    def get_l3_agents_ordered_by_num_routers(self, context, agent_ids):"},{"line_number":62,"context_line":"        if not agent_ids:"}],"source_content_type":"text/x-python","patch_set":1,"id":"9aed3d3a_bf6421e5","line":59,"range":{"start_line":59,"start_character":19,"end_line":59,"end_character":37},"in_reply_to":"9aed3d3a_91ca5a4e","updated":"2016-02-28 08:44:42.000000000","message":"Actually all of this code is gone now so... :\u003c","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"66930eb7b52db16ddf1f7d56840f86e6d27267ce","unresolved":false,"context_lines":[{"line_number":56,"context_line":"                            \u003d\u003d router_id)."},{"line_number":57,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.l3_agent_id"},{"line_number":58,"context_line":"                            \u003d\u003d agent_id))"},{"line_number":59,"context_line":"            return query.count() \u003d\u003d 1"},{"line_number":60,"context_line":""},{"line_number":61,"context_line":"    def get_l3_agents_ordered_by_num_routers(self, context, agent_ids):"},{"line_number":62,"context_line":"        if not agent_ids:"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_e602f30a","line":59,"range":{"start_line":59,"start_character":19,"end_line":59,"end_character":37},"in_reply_to":"bae84128_b66c9c09","updated":"2016-02-25 11:25:16.000000000","message":"Done","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":8124,"name":"cbrandily","email":"zzelle@gmail.com","username":"cbrandily"},"change_message_id":"bc7b3ae7497390ec3fa160a019a9ade8fc0f1fd5","unresolved":false,"context_lines":[{"line_number":56,"context_line":"                            \u003d\u003d router_id)."},{"line_number":57,"context_line":"                     filter(l3_sch_db.RouterL3AgentBinding.l3_agent_id"},{"line_number":58,"context_line":"                            \u003d\u003d agent_id))"},{"line_number":59,"context_line":"            return query.count() \u003d\u003d 1"},{"line_number":60,"context_line":""},{"line_number":61,"context_line":"    def get_l3_agents_ordered_by_num_routers(self, context, agent_ids):"},{"line_number":62,"context_line":"        if not agent_ids:"}],"source_content_type":"text/x-python","patch_set":1,"id":"9aed3d3a_91ca5a4e","line":59,"range":{"start_line":59,"start_character":19,"end_line":59,"end_character":37},"in_reply_to":"bae84128_e602f30a","updated":"2016-02-25 21:37:54.000000000","message":".count() avoids to unmarshall the db object so:\n\n query.limit(1).count()\n\nshould be more efficient?","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"}],"neutron/scheduler/l3_agent_scheduler.py":[{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"3b25cb82014401a32aeaaa66fd6d1420986518b1","unresolved":false,"context_lines":[{"line_number":133,"context_line":"        if not l3_agent:"},{"line_number":134,"context_line":"            return False"},{"line_number":135,"context_line":""},{"line_number":136,"context_line":"        LOG.debug(\"running auto_schedule_routers on %r: %r\" % (host, router_ids))"},{"line_number":137,"context_line":"        unscheduled_routers \u003d self._get_routers_to_schedule("},{"line_number":138,"context_line":"            context, plugin, router_ids)"},{"line_number":139,"context_line":"        if not unscheduled_routers:"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_16e2a89f","line":136,"range":{"start_line":136,"start_character":49,"end_line":136,"end_character":51},"updated":"2016-02-25 09:36:26.000000000","message":"nit: s/on/for host","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"66930eb7b52db16ddf1f7d56840f86e6d27267ce","unresolved":false,"context_lines":[{"line_number":133,"context_line":"        if not l3_agent:"},{"line_number":134,"context_line":"            return False"},{"line_number":135,"context_line":""},{"line_number":136,"context_line":"        LOG.debug(\"running auto_schedule_routers on %r: %r\" % (host, router_ids))"},{"line_number":137,"context_line":"        unscheduled_routers \u003d self._get_routers_to_schedule("},{"line_number":138,"context_line":"            context, plugin, router_ids)"},{"line_number":139,"context_line":"        if not unscheduled_routers:"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_590d8036","line":136,"range":{"start_line":136,"start_character":49,"end_line":136,"end_character":51},"in_reply_to":"bae84128_16e2a89f","updated":"2016-02-25 11:25:16.000000000","message":"This is actually a leftover debugging helper, so the line was removed.","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":8124,"name":"cbrandily","email":"zzelle@gmail.com","username":"cbrandily"},"change_message_id":"bc7b3ae7497390ec3fa160a019a9ade8fc0f1fd5","unresolved":false,"context_lines":[{"line_number":161,"context_line":"            # active any time"},{"line_number":162,"context_line":"            current_l3_agents \u003d plugin.get_l3_agents_hosting_routers("},{"line_number":163,"context_line":"                context, [sync_router[\u0027id\u0027]], admin_state_up\u003dTrue)"},{"line_number":164,"context_line":"            if not sync_router.get(\u0027ha\u0027, False) and current_l3_agents:"},{"line_number":165,"context_line":"                LOG.debug(\u0027Router %(router_id)s has already been hosted \u0027"},{"line_number":166,"context_line":"                          \u0027by L3 agent %(agent_id)s\u0027,"},{"line_number":167,"context_line":"                          {\u0027router_id\u0027: sync_router[\u0027id\u0027],"}],"source_content_type":"text/x-python","patch_set":1,"id":"9aed3d3a_71235606","line":164,"range":{"start_line":164,"start_character":41,"end_line":164,"end_character":46},"updated":"2016-02-25 21:37:54.000000000","message":"These conditions are difficult to understand, the following seems easier to understand:\n\n if sync_router.get(\u0027ha\u0027, False):\n   if len(...:\n     ...\n elif current_l3_agents:\n   ...","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"3b25cb82014401a32aeaaa66fd6d1420986518b1","unresolved":false,"context_lines":[{"line_number":161,"context_line":"            # active any time"},{"line_number":162,"context_line":"            current_l3_agents \u003d plugin.get_l3_agents_hosting_routers("},{"line_number":163,"context_line":"                context, [sync_router[\u0027id\u0027]], admin_state_up\u003dTrue)"},{"line_number":164,"context_line":"            if not sync_router.get(\u0027ha\u0027, False) and current_l3_agents:"},{"line_number":165,"context_line":"                LOG.debug(\u0027Router %(router_id)s has already been hosted \u0027"},{"line_number":166,"context_line":"                          \u0027by L3 agent %(agent_id)s\u0027,"},{"line_number":167,"context_line":"                          {\u0027router_id\u0027: sync_router[\u0027id\u0027],"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_5116faa7","line":164,"range":{"start_line":164,"start_character":19,"end_line":164,"end_character":47},"updated":"2016-02-25 09:36:26.000000000","message":"may use local \n is_ha \u003d sync_router.get(\u0027ha\u0027, False) here and at #170","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"1c660856317e9131634238936910d9e03938cc6a","unresolved":false,"context_lines":[{"line_number":161,"context_line":"            # active any time"},{"line_number":162,"context_line":"            current_l3_agents \u003d plugin.get_l3_agents_hosting_routers("},{"line_number":163,"context_line":"                context, [sync_router[\u0027id\u0027]], admin_state_up\u003dTrue)"},{"line_number":164,"context_line":"            if not sync_router.get(\u0027ha\u0027, False) and current_l3_agents:"},{"line_number":165,"context_line":"                LOG.debug(\u0027Router %(router_id)s has already been hosted \u0027"},{"line_number":166,"context_line":"                          \u0027by L3 agent %(agent_id)s\u0027,"},{"line_number":167,"context_line":"                          {\u0027router_id\u0027: sync_router[\u0027id\u0027],"}],"source_content_type":"text/x-python","patch_set":1,"id":"9aed3d3a_5f9cf5bf","line":164,"range":{"start_line":164,"start_character":41,"end_line":164,"end_character":46},"in_reply_to":"9aed3d3a_71235606","updated":"2016-02-28 08:44:42.000000000","message":"Done","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"66930eb7b52db16ddf1f7d56840f86e6d27267ce","unresolved":false,"context_lines":[{"line_number":161,"context_line":"            # active any time"},{"line_number":162,"context_line":"            current_l3_agents \u003d plugin.get_l3_agents_hosting_routers("},{"line_number":163,"context_line":"                context, [sync_router[\u0027id\u0027]], admin_state_up\u003dTrue)"},{"line_number":164,"context_line":"            if not sync_router.get(\u0027ha\u0027, False) and current_l3_agents:"},{"line_number":165,"context_line":"                LOG.debug(\u0027Router %(router_id)s has already been hosted \u0027"},{"line_number":166,"context_line":"                          \u0027by L3 agent %(agent_id)s\u0027,"},{"line_number":167,"context_line":"                          {\u0027router_id\u0027: sync_router[\u0027id\u0027],"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_b9400c37","line":164,"range":{"start_line":164,"start_character":19,"end_line":164,"end_character":47},"in_reply_to":"bae84128_5116faa7","updated":"2016-02-25 11:25:16.000000000","message":"Done","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"3b25cb82014401a32aeaaa66fd6d1420986518b1","unresolved":false,"context_lines":[{"line_number":204,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":205,"context_line":"        try:"},{"line_number":206,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"},{"line_number":207,"context_line":"                if not plugin.is_router_scheduled_to_agent(context,"},{"line_number":208,"context_line":"                                                           router_id,"},{"line_number":209,"context_line":"                                                           chosen_agent_id):"},{"line_number":210,"context_line":"                    binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"},{"line_number":211,"context_line":"                    binding.l3_agent \u003d chosen_agent"},{"line_number":212,"context_line":"                    binding.router_id \u003d router_id"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_e3a66552","line":209,"range":{"start_line":207,"start_character":16,"end_line":209,"end_character":76},"updated":"2016-02-25 09:36:26.000000000","message":"not sure I undrstand what this gives us, how is it different from catching DBDuplicateEntry?","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"58856493efe77d74cb02f8c3baed354f53111055","unresolved":false,"context_lines":[{"line_number":204,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":205,"context_line":"        try:"},{"line_number":206,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"},{"line_number":207,"context_line":"                if not plugin.is_router_scheduled_to_agent(context,"},{"line_number":208,"context_line":"                                                           router_id,"},{"line_number":209,"context_line":"                                                           chosen_agent_id):"},{"line_number":210,"context_line":"                    binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"},{"line_number":211,"context_line":"                    binding.l3_agent \u003d chosen_agent"},{"line_number":212,"context_line":"                    binding.router_id \u003d router_id"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_3726bc16","line":209,"range":{"start_line":207,"start_character":16,"end_line":209,"end_character":76},"in_reply_to":"bae84128_541a5e6f","updated":"2016-02-25 12:30:59.000000000","message":"Digging into this a bit deeper, it\u0027s actually the with statement at line 325 that tries to rollback() again (but since it was already closed an exception is raised - InvalidRequestError...)","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":5948,"name":"Oleg Bondarev","email":"obondarev@mirantis.com","username":"obondarev"},"change_message_id":"8c2d916e7be355fa204b00387226516428d20545","unresolved":false,"context_lines":[{"line_number":204,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":205,"context_line":"        try:"},{"line_number":206,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"},{"line_number":207,"context_line":"                if not plugin.is_router_scheduled_to_agent(context,"},{"line_number":208,"context_line":"                                                           router_id,"},{"line_number":209,"context_line":"                                                           chosen_agent_id):"},{"line_number":210,"context_line":"                    binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"},{"line_number":211,"context_line":"                    binding.l3_agent \u003d chosen_agent"},{"line_number":212,"context_line":"                    binding.router_id \u003d router_id"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_541a5e6f","line":209,"range":{"start_line":207,"start_character":16,"end_line":209,"end_character":76},"in_reply_to":"bae84128_c85d384a","updated":"2016-02-25 12:01:19.000000000","message":"So if the exception is handled, why \"the \u0027with\u0027 statement\u0027s __exit__ tries to rollback() the transaction\"? Explicit check for the record and then adding is also a race. We may probably use retry mechanism here (db_api.exc_to_retry)","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"66930eb7b52db16ddf1f7d56840f86e6d27267ce","unresolved":false,"context_lines":[{"line_number":204,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":205,"context_line":"        try:"},{"line_number":206,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"},{"line_number":207,"context_line":"                if not plugin.is_router_scheduled_to_agent(context,"},{"line_number":208,"context_line":"                                                           router_id,"},{"line_number":209,"context_line":"                                                           chosen_agent_id):"},{"line_number":210,"context_line":"                    binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"},{"line_number":211,"context_line":"                    binding.l3_agent \u003d chosen_agent"},{"line_number":212,"context_line":"                    binding.router_id \u003d router_id"}],"source_content_type":"text/x-python","patch_set":1,"id":"bae84128_c85d384a","line":209,"range":{"start_line":207,"start_character":16,"end_line":209,"end_character":76},"in_reply_to":"bae84128_e3a66552","updated":"2016-02-25 11:25:16.000000000","message":"The answer can be found in [1]. Basically,if context.session.add(binding) raises an exception it also closes the transaction. Then, the \u0027with\u0027 statement\u0027s __exit__ tries to rollback() the transaction (which was already closed) causes another exception (InvalidRequestError), which causes the whole \u0027create_router()\u0027 to fail. So an explicit check must be made here to ensure safe addition. This is actually a bug in the original code that I found along the way.\n\nIf someone has a better idea, I\u0027m all forward.\n\n[1]: http://docs.sqlalchemy.org/en/rel_0_8/faq.html#this-session-s-transaction-has-been-rolled-back-due-to-a-previous-exception-during-flush-or-similar","commit_id":"af6893af3f9ddf725bf9358427ee5b53f88043e6"},{"author":{"_account_id":1653,"name":"garyk","email":"gkotton@vmware.com","username":"garyk"},"change_message_id":"fbe548f003ee4e04f2e079e1ec77d86cbf280b44","unresolved":false,"context_lines":[{"line_number":153,"context_line":""},{"line_number":154,"context_line":"    def _get_candidates(self, plugin, context, sync_router):"},{"line_number":155,"context_line":"        \"\"\"Return L3 agents where a router could be scheduled.\"\"\""},{"line_number":156,"context_line":"        is_ha \u003d sync_router.get(\u0027ha\u0027, False)"},{"line_number":157,"context_line":"        with context.session.begin(subtransactions\u003dTrue):"},{"line_number":158,"context_line":"            # allow one router is hosted by just"},{"line_number":159,"context_line":"            # one enabled l3 agent hosting since active is just a"}],"source_content_type":"text/x-python","patch_set":2,"id":"9aed3d3a_9af4cbf2","line":156,"updated":"2016-02-28 10:02:39.000000000","message":"can we please have some unit tests to check these races...","commit_id":"80926fb1937b59acf8f13ebd0545d5b335c2213c"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"e1eddc7967c18ad746392476b6ff47a10a36927b","unresolved":false,"context_lines":[{"line_number":153,"context_line":""},{"line_number":154,"context_line":"    def _get_candidates(self, plugin, context, sync_router):"},{"line_number":155,"context_line":"        \"\"\"Return L3 agents where a router could be scheduled.\"\"\""},{"line_number":156,"context_line":"        is_ha \u003d sync_router.get(\u0027ha\u0027, False)"},{"line_number":157,"context_line":"        with context.session.begin(subtransactions\u003dTrue):"},{"line_number":158,"context_line":"            # allow one router is hosted by just"},{"line_number":159,"context_line":"            # one enabled l3 agent hosting since active is just a"}],"source_content_type":"text/x-python","patch_set":2,"id":"9aed3d3a_7ace27b5","line":156,"in_reply_to":"9aed3d3a_9af4cbf2","updated":"2016-02-28 10:04:06.000000000","message":"Done","commit_id":"80926fb1937b59acf8f13ebd0545d5b335c2213c"},{"author":{"_account_id":1653,"name":"garyk","email":"gkotton@vmware.com","username":"garyk"},"change_message_id":"fbe548f003ee4e04f2e079e1ec77d86cbf280b44","unresolved":false,"context_lines":[{"line_number":211,"context_line":""},{"line_number":212,"context_line":"                LOG.debug(\u0027Router %(router_id)s is scheduled to L3 agent \u0027"},{"line_number":213,"context_line":"                          \u0027%(agent_id)s\u0027, {\u0027router_id\u0027: router_id,"},{"line_number":214,"context_line":"                                           \u0027agent_id\u0027: chosen_agent.id})"},{"line_number":215,"context_line":"                return binding"},{"line_number":216,"context_line":"        except db_exc.DBDuplicateEntry:"},{"line_number":217,"context_line":"            LOG.debug(\u0027Router %(router_id)s has already been scheduled \u0027"}],"source_content_type":"text/x-python","patch_set":2,"id":"9aed3d3a_bad9cf85","line":214,"updated":"2016-02-28 10:02:39.000000000","message":"why chosen_agent.id here and below chosen_agent_id","commit_id":"80926fb1937b59acf8f13ebd0545d5b335c2213c"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"e1eddc7967c18ad746392476b6ff47a10a36927b","unresolved":false,"context_lines":[{"line_number":211,"context_line":""},{"line_number":212,"context_line":"                LOG.debug(\u0027Router %(router_id)s is scheduled to L3 agent \u0027"},{"line_number":213,"context_line":"                          \u0027%(agent_id)s\u0027, {\u0027router_id\u0027: router_id,"},{"line_number":214,"context_line":"                                           \u0027agent_id\u0027: chosen_agent.id})"},{"line_number":215,"context_line":"                return binding"},{"line_number":216,"context_line":"        except db_exc.DBDuplicateEntry:"},{"line_number":217,"context_line":"            LOG.debug(\u0027Router %(router_id)s has already been scheduled \u0027"}],"source_content_type":"text/x-python","patch_set":2,"id":"9aed3d3a_9acb2ba5","line":214,"in_reply_to":"9aed3d3a_bad9cf85","updated":"2016-02-28 10:04:06.000000000","message":"Done","commit_id":"80926fb1937b59acf8f13ebd0545d5b335c2213c"},{"author":{"_account_id":1653,"name":"garyk","email":"gkotton@vmware.com","username":"garyk"},"change_message_id":"6c75627d4ba0dc0567eedf6a3ec2d28cc63a9796","unresolved":false,"context_lines":[{"line_number":169,"context_line":"                return []"},{"line_number":170,"context_line":"            elif is_ha:"},{"line_number":171,"context_line":"                if (len(current_l3_agents) \u003e\u003d self.max_ha_agents and"},{"line_number":172,"context_line":"                    self.max_ha_agents \u003e 0):"},{"line_number":173,"context_line":"                    LOG.debug(\u0027HA router %s has already been hosted by the \u0027"},{"line_number":174,"context_line":"                              \u0027maximum number of agents\u0027, sync_router[\u0027id\u0027])"},{"line_number":175,"context_line":"                    return []"}],"source_content_type":"text/x-python","patch_set":3,"id":"9aed3d3a_116421e2","line":172,"updated":"2016-02-28 12:49:10.000000000","message":"Minor nit (you can save a few cycles here:\nif (self.max_ha_agents \u003e 0 and\n        len(current_l3_agents) \u003e\u003d self.max_ha_agents)):","commit_id":"ab5c29f4f51ae1afb558b3ef94a55918711069a1"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"c88697e7f77a5db3af0eb2da83d7a5625f7cc236","unresolved":false,"context_lines":[{"line_number":169,"context_line":"                return []"},{"line_number":170,"context_line":"            elif is_ha:"},{"line_number":171,"context_line":"                if (len(current_l3_agents) \u003e\u003d self.max_ha_agents and"},{"line_number":172,"context_line":"                    self.max_ha_agents \u003e 0):"},{"line_number":173,"context_line":"                    LOG.debug(\u0027HA router %s has already been hosted by the \u0027"},{"line_number":174,"context_line":"                              \u0027maximum number of agents\u0027, sync_router[\u0027id\u0027])"},{"line_number":175,"context_line":"                    return []"}],"source_content_type":"text/x-python","patch_set":3,"id":"9aed3d3a_b169f527","line":172,"in_reply_to":"9aed3d3a_116421e2","updated":"2016-02-28 13:48:22.000000000","message":"Done","commit_id":"ab5c29f4f51ae1afb558b3ef94a55918711069a1"},{"author":{"_account_id":11159,"name":"Hong Hui Xiao","email":"honghui_xiao@yeah.net","username":"HongHuiXiao"},"change_message_id":"73d136cc4da838491ad7be2cfe579186b94c3bec","unresolved":false,"context_lines":[{"line_number":167,"context_line":"                          {\u0027router_id\u0027: sync_router[\u0027id\u0027],"},{"line_number":168,"context_line":"                           \u0027agent_id\u0027: current_l3_agents[0][\u0027id\u0027]})"},{"line_number":169,"context_line":"                return []"},{"line_number":170,"context_line":"            elif is_ha:"},{"line_number":171,"context_line":"                if (self.max_ha_agents \u003e 0 and"},{"line_number":172,"context_line":"                    len(current_l3_agents) \u003e\u003d self.max_ha_agents):"},{"line_number":173,"context_line":"                    LOG.debug(\u0027HA router %s has already been hosted by the \u0027"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_18a8b98c","line":170,"range":{"start_line":170,"start_character":0,"end_line":170,"end_character":23},"updated":"2016-02-29 03:30:59.000000000","message":"I have this thought in my mind, correct me if I am wrong:\n\nThe issue in the description happened. We now have one l3 agent(agent A) that hosted the ha router, but not enough. So, the code moves on from line 177. But there are lots of l3 agents available, and the agent A don\u0027t win the election at _choose_router_agents_for_ha. So, the code will still bind (max_ha_agents) agents to ha router. As a result, we will have (max_ha_agents+1) agents bind to the ha router.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"d6fa586ae31324c6f92d1571a719a1a9e2b94826","unresolved":false,"context_lines":[{"line_number":167,"context_line":"                          {\u0027router_id\u0027: sync_router[\u0027id\u0027],"},{"line_number":168,"context_line":"                           \u0027agent_id\u0027: current_l3_agents[0][\u0027id\u0027]})"},{"line_number":169,"context_line":"                return []"},{"line_number":170,"context_line":"            elif is_ha:"},{"line_number":171,"context_line":"                if (self.max_ha_agents \u003e 0 and"},{"line_number":172,"context_line":"                    len(current_l3_agents) \u003e\u003d self.max_ha_agents):"},{"line_number":173,"context_line":"                    LOG.debug(\u0027HA router %s has already been hosted by the \u0027"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_569cc00e","line":170,"range":{"start_line":170,"start_character":0,"end_line":170,"end_character":23},"in_reply_to":"9aed3d3a_18a8b98c","updated":"2016-02-29 12:56:14.000000000","message":"Your specific scenario isn\u0027t possible - if you look at line 314, at most max_l3_agents_per_router bindings exist so no more can be added.\n\nYour comment did point me to the issue where the same agent might be scheduled twice (once concurrently and once again because _get_candidates() returns it). This leads to yet more bugs:\nSuppose max_l3_agents_per_router\u003d3 and there are 4 agents total. Also suppose 1 router has been scheduled concurrently. We need to subtract, from the candidates returned, the router that has already been scheduled and also ANOTHER router (because we only need to schedule at most 2 more routers). Also, we must ensure that amongst the port bindings that were returned in line 312, we don\u0027t override existing bindings.\nThis means that this code can be a lot more complicated and I\u0027m looking for the simplest way to do this right...","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":11159,"name":"Hong Hui Xiao","email":"honghui_xiao@yeah.net","username":"HongHuiXiao"},"change_message_id":"73d136cc4da838491ad7be2cfe579186b94c3bec","unresolved":false,"context_lines":[{"line_number":200,"context_line":""},{"line_number":201,"context_line":"    def bind_router(self, context, router_id, chosen_agent):"},{"line_number":202,"context_line":"        \"\"\"Bind the router to the l3 agent which has been chosen.\"\"\""},{"line_number":203,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":204,"context_line":"        try:"},{"line_number":205,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"},{"line_number":206,"context_line":"                binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_f89d1567","line":203,"updated":"2016-02-29 03:30:59.000000000","message":"nit: I think the change is not necessary here.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"d6fa586ae31324c6f92d1571a719a1a9e2b94826","unresolved":false,"context_lines":[{"line_number":200,"context_line":""},{"line_number":201,"context_line":"    def bind_router(self, context, router_id, chosen_agent):"},{"line_number":202,"context_line":"        \"\"\"Bind the router to the l3 agent which has been chosen.\"\"\""},{"line_number":203,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":204,"context_line":"        try:"},{"line_number":205,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"},{"line_number":206,"context_line":"                binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_76d5841a","line":203,"in_reply_to":"9aed3d3a_f89d1567","updated":"2016-02-29 12:56:14.000000000","message":"It is. If DBDuplicateEntry is raised, the transaction is rolled back. In this state, it\u0027s impossible to access chosen_agent.id any more (it raises an exception), so I save it before just in case.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"976a288e92c869d7159182a7e149ce5c3a181bae","unresolved":false,"context_lines":[{"line_number":313,"context_line":"                                                           [router_id])"},{"line_number":314,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":315,"context_line":""},{"line_number":316,"context_line":"            context.session.begin(subtransactions\u003dTrue)"},{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_4c89de74","line":316,"range":{"start_line":316,"start_character":12,"end_line":316,"end_character":55},"updated":"2016-02-29 09:15:54.000000000","message":"You should do that with \"with\", if exception occure in bind_router this transaction will hang.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"8af5602869c7c9f0e0764635ac833fbad7475ae8","unresolved":false,"context_lines":[{"line_number":313,"context_line":"                                                           [router_id])"},{"line_number":314,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":315,"context_line":""},{"line_number":316,"context_line":"            context.session.begin(subtransactions\u003dTrue)"},{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_cd44be1c","line":316,"range":{"start_line":316,"start_character":12,"end_line":316,"end_character":55},"in_reply_to":"9aed3d3a_0c2b5695","updated":"2016-02-29 13:22:32.000000000","message":"DBDuplicateError is not the only one exception that could be raised, so that is why we need to use context manager here. Also it should work properly with rollback, but you should use it for transaction, not for session. I mean\n\n    with connection.begin() as trans:\n         trans.rollback()\n\nIf you call rollback for the session, outer transaction will be rolled back, not the subtransaction you use here. That\u0027s why you\u0027re most likely get InvalidRequestError in that case.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"26efbefe447a717fc68d5ed44522c9cd0c935e3b","unresolved":false,"context_lines":[{"line_number":313,"context_line":"                                                           [router_id])"},{"line_number":314,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":315,"context_line":""},{"line_number":316,"context_line":"            context.session.begin(subtransactions\u003dTrue)"},{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_0c2b5695","line":316,"range":{"start_line":316,"start_character":12,"end_line":316,"end_character":55},"in_reply_to":"9aed3d3a_4c89de74","updated":"2016-02-29 09:31:32.000000000","message":"If bind_router fails (ie. DBDuplicateError is raised), then the inner transaction is rolled back (with rollback()).\n\nThe issue with doing a \u0027with\u0027 here is that in that case, the \u0027with\u0027 here will attempt to close() the transaction, which will fail (InvalidRequestError) because the transaction has already been rolled back and closed inside.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"1437817833aa5c1dcc57d8c599b71c24272b4996","unresolved":false,"context_lines":[{"line_number":313,"context_line":"                                                           [router_id])"},{"line_number":314,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":315,"context_line":""},{"line_number":316,"context_line":"            context.session.begin(subtransactions\u003dTrue)"},{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_2510d658","line":316,"range":{"start_line":316,"start_character":12,"end_line":316,"end_character":55},"in_reply_to":"9aed3d3a_cd44be1c","updated":"2016-02-29 17:09:28.000000000","message":"Ann, you\u0027re a genius. Thanks for the help.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"ebc8c2e1051bf25103252eb64740b40beef02d5d","unresolved":false,"context_lines":[{"line_number":316,"context_line":"            context.session.begin(subtransactions\u003dTrue)"},{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"},{"line_number":320,"context_line":"                context.session.rollback()"},{"line_number":321,"context_line":"                continue"},{"line_number":322,"context_line":"            port_binding.l3_agent_id \u003d agent.id"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_477b798c","line":319,"updated":"2016-02-29 09:35:59.000000000","message":"Add some test case for this bind_router return None to see if the rollback could work properly.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"1437817833aa5c1dcc57d8c599b71c24272b4996","unresolved":false,"context_lines":[{"line_number":316,"context_line":"            context.session.begin(subtransactions\u003dTrue)"},{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"},{"line_number":320,"context_line":"                context.session.rollback()"},{"line_number":321,"context_line":"                continue"},{"line_number":322,"context_line":"            port_binding.l3_agent_id \u003d agent.id"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_852a828e","line":319,"in_reply_to":"9aed3d3a_169b5873","updated":"2016-02-29 17:09:28.000000000","message":"I\u0027m sorry, reading back at your initial comment, my response doesn\u0027t really answer your request :)\n\nLooking back at this, the test code for this function is increasingly complicated (over 4 mocks, and I\u0027m not even done) because this function uses a lot of other objects. Since we only want to test here that if \u0027self.bind_router()\u0027 returns None, then rollback() is called - I\u0027m skipping this test as the cons outweigh the pros.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"d6fa586ae31324c6f92d1571a719a1a9e2b94826","unresolved":false,"context_lines":[{"line_number":316,"context_line":"            context.session.begin(subtransactions\u003dTrue)"},{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"},{"line_number":320,"context_line":"                context.session.rollback()"},{"line_number":321,"context_line":"                continue"},{"line_number":322,"context_line":"            port_binding.l3_agent_id \u003d agent.id"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_169b5873","line":319,"in_reply_to":"9aed3d3a_477b798c","updated":"2016-02-29 12:56:14.000000000","message":"bind_router rollbacks itself so this is done mainly to finish the transaction (so we won\u0027t have a begin() without a close()/rollback()). close() isn\u0027t used because this might be used as part of some other transaction and closing it here will raise exceptions later down the line, so rollback() it is.\n\nI\u0027ll add a comment.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"976a288e92c869d7159182a7e149ce5c3a181bae","unresolved":false,"context_lines":[{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"},{"line_number":320,"context_line":"                context.session.rollback()"},{"line_number":321,"context_line":"                continue"},{"line_number":322,"context_line":"            port_binding.l3_agent_id \u003d agent.id"},{"line_number":323,"context_line":"            context.session.commit()"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_6c6022a6","line":320,"range":{"start_line":320,"start_character":16,"end_line":320,"end_character":42},"updated":"2016-02-29 09:15:54.000000000","message":"I\u0027m not sure, what you tried to rollback here?","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"26efbefe447a717fc68d5ed44522c9cd0c935e3b","unresolved":false,"context_lines":[{"line_number":317,"context_line":"            # bind_router should catch all the exceptions and return None on"},{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"},{"line_number":320,"context_line":"                context.session.rollback()"},{"line_number":321,"context_line":"                continue"},{"line_number":322,"context_line":"            port_binding.l3_agent_id \u003d agent.id"},{"line_number":323,"context_line":"            context.session.commit()"}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_271c7569","line":320,"range":{"start_line":320,"start_character":16,"end_line":320,"end_character":42},"in_reply_to":"9aed3d3a_6c6022a6","updated":"2016-02-29 09:31:32.000000000","message":"As per above - in case there was an error, close() failed but we still want to \u0027clean\u0027 the transaction that we opened in line 316 - this is done with rollback().","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"ebc8c2e1051bf25103252eb64740b40beef02d5d","unresolved":false,"context_lines":[{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"},{"line_number":320,"context_line":"                context.session.rollback()"},{"line_number":321,"context_line":"                continue"},{"line_number":322,"context_line":"            port_binding.l3_agent_id \u003d agent.id"},{"line_number":323,"context_line":"            context.session.commit()"},{"line_number":324,"context_line":""}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_674f9d6b","line":321,"range":{"start_line":321,"start_character":16,"end_line":321,"end_character":24},"updated":"2016-02-29 09:35:59.000000000","message":"If one transaction was rollback, and then go to next bind_router, HA router will not have enough binding_agents for chosen_agents.","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"d6fa586ae31324c6f92d1571a719a1a9e2b94826","unresolved":false,"context_lines":[{"line_number":318,"context_line":"            # error."},{"line_number":319,"context_line":"            if not self.bind_router(context, router_id, agent):"},{"line_number":320,"context_line":"                context.session.rollback()"},{"line_number":321,"context_line":"                continue"},{"line_number":322,"context_line":"            port_binding.l3_agent_id \u003d agent.id"},{"line_number":323,"context_line":"            context.session.commit()"},{"line_number":324,"context_line":""}],"source_content_type":"text/x-python","patch_set":4,"id":"9aed3d3a_16c07829","line":321,"range":{"start_line":321,"start_character":16,"end_line":321,"end_character":24},"in_reply_to":"9aed3d3a_674f9d6b","updated":"2016-02-29 12:56:14.000000000","message":"Yes, but the only cases where this is (currently) feasible are:\n\n1) The router has been deleted concurrently - nothing will be bound so...\n2) The binding has already been added concurrently, so we can skip this one. We should still have the right amount of bindings here because we intended to bind X agents and we bound X-1 (but the last one was done concurrently so nothing was damaged).","commit_id":"e7d057540541de4893e9a77cb09e25cc9e6e0440"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"3d07a7f5d4c00c0bd0073acbdfedf52ccab5a0e2","unresolved":false,"context_lines":[{"line_number":221,"context_line":"        \"\"\"Bind the router to the l3 agent which has been chosen.\"\"\""},{"line_number":222,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":223,"context_line":"        try:"},{"line_number":224,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"},{"line_number":225,"context_line":"                binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"},{"line_number":226,"context_line":"                binding.l3_agent \u003d chosen_agent"},{"line_number":227,"context_line":"                binding.router_id \u003d router_id"}],"source_content_type":"text/x-python","patch_set":5,"id":"9aed3d3a_bf44c549","line":224,"range":{"start_line":224,"start_character":17,"end_line":224,"end_character":38},"updated":"2016-03-01 09:01:29.000000000","message":"I suggest to use autonested_transaction here, as it should be nested in case of rollback.","commit_id":"9c03a968bf53f62453883b4ebc890a6c62d52779"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"82849a8ced292a69fc32c513ed39d4597c32194a","unresolved":false,"context_lines":[{"line_number":221,"context_line":"        \"\"\"Bind the router to the l3 agent which has been chosen.\"\"\""},{"line_number":222,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":223,"context_line":"        try:"},{"line_number":224,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"},{"line_number":225,"context_line":"                binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"},{"line_number":226,"context_line":"                binding.l3_agent \u003d chosen_agent"},{"line_number":227,"context_line":"                binding.router_id \u003d router_id"}],"source_content_type":"text/x-python","patch_set":5,"id":"9aed3d3a_827b6a7a","line":224,"range":{"start_line":224,"start_character":17,"end_line":224,"end_character":38},"in_reply_to":"9aed3d3a_bf44c549","updated":"2016-03-01 09:33:11.000000000","message":"Done","commit_id":"9c03a968bf53f62453883b4ebc890a6c62d52779"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"3d07a7f5d4c00c0bd0073acbdfedf52ccab5a0e2","unresolved":false,"context_lines":[{"line_number":333,"context_line":"        port_bindings \u003d plugin.get_ha_router_port_bindings("},{"line_number":334,"context_line":"            context, [router_id], only_unbound\u003dTrue)"},{"line_number":335,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":336,"context_line":"            with context.session.connection().begin() as trans:"},{"line_number":337,"context_line":"                # bind_router should catch all the exceptions and return None"},{"line_number":338,"context_line":"                # on error."},{"line_number":339,"context_line":"                if not self.bind_router(context, router_id, agent):"}],"source_content_type":"text/x-python","patch_set":5,"id":"9aed3d3a_7c59ab8d","line":336,"range":{"start_line":336,"start_character":46,"end_line":336,"end_character":52},"updated":"2016-03-01 09:01:29.000000000","message":"Sorry, for confusion, you need to have subtransactions\u003dTrue here.\n\nBy the way, why you decided not to use autonested_transaction here? There was a discussion about it https://review.openstack.org/#/c/238122/13/neutron/scheduler/l3_agent_scheduler.py when I worked on it.","commit_id":"9c03a968bf53f62453883b4ebc890a6c62d52779"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"82849a8ced292a69fc32c513ed39d4597c32194a","unresolved":false,"context_lines":[{"line_number":333,"context_line":"        port_bindings \u003d plugin.get_ha_router_port_bindings("},{"line_number":334,"context_line":"            context, [router_id], only_unbound\u003dTrue)"},{"line_number":335,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":336,"context_line":"            with context.session.connection().begin() as trans:"},{"line_number":337,"context_line":"                # bind_router should catch all the exceptions and return None"},{"line_number":338,"context_line":"                # on error."},{"line_number":339,"context_line":"                if not self.bind_router(context, router_id, agent):"}],"source_content_type":"text/x-python","patch_set":5,"id":"9aed3d3a_826c0a09","line":336,"range":{"start_line":336,"start_character":46,"end_line":336,"end_character":52},"in_reply_to":"9aed3d3a_7c59ab8d","updated":"2016-03-01 09:33:11.000000000","message":"Done. Originally I had used autonested_transaction but I ran into too many problems, probably because bind_router wasn\u0027t autonested as well.","commit_id":"9c03a968bf53f62453883b4ebc890a6c62d52779"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"3d07a7f5d4c00c0bd0073acbdfedf52ccab5a0e2","unresolved":false,"context_lines":[{"line_number":334,"context_line":"            context, [router_id], only_unbound\u003dTrue)"},{"line_number":335,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":336,"context_line":"            with context.session.connection().begin() as trans:"},{"line_number":337,"context_line":"                # bind_router should catch all the exceptions and return None"},{"line_number":338,"context_line":"                # on error."},{"line_number":339,"context_line":"                if not self.bind_router(context, router_id, agent):"},{"line_number":340,"context_line":"                    trans.rollback()"}],"source_content_type":"text/x-python","patch_set":5,"id":"9aed3d3a_9c874fb4","line":337,"range":{"start_line":337,"start_character":37,"end_line":337,"end_character":61},"updated":"2016-03-01 09:01:29.000000000","message":"I would say \"If bind_router catch known exceptions...\"","commit_id":"9c03a968bf53f62453883b4ebc890a6c62d52779"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"82849a8ced292a69fc32c513ed39d4597c32194a","unresolved":false,"context_lines":[{"line_number":334,"context_line":"            context, [router_id], only_unbound\u003dTrue)"},{"line_number":335,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":336,"context_line":"            with context.session.connection().begin() as trans:"},{"line_number":337,"context_line":"                # bind_router should catch all the exceptions and return None"},{"line_number":338,"context_line":"                # on error."},{"line_number":339,"context_line":"                if not self.bind_router(context, router_id, agent):"},{"line_number":340,"context_line":"                    trans.rollback()"}],"source_content_type":"text/x-python","patch_set":5,"id":"9aed3d3a_ff05ad13","line":337,"range":{"start_line":337,"start_character":37,"end_line":337,"end_character":61},"in_reply_to":"9aed3d3a_9c874fb4","updated":"2016-03-01 09:33:11.000000000","message":"Changed the wording to indicate what you wanted.","commit_id":"9c03a968bf53f62453883b4ebc890a6c62d52779"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"0d818aff02cfbcb7e997230ab1c0c1b896f01e06","unresolved":false,"context_lines":[{"line_number":306,"context_line":"            try:"},{"line_number":307,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":308,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":309,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":310,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":311,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":312,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"5aef4532_12cd6c5d","side":"PARENT","line":309,"updated":"2016-03-08 15:12:48.000000000","message":"It seems the trace, http://paste.openstack.org/show/488732/, was caused by this autonested_transaction and bind_router.","commit_id":"3f153b485ab7a6814358f01cec40db070b8b6a17"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"9ee6fbabf06e12e41034d19823b19a8f9f76b2da","unresolved":false,"context_lines":[{"line_number":306,"context_line":"            try:"},{"line_number":307,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":308,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":309,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":310,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":311,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":312,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"5aef4532_921b3c80","side":"PARENT","line":309,"in_reply_to":"5aef4532_12cd6c5d","updated":"2016-03-08 15:16:15.000000000","message":"It does indeed seem the case :)","commit_id":"3f153b485ab7a6814358f01cec40db070b8b6a17"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"db5840ce72dfb37e02f0a6921cfcdc76397c93ab","unresolved":false,"context_lines":[{"line_number":306,"context_line":"            try:"},{"line_number":307,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":308,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":309,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":310,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":311,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":312,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"5aef4532_8cb5dc32","side":"PARENT","line":309,"in_reply_to":"5aef4532_921b3c80","updated":"2016-03-08 15:59:31.000000000","message":"It has \"self.delete_router(context, router_dict[\u0027id\u0027])\" in the trace and seems that always stop at the neutron code \"{\u0027agent_id\u0027: chosen_agent.id,\" in the bind_router function. Interesting....maybe some transaction was not properly set in neutron.db.l3_hamode_db.L3AgentSchedulerDbMixin:get_l3_agents or anywhere invoking that.","commit_id":"3f153b485ab7a6814358f01cec40db070b8b6a17"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"ba7850d2aa48dec2b777f8861d95ba1ec1ad14af","unresolved":false,"context_lines":[{"line_number":307,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":308,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":309,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":310,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":311,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":312,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"},{"line_number":313,"context_line":"                                        \u0027agent\u0027: agent.id})"}],"source_content_type":"text/x-python","patch_set":9,"id":"5aef4532_47adfd86","side":"PARENT","line":310,"updated":"2016-03-10 09:42:05.000000000","message":"Now we can simply reproduce that trace by adding a test case for this function, the result is here: http://paste.openstack.org/show/489965/, the trace is totally same as paste-488732. The rollback(DBDuplicateEntry) here will let the self.bind_router failed to process further. Do we need to add a new LP bug for that?","commit_id":"3f153b485ab7a6814358f01cec40db070b8b6a17"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"ab1d20653c99b31187e8c72d3df43cb6621bc138","unresolved":false,"context_lines":[{"line_number":307,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":308,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":309,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":310,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":311,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":312,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"},{"line_number":313,"context_line":"                                        \u0027agent\u0027: agent.id})"}],"source_content_type":"text/x-python","patch_set":9,"id":"5aef4532_7311da5c","side":"PARENT","line":310,"in_reply_to":"5aef4532_47adfd86","updated":"2016-03-10 11:22:12.000000000","message":"There is no need to add a new LP bug if it\u0027s described in the one already opened.\n\nAlso, can you please share the test code you used to reproduce the exception? If so, I\u0027ll add this to this patch (or whichever other patch I\u0027m working on that solves this).","commit_id":"3f153b485ab7a6814358f01cec40db070b8b6a17"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"f12d098a55648826b24e69ea36fa61195d104f8f","unresolved":false,"context_lines":[{"line_number":307,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":308,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":309,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":310,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":311,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":312,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"},{"line_number":313,"context_line":"                                        \u0027agent\u0027: agent.id})"}],"source_content_type":"text/x-python","patch_set":9,"id":"5aef4532_e7b8802c","side":"PARENT","line":310,"in_reply_to":"5aef4532_7311da5c","updated":"2016-03-10 12:12:07.000000000","message":"For now there is no test code for this function. And for reproducing the trace,  the test code is quite simple. Just try to run \"port_binding.l3_agent_id \u003d agent.id\" for one router in a same agent twice, there is no other patch do this test, only in my test env, here is my test case:\nneutron.tests.unit.scheduler.test_l3_agent_scheduler.L3AgentSchedulerDbMixinTestCase.test__bind_ha_router_to_agents\n\n+    def test__bind_ha_router_to_agents(self):\n+        agent \u003d self.plugin.get_agents_db(self.adminContext)[0]\n+        router \u003d self._create_ha_router()\n+        self.plugin.add_router_to_l3_agent(self.adminContext, agent.id,\n+                                           router[\u0027id\u0027])\n+        self.plugin.router_scheduler._bind_ha_router_to_agents(self.plugin,\n+                                       self.adminContext,\n+                                       router[\u0027id\u0027],\n+                                       [agent])","commit_id":"3f153b485ab7a6814358f01cec40db070b8b6a17"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"18e53ad3aa19b4b2a5042f83b2bb02a10c5f775f","unresolved":false,"context_lines":[{"line_number":307,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":308,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":309,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":310,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":311,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":312,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"},{"line_number":313,"context_line":"                                        \u0027agent\u0027: agent.id})"}],"source_content_type":"text/x-python","patch_set":9,"id":"5aef4532_87f7fcd1","side":"PARENT","line":310,"in_reply_to":"5aef4532_e7b8802c","updated":"2016-03-10 12:15:22.000000000","message":"And now we can ensure that the trace-488732 is really related to this bug 1550886. It\u0027s the get_router_ids rpc just do the \u0027bind_router\u0027 before the create_router(then schedule_router --\u003e create_ha_port_and_bind --\u003e bind_router).","commit_id":"3f153b485ab7a6814358f01cec40db070b8b6a17"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"4be7562c4cc9d49fbcad0b6ea9df9ee6d6bc02c8","unresolved":false,"context_lines":[{"line_number":221,"context_line":"        \"\"\"Bind the router to the l3 agent which has been chosen.\"\"\""},{"line_number":222,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":223,"context_line":"        try:"},{"line_number":224,"context_line":"            with db_api.autonested_transaction(context.session):"},{"line_number":225,"context_line":"                binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"},{"line_number":226,"context_line":"                binding.l3_agent \u003d chosen_agent"},{"line_number":227,"context_line":"                binding.router_id \u003d router_id"}],"source_content_type":"text/x-python","patch_set":9,"id":"fa0719c6_99bdb4da","line":224,"range":{"start_line":224,"start_character":12,"end_line":224,"end_character":64},"updated":"2016-03-24 07:36:41.000000000","message":"I think this will be still needed, as this will help to avoid http://paste.openstack.org/show/491548/","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"9cd43af113e5b225eb68978c59d7624755c8f272","unresolved":false,"context_lines":[{"line_number":221,"context_line":"        \"\"\"Bind the router to the l3 agent which has been chosen.\"\"\""},{"line_number":222,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":223,"context_line":"        try:"},{"line_number":224,"context_line":"            with db_api.autonested_transaction(context.session):"},{"line_number":225,"context_line":"                binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"},{"line_number":226,"context_line":"                binding.l3_agent \u003d chosen_agent"},{"line_number":227,"context_line":"                binding.router_id \u003d router_id"}],"source_content_type":"text/x-python","patch_set":9,"id":"fa0719c6_b946b878","line":224,"range":{"start_line":224,"start_character":12,"end_line":224,"end_character":64},"in_reply_to":"fa0719c6_99bdb4da","updated":"2016-03-24 07:48:43.000000000","message":"I agree. I will export it to another patch in the following days.","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"ae211cfa12816737c0987586ab6b1e1c3fef01e8","unresolved":false,"context_lines":[{"line_number":289,"context_line":"        \"\"\"Creates and binds a new HA port for this agent.\"\"\""},{"line_number":290,"context_line":"        ha_network \u003d plugin.get_ha_network(context, tenant_id)"},{"line_number":291,"context_line":"        if not ha_network:"},{"line_number":292,"context_line":"            ha_network \u003d self._create_ha_network(context, tenant_id)"},{"line_number":293,"context_line":""},{"line_number":294,"context_line":"        try:"},{"line_number":295,"context_line":"            port_binding \u003d plugin.add_ha_port(context.elevated(), router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"7af24918_7550ced4","line":292,"updated":"2016-03-03 10:21:41.000000000","message":"This was handled here:\nhttps://review.openstack.org/#/c/265682/15/neutron/scheduler/l3_agent_scheduler.py\n\nIMHO, just let it pass ASAP, and let the new HA router creation procedure to do the HA network creation.","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"6b1602949638e2090dd45a536e1575c9f7401052","unresolved":false,"context_lines":[{"line_number":289,"context_line":"        \"\"\"Creates and binds a new HA port for this agent.\"\"\""},{"line_number":290,"context_line":"        ha_network \u003d plugin.get_ha_network(context, tenant_id)"},{"line_number":291,"context_line":"        if not ha_network:"},{"line_number":292,"context_line":"            ha_network \u003d self._create_ha_network(context, tenant_id)"},{"line_number":293,"context_line":""},{"line_number":294,"context_line":"        try:"},{"line_number":295,"context_line":"            port_binding \u003d plugin.add_ha_port(context.elevated(), router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"7af24918_5faacb85","line":292,"in_reply_to":"7af24918_3ea1c546","updated":"2016-03-04 10:24:17.000000000","message":"Yes, as I told former, let it just pass(skip) the binding ASAP if no HA network, something like https://review.openstack.org/#/c/265682/16/neutron/scheduler/l3_agent_scheduler.py. Again for the change here, I\u0027d like to say we must not just solve one race and introduce another.","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"41760bed64eae12d98d3fe4e9be12111ea74f23b","unresolved":false,"context_lines":[{"line_number":289,"context_line":"        \"\"\"Creates and binds a new HA port for this agent.\"\"\""},{"line_number":290,"context_line":"        ha_network \u003d plugin.get_ha_network(context, tenant_id)"},{"line_number":291,"context_line":"        if not ha_network:"},{"line_number":292,"context_line":"            ha_network \u003d self._create_ha_network(context, tenant_id)"},{"line_number":293,"context_line":""},{"line_number":294,"context_line":"        try:"},{"line_number":295,"context_line":"            port_binding \u003d plugin.add_ha_port(context.elevated(), router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"7af24918_3ea1c546","line":292,"in_reply_to":"7af24918_4d3a29e8","updated":"2016-03-04 09:31:21.000000000","message":"May be the better way here is skip binding in case if ha_network is not created, because creating it here could increase possibility of races with it.","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"a736a2cc7faa5853a132030b1d2b062d1a2ad2e4","unresolved":false,"context_lines":[{"line_number":289,"context_line":"        \"\"\"Creates and binds a new HA port for this agent.\"\"\""},{"line_number":290,"context_line":"        ha_network \u003d plugin.get_ha_network(context, tenant_id)"},{"line_number":291,"context_line":"        if not ha_network:"},{"line_number":292,"context_line":"            ha_network \u003d self._create_ha_network(context, tenant_id)"},{"line_number":293,"context_line":""},{"line_number":294,"context_line":"        try:"},{"line_number":295,"context_line":"            port_binding \u003d plugin.add_ha_port(context.elevated(), router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"7af24918_91c28751","line":292,"in_reply_to":"7af24918_5faacb85","updated":"2016-03-04 10:34:24.000000000","message":"I agree - solving this race by creating a new one is no solution at all. I\u0027m working on a different solution for this problem so I\u0027m setting -Workflow in the meantime.","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"fce5bba3ecd566adf9901c3a610319ac067cd46e","unresolved":false,"context_lines":[{"line_number":289,"context_line":"        \"\"\"Creates and binds a new HA port for this agent.\"\"\""},{"line_number":290,"context_line":"        ha_network \u003d plugin.get_ha_network(context, tenant_id)"},{"line_number":291,"context_line":"        if not ha_network:"},{"line_number":292,"context_line":"            ha_network \u003d self._create_ha_network(context, tenant_id)"},{"line_number":293,"context_line":""},{"line_number":294,"context_line":"        try:"},{"line_number":295,"context_line":"            port_binding \u003d plugin.add_ha_port(context.elevated(), router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"7af24918_4d3a29e8","line":292,"in_reply_to":"7af24918_610e4c3c","updated":"2016-03-04 08:32:49.000000000","message":"I think we should not make a queue of changes here as current change is already in almost complete. Current change is extremely important for gate, Assaf mentioned that fullstack failure rate is around 60% and current change should address the main failure of the HA routers test. It is OK to fix things step by step, all things are connected, but these are separate issues.","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"4ed9395c7889b6c2480190970b361fb7331ecc20","unresolved":false,"context_lines":[{"line_number":289,"context_line":"        \"\"\"Creates and binds a new HA port for this agent.\"\"\""},{"line_number":290,"context_line":"        ha_network \u003d plugin.get_ha_network(context, tenant_id)"},{"line_number":291,"context_line":"        if not ha_network:"},{"line_number":292,"context_line":"            ha_network \u003d self._create_ha_network(context, tenant_id)"},{"line_number":293,"context_line":""},{"line_number":294,"context_line":"        try:"},{"line_number":295,"context_line":"            port_binding \u003d plugin.add_ha_port(context.elevated(), router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"7af24918_a67fcaa9","line":292,"in_reply_to":"7af24918_7550ced4","updated":"2016-03-03 11:20:57.000000000","message":"As per Kevin\u0027s reply on that patch, I\u0027m not sure it will get merged at all since it was handled in an already-merged patch (282876). Either way the behaviour there is not what I\u0027m looking for: my code doesn\u0027t treat \"ha_network \u003d\u003d None\" as an error - it tries to create it anyway, whereas your code just prints a warning (which I\u0027m not sure is the proper behaviour we want in this case since it might can just be created on its own..)","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"6fcaaae1998d242cfd200805664cbcf934594339","unresolved":false,"context_lines":[{"line_number":289,"context_line":"        \"\"\"Creates and binds a new HA port for this agent.\"\"\""},{"line_number":290,"context_line":"        ha_network \u003d plugin.get_ha_network(context, tenant_id)"},{"line_number":291,"context_line":"        if not ha_network:"},{"line_number":292,"context_line":"            ha_network \u003d self._create_ha_network(context, tenant_id)"},{"line_number":293,"context_line":""},{"line_number":294,"context_line":"        try:"},{"line_number":295,"context_line":"            port_binding \u003d plugin.add_ha_port(context.elevated(), router_id,"}],"source_content_type":"text/x-python","patch_set":9,"id":"7af24918_610e4c3c","line":292,"in_reply_to":"7af24918_a67fcaa9","updated":"2016-03-03 11:35:13.000000000","message":"As we discussed in IRC this race you handled here happened between L3 agent and a new HA router scheduler. If tenant has no HA network just let the HA-router-create-procedure to create it. If the L3 agent get_router_ids may also start a HA network may get  multiple HA networks per tenant as Kevin and Ann discussed in (282876), this may be racy for the HA network creation. It\u0027s better to let only one way(procedure) to create the shared resource. And besides, the patch 282876 is still WIP : ), also mine.","commit_id":"c8e0b3151039d8a97965e608acf0e0b8c87af77a"},{"author":{"_account_id":10267,"name":"venkata anil","email":"anilvenkata@redhat.com","username":"anil"},"change_message_id":"592c2f3ec2bf6e373a4adfd22b2fae5fad0fbd45","unresolved":false,"context_lines":[{"line_number":163,"context_line":"            # active any time"},{"line_number":164,"context_line":"            current_l3_agents \u003d plugin.get_l3_agents_hosting_routers("},{"line_number":165,"context_line":"                context, [sync_router[\u0027id\u0027]], admin_state_up\u003dTrue)"},{"line_number":166,"context_line":"            if not is_ha and current_l3_agents:"},{"line_number":167,"context_line":"                LOG.debug(\u0027Router %(router_id)s has already been hosted \u0027"},{"line_number":168,"context_line":"                          \u0027by L3 agent %(agent_id)s\u0027,"},{"line_number":169,"context_line":"                          {\u0027router_id\u0027: sync_router[\u0027id\u0027],"}],"source_content_type":"text/x-python","patch_set":10,"id":"ba0121b8_1e300656","line":166,"updated":"2016-03-29 10:48:59.000000000","message":"this could have been better :)\n\nif is_ha:\n   ...\n   ...\nelif current_l3_agents:\n   ...\n   ...","commit_id":"50209dd8e26e14c0cda9a9a0e46292a92926efe2"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"1596c6261fb493e6c902d696bc8243691423237f","unresolved":false,"context_lines":[{"line_number":163,"context_line":"            # active any time"},{"line_number":164,"context_line":"            current_l3_agents \u003d plugin.get_l3_agents_hosting_routers("},{"line_number":165,"context_line":"                context, [sync_router[\u0027id\u0027]], admin_state_up\u003dTrue)"},{"line_number":166,"context_line":"            if not is_ha and current_l3_agents:"},{"line_number":167,"context_line":"                LOG.debug(\u0027Router %(router_id)s has already been hosted \u0027"},{"line_number":168,"context_line":"                          \u0027by L3 agent %(agent_id)s\u0027,"},{"line_number":169,"context_line":"                          {\u0027router_id\u0027: sync_router[\u0027id\u0027],"}],"source_content_type":"text/x-python","patch_set":10,"id":"ba0121b8_7e9f8203","line":166,"in_reply_to":"ba0121b8_1e300656","updated":"2016-03-29 10:56:14.000000000","message":"Done","commit_id":"50209dd8e26e14c0cda9a9a0e46292a92926efe2"},{"author":{"_account_id":10267,"name":"venkata anil","email":"anilvenkata@redhat.com","username":"anil"},"change_message_id":"592c2f3ec2bf6e373a4adfd22b2fae5fad0fbd45","unresolved":false,"context_lines":[{"line_number":335,"context_line":"                # None and we\u0027ll know to skip the binding."},{"line_number":336,"context_line":"                if not self.bind_router(context, router_id, agent):"},{"line_number":337,"context_line":"                    continue"},{"line_number":338,"context_line":"                port_binding.l3_agent_id \u003d agent.id"},{"line_number":339,"context_line":""},{"line_number":340,"context_line":"            LOG.debug(\u0027HA Router %(router_id)s is scheduled to L3 agent \u0027"},{"line_number":341,"context_line":"                      \u0027%(agent_id)s)\u0027,"}],"source_content_type":"text/x-python","patch_set":10,"id":"ba0121b8_fec43241","line":338,"updated":"2016-03-29 10:48:59.000000000","message":"So we never get db_exc.DBDuplicateEntry for L338? i.e\nport_binding.l3_agent_id \u003d agent.id","commit_id":"50209dd8e26e14c0cda9a9a0e46292a92926efe2"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"1596c6261fb493e6c902d696bc8243691423237f","unresolved":false,"context_lines":[{"line_number":335,"context_line":"                # None and we\u0027ll know to skip the binding."},{"line_number":336,"context_line":"                if not self.bind_router(context, router_id, agent):"},{"line_number":337,"context_line":"                    continue"},{"line_number":338,"context_line":"                port_binding.l3_agent_id \u003d agent.id"},{"line_number":339,"context_line":""},{"line_number":340,"context_line":"            LOG.debug(\u0027HA Router %(router_id)s is scheduled to L3 agent \u0027"},{"line_number":341,"context_line":"                      \u0027%(agent_id)s)\u0027,"}],"source_content_type":"text/x-python","patch_set":10,"id":"ba0121b8_1e9ac614","line":338,"in_reply_to":"ba0121b8_fec43241","updated":"2016-03-29 10:56:14.000000000","message":"No. Such a collision will be detected by bind_router, which will raise DBDuplicateEntry and cause it to return None, which in turn will mean that this like will not execute at all.\n\nI\u0027ve added a comment to address this.","commit_id":"50209dd8e26e14c0cda9a9a0e46292a92926efe2"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"2e45b05b5d594fecc8ec299820d5012bd4b4b822","unresolved":false,"context_lines":[{"line_number":324,"context_line":"            try:"},{"line_number":325,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":326,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":327,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":328,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":329,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":330,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba0121b8_acaf867b","side":"PARENT","line":327,"range":{"start_line":327,"start_character":20,"end_line":327,"end_character":63},"updated":"2016-04-01 02:38:00.000000000","message":"For my test env, I just move this line out of this autonested_transaction and try-catch block. Then the DBDuplicateEntry here and bind_router will all make sense. What about this simple change?","commit_id":"7512d8aa26a945a695e889e0a97c6414cec6ac10"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"87dd9786e9216f92a58e2d034d5c1beb87dada2c","unresolved":false,"context_lines":[{"line_number":324,"context_line":"            try:"},{"line_number":325,"context_line":"                with db_api.autonested_transaction(context.session):"},{"line_number":326,"context_line":"                    port_binding.l3_agent_id \u003d agent.id"},{"line_number":327,"context_line":"                    self.bind_router(context, router_id, agent)"},{"line_number":328,"context_line":"            except db_exc.DBDuplicateEntry:"},{"line_number":329,"context_line":"                LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":330,"context_line":"                          \"%(agent)s\", {\u0027router\u0027: router_id,"}],"source_content_type":"text/x-python","patch_set":11,"id":"9a061dce_aa76123c","side":"PARENT","line":327,"range":{"start_line":327,"start_character":20,"end_line":327,"end_character":63},"in_reply_to":"ba0121b8_acaf867b","updated":"2016-04-04 12:51:24.000000000","message":"This will cause a race condition where if line 287 occurs concurrently, this will cause an exception while the current code suggestion won\u0027t.","commit_id":"7512d8aa26a945a695e889e0a97c6414cec6ac10"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"87dd9786e9216f92a58e2d034d5c1beb87dada2c","unresolved":false,"context_lines":[{"line_number":163,"context_line":"            # active any time"},{"line_number":164,"context_line":"            current_l3_agents \u003d plugin.get_l3_agents_hosting_routers("},{"line_number":165,"context_line":"                context, [sync_router[\u0027id\u0027]], admin_state_up\u003dTrue)"},{"line_number":166,"context_line":"            if is_ha:"},{"line_number":167,"context_line":"                if (self.max_ha_agents \u003e 0 and"},{"line_number":168,"context_line":"                    len(current_l3_agents) \u003e\u003d self.max_ha_agents):"},{"line_number":169,"context_line":"                    LOG.debug(\u0027HA router %s has already been hosted by the \u0027"}],"source_content_type":"text/x-python","patch_set":11,"id":"9a061dce_8a7eaeac","line":166,"range":{"start_line":166,"start_character":15,"end_line":166,"end_character":21},"updated":"2016-04-04 12:51:24.000000000","message":"This seems unrelated to the change (a leftover from previous revisions).","commit_id":"c5fdd2d5fa91290ec84a0a77496c7b5e1ecf5bd6"},{"author":{"_account_id":10267,"name":"venkata anil","email":"anilvenkata@redhat.com","username":"anil"},"change_message_id":"29966e3276e6a426402d2c69dd1c08823612c3da","unresolved":false,"context_lines":[{"line_number":325,"context_line":""},{"line_number":326,"context_line":"        return scheduled"},{"line_number":327,"context_line":""},{"line_number":328,"context_line":"    def _bind_ha_router_to_agents(self, plugin, context, router_id,"},{"line_number":329,"context_line":"                                 chosen_agents):"},{"line_number":330,"context_line":"        port_bindings \u003d plugin.get_ha_router_port_bindings(context,"},{"line_number":331,"context_line":"                                                           [router_id])"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba0121b8_4013c90d","line":328,"updated":"2016-04-03 16:27:14.000000000","message":"follow the same sequence in both create_ha_port_and_bind and _bind_ha_router_to_agents i.e\n1) first try binding in RouterL3AgentBinding\n2) if the above operation is success, then only try binding in L3HARouterAgentPortBinding\nThis way we can force synchronization between both code paths\n i.e the original create_router (invoked from the REST API) and from the L3 agent\u0027s get_router_ids/sync_routers.","commit_id":"c5fdd2d5fa91290ec84a0a77496c7b5e1ecf5bd6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"87dd9786e9216f92a58e2d034d5c1beb87dada2c","unresolved":false,"context_lines":[{"line_number":325,"context_line":""},{"line_number":326,"context_line":"        return scheduled"},{"line_number":327,"context_line":""},{"line_number":328,"context_line":"    def _bind_ha_router_to_agents(self, plugin, context, router_id,"},{"line_number":329,"context_line":"                                 chosen_agents):"},{"line_number":330,"context_line":"        port_bindings \u003d plugin.get_ha_router_port_bindings(context,"},{"line_number":331,"context_line":"                                                           [router_id])"}],"source_content_type":"text/x-python","patch_set":11,"id":"9a061dce_6a26ba17","line":328,"in_reply_to":"9a061dce_340c2994","updated":"2016-04-04 12:51:24.000000000","message":"The code suggestion requires some changes to create_object_with_dependency so this can be left to some future patch instead.","commit_id":"c5fdd2d5fa91290ec84a0a77496c7b5e1ecf5bd6"},{"author":{"_account_id":10267,"name":"venkata anil","email":"anilvenkata@redhat.com","username":"anil"},"change_message_id":"48286f592e24bae9b45428f67b5b68d8d043fb1f","unresolved":false,"context_lines":[{"line_number":325,"context_line":""},{"line_number":326,"context_line":"        return scheduled"},{"line_number":327,"context_line":""},{"line_number":328,"context_line":"    def _bind_ha_router_to_agents(self, plugin, context, router_id,"},{"line_number":329,"context_line":"                                 chosen_agents):"},{"line_number":330,"context_line":"        port_bindings \u003d plugin.get_ha_router_port_bindings(context,"},{"line_number":331,"context_line":"                                                           [router_id])"}],"source_content_type":"text/x-python","patch_set":11,"id":"9a061dce_340c2994","line":328,"in_reply_to":"ba0121b8_4013c90d","updated":"2016-04-04 11:49:33.000000000","message":"i.e something like\n        try:\n            port_binding \u003d utils.create_object_with_dependency(\n                creator, dep_getter, dep_creator, dep_id_attr)[0]\n            if not self.bind_router(context, router_id, agent):\n                    continue\n            with db_api.autonested_transaction(context.session):\n                port_binding.l3_agent_id \u003d agent[\u0027id\u0027]\n\nin create_ha_port_and_bind()","commit_id":"c5fdd2d5fa91290ec84a0a77496c7b5e1ecf5bd6"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"87dd9786e9216f92a58e2d034d5c1beb87dada2c","unresolved":false,"context_lines":[{"line_number":335,"context_line":"                # None and we\u0027ll know to skip the binding."},{"line_number":336,"context_line":"                if not self.bind_router(context, router_id, agent):"},{"line_number":337,"context_line":"                    continue"},{"line_number":338,"context_line":"                # This can\u0027t raise DBDuplicateEntry because such a race"},{"line_number":339,"context_line":"                # condition will be caught by self.bind_router() above. Since"},{"line_number":340,"context_line":"                # it will return None in case such a race is detected, this is"},{"line_number":341,"context_line":"                # safe."}],"source_content_type":"text/x-python","patch_set":11,"id":"9a061dce_4ad816f0","line":338,"range":{"start_line":338,"start_character":16,"end_line":338,"end_character":51},"updated":"2016-04-04 12:51:24.000000000","message":"Following my conversation with Anil, this comment is completely wrong. Another example of race conditions we keep finding...","commit_id":"c5fdd2d5fa91290ec84a0a77496c7b5e1ecf5bd6"},{"author":{"_account_id":10267,"name":"venkata anil","email":"anilvenkata@redhat.com","username":"anil"},"change_message_id":"29966e3276e6a426402d2c69dd1c08823612c3da","unresolved":false,"context_lines":[{"line_number":339,"context_line":"                # condition will be caught by self.bind_router() above. Since"},{"line_number":340,"context_line":"                # it will return None in case such a race is detected, this is"},{"line_number":341,"context_line":"                # safe."},{"line_number":342,"context_line":"                port_binding.l3_agent_id \u003d agent.id"},{"line_number":343,"context_line":""},{"line_number":344,"context_line":"            LOG.debug(\u0027HA Router %(router_id)s is scheduled to L3 agent \u0027"},{"line_number":345,"context_line":"                      \u0027%(agent_id)s)\u0027,"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba0121b8_60fd2d6e","line":342,"updated":"2016-04-03 16:27:14.000000000","message":"Also free up unused ports here it self instead of in _delete_ha_interfaces during router_delete. But this is a sepearate patch and not a suggestion for this patch.","commit_id":"c5fdd2d5fa91290ec84a0a77496c7b5e1ecf5bd6"},{"author":{"_account_id":10267,"name":"venkata anil","email":"anilvenkata@redhat.com","username":"anil"},"change_message_id":"0ca6cec4fbe1c143f333cfa2124a9715738cff4e","unresolved":false,"context_lines":[{"line_number":284,"context_line":"                creator, dep_getter, dep_creator, dep_id_attr)[0]"},{"line_number":285,"context_line":"            with db_api.autonested_transaction(context.session):"},{"line_number":286,"context_line":"                port_binding.l3_agent_id \u003d agent[\u0027id\u0027]"},{"line_number":287,"context_line":"        except db_exc.DBDuplicateEntry:"},{"line_number":288,"context_line":"            LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":289,"context_line":"                      \"%(agent)s\", {\u0027router\u0027: router_id, \u0027agent\u0027: agent[\u0027id\u0027]})"},{"line_number":290,"context_line":"        except l3.RouterNotFound:"}],"source_content_type":"text/x-python","patch_set":12,"id":"9a061dce_fcd8c11f","line":287,"updated":"2016-04-04 18:11:49.000000000","message":"I think you can remove db_exc.DBDuplicateEntry","commit_id":"13a62b6d91c79e1b28c08e0d0a2984b4003b7c40"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"a7fceab77fc1abcf5411d4ef4e60dd2c0f182d3d","unresolved":false,"context_lines":[{"line_number":284,"context_line":"                creator, dep_getter, dep_creator, dep_id_attr)[0]"},{"line_number":285,"context_line":"            with db_api.autonested_transaction(context.session):"},{"line_number":286,"context_line":"                port_binding.l3_agent_id \u003d agent[\u0027id\u0027]"},{"line_number":287,"context_line":"        except db_exc.DBDuplicateEntry:"},{"line_number":288,"context_line":"            LOG.debug(\"Router %(router)s already scheduled for agent \""},{"line_number":289,"context_line":"                      \"%(agent)s\", {\u0027router\u0027: router_id, \u0027agent\u0027: agent[\u0027id\u0027]})"},{"line_number":290,"context_line":"        except l3.RouterNotFound:"}],"source_content_type":"text/x-python","patch_set":12,"id":"9a061dce_1c96f13e","line":287,"in_reply_to":"9a061dce_fcd8c11f","updated":"2016-04-06 11:41:56.000000000","message":"Pretty sure line 286 still can raise DBDuplicateEntry (but have not checked). I\u0027ll check this if there\u0027s a new patchset and if it\u0027s not needed I\u0027ll remove this.","commit_id":"13a62b6d91c79e1b28c08e0d0a2984b4003b7c40"},{"author":{"_account_id":10267,"name":"venkata anil","email":"anilvenkata@redhat.com","username":"anil"},"change_message_id":"c6cbf43454e2495172475333bde157c00bee2976","unresolved":false,"context_lines":[{"line_number":323,"context_line":""},{"line_number":324,"context_line":"    def _bind_ha_router_to_agents(self, plugin, context, router_id,"},{"line_number":325,"context_line":"                                 chosen_agents):"},{"line_number":326,"context_line":"        port_bindings \u003d plugin.get_ha_router_port_bindings(context,"},{"line_number":327,"context_line":"                                                           [router_id])"},{"line_number":328,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":329,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"}],"source_content_type":"text/x-python","patch_set":12,"id":"9a061dce_bc25a4c3","line":326,"updated":"2016-04-04 20:06:54.000000000","message":"get_ha_router_port_bindings returns all ports with matching router_id. If agent\u0027s rpc worker already created port bindings, then we can have entries like this\nport1, router1,\nport2, router1\nport3, router1\nport4, router1, agent8\nHere port1 to port4 are created by api worker and port4 by rpc worker.\nIf last created port always comes at the end in the query then we dont have any problem. Otherwise, in above example, at L328 if we get port4(which already bound to a agent), we may overriding that with new agent at L338.  \ni.e\nport4, router1, agent8\nwill be replaced by\nport4, router1, agent1   (new agent)","commit_id":"13a62b6d91c79e1b28c08e0d0a2984b4003b7c40"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"a7fceab77fc1abcf5411d4ef4e60dd2c0f182d3d","unresolved":false,"context_lines":[{"line_number":323,"context_line":""},{"line_number":324,"context_line":"    def _bind_ha_router_to_agents(self, plugin, context, router_id,"},{"line_number":325,"context_line":"                                 chosen_agents):"},{"line_number":326,"context_line":"        port_bindings \u003d plugin.get_ha_router_port_bindings(context,"},{"line_number":327,"context_line":"                                                           [router_id])"},{"line_number":328,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":329,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"}],"source_content_type":"text/x-python","patch_set":12,"id":"9a061dce_7c33ad62","line":326,"in_reply_to":"9a061dce_a5d732ec","updated":"2016-04-06 11:41:56.000000000","message":"Your analysis is correct, but it\u0027s not something I wish to deal with in this patch,\n\nEither way, lets see if the ALLOCATING patch goes through and if it does this is not needed.","commit_id":"13a62b6d91c79e1b28c08e0d0a2984b4003b7c40"},{"author":{"_account_id":10267,"name":"venkata anil","email":"anilvenkata@redhat.com","username":"anil"},"change_message_id":"0793ff222154341b08326047a7eee38ae38920df","unresolved":false,"context_lines":[{"line_number":323,"context_line":""},{"line_number":324,"context_line":"    def _bind_ha_router_to_agents(self, plugin, context, router_id,"},{"line_number":325,"context_line":"                                 chosen_agents):"},{"line_number":326,"context_line":"        port_bindings \u003d plugin.get_ha_router_port_bindings(context,"},{"line_number":327,"context_line":"                                                           [router_id])"},{"line_number":328,"context_line":"        for port_binding, agent in zip(port_bindings, chosen_agents):"},{"line_number":329,"context_line":"            with context.session.begin(subtransactions\u003dTrue):"}],"source_content_type":"text/x-python","patch_set":12,"id":"9a061dce_a5d732ec","line":326,"in_reply_to":"9a061dce_bc25a4c3","updated":"2016-04-05 10:12:22.000000000","message":"use ports with no l3 agent bindings\n\nport_bindings \u003d [binding for binding in plugin.get_ha_router_port_bindings(context, [router_id])\n                 if binding.l3_agent_id is None]\n for port_binding, agent in zip(port_bindings, chosen_agents):\n    with context.session.begin(subtransactions\u003dTrue):","commit_id":"13a62b6d91c79e1b28c08e0d0a2984b4003b7c40"},{"author":{"_account_id":19999,"name":"Trinath Somanchi","email":"trinaths.dev@gmail.com","username":"trinath-somanchi"},"change_message_id":"2a9890c6be64fc82b1942eed276c53999d806778","unresolved":false,"context_lines":[{"line_number":200,"context_line":""},{"line_number":201,"context_line":"    def bind_router(self, context, router_id, chosen_agent):"},{"line_number":202,"context_line":"        \"\"\"Bind the router to the l3 agent which has been chosen.\"\"\""},{"line_number":203,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":204,"context_line":"        try:"},{"line_number":205,"context_line":"            with db_api.autonested_transaction(context.session):"},{"line_number":206,"context_line":"                binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"}],"source_content_type":"text/x-python","patch_set":15,"id":"bacf61ea_4250af5d","line":203,"range":{"start_line":203,"start_character":8,"end_line":203,"end_character":41},"updated":"2016-07-29 09:25:58.000000000","message":"chosen_agent.id can be directly be used. will this assignment be any thing special?","commit_id":"af6d3f65d0f51a0ead4e4a67f8ffc25e24b7a70f"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"efceb70dc4af298f9a9141509d54f77243cf465c","unresolved":false,"context_lines":[{"line_number":200,"context_line":""},{"line_number":201,"context_line":"    def bind_router(self, context, router_id, chosen_agent):"},{"line_number":202,"context_line":"        \"\"\"Bind the router to the l3 agent which has been chosen.\"\"\""},{"line_number":203,"context_line":"        chosen_agent_id \u003d chosen_agent.id"},{"line_number":204,"context_line":"        try:"},{"line_number":205,"context_line":"            with db_api.autonested_transaction(context.session):"},{"line_number":206,"context_line":"                binding \u003d l3_agentschedulers_db.RouterL3AgentBinding()"}],"source_content_type":"text/x-python","patch_set":15,"id":"bacf61ea_fd4064a7","line":203,"range":{"start_line":203,"start_character":8,"end_line":203,"end_character":41},"in_reply_to":"bacf61ea_4250af5d","updated":"2016-07-29 09:44:59.000000000","message":"chosen_agent.id can\u0027t be used, since trying to get that field triggers a SELECT query, which might trigger a StaleDataError in case the data has been concurrently modified. It might work for line 207 but line 213 must have the pre-cached value (otherwise DBDuplicateEntry will always trigger StaleDataError, as the commit/bug describes). So we might as well use the cached value everywhere for consistency.","commit_id":"af6d3f65d0f51a0ead4e4a67f8ffc25e24b7a70f"}],"neutron/tests/unit/scheduler/test_l3_agent_scheduler.py":[{"author":{"_account_id":7249,"name":"Ann Taraday","email":"akamyshnikova@mirantis.com","username":"AKamyshnikova"},"change_message_id":"f86a0b45e6e701e29b3d3d1bed3e466d274adefc","unresolved":false,"context_lines":[{"line_number":1340,"context_line":"        cfg.CONF.set_override(\u0027max_l3_agents_per_router\u0027, 3)"},{"line_number":1341,"context_line":"        with mock.patch.object(l3_agentschedulers_db.L3AgentSchedulerDbMixin,"},{"line_number":1342,"context_line":"                               \u0027get_l3_agents_hosting_routers\u0027,"},{"line_number":1343,"context_line":"                               side_effect\u003dside_effect):"},{"line_number":1344,"context_line":"            router \u003d self._create_ha_router()"},{"line_number":1345,"context_line":""},{"line_number":1346,"context_line":"        result \u003d self.plugin.get_ha_routers_l3_agents_count(self.adminContext)"}],"source_content_type":"text/x-python","patch_set":6,"id":"7af24918_20193b89","line":1343,"range":{"start_line":1343,"start_character":31,"end_line":1343,"end_character":54},"updated":"2016-03-02 09:07:00.000000000","message":"why not just return_value\u003d[self.agent1]?","commit_id":"5d5cbea99038e912fdd5d9374bba377abeddb857"},{"author":{"_account_id":12444,"name":"John Schwarz","email":"jschwarz@redhat.com","username":"jschwarz"},"change_message_id":"ce059dfba82052e0f66a22b91bf1a991afa0138d","unresolved":false,"context_lines":[{"line_number":1340,"context_line":"        cfg.CONF.set_override(\u0027max_l3_agents_per_router\u0027, 3)"},{"line_number":1341,"context_line":"        with mock.patch.object(l3_agentschedulers_db.L3AgentSchedulerDbMixin,"},{"line_number":1342,"context_line":"                               \u0027get_l3_agents_hosting_routers\u0027,"},{"line_number":1343,"context_line":"                               side_effect\u003dside_effect):"},{"line_number":1344,"context_line":"            router \u003d self._create_ha_router()"},{"line_number":1345,"context_line":""},{"line_number":1346,"context_line":"        result \u003d self.plugin.get_ha_routers_l3_agents_count(self.adminContext)"}],"source_content_type":"text/x-python","patch_set":6,"id":"7af24918_c14deb9a","line":1343,"range":{"start_line":1343,"start_character":31,"end_line":1343,"end_character":54},"in_reply_to":"7af24918_20193b89","updated":"2016-03-02 13:37:11.000000000","message":"Done","commit_id":"5d5cbea99038e912fdd5d9374bba377abeddb857"}]}
