How to use module_name method in avocado

Best Python code snippet using avocado_python

mgr_modules.py

Source:mgr_modules.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import absolute_import3from . import ApiController, RESTController4from .. import mgr5from ..security import Scope6from ..services.ceph_service import CephService7from ..services.exception import handle_send_command_error8from ..tools import find_object_in_list, str_to_bool9@ApiController('/mgr/module', Scope.CONFIG_OPT)10class MgrModules(RESTController):11 ignore_modules = ['selftest']12 def list(self):13 """14 Get the list of managed modules.15 :return: A list of objects with the fields 'enabled', 'name' and 'options'.16 :rtype: list17 """18 result = []19 mgr_map = mgr.get('mgr_map')20 always_on_modules = mgr_map['always_on_modules'][mgr.release_name]21 for module_config in mgr_map['available_modules']:22 module_name = module_config['name']23 if module_name not in self.ignore_modules:24 always_on = module_name in always_on_modules25 enabled = module_name in mgr_map['modules'] or always_on26 result.append({27 'name': module_name,28 'enabled': enabled,29 'always_on': always_on,30 'options': self._convert_module_options(31 module_config['module_options'])32 })33 return result34 def get(self, module_name):35 """36 Retrieve the values of the persistent configuration settings.37 :param module_name: The name of the Ceph Mgr module.38 :type module_name: str39 :return: The values of the module options.40 :rtype: dict41 """42 assert self._is_module_managed(module_name)43 options = self._get_module_options(module_name)44 result = {}45 for name, option in options.items():46 result[name] = mgr.get_module_option_ex(module_name, name,47 option['default_value'])48 return result49 @RESTController.Resource('PUT')50 def set(self, module_name, config):51 """52 Set the values of the persistent configuration settings.53 :param module_name: The name of the Ceph Mgr module.54 :type module_name: str55 :param config: The values of the module options to be stored.56 :type config: dict57 """58 assert self._is_module_managed(module_name)59 options = self._get_module_options(module_name)60 for name in options.keys():61 if name in config:62 mgr.set_module_option_ex(module_name, name, config[name])63 @RESTController.Resource('POST')64 @handle_send_command_error('mgr_modules')65 def enable(self, module_name):66 """67 Enable the specified Ceph Mgr module.68 :param module_name: The name of the Ceph Mgr module.69 :type module_name: str70 """71 assert self._is_module_managed(module_name)72 CephService.send_command(73 'mon', 'mgr module enable', module=module_name)74 @RESTController.Resource('POST')75 @handle_send_command_error('mgr_modules')76 def disable(self, module_name):77 """78 Disable the specified Ceph Mgr module.79 :param module_name: The name of the Ceph Mgr module.80 :type module_name: str81 """82 assert self._is_module_managed(module_name)83 CephService.send_command(84 'mon', 'mgr module disable', module=module_name)85 @RESTController.Resource('GET')86 def options(self, module_name):87 """88 Get the module options of the specified Ceph Mgr module.89 :param module_name: The name of the Ceph Mgr module.90 :type module_name: str91 :return: The module options as list of dicts.92 :rtype: list93 """94 assert self._is_module_managed(module_name)95 return self._get_module_options(module_name)96 def _is_module_managed(self, module_name):97 """98 Check if the specified Ceph Mgr module is managed by this service.99 :param module_name: The name of the Ceph Mgr module.100 :type module_name: str101 :return: Returns ``true`` if the Ceph Mgr module is managed by102 this service, otherwise ``false``.103 :rtype: bool104 """105 if module_name in self.ignore_modules:106 return False107 mgr_map = mgr.get('mgr_map')108 for module_config in mgr_map['available_modules']:109 if module_name == module_config['name']:110 return True111 return False112 def _get_module_config(self, module_name):113 """114 Helper function to get detailed module configuration.115 :param module_name: The name of the Ceph Mgr module.116 :type module_name: str117 :return: The module information, e.g. module name, can run,118 error string and available module options.119 :rtype: dict or None120 """121 mgr_map = mgr.get('mgr_map')122 return find_object_in_list('name', module_name,123 mgr_map['available_modules'])124 def _get_module_options(self, module_name):125 """126 Helper function to get the module options.127 :param module_name: The name of the Ceph Mgr module.128 :type module_name: str129 :return: The module options.130 :rtype: dict131 """132 options = self._get_module_config(module_name)['module_options']133 return self._convert_module_options(options)134 def _convert_module_options(self, options):135 # Workaround a possible bug in the Ceph Mgr implementation.136 # Various fields (e.g. default_value, min, max) are always137 # returned as a string.138 for option in options.values():139 if option['type'] == 'str':140 if option['default_value'] == 'None': # This is Python None141 option['default_value'] = ''142 elif option['type'] == 'bool':143 if option['default_value'] == '':144 option['default_value'] = False145 else:146 option['default_value'] = str_to_bool(147 option['default_value'])148 elif option['type'] == 'float':149 for name in ['default_value', 'min', 'max']:150 if option[name]: # Skip empty entries151 option[name] = float(option[name])152 elif option['type'] in ['uint', 'int', 'size', 'secs']:153 for name in ['default_value', 'min', 'max']:154 if option[name]: # Skip empty entries155 option[name] = int(option[name])...

Full Screen

Full Screen

patch.py

Source:patch.py Github

copy

Full Screen

1import sys2import importlib3from types import FunctionType, ModuleType4class SoftPatch(object):5 def __init__(self, module_name):6 self.module_name = module_name7 patcher._register(module_name, self)8 def _apply_patch(self, module):9 apply_patch = FunctionType(self.apply_patch.func_code, module.__dict__)10 module.__dict__.update(apply_patch())11 @staticmethod12 def apply_patch():13 return {}14class HardPatch(object):15 def __init__(self, module_name):16 self.module_name = module_name17 patcher._register(module_name, self)18 def _create_module(self):19 module = ModuleType(self.module_name)20 apply_patch = FunctionType(self.apply_patch.func_code, dict(globals(), **module.__dict__))21 module.__dict__.update(apply_patch())22 return module23 @staticmethod24 def apply_patch():25 return {}26class Patcher(object):27 def __init__(self):28 self._patch = {}29 self._soft_patches = {}30 self._hard_patches = {}31 self._loaded = {}32 self._loading = {}33 def _register(self, module_name, patch):34 if isinstance(patch, SoftPatch):35 if module_name not in self._soft_patches:36 self._soft_patches[module_name] = []37 self._soft_patches[module_name].append(patch)38 elif isinstance(patch, HardPatch):39 self._hard_patches[module_name] = patch40 else:41 raise TypeError(type(patch))42 self._patch[module_name] = True43 def find_module(self, module_name, path=None):44 if self._patch.get(module_name, False):45 return self46 def load_module(self, module_name):47 if module_name not in self._loaded:48 hard_patch = self._hard_patches.get(module_name, None)49 if hard_patch:50 module = hard_patch._create_module()51 sys.modules[module_name] = module52 else:53 # Before actually importing, we have to bypass our54 # find_module function.55 self._patch[module_name] = False56 module = importlib.import_module(module_name)57 self._patch[module_name] = True58 # Apply soft patches the module59 for patch in self._soft_patches.get(module_name, []):60 patch._apply_patch(module)61 self._loaded[module_name] = module62 return self._loaded[module_name]63patcher = Patcher()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful