def setup_package(): bonding_dump_patchers.append( mock.patch( 'vdsm.network.link.bond.sysfs_options.BONDING_DEFAULTS', ALTERNATIVE_BONDING_DEFAULTS, )) bonding_dump_patchers.append( mock.patch( 'vdsm.network.link.bond.sysfs_options_mapper.' 'BONDING_NAME2NUMERIC_PATH', ALTERNATIVE_BONDING_NAME2NUMERIC_PATH, )) for patcher in bonding_dump_patchers: patcher.start() if has_sysfs_bond_permission(): try: sysfs_options_mapper.dump_bonding_options() except EnvironmentError as e: if e.errno != errno.ENOENT: raise if os.geteuid() == 0: _pre_cleanup_stale_iprules()
def bond_option_mapping(): file1 = tempfile.NamedTemporaryFile() file2 = tempfile.NamedTemporaryFile() with file1 as f_bond_defaults, file2 as f_bond_name2numeric: if has_sysfs_bond_permission(): ALTERNATIVE_BONDING_DEFAULTS = f_bond_defaults.name ALTERNATIVE_BONDING_NAME2NUMERIC_PATH = f_bond_name2numeric.name else: ALTERNATIVE_BONDING_DEFAULTS = os.path.join( os.path.dirname(network_tests.__file__), 'static', 'bonding-defaults.json', ) ALTERNATIVE_BONDING_NAME2NUMERIC_PATH = os.path.join( os.path.dirname(network_tests.__file__), 'static', 'bonding-name2numeric.json', ) patch_bonding_defaults = mock.patch( 'vdsm.network.link.bond.sysfs_options.BONDING_DEFAULTS', ALTERNATIVE_BONDING_DEFAULTS, ) patch_bonding_name2num = mock.patch( 'vdsm.network.link.bond.sysfs_options_mapper.' 'BONDING_NAME2NUMERIC_PATH', ALTERNATIVE_BONDING_NAME2NUMERIC_PATH, ) with patch_bonding_defaults, patch_bonding_name2num: if has_sysfs_bond_permission(): sysfs_options_mapper.dump_bonding_options() yield
def bond_option_mapping(): file1 = tempfile.NamedTemporaryFile() file2 = tempfile.NamedTemporaryFile() with file1 as f_bond_defaults, file2 as f_bond_name2numeric: if has_sysfs_bond_permission(): ALTERNATIVE_BONDING_DEFAULTS = f_bond_defaults.name ALTERNATIVE_BONDING_NAME2NUMERIC_PATH = f_bond_name2numeric.name else: ALTERNATIVE_BONDING_DEFAULTS = os.path.join( os.path.dirname(network_tests.__file__), 'static', 'bonding-defaults.json' ) ALTERNATIVE_BONDING_NAME2NUMERIC_PATH = os.path.join( os.path.dirname(network_tests.__file__), 'static', 'bonding-name2numeric.json' ) patch_bonding_defaults = mock.patch( 'vdsm.network.link.bond.sysfs_options.BONDING_DEFAULTS', ALTERNATIVE_BONDING_DEFAULTS ) patch_bonding_name2num = mock.patch( 'vdsm.network.link.bond.sysfs_options_mapper.' 'BONDING_NAME2NUMERIC_PATH', ALTERNATIVE_BONDING_NAME2NUMERIC_PATH ) with patch_bonding_defaults, patch_bonding_name2num: if has_sysfs_bond_permission(): sysfs_options_mapper.dump_bonding_options() yield
def bonding_default_fpath(): if _has_sysfs_bond_permission(): sysfs_options_mapper.dump_bonding_options() if os.path.exists(BONDING_DEFAULTS): file_path = BONDING_DEFAULTS else: file_path = ALTERNATIVE_BONDING_DEFAULTS return file_path
def bonding_default_fpath(): if _has_sysfs_bond_permission(): sysfs_options_mapper.dump_bonding_options() if os.path.exists(BONDING_DEFAULTS): file_path = BONDING_DEFAULTS else: file_path = ALTERNATIVE_BONDING_DEFAULTS return file_path
def dump_bonding_options(*args): """dump-bonding-options Two actions are taken: - Read bonding option defaults (per mode) and dump them to BONDING_DEFAULTS in JSON format. - Read bonding option possible values (per mode) and dump them to BONDING_NAME2NUMERIC_PATH in JSON format. """ if len(args) > 1: raise ExtraArgsError() sysfs_options_mapper.dump_bonding_options()
def dump_bonding_options(*args): """dump-bonding-options Two actions are taken: - Read bonding option defaults (per mode) and dump them to BONDING_DEFAULTS in JSON format. - Read bonding option possible values (per mode) and dump them to BONDING_NAME2NUMERIC_PATH in JSON format. """ if len(args) > 1: raise ExtraArgsError() sysfs_options_mapper.dump_bonding_options()
def bonding_default_fpath(): bonding_defaults_fpath = ALTERNATIVE_BONDING_DEFAULTS bonding_name2num_fpath = ALTERNATIVE_BONDING_NAME2NUMERIC_PATH if _has_sysfs_bond_permission(): try: sysfs_options_mapper.dump_bonding_options() except EnvironmentError as e: if e.errno != errno.ENOENT: raise if os.path.exists(BONDING_DEFAULTS): bonding_defaults_fpath = BONDING_DEFAULTS if os.path.exists(sysfs_options_mapper.BONDING_NAME2NUMERIC_PATH): bonding_name2num_fpath = sysfs_options_mapper.BONDING_NAME2NUMERIC_PATH return bonding_defaults_fpath, bonding_name2num_fpath
def configure(): sysfs_options_mapper.dump_bonding_options()