Nir Soffer has uploaded a new change for review.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
cache: Replace utils.memoized with cache.memoized()
Repalce users of utils.memoized with cache.memoized() and remove utils.memoized. No behavior change is expected.
Change-Id: I12e2f2919cf92ff7d0758d70e2ed40523d66174f Signed-off-by: Nir Soffer nsoffer@redhat.com --- M lib/vdsm/netinfo.py M lib/vdsm/utils.py M tests/vmApiTests.py M vdsm/caps.py M vdsm/dmidecodeUtil.py M vdsm/ppc64HardwareInfo.py M vdsm/supervdsmServer M vdsm/virt/sampling.py 8 files changed, 30 insertions(+), 51 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/10/34710/1
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index d2ef90b..8c56863 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -43,7 +43,7 @@ from .ipwrapper import routeShowGateways from . import libvirtconnection from .netconfpersistence import RunningConfig -from .utils import memoized +from .cache import memoized from .netlink import link as nl_link from .netlink import addr as nl_addr from .netlink import route as nl_route @@ -395,7 +395,7 @@ return paddr
-@memoized +@memoized() def _getAllDefaultBondingOptions(): """ Return default options per mode, in a dictionary of dictionaries. All keys @@ -405,7 +405,7 @@ return json.loads(defaults.read())
-@memoized +@memoized() def _getDefaultBondingOptions(mode=None): """ Return default options for the given mode. If it is None, return options diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py index feb4079..131145c 100644 --- a/lib/vdsm/utils.py +++ b/lib/vdsm/utils.py @@ -51,6 +51,7 @@ import vdsm.infra.zombiereaper as zombiereaper
from cpopen import CPopen +from . import cache from . import constants
# Buffsize is 1K because I tested it on some use cases and 1K was fastest. If @@ -828,32 +829,6 @@ fcntl.fcntl(fd, fcntl.F_SETFD, old | fcntl.FD_CLOEXEC)
-class memoized(object): - """ - Decorator that caches a function's return value each time it is called. - If called later with the same arguments, the cached value is returned, and - not re-evaluated. There is no support for uncachable arguments. - - Adaptation from http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize - """ - def __init__(self, func): - self.func = func - self.cache = {} - functools.update_wrapper(self, func) - - def __call__(self, *args): - try: - return self.cache[args] - except KeyError: - value = self.func(*args) - self.cache[args] = value - return value - - def __get__(self, obj, objtype): - """Support instance methods.""" - return functools.partial(self.__call__, obj) - - def validateMinimalKeySet(dictionary, reqParams): if not all(key in dictionary for key in reqParams): raise ValueError @@ -993,7 +968,7 @@ sys.exit(-3)
-@memoized +@cache.memoized() def isOvirtNode(): return (os.path.exists('/etc/rhev-hypervisor-release') or bool(glob.glob('/etc/ovirt-node-*-release'))) diff --git a/tests/vmApiTests.py b/tests/vmApiTests.py index eb89fb1..4f940cf 100644 --- a/tests/vmApiTests.py +++ b/tests/vmApiTests.py @@ -25,14 +25,14 @@ from virt import vmexitreason from vdsm import define from testlib import VdsmTestCase as TestCaseBase -from vdsm import utils +from vdsm import cache from rpc import vdsmapi
import vmfakelib as fake
class TestSchemaCompliancyBase(TestCaseBase): - @utils.memoized + @cache.memoized() def _getAPI(self): testPath = os.path.realpath(__file__) dirName = os.path.split(testPath)[0] diff --git a/vdsm/caps.py b/vdsm/caps.py index dba9b5b..6e261d8 100644 --- a/vdsm/caps.py +++ b/vdsm/caps.py @@ -40,6 +40,7 @@ import dsaversion from vdsm import netinfo import hooks +from vdsm import cache from vdsm import utils import storage.hba from network.configurators import qos @@ -218,12 +219,12 @@ ENABLED = 1
-@utils.memoized +@cache.memoized() def _getCapsXMLStr(): return libvirtconnection.get().getCapabilities()
-@utils.memoized +@cache.memoized() def _getCpuTopology(capabilities): if capabilities is None: capabilities = _getCapsXMLStr() @@ -277,7 +278,7 @@ return None
-@utils.memoized +@cache.memoized() def _getLiveSnapshotSupport(arch, capabilities=None): if capabilities is None: capabilities = _getCapsXMLStr() @@ -294,7 +295,7 @@ return None
-@utils.memoized +@cache.memoized() def getLiveMergeSupport(): """ Determine if libvirt provides the necessary features to enable live merge. @@ -318,7 +319,7 @@ return True
-@utils.memoized +@cache.memoized() def getNumaTopology(): capabilities = _getCapsXMLStr() caps = minidom.parseString(capabilities) @@ -369,7 +370,7 @@ return memDict
-@utils.memoized +@cache.memoized() def getNumaNodeDistance(): nodeDistance = {} retcode, out, err = utils.execCmd(['numactl', '--hardware']) @@ -385,7 +386,7 @@ return nodeDistance
-@utils.memoized +@cache.memoized() def getAutoNumaBalancingInfo(): retcode, out, err = utils.execCmd(['sysctl', '-n', '-e', 'kernel.numa_balancing']) @@ -399,7 +400,7 @@ return AutoNumaBalancingStatus.UNKNOWN
-@utils.memoized +@cache.memoized() def _getEmulatedMachines(arch, capabilities=None): if capabilities is None: capabilities = _getCapsXMLStr() @@ -461,7 +462,7 @@ return allModels
-@utils.memoized +@cache.memoized() def _getCompatibleCpuModels(): c = libvirtconnection.get() allModels = _getAllCpuModels() @@ -532,7 +533,7 @@ return kdumpStatus
-@utils.memoized +@cache.memoized() def getos(): if os.path.exists('/etc/rhev-hypervisor-release'): return OSName.RHEVH @@ -550,7 +551,7 @@ return OSName.UNKNOWN
-@utils.memoized +@cache.memoized() def osversion(): version = release = ''
@@ -700,7 +701,7 @@ return info
-@utils.memoized +@cache.memoized() def _getVersionInfo(): if not hasattr(libvirt, 'VIR_MIGRATE_ABORT_ON_ERROR'): return _dropVersion('3.4', diff --git a/vdsm/dmidecodeUtil.py b/vdsm/dmidecodeUtil.py index add2526..f0c72fa 100644 --- a/vdsm/dmidecodeUtil.py +++ b/vdsm/dmidecodeUtil.py @@ -18,7 +18,7 @@ # Refer to the README and COPYING files for full details of the license #
-from vdsm import utils +from vdsm import cache
# This function gets dict and returns new dict that includes only string @@ -35,7 +35,7 @@ return ret
-@utils.memoized +@cache.memoized() def getAllDmidecodeInfo(): import dmidecode
@@ -45,7 +45,7 @@ return myLeafDict
-@utils.memoized +@cache.memoized() def getHardwareInfoStructure(): dmiInfo = getAllDmidecodeInfo() sysStruct = {} diff --git a/vdsm/ppc64HardwareInfo.py b/vdsm/ppc64HardwareInfo.py index 23f7388..1a89639 100644 --- a/vdsm/ppc64HardwareInfo.py +++ b/vdsm/ppc64HardwareInfo.py @@ -16,6 +16,7 @@ # Refer to the README and COPYING files for full details of the license #
+from vdsm import cache from vdsm import utils
import os @@ -31,7 +32,7 @@ return 'unavailable'
-@utils.memoized +@cache.memoized() def getHardwareInfoStructure(): infoStructure = {'systemSerialNumber': 'unavailable', 'systemFamily': 'unavailable', @@ -59,7 +60,7 @@ return infoStructure
-@utils.memoized +@cache.memoized() def getCpuTopology(capabilities): topology = {}
diff --git a/vdsm/supervdsmServer b/vdsm/supervdsmServer index c6c139b..aba32fb 100755 --- a/vdsm/supervdsmServer +++ b/vdsm/supervdsmServer @@ -51,6 +51,7 @@ except ImportError: _glusterEnabled = False
+from vdsm import cache from vdsm import utils from vdsm.tool import restore_nets from parted_utils import getDevicePartedInfo as _getDevicePartedInfo @@ -378,7 +379,7 @@ raise OSError(errno.EINVAL, "Could not reload-rules for device " "%s" % guid)
- @utils.memoized + @cache.memoized() def __udevVersion(self): cmd = [EXT_UDEVADM, '--version'] rc, out, err = utils.execCmd(cmd) diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py index 6bb4211..b1c3db6 100644 --- a/vdsm/virt/sampling.py +++ b/vdsm/virt/sampling.py @@ -30,6 +30,7 @@ import errno import re
+from vdsm import cache from vdsm import utils from vdsm import netinfo from vdsm.ipwrapper import getLinks @@ -524,7 +525,7 @@ if not self._stopEvent.isSet(): self._log.error("Error while sampling stats", exc_info=True)
- @utils.memoized + @cache.memoized() def _boot_time(self): # Try to get boot time only once, if N/A just log the error and never # include it in the response.
Nir Soffer has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 2:
Version 2 is rebased and minimize the change in utils.py.
Francesco Romani has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 2: Code-Review+1
(1 comment)
http://gerrit.ovirt.org/#/c/34710/2//COMMIT_MSG Commit Message:
Line 5: CommitDate: 2014-11-02 20:23:17 +0200 Line 6: Line 7: cache: Replace utils.memoized with cache.memoized() Line 8: Line 9: Repalce users of utils.memoized with cache.memoized() and remove typo: replace Line 10: utils.memoized. No behavior change is expected. Line 11: Line 12: Change-Id: I12e2f2919cf92ff7d0758d70e2ed40523d66174f
oVirt Jenkins CI Server has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 1:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13315/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/13155/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/12365/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1879/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_network_functional_tests_gerrit/212... : There was an infra issue, please contact infra@ovirt.org
oVirt Jenkins CI Server has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 2:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13325/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/13165/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/12375/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1881/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_network_functional_tests_gerrit/212... : There was an infra issue, please contact infra@ovirt.org
oVirt Jenkins CI Server has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 3:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13350/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/13190/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/12400/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1888/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_network_functional_tests_gerrit/213... : There was an infra issue, please contact infra@ovirt.org
oVirt Jenkins CI Server has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13354/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/13194/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/12404/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1889/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_network_functional_tests_gerrit/213... : There was an infra issue, please contact infra@ovirt.org
Nir Soffer has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4:
Versions 3 and 4 are rebase, no code change.
oVirt Jenkins CI Server has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13354/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/13194/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/12404/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1889/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_network_functional_tests_gerrit/213... : There was an infra issue, please contact infra@ovirt.org
Federico Simoncelli has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4: Code-Review+2
Yaniv Bronhaim has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4: Code-Review+1
Jenkins CI RO has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4:
Abandoned due to no activity - please restore if still relevant
Jenkins CI RO has abandoned this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Abandoned
Abandoned due to no activity - please restore if still relevant
automation@ovirt.org has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4:
* Update tracker::IGNORE, no Bug-Url found
Nir Soffer has restored this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Restored
Unabandon
Yaniv Bronhaim has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4:
please continue and verify
Jenkins CI RO has abandoned this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Abandoned
Abandoned due to no activity - please restore if still relevant
gerrit-hooks has posted comments on this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Patch Set 4:
* Update tracker: IGNORE, no Bug-Url found
Nir Soffer has restored this change.
Change subject: cache: Replace utils.memoized with cache.memoized() ......................................................................
Restored
vdsm-patches@lists.fedorahosted.org