{"action":"created","comment":{"url":"https://api.github.com/repos/Metaswitch/calico/pulls/comments/28880343","id":28880343,"diff_hunk":"@@ -289,13 +289,30 @@ def __init__(self, tag, ip_type):\n         # Members which really are in the ipset.\n         self.programmed_members = None\n \n-        # Do the sets exist?\n-        self.set_exists = ipset_exists(self.name)\n-        self.tmpset_exists = ipset_exists(self.tmpname)\n+        # Do the sets exist? We don't know yet.\n+        self.set_exists = None\n+        self.tmpset_exists = None\n \n         # Notified ready?\n         self.notified_ready = False\n \n+    def _set_exists(self, real):\n+        \"\"\"\n+        Returns whether the set exists. We only check once and remember, but\n+        must not do so until the greenlet is running (in case another greenlet\n+        for this ipset is still working under our feet).\n+\n+        :param bool real: Whether the real set (vs. the tmp one).\n+        \"\"\"\n+        if real:\n+            if self.set_exists is None:\n+                self.set_exists = ipset_exists(self.name)\n+            return self.set_exists\n+        else:\n+            if self.tmpset_exists is None:\n+                self.tmpset_exists = ipset_exists(self.tmpname)\n+            return self.tmpset_exists\n+","path":"calico/felix/ipsets.py","position":30,"original_position":30,"commit_id":"28f4a5a22f81f304879aa1511cf970d15315da2c","original_commit_id":"28f4a5a22f81f304879aa1511cf970d15315da2c","user":{"login":"Lukasa","id":1382556,"avatar_url":"https://avatars.githubusercontent.com/u/1382556?v=3","gravatar_id":"","url":"https://api.github.com/users/Lukasa","html_url":"https://github.com/Lukasa","followers_url":"https://api.github.com/users/Lukasa/followers","following_url":"https://api.github.com/users/Lukasa/following{/other_user}","gists_url":"https://api.github.com/users/Lukasa/gists{/gist_id}","starred_url":"https://api.github.com/users/Lukasa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lukasa/subscriptions","organizations_url":"https://api.github.com/users/Lukasa/orgs","repos_url":"https://api.github.com/users/Lukasa/repos","events_url":"https://api.github.com/users/Lukasa/events{/privacy}","received_events_url":"https://api.github.com/users/Lukasa/received_events","type":"User","site_admin":false},"body":"There are two identical branches of code here, which seem entirely redundant to me, along with a boolean parameter that you pass into the function undecorated (which looks really weird).\r\n\r\nThe correct refactor here seems to be modifying `ipset_exists` to check if `None` is passed to it, and return `False` in that case. Then, all the calls to `self._set_exists()` turn into calls to `ipset_exists` with parameters on self. Probably saves about 15 lines of diff.","created_at":"2015-04-22T14:57:19Z","updated_at":"2015-04-22T14:57:19Z","html_url":"https://github.com/Metaswitch/calico/pull/443#discussion_r28880343","pull_request_url":"https://api.github.com/repos/Metaswitch/calico/pulls/443","_links":{"self":{"href":"https://api.github.com/repos/Metaswitch/calico/pulls/comments/28880343"},"html":{"href":"https://github.com/Metaswitch/calico/pull/443#discussion_r28880343"},"pull_request":{"href":"https://api.github.com/repos/Metaswitch/calico/pulls/443"}}},"pull_request":{"url":"https://api.github.com/repos/Metaswitch/calico/pulls/443","id":33865376,"html_url":"https://github.com/Metaswitch/calico/pull/443","diff_url":"https://github.com/Metaswitch/calico/pull/443.diff","patch_url":"https://github.com/Metaswitch/calico/pull/443.patch","issue_url":"https://api.github.com/repos/Metaswitch/calico/issues/443","number":443,"state":"open","locked":false,"title":"Fix problem where we check whether ipset exists before another actor deletes it.","user":{"login":"plwhite","id":8448749,"avatar_url":"https://avatars.githubusercontent.com/u/8448749?v=3","gravatar_id":"","url":"https://api.github.com/users/plwhite","html_url":"https://github.com/plwhite","followers_url":"https://api.github.com/users/plwhite/followers","following_url":"https://api.github.com/users/plwhite/following{/other_user}","gists_url":"https://api.github.com/users/plwhite/gists{/gist_id}","starred_url":"https://api.github.com/users/plwhite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plwhite/subscriptions","organizations_url":"https://api.github.com/users/plwhite/orgs","repos_url":"https://api.github.com/users/plwhite/repos","events_url":"https://api.github.com/users/plwhite/events{/privacy}","received_events_url":"https://api.github.com/users/plwhite/received_events","type":"User","site_admin":false},"body":"Fixes bug #436.","created_at":"2015-04-22T14:45:27Z","updated_at":"2015-04-22T14:57:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6bb414a2417ddac77f2f91b5878ce41ee6315a31","assignee":{"login":"Lukasa","id":1382556,"avatar_url":"https://avatars.githubusercontent.com/u/1382556?v=3","gravatar_id":"","url":"https://api.github.com/users/Lukasa","html_url":"https://github.com/Lukasa","followers_url":"https://api.github.com/users/Lukasa/followers","following_url":"https://api.github.com/users/Lukasa/following{/other_user}","gists_url":"https://api.github.com/users/Lukasa/gists{/gist_id}","starred_url":"https://api.github.com/users/Lukasa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lukasa/subscriptions","organizations_url":"https://api.github.com/users/Lukasa/orgs","repos_url":"https://api.github.com/users/Lukasa/repos","events_url":"https://api.github.com/users/Lukasa/events{/privacy}","received_events_url":"https://api.github.com/users/Lukasa/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Metaswitch/calico/pulls/443/commits","review_comments_url":"https://api.github.com/repos/Metaswitch/calico/pulls/443/comments","review_comment_url":"https://api.github.com/repos/Metaswitch/calico/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Metaswitch/calico/issues/443/comments","statuses_url":"https://api.github.com/repos/Metaswitch/calico/statuses/28f4a5a22f81f304879aa1511cf970d15315da2c","head":{"label":"Metaswitch:issue436ipsets","ref":"issue436ipsets","sha":"28f4a5a22f81f304879aa1511cf970d15315da2c","user":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":21242831,"name":"calico","full_name":"Metaswitch/calico","owner":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Metaswitch/calico","description":"Project Calico core repository.","fork":false,"url":"https://api.github.com/repos/Metaswitch/calico","forks_url":"https://api.github.com/repos/Metaswitch/calico/forks","keys_url":"https://api.github.com/repos/Metaswitch/calico/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Metaswitch/calico/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Metaswitch/calico/teams","hooks_url":"https://api.github.com/repos/Metaswitch/calico/hooks","issue_events_url":"https://api.github.com/repos/Metaswitch/calico/issues/events{/number}","events_url":"https://api.github.com/repos/Metaswitch/calico/events","assignees_url":"https://api.github.com/repos/Metaswitch/calico/assignees{/user}","branches_url":"https://api.github.com/repos/Metaswitch/calico/branches{/branch}","tags_url":"https://api.github.com/repos/Metaswitch/calico/tags","blobs_url":"https://api.github.com/repos/Metaswitch/calico/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Metaswitch/calico/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Metaswitch/calico/git/refs{/sha}","trees_url":"https://api.github.com/repos/Metaswitch/calico/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Metaswitch/calico/statuses/{sha}","languages_url":"https://api.github.com/repos/Metaswitch/calico/languages","stargazers_url":"https://api.github.com/repos/Metaswitch/calico/stargazers","contributors_url":"https://api.github.com/repos/Metaswitch/calico/contributors","subscribers_url":"https://api.github.com/repos/Metaswitch/calico/subscribers","subscription_url":"https://api.github.com/repos/Metaswitch/calico/subscription","commits_url":"https://api.github.com/repos/Metaswitch/calico/commits{/sha}","git_commits_url":"https://api.github.com/repos/Metaswitch/calico/git/commits{/sha}","comments_url":"https://api.github.com/repos/Metaswitch/calico/comments{/number}","issue_comment_url":"https://api.github.com/repos/Metaswitch/calico/issues/comments{/number}","contents_url":"https://api.github.com/repos/Metaswitch/calico/contents/{+path}","compare_url":"https://api.github.com/repos/Metaswitch/calico/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Metaswitch/calico/merges","archive_url":"https://api.github.com/repos/Metaswitch/calico/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Metaswitch/calico/downloads","issues_url":"https://api.github.com/repos/Metaswitch/calico/issues{/number}","pulls_url":"https://api.github.com/repos/Metaswitch/calico/pulls{/number}","milestones_url":"https://api.github.com/repos/Metaswitch/calico/milestones{/number}","notifications_url":"https://api.github.com/repos/Metaswitch/calico/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Metaswitch/calico/labels{/name}","releases_url":"https://api.github.com/repos/Metaswitch/calico/releases{/id}","created_at":"2014-06-26T14:08:43Z","updated_at":"2015-04-22T14:01:32Z","pushed_at":"2015-04-22T14:45:28Z","git_url":"git://github.com/Metaswitch/calico.git","ssh_url":"git@github.com:Metaswitch/calico.git","clone_url":"https://github.com/Metaswitch/calico.git","svn_url":"https://github.com/Metaswitch/calico","homepage":"http://projectcalico.org/","size":10181,"stargazers_count":44,"watchers_count":44,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":70,"forks":12,"open_issues":70,"watchers":44,"default_branch":"master"}},"base":{"label":"Metaswitch:master","ref":"master","sha":"8d2fa2e8d1620dbdff7aee682f91d4ceeb65c1de","user":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":21242831,"name":"calico","full_name":"Metaswitch/calico","owner":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Metaswitch/calico","description":"Project Calico core repository.","fork":false,"url":"https://api.github.com/repos/Metaswitch/calico","forks_url":"https://api.github.com/repos/Metaswitch/calico/forks","keys_url":"https://api.github.com/repos/Metaswitch/calico/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Metaswitch/calico/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Metaswitch/calico/teams","hooks_url":"https://api.github.com/repos/Metaswitch/calico/hooks","issue_events_url":"https://api.github.com/repos/Metaswitch/calico/issues/events{/number}","events_url":"https://api.github.com/repos/Metaswitch/calico/events","assignees_url":"https://api.github.com/repos/Metaswitch/calico/assignees{/user}","branches_url":"https://api.github.com/repos/Metaswitch/calico/branches{/branch}","tags_url":"https://api.github.com/repos/Metaswitch/calico/tags","blobs_url":"https://api.github.com/repos/Metaswitch/calico/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Metaswitch/calico/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Metaswitch/calico/git/refs{/sha}","trees_url":"https://api.github.com/repos/Metaswitch/calico/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Metaswitch/calico/statuses/{sha}","languages_url":"https://api.github.com/repos/Metaswitch/calico/languages","stargazers_url":"https://api.github.com/repos/Metaswitch/calico/stargazers","contributors_url":"https://api.github.com/repos/Metaswitch/calico/contributors","subscribers_url":"https://api.github.com/repos/Metaswitch/calico/subscribers","subscription_url":"https://api.github.com/repos/Metaswitch/calico/subscription","commits_url":"https://api.github.com/repos/Metaswitch/calico/commits{/sha}","git_commits_url":"https://api.github.com/repos/Metaswitch/calico/git/commits{/sha}","comments_url":"https://api.github.com/repos/Metaswitch/calico/comments{/number}","issue_comment_url":"https://api.github.com/repos/Metaswitch/calico/issues/comments{/number}","contents_url":"https://api.github.com/repos/Metaswitch/calico/contents/{+path}","compare_url":"https://api.github.com/repos/Metaswitch/calico/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Metaswitch/calico/merges","archive_url":"https://api.github.com/repos/Metaswitch/calico/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Metaswitch/calico/downloads","issues_url":"https://api.github.com/repos/Metaswitch/calico/issues{/number}","pulls_url":"https://api.github.com/repos/Metaswitch/calico/pulls{/number}","milestones_url":"https://api.github.com/repos/Metaswitch/calico/milestones{/number}","notifications_url":"https://api.github.com/repos/Metaswitch/calico/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Metaswitch/calico/labels{/name}","releases_url":"https://api.github.com/repos/Metaswitch/calico/releases{/id}","created_at":"2014-06-26T14:08:43Z","updated_at":"2015-04-22T14:01:32Z","pushed_at":"2015-04-22T14:45:28Z","git_url":"git://github.com/Metaswitch/calico.git","ssh_url":"git@github.com:Metaswitch/calico.git","clone_url":"https://github.com/Metaswitch/calico.git","svn_url":"https://github.com/Metaswitch/calico","homepage":"http://projectcalico.org/","size":10181,"stargazers_count":44,"watchers_count":44,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":70,"forks":12,"open_issues":70,"watchers":44,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Metaswitch/calico/pulls/443"},"html":{"href":"https://github.com/Metaswitch/calico/pull/443"},"issue":{"href":"https://api.github.com/repos/Metaswitch/calico/issues/443"},"comments":{"href":"https://api.github.com/repos/Metaswitch/calico/issues/443/comments"},"review_comments":{"href":"https://api.github.com/repos/Metaswitch/calico/pulls/443/comments"},"review_comment":{"href":"https://api.github.com/repos/Metaswitch/calico/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Metaswitch/calico/pulls/443/commits"},"statuses":{"href":"https://api.github.com/repos/Metaswitch/calico/statuses/28f4a5a22f81f304879aa1511cf970d15315da2c"}}}}