def run_script_on_compute_nodes(script, stdout, stderr, interpreter='sh'): """Run an inline script on compute nodes. """ geopm_test_launcher.allocation_node_test( 'dummy -- {}'.format('{} -c {}'.format(interpreter, pipes.quote(script))), stdout, stderr)
def skip_unless_stressng(): if not g_util.skip_launch(): try: test_exec = "dummy -- stress-ng -h" dev_null = open('/dev/null', 'w') geopm_test_launcher.allocation_node_test(test_exec, dev_null, dev_null) dev_null.close() except subprocess.CalledProcessError: return unittest.skip( "Missing stress-ng. Please install in the compute image.") return lambda func: func
def skip_unless_cpufreq(): if not g_util.skip_launch(): try: test_exec = "dummy -- stat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq" dev_null = open('/dev/null', 'w') geopm_test_launcher.allocation_node_test(test_exec, dev_null, dev_null) dev_null.close() except subprocess.CalledProcessError: return unittest.skip( "Could not determine min frequency, enable cpufreq driver to run this test." ) return lambda func: func
def skip_unless_library_in_ldconfig(library): """Skip the test if the given library is not in ldconfig on the compute nodes. """ if not g_util.skip_launch(): try: with open('/dev/null', 'w') as dev_null: stdout = StringIO() geopm_test_launcher.allocation_node_test( 'dummy -- ldconfig --print-cache', stdout, dev_null) stdout.seek(0) if not any( line.startswith('\t{}'.format(library)) for line in stdout): return unittest.skip( "Library '{}' not in ldconfig".format(library)) except subprocess.CalledProcessError: return unittest.skip("Unable to run ldconfig") return lambda func: func
def setUpClass(cls): script_dir = os.path.dirname(os.path.realpath(__file__)) cls._app_exec_path = os.path.join(script_dir, '.libs', 'test_enforce_policy') # note: if /etc/geopm/environment-*.json sets the same variables, this # test will not work. for env_file in ['/etc/geopm/environment-default.json', '/etc/geopm/environment-override.json']: try: stdout = io.StringIO() stderr = io.StringIO() geopm_test_launcher.allocation_node_test('dummy -- cat {}'.format(env_file), stdout, stderr) file_contents = stdout.getvalue() if "GEOPM_POLICY" in file_contents: raise RuntimeError("{} contains GEOPM_POLICY".format(env_file)) if "GEOPM_AGENT" in file_contents: raise RuntimeError("{} contains GEOPM_AGENT".format(env_file)) except subprocess.CalledProcessError: pass
def skip_or_ensure_writable_file(path): """Skip the test unless the given file can be created or modified on compute nodes. """ if g_util.skip_launch(): return unittest.skip( "This test requires launch; do not use --skip-launch") stdout = StringIO() created_directories = list() try: dirname = os.path.dirname(path) with open('/dev/null', 'w') as dev_null: # Ensure the parent directory exists geopm_test_launcher.allocation_node_test( 'dummy -- mkdir -vp {}'.format(dirname), stdout, dev_null) stdout.seek(0) pattern = re.compile(r"mkdir: created directory '([^']+)'") for line in stdout: match = pattern.search(line) if match: created_directories.append(match.group(1)) run_script_on_compute_nodes( "test '(' '!' -e {path} -a -w {dirname} ')' -o -w {path}". format(path=pipes.quote(path), dirname=pipes.quote(dirname)), sys.stdout, sys.stdout) except subprocess.CalledProcessError as e: return unittest.skip("Cannot write to path: {}".format(path)) def cleanup_decorator(func): def cleanup_wrapper(*args, **kwargs): try: func(*args, **kwargs) finally: for directory in reversed(created_directories): shutil.rmtree(directory) return cleanup_wrapper return cleanup_decorator
def remove_file_on_compute_nodes(file_path): """Remove a file from compute nodes. """ with open('/dev/null', 'w') as dev_null: geopm_test_launcher.allocation_node_test( 'dummy -- rm {}'.format(file_path), dev_null, dev_null)