Skip to content

Commit

Permalink
fix: fix unit tests for multi-VO handling
Browse files Browse the repository at this point in the history
  • Loading branch information
martynia committed Oct 31, 2022
1 parent 0f5c07e commit 010991b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,5 @@ def test_executeForVO(self, mockProxy, mockTC, mockisfile, mockremove, mocklistd


if __name__ == "__main__":
suite = unittest.defaultTestLoader.loadTestsFromTestCase(PilotAgentTestCase)
suite = unittest.defaultTestLoader.loadTestsFromTestCase()
testResult = unittest.TextTestResult(verbosity=2).run(suite)
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ def test_FileCachePlugin(self, mockExists, mockGetcwd, mockMakedirs):
+ "2022-02-23 13:48:36.123456 UTC DEBUG [PilotParams] JSON file analysed: pilot.json"
)
messageJSON = json.dumps(messsageText)
vo = "anyVO"
pilotUUID = "78f39a90-2073-11ec-98d7-b496913c0cf4"

# use a temporary dir, not the one above. Plugin will create the file to write into.
with tempfile.TemporaryDirectory(suffix="pilottests") as d:
plugin.meta["LogPath"] = d
res = plugin.sendMessage(messageJSON, pilotUUID)
res = plugin.sendMessage(messageJSON, pilotUUID, vo)
self.assertTrue(res["OK"])
with open(os.path.join(d, pilotUUID), "r") as pilotLog:
content = pilotLog.read()
Expand All @@ -99,11 +100,11 @@ def test_FileCachePlugin(self, mockExists, mockGetcwd, mockMakedirs):
with tempfile.TemporaryDirectory(suffix="pilottests") as d:
plugin.meta["LogPath"] = d
os.chmod(d, 0o0000)
res = plugin.sendMessage(messageJSON, pilotUUID)
res = plugin.sendMessage(messageJSON, pilotUUID, vo)
self.assertFalse(res["OK"])

pilotUUID = "whatever"
res = plugin.sendMessage(messageJSON, pilotUUID)
res = plugin.sendMessage(messageJSON, pilotUUID, vo)
self.assertFalse(res["OK"])

@patch.object(DIRAC.WorkloadManagementSystem.Service.TornadoPilotLoggingHandler.os.path, "exists")
Expand All @@ -124,22 +125,23 @@ def test_finaliseLogs(self, mockGetcwd, mockExists):
mockExists.return_value = True # will not create a file
mockGetcwd.return_value = "/tornado/document/root" # so we have a path defined (will overwrite it below)
plugin = FileCacheLoggingPlugin()
vo = "anyVO"

with tempfile.TemporaryDirectory(suffix="pilottests") as d:
plugin.meta["LogPath"] = d
payload = '{"retCode": 0}'
logfile = "78f39a90-2073-11ec-98d7-b496913c0cf4" # == pilotUUID
# will fail here...
res = plugin.finaliseLogs(payload, logfile)
res = plugin.finaliseLogs(payload, logfile, vo)
self.assertFalse(res["OK"])
# create a file ..
with open(os.path.join(d, logfile), "w") as f:
f.write("Create a dummy logfile")
res = plugin.finaliseLogs(payload, logfile)
res = plugin.finaliseLogs(payload, logfile, vo)
self.assertTrue(res["OK"])

logfile = "invalid!"
res = plugin.finaliseLogs(payload, logfile)
res = plugin.finaliseLogs(payload, logfile, vo)
self.assertFalse(res["OK"])


Expand Down

0 comments on commit 010991b

Please sign in to comment.