Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: setup: expose total memory in env ......................................................................
packaging: setup: expose total memory in env Includes I9d07718b1852f545813ce3893cca790a3294e2ad and I9d07718b1852f545813ce3893cca790a3294e2ad squashed. Change-Id: Ia25b24fb263390c9f6ae50708e2c3791d2c7a987 Bug-Url: https://bugzilla.redhat.com/1185411 Signed-off-by: Yedidyah Bar David <[email protected]> --- M packaging/setup/ovirt_engine_setup/constants.py M packaging/setup/plugins/ovirt-engine-common/base/system/__init__.py A packaging/setup/plugins/ovirt-engine-common/base/system/mem.py M packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/memcheck.py 4 files changed, 83 insertions(+), 31 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/75/37575/1 diff --git a/packaging/setup/ovirt_engine_setup/constants.py b/packaging/setup/ovirt_engine_setup/constants.py index 2d61383..e7d167f 100644 --- a/packaging/setup/ovirt_engine_setup/constants.py +++ b/packaging/setup/ovirt_engine_setup/constants.py @@ -416,6 +416,7 @@ def REMOTE_ENGINE_HOST_ROOT_PASSWORD(self): return 'OVESETUP_CONFIG/remoteEngineHostRootPassword' + TOTAL_MEMORY_MB = 'OVESETUP_CONFIG/totalMemoryMB' @util.export @util.codegen diff --git a/packaging/setup/plugins/ovirt-engine-common/base/system/__init__.py b/packaging/setup/plugins/ovirt-engine-common/base/system/__init__.py index 6986853..fbf4b53 100644 --- a/packaging/setup/plugins/ovirt-engine-common/base/system/__init__.py +++ b/packaging/setup/plugins/ovirt-engine-common/base/system/__init__.py @@ -1,6 +1,6 @@ # # ovirt-engine-setup -- ovirt engine setup -# Copyright (C) 2013 Red Hat, Inc. +# Copyright (C) 2013-2015 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,11 +23,13 @@ from . import hostile_services +from . import mem @util.export def createPlugins(context): hostile_services.Plugin(context=context) + mem.Plugin(context=context) # vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-common/base/system/mem.py b/packaging/setup/plugins/ovirt-engine-common/base/system/mem.py new file mode 100644 index 0000000..599c5b2 --- /dev/null +++ b/packaging/setup/plugins/ovirt-engine-common/base/system/mem.py @@ -0,0 +1,72 @@ +# +# ovirt-engine-setup -- ovirt engine setup +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import re +import gettext +_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup') + + +from otopi import util +from otopi import plugin + +from ovirt_engine_setup import constants as osetupcons + + [email protected] +class Plugin(plugin.PluginBase): + + _RE_MEMINFO_MEMTOTAL = re.compile( + flags=re.VERBOSE, + pattern=r""" + ^ + MemTotal: + \s+ + (?P<value>\d+) + \s+ + (?P<unit>\w+) + """ + ) + + def __init__(self, context): + super(Plugin, self).__init__(context=context) + self.environment.setdefault( + osetupcons.ConfigEnv.TOTAL_MEMORY_MB, + None + ) + + @plugin.event( + stage=plugin.Stages.STAGE_SETUP, + ) + def _setup(self): + self.logger.debug('Checking total memory') + with open('/proc/meminfo', 'r') as f: + content = f.read() + + match = self._RE_MEMINFO_MEMTOTAL.match(content) + if match is None: + raise RuntimeError(_("Unable to parse /proc/meminfo")) + + if self.environment[osetupcons.ConfigEnv.TOTAL_MEMORY_MB] is None: + self.environment[osetupcons.ConfigEnv.TOTAL_MEMORY_MB] = int( + match.group('value') + ) + if match.group('unit') == "kB": + self.environment[osetupcons.ConfigEnv.TOTAL_MEMORY_MB] //= 1024 + + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/memcheck.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/memcheck.py index 5a1af96..e177a77 100644 --- a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/memcheck.py +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/memcheck.py @@ -1,6 +1,6 @@ # # ovirt-engine-setup -- ovirt engine setup -# Copyright (C) 2013 Red Hat, Inc. +# Copyright (C) 2013-2015 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ """ -import re import gettext _ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup') @@ -39,25 +38,15 @@ """ Available memory checking plugin. """ - _RE_MEMINFO_MEMTOTAL = re.compile( - flags=re.VERBOSE, - pattern=r""" - ^ - MemTotal: - \s+ - (?P<value>\d+) - \s+ - (?P<unit>\w+) - """ - ) def __init__(self, context): super(Plugin, self).__init__(context=context) - self._total_memory = 0 def _check_requirements(self): satisfied = False - if self._total_memory < self.environment[ + if self.environment[ + osetupcons.ConfigEnv.TOTAL_MEMORY_MB + ] < self.environment[ oenginecons.SystemEnv.MEMCHECK_MINIMUM_MB ] * self.environment[ oenginecons.SystemEnv.MEMCHECK_THRESHOLD @@ -78,7 +67,9 @@ ) else: satisfied = True - if self._total_memory < self.environment[ + if self.environment[ + osetupcons.ConfigEnv.TOTAL_MEMORY_MB + ] < self.environment[ oenginecons.SystemEnv.MEMCHECK_RECOMMENDED_MB ] * self.environment[ oenginecons.SystemEnv.MEMCHECK_THRESHOLD @@ -124,20 +115,6 @@ """ Check if the system met the memory requirements. """ - self.logger.debug('Checking total memory') - with open('/proc/meminfo', 'r') as f: - content = f.read() - - match = self._RE_MEMINFO_MEMTOTAL.match(content) - if match is None: - raise RuntimeError(_("Unable to parse /proc/meminfo")) - - self._total_memory = int( - match.group('value') - ) - if match.group('unit') == "kB": - self._total_memory //= 1024 - self._satisfied = self._check_requirements() @plugin.event( -- To view, visit http://gerrit.ovirt.org/37575 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia25b24fb263390c9f6ae50708e2c3791d2c7a987 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Yedidyah Bar David <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
