)]}'
{"neutron/agent/l3/ha_router.py":[{"author":{"_account_id":8873,"name":"Assaf Muller","email":"amuller@redhat.com","username":"amuller"},"change_message_id":"11e4baea350deabf1e7b6e92b3d27871dd299d5c","unresolved":false,"context_lines":[{"line_number":363,"context_line":"        if self.ha_port:"},{"line_number":364,"context_line":"            self.enable_keepalived()"},{"line_number":365,"context_line":""},{"line_number":366,"context_line":"    @common_utils.synchronized(\u0027l3-agent\u0027)"},{"line_number":367,"context_line":"    def enable_radvd(self, internal_ports\u003dNone):"},{"line_number":368,"context_line":"        if (self.keepalived_manager.get_process().active and"},{"line_number":369,"context_line":"                self.ha_state \u003d\u003d \u0027master\u0027):"}],"source_content_type":"text/x-python","patch_set":2,"id":"3a50d1a3_043cc8c6","line":366,"updated":"2015-07-21 17:54:24.000000000","message":"Let\u0027s just change the lock name to something like \u0027enable_radvd\u0027 so that if someone adds a lock with the name \u0027l3-agent\u0027 later we won\u0027t get very confusing issues. Other than that this LGTM.","commit_id":"0ec43796c7ee545c78767f5214ab2ae5ada4ff83"},{"author":{"_account_id":10257,"name":"Sridhar Gaddam","email":"sgaddam@redhat.com","username":"sridhargaddam"},"change_message_id":"861ef843175c719458b21ae1a48a41febd4310b7","unresolved":false,"context_lines":[{"line_number":363,"context_line":"        if self.ha_port:"},{"line_number":364,"context_line":"            self.enable_keepalived()"},{"line_number":365,"context_line":""},{"line_number":366,"context_line":"    @common_utils.synchronized(\u0027l3-agent\u0027)"},{"line_number":367,"context_line":"    def enable_radvd(self, internal_ports\u003dNone):"},{"line_number":368,"context_line":"        if (self.keepalived_manager.get_process().active and"},{"line_number":369,"context_line":"                self.ha_state \u003d\u003d \u0027master\u0027):"}],"source_content_type":"text/x-python","patch_set":2,"id":"3a50d1a3_c491009b","line":366,"in_reply_to":"3a50d1a3_043cc8c6","updated":"2015-07-21 17:57:21.000000000","message":"Sure, thanks.","commit_id":"0ec43796c7ee545c78767f5214ab2ae5ada4ff83"}],"neutron/tests/functional/agent/test_l3_agent.py":[{"author":{"_account_id":8873,"name":"Assaf Muller","email":"amuller@redhat.com","username":"amuller"},"change_message_id":"fc1cabde2f1d1fd25defa42fe273b4d7afa86cbf","unresolved":false,"context_lines":[{"line_number":801,"context_line":"                ip_version\u003d6, ipv6_subnet_modes\u003d[slaac_mode],"},{"line_number":802,"context_line":"                interface_id\u003dinterface_id)"},{"line_number":803,"context_line":"        router.process(self.agent)"},{"line_number":804,"context_line":"        utils.wait_until_true(lambda: router.ha_state \u003d\u003d \u0027master\u0027)"},{"line_number":805,"context_line":"        utils.wait_until_true(lambda: router.radvd.enabled)"},{"line_number":806,"context_line":""},{"line_number":807,"context_line":"        # Verify that router internal interface is present and is configured"}],"source_content_type":"text/x-python","patch_set":1,"id":"fa32b979_b67c39ec","line":804,"updated":"2015-06-23 03:30:53.000000000","message":"The issue with this approach is that additional ipv6 l3 agent functional tests can forget to do this and run in to cryptic issues later on. I was thinking... The keepalived_state_change process currently writes the new status first, then notifies the agent. We could just notify the agent and have it write the new status as the *last* thing it does in a try/finally block. But, this means that the agent has to be up in order for the status file to be updated. That file is used twice, once in _should_delete_ipv6_lladdr, and once in enable_radvd. I suppose the only issue is if the L3 agent agent was down during a transition and so the file would not be updated, but the agent syncs up and writes the current state anyhow when it starts. It\u0027s late, I\u0027m rambling and I might be missing an issue. Thoughts are welcome.","commit_id":"8c81a15120b74b0fc98d8698b7fb3c56f475d45b"},{"author":{"_account_id":10257,"name":"Sridhar Gaddam","email":"sgaddam@redhat.com","username":"sridhargaddam"},"change_message_id":"07d62f0e5e85f3b068a370a206c98a8a2e9d748c","unresolved":false,"context_lines":[{"line_number":801,"context_line":"                ip_version\u003d6, ipv6_subnet_modes\u003d[slaac_mode],"},{"line_number":802,"context_line":"                interface_id\u003dinterface_id)"},{"line_number":803,"context_line":"        router.process(self.agent)"},{"line_number":804,"context_line":"        utils.wait_until_true(lambda: router.ha_state \u003d\u003d \u0027master\u0027)"},{"line_number":805,"context_line":"        utils.wait_until_true(lambda: router.radvd.enabled)"},{"line_number":806,"context_line":""},{"line_number":807,"context_line":"        # Verify that router internal interface is present and is configured"}],"source_content_type":"text/x-python","patch_set":1,"id":"3a50d1a3_020e5c34","line":804,"in_reply_to":"9a41bdd9_158f2d24","updated":"2015-07-20 06:33:37.000000000","message":"Background:\nI was not able to reproduce this issue locally inspite of running the functional test multiple times. \nI worked for a good amount of time in L3 HA setup but have not seen this issue so far in my setup. \n\nComing back to the actual problem: \nBased on the error logs, I share the same opinion as what @Assaf expressed in steps (1 to 4) above. \n\nSince the test-code is running outside the green thread (i.e., router.process) but keepalived \nnotification handler was part of green thread, which is slightly different to production where \nboth of them happen in the green thread context, I felt that test-case fix could be sufficient. \nHowever, I only have some basic understanding of eventlets and not fully familiar with the internals. \nLooking at the explanation provided by @Assaf and @Kevin, it makes sense to use locking\nin the actual code instead of the test-case.\n\n@Assaf, IMO an external lock is not required as we need to sync\u0027 the calls to enable_radvd() between \nthreads in the \"same\" process and not across two different processes. Please let me know if you have a different view.\n\nThanks @Assaf and @Kevin for your review comments. I\u0027ll update the patch accordingly with a simple lock.","commit_id":"8c81a15120b74b0fc98d8698b7fb3c56f475d45b"},{"author":{"_account_id":10257,"name":"Sridhar Gaddam","email":"sgaddam@redhat.com","username":"sridhargaddam"},"change_message_id":"c649344da7aabb4f3a16e9965f8accf91c1d3623","unresolved":false,"context_lines":[{"line_number":801,"context_line":"                ip_version\u003d6, ipv6_subnet_modes\u003d[slaac_mode],"},{"line_number":802,"context_line":"                interface_id\u003dinterface_id)"},{"line_number":803,"context_line":"        router.process(self.agent)"},{"line_number":804,"context_line":"        utils.wait_until_true(lambda: router.ha_state \u003d\u003d \u0027master\u0027)"},{"line_number":805,"context_line":"        utils.wait_until_true(lambda: router.radvd.enabled)"},{"line_number":806,"context_line":""},{"line_number":807,"context_line":"        # Verify that router internal interface is present and is configured"}],"source_content_type":"text/x-python","patch_set":1,"id":"9a41bdd9_b9945ce8","line":804,"in_reply_to":"9a41bdd9_559d8cba","updated":"2015-07-17 13:34:01.000000000","message":"I had a close look at the code again. In a normal flow, the calling context of enable_radvd() would be via one of the following contexts.\n\n1. Triggered via _process_router_update()\n                   -\u003e_process_router_if_compatible()\n                        -\u003e_process_updated_router()\n                             -\u003eri.process()\n                                 -\u003e_process_internal_ports()\n                                      -\u003eenable_radvd()\n2. Triggered via _start_keepalived_notifications_server()\n                   -\u003eL3AgentKeepalivedStateChangeServer()\n                      -\u003eKeepalivedStateChangeHandler()\n                          -\u003eenqueue_state_change()\n                              -\u003e_update_radvd_daemon()\n                                   -\u003eenable_radvd()\n\nBoth 1 and 2 are eventlet green threads, so AFAIU it may not be an issue with the actual agent code.\n\nHowever, in this functional test-case we are manually calling ri.process (L824), so there could be a likelihood for the race condition as @Salvatore as pointed out. \n\nI\u0027m not an expert in the way eventlet green threads work, so I would like to hear @Assaf\u0027s expert views on this. Thanks.","commit_id":"8c81a15120b74b0fc98d8698b7fb3c56f475d45b"},{"author":{"_account_id":7787,"name":"Kevin Benton","email":"kevin@benton.pub","username":"blak111"},"change_message_id":"42b1f650dac278b6cdc10a4bd5b2388127a1b3b7","unresolved":false,"context_lines":[{"line_number":801,"context_line":"                ip_version\u003d6, ipv6_subnet_modes\u003d[slaac_mode],"},{"line_number":802,"context_line":"                interface_id\u003dinterface_id)"},{"line_number":803,"context_line":"        router.process(self.agent)"},{"line_number":804,"context_line":"        utils.wait_until_true(lambda: router.ha_state \u003d\u003d \u0027master\u0027)"},{"line_number":805,"context_line":"        utils.wait_until_true(lambda: router.radvd.enabled)"},{"line_number":806,"context_line":""},{"line_number":807,"context_line":"        # Verify that router internal interface is present and is configured"}],"source_content_type":"text/x-python","patch_set":1,"id":"9a41bdd9_158f2d24","line":804,"in_reply_to":"9a41bdd9_b6e77911","updated":"2015-07-18 06:58:10.000000000","message":"Yeah, this sounds correct. You have to assume eventlet will yield on every IO/sys call like that. A simple lock should work to make sure they both don\u0027t happen at the same time.","commit_id":"8c81a15120b74b0fc98d8698b7fb3c56f475d45b"},{"author":{"_account_id":8873,"name":"Assaf Muller","email":"amuller@redhat.com","username":"amuller"},"change_message_id":"7472b0a58db51c39440f054602d88f5474a2fac1","unresolved":false,"context_lines":[{"line_number":801,"context_line":"                ip_version\u003d6, ipv6_subnet_modes\u003d[slaac_mode],"},{"line_number":802,"context_line":"                interface_id\u003dinterface_id)"},{"line_number":803,"context_line":"        router.process(self.agent)"},{"line_number":804,"context_line":"        utils.wait_until_true(lambda: router.ha_state \u003d\u003d \u0027master\u0027)"},{"line_number":805,"context_line":"        utils.wait_until_true(lambda: router.radvd.enabled)"},{"line_number":806,"context_line":""},{"line_number":807,"context_line":"        # Verify that router internal interface is present and is configured"}],"source_content_type":"text/x-python","patch_set":1,"id":"9a41bdd9_b6e77911","line":804,"in_reply_to":"9a41bdd9_b9945ce8","updated":"2015-07-17 19:18:58.000000000","message":"Even with this change, isn\u0027t there a race between the keepalived_state_change_monitor and the process on line 803? (The failures I\u0027ve seen are a result of line 824, which this would fix, but still). You could also move the wait_until_true to line 788 which I think would be a more robust fix.\n\nThat being said, I think that this test exposes a race in the actual code, and not a test-only issue. A single HA router creation cannot race with it transitioning to master. However, creating an HA router, then sending an update (Say, adding an additional interface) could.\n\n1) Create HA router\n\n2) radvd is not enabled during the creation because the router is not master\n\nSteps 3 and 4 happen at the same time:\n\n3) Add an interface to the router (This is processed immediately as the router creation update has already finished). In the mean time the router transitions to master, keepalived-state-change writes the state \u0027master\u0027 to the state file. When the update code checks if radvd if the router is master it sees yes (Because the file has been updated), and tries to enable radvd.\n\n4) The router transitions to master, enabling radvd\n\nIs this correct? If so the code itself needs to be fixed, and this test should not be touched.\n\nI don\u0027t think that eventlet here is providing some sort of implicit locking. Is this test code different than production code in that sense? Here, the test code is running outside of a green thread, but the keepalived notification handler is, and we see that two parallel invocations of external_process.active are raceful. Is this different than production code where both the router update and the keepalived notification handling would occur in green threads? I don\u0027t think so but I am not intimately familiar with eventlet implementation details.\n\nPrepare for some hand waving:\nProcessManager.enable could yield perhaps after os.open (Which is patched by eventlet), or later during get_pid_file_name which can call os.makedirs, or on subprocess.Popen.communicate (Which eventlet does yield on). I think it\u0027s possible for example to eventlet call subprocess.Popen, yield on communicate, but radvd will still not write its pid file, then the second eventlet thread comes in and checks if the process is active by opening the pid file, but it\u0027s not there yet, so it tries to enable radvd as well.\n\nIn summation, I think that solving the race in the production code itself is a better idea. We could place an external Oslo lock on enable_radvd and be done with it.","commit_id":"8c81a15120b74b0fc98d8698b7fb3c56f475d45b"},{"author":{"_account_id":261,"name":"Salvatore Orlando","email":"salv.orlando@gmail.com","username":"salvatore-orlando"},"change_message_id":"637cdff7cffda27d2e9115552e36a0ae9b193416","unresolved":false,"context_lines":[{"line_number":801,"context_line":"                ip_version\u003d6, ipv6_subnet_modes\u003d[slaac_mode],"},{"line_number":802,"context_line":"                interface_id\u003dinterface_id)"},{"line_number":803,"context_line":"        router.process(self.agent)"},{"line_number":804,"context_line":"        utils.wait_until_true(lambda: router.ha_state \u003d\u003d \u0027master\u0027)"},{"line_number":805,"context_line":"        utils.wait_until_true(lambda: router.radvd.enabled)"},{"line_number":806,"context_line":""},{"line_number":807,"context_line":"        # Verify that router internal interface is present and is configured"}],"source_content_type":"text/x-python","patch_set":1,"id":"9a41bdd9_559d8cba","line":804,"in_reply_to":"fa32b979_72c0e850","updated":"2015-07-14 14:19:46.000000000","message":"As you point out in step 6, this is probably highlighting something which is not right in the design of the test. The test appears to be dictating a behaviour which is incorrect - enablidng radvd twice, which is not the behaviour of the agent.\n\nOn the other hand, if this behaviour is entirely possible, then the agent should be idempotent and not fail is enable_radvd is called a second time when it\u0027s already enabled.","commit_id":"8c81a15120b74b0fc98d8698b7fb3c56f475d45b"},{"author":{"_account_id":10257,"name":"Sridhar Gaddam","email":"sgaddam@redhat.com","username":"sridhargaddam"},"change_message_id":"3ccb395757f104bf4eb942f14708d72b15ca2d20","unresolved":false,"context_lines":[{"line_number":801,"context_line":"                ip_version\u003d6, ipv6_subnet_modes\u003d[slaac_mode],"},{"line_number":802,"context_line":"                interface_id\u003dinterface_id)"},{"line_number":803,"context_line":"        router.process(self.agent)"},{"line_number":804,"context_line":"        utils.wait_until_true(lambda: router.ha_state \u003d\u003d \u0027master\u0027)"},{"line_number":805,"context_line":"        utils.wait_until_true(lambda: router.radvd.enabled)"},{"line_number":806,"context_line":""},{"line_number":807,"context_line":"        # Verify that router internal interface is present and is configured"}],"source_content_type":"text/x-python","patch_set":1,"id":"fa32b979_72c0e850","line":804,"in_reply_to":"fa32b979_b67c39ec","updated":"2015-06-23 12:42:45.000000000","message":"@Assaf, the issue here is a possible race condition when we are spawning \nradvd in the router namespace when a previous instance of radvd is \"just\"\nbecomes active. \n\nI\u0027ll explain the scenario as per my understanding. \n1. In this test-case, we are creating an HA Router with some IPv6 subnets. \n2. We are waiting for the HA router to become Master (L804).\n3. When router becomes Master, keepalived-state-change-monitor informs the L3 agent about the new state which is \"Master\".\n4. As you know, L3 agent would invoke enable_radvd.\n5. In parallel (i.e., steps 2 to 4) are happening, the test-case proceeds further, updates the subnets on the network and invokes router.process() L824\n6. During router.process, L3 agent would call enable_radvd [1]. So, enable_radvd is invoked in Step4 and here.\n7. If we dig a bit into enable_radvd api, the call goes all the way until external_process.enable [2].\n8. In [2], we check if the radvd process is active or not. If active, we simply reload the config otherwise we spawn the radvd process. \n9. I\u0027m suspecting that there is a race condition here. We are trying to spawn radvd again when the previous instance \"just\" got active.\n10. radvd exits with an error code of 1 when we do that. Because of this, ip_wrapper.netns.execute code is tracing out [3].\n11. One other fix to this problem is to invoke pm.enable(reload_cfg\u003dTrue, \"extra_ok_codes\u003d1\") in _spawn_radvd of ra.py. \n    But the issue in this approach is there could be other cases when radvd could fail with error code 1 and they could be masked out. \n\nYour thoughts?\n\n[1] - https://github.com/openstack/neutron/blob/master/neutron/agent/l3/router_info.py#L399\n[2] - https://github.com/openstack/neutron/blob/master/neutron/agent/linux/external_process.py#L84\n[3] - http://logs.openstack.org/50/194550/1/check/check-neutron-dsvm-functional/69c15c5/console.html#_2015-06-23_08_59_37_143","commit_id":"8c81a15120b74b0fc98d8698b7fb3c56f475d45b"}]}
