Revision 7e6b6f1f
b/test/ganeti.rpc_unittest.py | ||
---|---|---|
687 | 687 |
class _FakeConfigForRpcRunner: |
688 | 688 |
GetAllNodesInfo = NotImplemented |
689 | 689 |
|
690 |
def __init__(self, cluster=NotImplemented): |
|
691 |
self._cluster = cluster |
|
692 |
|
|
690 | 693 |
def GetNodeInfo(self, name): |
691 | 694 |
return objects.Node(name=name) |
692 | 695 |
|
696 |
def GetClusterInfo(self): |
|
697 |
return self._cluster |
|
698 |
|
|
693 | 699 |
|
694 | 700 |
class TestRpcRunner(unittest.TestCase): |
695 | 701 |
def testUploadFile(self): |
... | ... | |
708 | 714 |
self.assertEqual(uldata[2], st.st_mode) |
709 | 715 |
self.assertEqual(uldata[3], "user%s" % os.getuid()) |
710 | 716 |
self.assertEqual(uldata[4], "group%s" % os.getgid()) |
711 |
self.assertEqual(uldata[5], st.st_atime)
|
|
717 |
self.assertTrue(uldata[5] is not None)
|
|
712 | 718 |
self.assertEqual(uldata[6], st.st_mtime) |
713 | 719 |
|
714 | 720 |
req.success = True |
... | ... | |
735 | 741 |
for (idx, (node, res)) in enumerate(result.items()): |
736 | 742 |
self.assertFalse(res.fail_msg) |
737 | 743 |
|
744 |
def testEncodeInstance(self): |
|
745 |
cluster = objects.Cluster(hvparams={ |
|
746 |
constants.HT_KVM: { |
|
747 |
constants.HV_BLOCKDEV_PREFIX: "foo", |
|
748 |
}, |
|
749 |
}, |
|
750 |
beparams={ |
|
751 |
constants.PP_DEFAULT: { |
|
752 |
constants.BE_MAXMEM: 8192, |
|
753 |
}, |
|
754 |
}, |
|
755 |
os_hvp={}, |
|
756 |
osparams={ |
|
757 |
"linux": { |
|
758 |
"role": "unknown", |
|
759 |
}, |
|
760 |
}) |
|
761 |
cluster.UpgradeConfig() |
|
762 |
|
|
763 |
inst = objects.Instance(name="inst1.example.com", |
|
764 |
hypervisor=constants.HT_FAKE, |
|
765 |
os="linux", |
|
766 |
hvparams={ |
|
767 |
constants.HT_KVM: { |
|
768 |
constants.HV_BLOCKDEV_PREFIX: "bar", |
|
769 |
constants.HV_ROOT_PATH: "/tmp", |
|
770 |
}, |
|
771 |
}, |
|
772 |
beparams={ |
|
773 |
constants.BE_MINMEM: 128, |
|
774 |
constants.BE_MAXMEM: 256, |
|
775 |
}, |
|
776 |
nics=[ |
|
777 |
objects.NIC(nicparams={ |
|
778 |
constants.NIC_MODE: "mymode", |
|
779 |
}), |
|
780 |
], |
|
781 |
disks=[]) |
|
782 |
inst.UpgradeConfig() |
|
783 |
|
|
784 |
cfg = _FakeConfigForRpcRunner(cluster=cluster) |
|
785 |
runner = rpc.RpcRunner(cfg, None, |
|
786 |
_req_process_fn=NotImplemented, |
|
787 |
_getents=mocks.FakeGetentResolver) |
|
788 |
|
|
789 |
def _CheckBasics(result): |
|
790 |
self.assertEqual(result["name"], "inst1.example.com") |
|
791 |
self.assertEqual(result["os"], "linux") |
|
792 |
self.assertEqual(result["beparams"][constants.BE_MINMEM], 128) |
|
793 |
self.assertEqual(len(result["hvparams"]), 1) |
|
794 |
self.assertEqual(len(result["nics"]), 1) |
|
795 |
self.assertEqual(result["nics"][0]["nicparams"][constants.NIC_MODE], |
|
796 |
"mymode") |
|
797 |
|
|
798 |
# Generic object serialization |
|
799 |
result = runner._encoder((rpc_defs.ED_OBJECT_DICT, inst)) |
|
800 |
_CheckBasics(result) |
|
801 |
|
|
802 |
result = runner._encoder((rpc_defs.ED_OBJECT_DICT_LIST, 5 * [inst])) |
|
803 |
map(_CheckBasics, result) |
|
804 |
|
|
805 |
# Just an instance |
|
806 |
result = runner._encoder((rpc_defs.ED_INST_DICT, inst)) |
|
807 |
_CheckBasics(result) |
|
808 |
self.assertEqual(result["beparams"][constants.BE_MAXMEM], 256) |
|
809 |
self.assertEqual(result["hvparams"][constants.HT_KVM], { |
|
810 |
constants.HV_BLOCKDEV_PREFIX: "bar", |
|
811 |
constants.HV_ROOT_PATH: "/tmp", |
|
812 |
}) |
|
813 |
self.assertEqual(result["osparams"], { |
|
814 |
"role": "unknown", |
|
815 |
}) |
|
816 |
|
|
817 |
# Instance with OS parameters |
|
818 |
result = runner._encoder((rpc_defs.ED_INST_DICT_OSP, (inst, { |
|
819 |
"role": "webserver", |
|
820 |
"other": "field", |
|
821 |
}))) |
|
822 |
_CheckBasics(result) |
|
823 |
self.assertEqual(result["beparams"][constants.BE_MAXMEM], 256) |
|
824 |
self.assertEqual(result["hvparams"][constants.HT_KVM], { |
|
825 |
constants.HV_BLOCKDEV_PREFIX: "bar", |
|
826 |
constants.HV_ROOT_PATH: "/tmp", |
|
827 |
}) |
|
828 |
self.assertEqual(result["osparams"], { |
|
829 |
"role": "webserver", |
|
830 |
"other": "field", |
|
831 |
}) |
|
832 |
|
|
833 |
# Instance with hypervisor and backend parameters |
|
834 |
result = runner._encoder((rpc_defs.ED_INST_DICT_HVP_BEP, (inst, { |
|
835 |
constants.HT_KVM: { |
|
836 |
constants.HV_BOOT_ORDER: "xyz", |
|
837 |
}, |
|
838 |
}, { |
|
839 |
constants.BE_VCPUS: 100, |
|
840 |
constants.BE_MAXMEM: 4096, |
|
841 |
}))) |
|
842 |
_CheckBasics(result) |
|
843 |
self.assertEqual(result["beparams"][constants.BE_MAXMEM], 4096) |
|
844 |
self.assertEqual(result["beparams"][constants.BE_VCPUS], 100) |
|
845 |
self.assertEqual(result["hvparams"][constants.HT_KVM], { |
|
846 |
constants.HV_BOOT_ORDER: "xyz", |
|
847 |
}) |
|
848 |
|
|
738 | 849 |
|
739 | 850 |
if __name__ == "__main__": |
740 | 851 |
testutils.GanetiTestProgram() |
Also available in: Unified diff