Royce Lv has uploaded a new change for review. Change subject: Change mom policy related interface to support multi-policy ......................................................................
Change mom policy related interface to support multi-policy Change-Id: I09c40fee74b10d3eb41f4ec3ca18096a9b20dfcd Signed-off-by: Royce Lv<[email protected]> --- M .gitignore M tests/functional/Makefile.am R tests/functional/momTests.py.in M vdsm/API.py M vdsm/BindingXMLRPC.py M vdsm/momIF.py M vdsm_cli/vdsClient.py 7 files changed, 56 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/12466/1 diff --git a/.gitignore b/.gitignore index 41066dd..b9b992c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ config.status configure results.log +tests/functional/momTests.py tests/run_tests.sh tests/run_tests_local.sh vdsm-*.tar.gz diff --git a/tests/functional/Makefile.am b/tests/functional/Makefile.am index 030242b..fe4f276 100644 --- a/tests/functional/Makefile.am +++ b/tests/functional/Makefile.am @@ -17,12 +17,21 @@ # # Refer to the README and COPYING files for full details of the license # +include $(top_srcdir)/build-aux/Makefile.subs vdsmfunctestsdir = ${vdsmtestsdir}/functional dist_vdsmfunctests_PYTHON = \ - momTests.py \ sosPluginTests.py \ xmlrpcTests.py \ $(NULL) +nodist_vdsmfunctests_PYTHON = \ + momTests.py + +EXTRA_DIST = \ + momTests.py.in + +CLEANFILES = \ + $(nodist_vdsmfunctests_PYTHON) + diff --git a/tests/functional/momTests.py b/tests/functional/momTests.py.in similarity index 76% rename from tests/functional/momTests.py rename to tests/functional/momTests.py.in index 1981e05..c54b427 100644 --- a/tests/functional/momTests.py +++ b/tests/functional/momTests.py.in @@ -18,6 +18,7 @@ # Refer to the README and COPYING files for full details of the license # import imp +import os import random import time @@ -54,3 +55,17 @@ hostStats = s.getVdsStats()['info'] self.assertEqual(bool(run), hostStats['ksmState']) self.assertEqual(pages_to_scan, hostStats['ksmPages']) + + @testValidation.ValidateRunningAsRoot + def testDefaultPolicy(self): + s = vdscli.connect() + r = s.getMOMPolicy() + + policy_dir = '@CONFDIR@/mom-policy-dir' + names = sorted(os.listdir(policy_dir)) + for name in names: + if name.startswith('.') or not name.endswith('.policy'): + fname = os.path.join(policy_dir, name) + with open(fname, 'r') as f: + policyStr = f.read() + self.assertEqual(policyStr, r['policyDict'].get(name)) diff --git a/vdsm/API.py b/vdsm/API.py index 0046b57..0f02fde 100644 --- a/vdsm/API.py +++ b/vdsm/API.py @@ -1379,6 +1379,12 @@ except: return errCode['momErr'] + def getMOMPolicy(self): + try: + return dict(status=doneCode, + policyDict=self._cif.mom.getPolicy()) + except: + return errCode['momErr'] # take a rough estimate on how much free mem is available for new vm # memTotal = memFree + memCached + mem_used_by_non_qemu + resident . # simply returning (memFree + memCached) is not good enough, as the diff --git a/vdsm/BindingXMLRPC.py b/vdsm/BindingXMLRPC.py index 9a4db12..a540900 100644 --- a/vdsm/BindingXMLRPC.py +++ b/vdsm/BindingXMLRPC.py @@ -401,6 +401,10 @@ api = API.Global() return api.setMOMPolicy(policy) + def getMOMPolicy(self): + api = API.Global() + return api.getMOMPolicy() + def domainActivate(self, sdUUID, spUUID, options=None): domain = API.StorageDomain(sdUUID) return domain.activate(spUUID) @@ -807,6 +811,7 @@ (self.fenceNode, 'fenceNode'), (self.prepareForShutdown, 'prepareForShutdown'), (self.setLogLevel, 'setLogLevel'), + (self.getMOMPolicy, 'getMOMPolicy'), (self.setMOMPolicy, 'setMOMPolicy'), (self.vmHotplugDisk, 'hotplugDisk'), (self.vmHotunplugDisk, 'hotunplugDisk'), diff --git a/vdsm/momIF.py b/vdsm/momIF.py index d0f63d1..831b649 100644 --- a/vdsm/momIF.py +++ b/vdsm/momIF.py @@ -56,9 +56,16 @@ ret['ksmCpu'] = stats['ksmd_cpu_usage'] return ret - def setPolicy(self, policyStr): - # mom.setPolicy will raise an exception on failure. - self._mom.setPolicy(policyStr) + def setPolicy(self, policyParam): + if isinstance(policyParam, dict) and len(policyParam) == 1: + policy = policyParam.popItem() + self._mom.setNamedPolicy(policy[0], policy[1]) + else: + # mom.setPolicy will raise an exception on failure. + self._mom.setPolicy(policyParam) + + def getPolicy(self): + return self._mom.getNamedPolicies() def stop(self): if self._mom is not None: diff --git a/vdsm_cli/vdsClient.py b/vdsm_cli/vdsClient.py index 1da7d5f..1fa0d22 100644 --- a/vdsm_cli/vdsClient.py +++ b/vdsm_cli/vdsClient.py @@ -1404,6 +1404,12 @@ return stats['status']['code'], stats['status']['message'] return 0, '' + def do_getMOMPolicy(self, policyFile): + stats = self.s.getMOMPolicy() + if stats['status']['code']: + return stats['status']['code'], stats['status']['message'] + return 0, '' + def do_setMOMPolicy(self, policyFile): stats = self.s.setMOMPolicy(policyFile) if stats['status']['code']: @@ -2253,6 +2259,9 @@ ('<level> [logName][,logName]...', 'set log verbosity' ' level (10=DEBUG, 50=CRITICAL' )), + 'getMOMPolicy': (serv.do_getMOMPolicy, + ('', 'get MOM policy')), + 'setMOMPolicy': (serv.do_setMOMPolicy, ('<policyfile>', 'set MOM policy')), 'deleteImage': (serv.deleteImage, -- To view, visit http://gerrit.ovirt.org/12466 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I09c40fee74b10d3eb41f4ec3ca18096a9b20dfcd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Royce Lv <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
