Merge lp:~patrick-crews/drizzle/dbqp_bug713802 into lp:drizzle/7.0

Proposed by Patrick Crews
Status: Merged
Approved by: Lee Bieber
Approved revision: 2149
Merged at revision: 2149
Proposed branch: lp:~patrick-crews/drizzle/dbqp_bug713802
Merge into: lp:drizzle/7.0
Diff against target: 150 lines (+49/-47)
2 files modified
tests/lib/sys_mgmt/port_management.py (+39/-46)
tests/lib/test_mgmt/test_execution.py (+10/-1)
To merge this branch: bzr merge lp:~patrick-crews/drizzle/dbqp_bug713802
Reviewer Review Type Date Requested Status
Drizzle Developers Pending
Review via email: mp+48807@code.launchpad.net

Description of the change

Fixed port management - we now write per-port files to /tmp that we clean up post-run.
This allows different access-having users to all use the system (we only see if a port file exists to know it is 'locked') We also clean up after ourselves to be a good citizen : )

To post a comment you must log in.
2150. By Patrick Crews

Minor tweak to start-and-exit (report server info prior to exit) and update of port_file_naming

2151. By Patrick Crews

Further port_management work. Blow away unused port files on --start-and-exit. Also removed previous references to port catalog (old method). Tweaked when we report server information on --start-and-exit

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/lib/sys_mgmt/port_management.py'
--- tests/lib/sys_mgmt/port_management.py 2011-02-04 20:41:08 +0000
+++ tests/lib/sys_mgmt/port_management.py 2011-02-07 18:13:20 +0000
@@ -37,7 +37,8 @@
37 self.skip_keys = [ 'port_file_delimiter'37 self.skip_keys = [ 'port_file_delimiter'
38 , 'system_manager'38 , 'system_manager'
39 ]39 ]
40 self.port_catalog = "/tmp/drizzle_test_port_catalog.dat"40 self.working_dir = "/tmp"
41 self.file_prefix = "dbqp_port"
41 self.port_file_delimiter = ':' # what we use to separate port:owner 42 self.port_file_delimiter = ':' # what we use to separate port:owner
42 self.debug = debug43 self.debug = debug
43 self.logging = system_manager.logging44 self.logging = system_manager.logging
@@ -96,7 +97,7 @@
96 sys.exit(1)97 sys.exit(1)
9798
98 def check_port_status(self, port):99 def check_port_status(self, port):
99 """ Check if a port is in use, via the catalog file 100 """ Check if a port is in use, via the port files
100 which all copies of dbqp.py should use101 which all copies of dbqp.py should use
101102
102 Not *really* sure how well this works with multiple103 Not *really* sure how well this works with multiple
@@ -104,9 +105,9 @@
104 to work 105 to work
105106
106 """107 """
107 # read the catalog file108 # check existing ports dbqp has created
108 port_catalog = self.process_port_catalog()109 dbqp_ports = self.check_dbqp_ports()
109 if port not in port_catalog and not self.is_port_used(port):110 if port not in dbqp_ports and not self.is_port_used(port):
110 return 1111 return 1
111 else:112 else:
112 return 0113 return 0
@@ -143,59 +144,51 @@
143 return 1144 return 1
144 return 0145 return 0
145146
146 def process_port_catalog(self):147
147 """ Read in the catalog file so that we can see148
148 if the port is in use or not149 def check_dbqp_ports(self):
150 """ Scan the files in /tmp for those files named
151 dbqp_port_NNNN. Existence indicates said port is 'locked'
149152
150 """153 """
151 port_catalog = {}154 used_ports = []
152 delimiter = ':'155 tmp_files = os.listdir('/tmp')
153 if os.path.exists(self.port_catalog):156 for tmp_file in tmp_files:
154 try:157 if tmp_file.startswith('dbqp_port'):
155 port_file = open(self.port_catalog,'r')158 used_ports.append(int(tmp_file.split('_')[-1]))
156 for line in port_file:159 return used_ports
157 line = line.strip()
158 port, owner = line.split(self.port_file_delimiter)
159 port_catalog[port] = owner
160 port_file.close()
161 except IOError, e:
162 self.logging.error("Problem opening port catalog file: %s" %(self.port_catalog))
163 self.logging.error("%s" %e)
164 sys.exit(1)
165 return port_catalog
166160
167 def assign_port(self, owner, port):161 def assign_port(self, owner, port):
168 """Assigns a port - logs it in the port_catalog file"""162 """Assigns a port - create a tmpfile
169163 with a name that 'logs' the port
170 data_string = "%d:%s\n" %(port, owner)164 as being used
171 try:165
172 port_file = open(self.port_catalog,'a')166 """
173 port_file.write(data_string)167
174 port_file.close()168 out_file = open(self.get_file_name(port),'w')
175 except IOError, e:169 out_file.write("%s:%d\n" %(owner, port))
176 self.logging.error("Problem opening port catalog file: %s" %(self.port_catalog))170 out_file.close()
177 self.logging.error("%s" %e)
178 sys.exit(1)
179171
180 def free_ports(self, portlist):172 def free_ports(self, portlist):
181 """ Clean up our port catalog """173 """ Clean up our ports """
182 for port in portlist:174 for port in portlist:
183 self.free_port(port)175 self.free_port(port)
184176
185 def free_port(self, port):177 def free_port(self, port):
186 """ Free a single port from the catalog """178 """ Free a single port - we delete the file
179 that 'locks' it
180
181 """
182
187 if self.debug:183 if self.debug:
188 self.logging.debug("Freeing port %d" %(port))184 self.logging.debug("Freeing port %d" %(port))
189 port_catalog = self.process_port_catalog()185 os.remove(self.get_file_name(port))
190 port_catalog.pop(str(port),None)186
191 self.write_port_catalog(port_catalog)187 def get_file_name(self, port):
192188 """ We generate a file name for the port """
193 def write_port_catalog(self, port_catalog):189
194 port_file = open(self.port_catalog, 'w')190 port_file_name = "%s_%s_%d" %(self.file_prefix, self.system_manager.cur_user, port )
195 for key, value in port_catalog.items():191 return os.path.join(self.working_dir, port_file_name)
196 port_file.write(("%s:%s\n" %(key, value)))
197 port_file.close()
198
199 192
200 193
201 194
202195
=== modified file 'tests/lib/test_mgmt/test_execution.py'
--- tests/lib/test_mgmt/test_execution.py 2011-02-04 20:41:08 +0000
+++ tests/lib/test_mgmt/test_execution.py 2011-02-07 18:13:20 +0000
@@ -111,7 +111,16 @@
111 else:111 else:
112 if start_and_exit:112 if start_and_exit:
113 # TODO: Report out all started servers via server_manager/server objects?113 # TODO: Report out all started servers via server_manager/server objects?
114 self.logging.info("User specified --start-and-exit. dbqp.py exiting and leaving servers running...")114 self.current_servers[0].report()
115 self.logging.info("User specified --start-and-exit. dbqp.py exiting and leaving servers running...")
116 # We blow away any port_management files for our ports
117 # Technically this won't let us 'lock' any ports that
118 # we aren't explicitly using (visible to netstat scan)
119 # However one could argue that if we aren't using it,
120 # We shouldn't hog it ; )
121 # We might need to do this better later
122 for server in current_servers:
123 server.cleanup() # this only removes any port files
115 sys.exit(0)124 sys.exit(0)
116 if self.initial_run:125 if self.initial_run:
117 self.initial_run = 0126 self.initial_run = 0

Subscribers

People subscribed via source and target branches