equal
deleted
inserted
replaced
27 import errno |
27 import errno |
28 import glob |
28 import glob |
29 import json |
29 import json |
30 import os |
30 import os |
31 import shutil |
31 import shutil |
32 from subprocess import Popen, PIPE |
32 from subprocess import CalledProcessError, Popen, PIPE, check_call |
33 import time |
33 import time |
34 import uuid |
34 import uuid |
35 |
35 |
36 import iniparse |
36 import iniparse |
37 |
37 |
288 try: |
288 try: |
289 core_plugin = parser.get("DEFAULT", "core_plugin") |
289 core_plugin = parser.get("DEFAULT", "core_plugin") |
290 except NoOptionError: |
290 except NoOptionError: |
291 return False |
291 return False |
292 return "ml2" in core_plugin.lower() |
292 return "ml2" in core_plugin.lower() |
|
293 |
|
294 |
|
295 def kill_contract(attempts, interval, ctid): |
|
296 """ Keeps issuing SIGTERM to contract-id at specified intervals until |
|
297 either the contract is empty or the specified number of attempts are made. |
|
298 Returns 0 if pkill failed, 1 if contract was successfully emptied and 2 |
|
299 if attempts were exhausted before the contract could be emptied. |
|
300 """ |
|
301 for _ in xrange(attempts): |
|
302 # Kill the SMF contract |
|
303 try: |
|
304 check_call(["/usr/bin/pkill", "-c", ctid]) |
|
305 except CalledProcessError as err: |
|
306 print "failed to kill the SMF contract: %s" % err |
|
307 return 0 |
|
308 time.sleep(interval) |
|
309 try: |
|
310 # check if contract is empty |
|
311 check_call(["/usr/bin/pgrep", "-c", ctid], stdout=PIPE, |
|
312 stderr=PIPE) |
|
313 except: |
|
314 # contract is empty |
|
315 return 1 |
|
316 return 2 |