From 431871eae84b10817ce1d38dba5edb1dfdc5868c Mon Sep 17 00:00:00 2001 From: David Zafman Date: Mon, 13 Jun 2016 15:59:55 -0700 Subject: [PATCH] test: Explicitly use tempfile delete= feature instead of os.unlink() The warning messages are caused by new delete= tempfile feature trying to unlink a file after test has used os.unlink(). Signed-off-by: David Zafman --- src/test/ceph_objectstore_tool.py | 36 +++++++------------------------ 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/test/ceph_objectstore_tool.py b/src/test/ceph_objectstore_tool.py index 21e4fc6a271b3..d3f7d488080a5 100755 --- a/src/test/ceph_objectstore_tool.py +++ b/src/test/ceph_objectstore_tool.py @@ -428,14 +428,14 @@ def check_data(DATADIR, TMPFILE, OSDDIR, SPLIT_NAME): def set_osd_weight(CFSD_PREFIX, osd_ids, osd_path, weight): # change the weight of osd.0 to math.pi in the newest osdmap of given osd - osdmap_file = tempfile.NamedTemporaryFile() + osdmap_file = tempfile.NamedTemporaryFile(delete=True) cmd = (CFSD_PREFIX + "--op get-osdmap --file {osdmap_file}").format(osd=osd_path, osdmap_file=osdmap_file.name) output = check_output(cmd, shell=True) epoch = int(re.findall('#(\d+)', output)[0]) - new_crush_file = tempfile.NamedTemporaryFile(delete=False) - old_crush_file = tempfile.NamedTemporaryFile(delete=False) + new_crush_file = tempfile.NamedTemporaryFile(delete=True) + old_crush_file = tempfile.NamedTemporaryFile(delete=True) ret = call("{path}/osdmaptool --export-crush {crush_file} {osdmap_file}".format(osdmap_file=osdmap_file.name, crush_file=old_crush_file.name, path=CEPH_BIN), stdout=subprocess.DEVNULL, @@ -475,17 +475,10 @@ def set_osd_weight(CFSD_PREFIX, osd_ids, osd_path, weight): cmd = cmd.format(osd=osd_path, osdmap_file=osdmap_file.name, epoch=epoch) ret = call(cmd, stdout=subprocess.DEVNULL, shell=True) - try: - os.unlink(osdmap_file.name) - os.unlink(new_crush_file.name) - os.unlink(old_crush_file.name) - except: - pass - return ret == 0 def get_osd_weights(CFSD_PREFIX, osd_ids, osd_path): - osdmap_file = tempfile.NamedTemporaryFile() + osdmap_file = tempfile.NamedTemporaryFile(delete=True) cmd = (CFSD_PREFIX + "--op get-osdmap --file {osdmap_file}").format(osd=osd_path, osdmap_file=osdmap_file.name) ret = call(cmd, stdout=subprocess.DEVNULL, shell=True) @@ -494,7 +487,7 @@ def get_osd_weights(CFSD_PREFIX, osd_ids, osd_path): # we have to read the weights from the crush map, even we can query the weights using # osdmaptool, but please keep in mind, they are different: # item weights in crush map versus weight associated with each osd in osdmap - crush_file = tempfile.NamedTemporaryFile(delete=False) + crush_file = tempfile.NamedTemporaryFile(delete=True) ret = call("{path}/osdmaptool --export-crush {crush_file} {osdmap_file}".format(osdmap_file=osdmap_file.name, crush_file=crush_file.name, path=CEPH_BIN), stdout=subprocess.DEVNULL, @@ -509,12 +502,6 @@ def get_osd_weights(CFSD_PREFIX, osd_ids, osd_path): osd_id, weight, osd_name = re.split('\s+', line) weights.append(float(weight)) - try: - os.unlink(osdmap_file.name) - os.unlink(crush_file.name) - except: - pass - return weights @@ -548,14 +535,14 @@ def test_get_set_inc_osdmap(CFSD_PREFIX, osd_path): # OSD's peers, so an obvious way to test it is simply overwrite an epoch # with a different copy, and read it back to see if it matches. kill_daemons() - file_e2 = tempfile.NamedTemporaryFile() + file_e2 = tempfile.NamedTemporaryFile(delete=True) cmd = (CFSD_PREFIX + "--op get-inc-osdmap --file {file}").format(osd=osd_path, file=file_e2.name) output = check_output(cmd, shell=True) epoch = int(re.findall('#(\d+)', output)[0]) # backup e1 incremental before overwriting it epoch -= 1 - file_e1_backup = tempfile.NamedTemporaryFile() + file_e1_backup = tempfile.NamedTemporaryFile(delete=True) cmd = CFSD_PREFIX + "--op get-inc-osdmap --epoch {epoch} --file {file}" ret = call(cmd.format(osd=osd_path, epoch=epoch, file=file_e1_backup.name), shell=True) if ret: return 1 @@ -568,7 +555,7 @@ def test_get_set_inc_osdmap(CFSD_PREFIX, osd_path): ret = call(cmd.format(osd=osd_path, epoch=epoch, file=file_e1_backup.name), shell=True) if ret: return 1 # read from e1 - file_e1_read = tempfile.NamedTemporaryFile(delete=False) + file_e1_read = tempfile.NamedTemporaryFile(delete=True) cmd = CFSD_PREFIX + "--op get-inc-osdmap --epoch {epoch} --file {file}" ret = call(cmd.format(osd=osd_path, epoch=epoch, file=file_e1_read.name), shell=True) if ret: return 1 @@ -585,13 +572,6 @@ def test_get_set_inc_osdmap(CFSD_PREFIX, osd_path): logging.error("Failed to revert the changed inc-osdmap") errors += 1 - try: - os.unlink(file_e2.name) - os.unlink(file_e1_read.name) - os.unlink(file_e1_backup.name) - except: - pass - return errors -- 2.39.5