OLD | NEW |
1 from collections import namedtuple | 1 from collections import namedtuple |
2 from UserDict import DictMixin | 2 from UserDict import DictMixin |
3 import socket | 3 import socket |
4 import errno | 4 import errno |
5 import time | 5 import time |
6 | 6 |
7 from twisted.internet.defer import inlineCallbacks, returnValue | 7 from twisted.internet.defer import inlineCallbacks, returnValue |
8 from twisted.internet.threads import deferToThread | 8 from twisted.internet.threads import deferToThread |
9 from txzookeeper.utils import retry_change | 9 from txzookeeper.utils import retry_change |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 | 78 |
79 @inlineCallbacks | 79 @inlineCallbacks |
80 def remove_tree(client, path): | 80 def remove_tree(client, path): |
81 children = yield client.get_children(path) | 81 children = yield client.get_children(path) |
82 for child in children: | 82 for child in children: |
83 yield remove_tree(client, "%s/%s" % (path, child)) | 83 yield remove_tree(client, "%s/%s" % (path, child)) |
84 yield client.delete(path) | 84 yield client.delete(path) |
85 | 85 |
86 | 86 |
87 def get_open_port(host=""): | |
88 """Get an open port on the machine. | |
89 """ | |
90 temp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
91 temp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
92 temp_sock.bind((host, 0)) | |
93 port = temp_sock.getsockname()[1] | |
94 temp_sock.close() | |
95 del temp_sock | |
96 return port | |
97 | |
98 | |
99 def dict_merge(d1, d2): | 87 def dict_merge(d1, d2): |
100 """Return a union of dicts if they have no conflicting values. | 88 """Return a union of dicts if they have no conflicting values. |
101 | 89 |
102 Else raise a StateChanged error. | 90 Else raise a StateChanged error. |
103 """ | 91 """ |
104 must_match = set(d1).intersection(d2) | 92 must_match = set(d1).intersection(d2) |
105 for k in must_match: | 93 for k in must_match: |
106 if not d1[k] == d2[k]: | 94 if not d1[k] == d2[k]: |
107 raise StateChanged() | 95 raise StateChanged() |
108 | 96 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 258 |
271 @inlineCallbacks | 259 @inlineCallbacks |
272 def _set_node_value(self, key, value): | 260 def _set_node_value(self, key, value): |
273 node_data = YAMLState(self._client, self._zk_path) | 261 node_data = YAMLState(self._client, self._zk_path) |
274 try: | 262 try: |
275 yield node_data.read(required=True) | 263 yield node_data.read(required=True) |
276 except StateNotFound: | 264 except StateNotFound: |
277 self._node_missing() | 265 self._node_missing() |
278 node_data[key] = value | 266 node_data[key] = value |
279 yield node_data.write() | 267 yield node_data.write() |
OLD | NEW |