Merge lp:~cbehrens/openstack-guest-agents/lp764221 into lp:openstack-guest-agents

Proposed by Chris Behrens
Status: Merged
Merged at revision: 13
Proposed branch: lp:~cbehrens/openstack-guest-agents/lp764221
Merge into: lp:openstack-guest-agents
Diff against target: 149 lines (+109/-13)
1 file modified
unix/plugins/xscomm.py (+109/-13)
To merge this branch: bzr merge lp:~cbehrens/openstack-guest-agents/lp764221
Reviewer Review Type Date Requested Status
Ozone Pending
Review via email: mp+58204@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'unix/plugins/xscomm.py'
--- unix/plugins/xscomm.py 2011-04-11 18:30:08 +0000
+++ unix/plugins/xscomm.py 2011-04-18 21:56:18 +0000
@@ -48,26 +48,111 @@
48 XenStore communication plugin for nova-agent48 XenStore communication plugin for nova-agent
49 """49 """
5050
51 def __init__(self):51 def __init__(self, *args, **kwargs):
52
53 self.request_path = kwargs.get("request_path",
54 XENSTORE_REQUEST_PATH)
55 self.response_path = kwargs.get("response_path",
56 XENSTORE_RESPONSE_PATH)
57
52 self.xs_handle = pyxenstore.Handle()58 self.xs_handle = pyxenstore.Handle()
59 self.xs_handle.mkdir(self.request_path)
53 self.requests = []60 self.requests = []
5461
62 def _check_handle(self):
63 if not self.xs_handle:
64 self.xs_handle = pyxenstore.Handle()
65
55 def _get_requests(self):66 def _get_requests(self):
56 """67 """
57 Get requests out of XenStore and cache for later use68 Get requests out of XenStore and cache for later use
58 """69 """
5970
60 self.xs_handle.transaction_start()71 self._check_handle()
6172
62 entries = self.xs_handle.entries(XENSTORE_REQUEST_PATH)73 try:
74 self.xs_handle.transaction_start()
75 except pyxenstore.PyXenStoreError, e:
76 # Need to have the handle reopened later
77 self.xs_handle = None
78 raise e
79
80 try:
81 entries = self.xs_handle.entries(self.request_path)
82 except pyxenstore.NotFoundError:
83 # Someone removed the path on us ?
84 try:
85 self.xs_handle.transaction_end()
86 except Exception:
87 # No matter what exception we get, since we couldn't
88 # end the transaction, we're going to need to reopen
89 # the handle later
90 self.xs_handle = None
91
92 try:
93 self.xs_handle.mkdir(self.request_path)
94 except pyxenstore.PyXenStoreError, e:
95 # Need to have the handle reopened later
96 self.xs_handle = None
97 raise e
98 # Re-try after mkdir()
99 return self._get_requests()
100 except pyxenstore.PyXenStoreError, e:
101 # Any other XenStore errors need to have handle reopened
102 self.xs_handle = None
103 raise e
104 except Exception, e:
105 try:
106 self.xs_handle.transaction_end()
107 except:
108 # No matter what exception we get, since we couldn't
109 # end the transaction, we're going to need to reopen
110 # the handle later
111 self.xs_handle = None
112 raise e
113 raise e
63114
64 for entry in entries:115 for entry in entries:
65 path = XENSTORE_REQUEST_PATH + '/' + entry116 path = self.request_path + '/' + entry
66 data = self.xs_handle.read(path)117 try:
67118 data = self.xs_handle.read(path)
68 self.requests.append({'path': path, 'data': data})119 except pyxenstore.NotFoundError:
69120 continue
70 self.xs_handle.transaction_end()121 except pyxenstore.PyXenStoreError, e:
122 # Any other XenStore errors need to have handle reopened
123 self.xs_handle = None
124 raise e
125 except Exception, e:
126 try:
127 self.xs_handle.transaction_end()
128 except:
129 # No matter what exception we get, since we couldn't
130 # end the transaction, we're going to need to reopen
131 # the handle later
132 self.xs_handle = None
133 raise e
134
135 try:
136 self.requests.append({'path': path, 'data': data})
137 except Exception, e:
138 try:
139 self.xs_handle.transaction_end()
140 except:
141 # No matter what exception we get, since we couldn't
142 # end the transaction, we're going to need to reopen
143 # the handle later
144 self.xs_handle = None
145 raise e
146
147 try:
148 self.xs_handle.transaction_end()
149 except:
150 # No matter what exception we get, since we couldn't
151 # end the transaction, we're going to need to reopen
152 # the handle later
153 self.xs_handle = None
154 raise e
155 return len(self.requests) > 0
71156
72 def get_request(self):157 def get_request(self):
73 """158 """
@@ -86,9 +171,20 @@
86 Remove original request from XenStore and write out the response171 Remove original request from XenStore and write out the response
87 """172 """
88173
89 self.xs_handle.rm(req['path'])174 self._check_handle()
175
176 try:
177 self.xs_handle.rm(req['path'])
178 except pyxenstore.PyXenStoreError, e:
179 self.xs_handle = None
180 self._check_handle()
181 # Fall through...
90182
91 basename = req['path'].rsplit('/', 1)[1]183 basename = req['path'].rsplit('/', 1)[1]
92 resp_path = XENSTORE_RESPONSE_PATH + '/' + basename184 resp_path = self.response_path + '/' + basename
93185
94 self.xs_handle.write(resp_path, resp['data'])186 try:
187 self.xs_handle.write(resp_path, resp['data'])
188 except pyxenstore.PyXenStoreError, e:
189 self.xs_handle = None
190 raise e

Subscribers

People subscribed via source and target branches