From 67628dae8b37a226cb6899ffebffd66b40e74161 Mon Sep 17 00:00:00 2001 From: Michael E Brown Date: Tue, 8 Jan 2008 14:54:10 -0600 Subject: add ability to conditionally enable tmpfs based on minimum ram availability. --- etc/mock/defaults.cfg | 2 +- py/mock.py | 2 +- py/mock/plugins/tmpfs.py | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/etc/mock/defaults.cfg b/etc/mock/defaults.cfg index 626ef99..802f4c3 100644 --- a/etc/mock/defaults.cfg +++ b/etc/mock/defaults.cfg @@ -66,7 +66,7 @@ # config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('/host/path', '/bind/mount/path/in/chroot/' )) # # config_opts['plugin_conf']['tmpfs_enable'] = False -# config_opts['plugin_conf']['tmpfs_opts'] = {} +# config_opts['plugin_conf']['tmpfs_opts'] = {'required_ram_mb': 1024} ############################################################################# # diff --git a/py/mock.py b/py/mock.py index bf0d616..d27d73e 100755 --- a/py/mock.py +++ b/py/mock.py @@ -240,7 +240,7 @@ def setup_default_config_opts(config_opts, unprivUid): # ('/another/host/path', '/another/bind/mount/path/in/chroot/'), ]}, 'tmpfs_enable': False, - 'tmpfs_opts': {}, + 'tmpfs_opts': {'required_ram_mb': 900}, } # dependent on guest OS diff --git a/py/mock/plugins/tmpfs.py b/py/mock/plugins/tmpfs.py index 74c39a1..4896d26 100644 --- a/py/mock/plugins/tmpfs.py +++ b/py/mock/plugins/tmpfs.py @@ -15,7 +15,16 @@ requires_api_version = "1.0" # plugin entry point decorate(traceLog()) def init(rootObj, conf): - Tmpfs(rootObj, conf) + system_ram_bytes = os.sysconf(os.sysconf_names['SC_PAGE_SIZE']) * os.sysconf(os.sysconf_names['SC_PHYS_PAGES']) + system_ram_mb = system_ram_bytes / (1024 * 1024) + if system_ram_mb > conf['required_ram_mb']: + Tmpfs(rootObj, conf) + else: + getLog().warning("Tmpfs plugin disabled. " + "System does not have the required amount of RAM to enable the tmpfs plugin. " + "System has %sMB RAM, but the config specifies the minimum required is %sMB RAM. " + % + (system_ram_mb, conf['required_ram_mb'])) # classes class Tmpfs(object): -- cgit