Skip to content

Commit

Permalink
Merge pull request #916 from projectcalico/smc-fix-dir-continue
Browse files Browse the repository at this point in the history
Fix incorrect next_index calculation for directory creations.
  • Loading branch information
Shaun Crampton committed Nov 24, 2015
2 parents 74a295e + 27744cb commit c8d81ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions calico/etcddriver/driver.py
Expand Up @@ -722,6 +722,7 @@ def watch_etcd(self, next_index, event_queue, stop_event):
action = ACTION_MAPPING[etcd_resp["action"]]
is_dir = node.get("dir", False)
value = node.get("value")
dir_creation = False
if is_dir:
if action == "delete":
if key.rstrip("/") in (VERSION_DIR, ROOT_DIR):
Expand All @@ -738,15 +739,20 @@ def watch_etcd(self, next_index, event_queue, stop_event):
# Just ignore sets to directories, we only track
# leaves.
_log.debug("Skipping non-delete to dir %s", key)
continue
dir_creation = True
modified_index = node["modifiedIndex"]
except (KeyError, TypeError, ValueError):
_log.exception("Unexpected format for etcd response: %r;"
"triggering a resync.",
resp_body)
break
else:
event_queue.put((modified_index, key, value))
if not dir_creation:
# The resync thread doesn't need to know about
# directory creations so we skip them. (It does need
# to know about deletions in order to clean up
# sub-keys.)
event_queue.put((modified_index, key, value))
next_index = modified_index + 1
except:
_log.exception("Exception finishing watcher thread.")
Expand Down
10 changes: 8 additions & 2 deletions calico/etcddriver/test/test_driver.py
Expand Up @@ -392,11 +392,17 @@ def test_directory_deletion(self):
"action": "create",
"node": {
"key": "/calico/v1/foo",
"dir": True
"dir": True,
"modifiedIndex": 100,
}
}), 100, 200)
# Then a whole directory is deleted.
watcher_req = self.watcher_etcd.get_next_request()
watcher_req = self.watcher_etcd.assert_request(
VERSION_DIR,
timeout=90,
recursive=True,
wait_index=101,
)
watcher_req.respond_with_value(
"/calico/v1/adir",
dir=True,
Expand Down

0 comments on commit c8d81ef

Please sign in to comment.