Revision 601dfcbb test/ganeti.rpc_unittest.py
b/test/ganeti.rpc_unittest.py | ||
---|---|---|
25 | 25 |
import sys |
26 | 26 |
import unittest |
27 | 27 |
import random |
28 |
import tempfile |
|
28 | 29 |
|
29 | 30 |
from ganeti import constants |
30 | 31 |
from ganeti import compat |
... | ... | |
37 | 38 |
from ganeti import backend |
38 | 39 |
|
39 | 40 |
import testutils |
41 |
import mocks |
|
40 | 42 |
|
41 | 43 |
|
42 | 44 |
class _FakeRequestProcessor: |
... | ... | |
682 | 684 |
self.assertFalse(res.fail_msg) |
683 | 685 |
|
684 | 686 |
|
687 |
class _FakeConfigForRpcRunner: |
|
688 |
GetAllNodesInfo = NotImplemented |
|
689 |
|
|
690 |
def GetNodeInfo(self, name): |
|
691 |
return objects.Node(name=name) |
|
692 |
|
|
693 |
|
|
685 | 694 |
class TestRpcRunner(unittest.TestCase): |
686 | 695 |
def testUploadFile(self): |
687 |
runner = rpc.RpcRunner(_req_process_fn=http_proc) |
|
696 |
data = 1779 * "Hello World\n" |
|
697 |
|
|
698 |
tmpfile = tempfile.NamedTemporaryFile() |
|
699 |
tmpfile.write(data) |
|
700 |
tmpfile.flush() |
|
701 |
st = os.stat(tmpfile.name) |
|
702 |
|
|
703 |
def _VerifyRequest(req): |
|
704 |
(uldata, ) = serializer.LoadJson(req.post_data) |
|
705 |
self.assertEqual(len(uldata), 7) |
|
706 |
self.assertEqual(uldata[0], tmpfile.name) |
|
707 |
self.assertEqual(list(uldata[1]), list(rpc._Compress(data))) |
|
708 |
self.assertEqual(uldata[2], st.st_mode) |
|
709 |
self.assertEqual(uldata[3], "user%s" % os.getuid()) |
|
710 |
self.assertEqual(uldata[4], "group%s" % os.getgid()) |
|
711 |
self.assertEqual(uldata[5], st.st_atime) |
|
712 |
self.assertEqual(uldata[6], st.st_mtime) |
|
713 |
|
|
714 |
req.success = True |
|
715 |
req.resp_status_code = http.HTTP_OK |
|
716 |
req.resp_body = serializer.DumpJson((True, None)) |
|
717 |
|
|
718 |
http_proc = _FakeRequestProcessor(_VerifyRequest) |
|
719 |
cfg = _FakeConfigForRpcRunner() |
|
720 |
runner = rpc.RpcRunner(cfg, None, _req_process_fn=http_proc, |
|
721 |
_getents=mocks.FakeGetentResolver) |
|
722 |
|
|
723 |
nodes = [ |
|
724 |
"node1.example.com", |
|
725 |
] |
|
726 |
|
|
727 |
result = runner.call_upload_file(nodes, tmpfile.name) |
|
728 |
self.assertEqual(len(result), len(nodes)) |
|
729 |
for (idx, (node, res)) in enumerate(result.items()): |
|
730 |
self.assertFalse(res.fail_msg) |
|
688 | 731 |
|
689 | 732 |
|
690 | 733 |
if __name__ == "__main__": |
Also available in: Unified diff