How to use get_blk_string method in avocado

Best Python code snippet using avocado_python

memory.py

Source:memory.py Github

copy

Full Screen

...26class MemError(Exception):27 """28 called when memory operations fails29 """30def get_blk_string(block):31 """32 Format the given block id to string33 :param block: memory block id or block string.34 :type string: like 198 or memory19835 :return: returns string memory198 if id 198 is given36 :rtype: string37 """38 if not block.startswith("memory"):39 return "memory%s" % block40 return block41def _check_memory_state(block):42 """43 Check the given memory block is online or offline44 :param block: memory block id.45 :type string: like 198 or memory19846 :return: 'True' if online or 'False' if offline47 :rtype: bool48 """49 def _is_online():50 path = '/sys/devices/system/memory/%s/state' % get_blk_string(block)51 if genio.read_file(path) == 'online\n':52 return True53 return False54 return wait.wait_for(_is_online, timeout=10, step=0.2) or False55def check_hotplug():56 """57 Check kernel support for memory hotplug58 :return: True if hotplug supported, else False59 :rtype: 'bool'60 """61 if glob.glob('/sys/devices/system/memory/memory*'):62 return True63 return False64def is_hot_pluggable(block):65 """66 Check if the given memory block is hotpluggable67 :param block: memory block id.68 :type string: like 198 or memory19869 :return: True if hotpluggable, else False70 :rtype: 'bool'71 """72 path = '/sys/devices/system/memory/%s/removable' % get_blk_string(block)73 return bool(int(genio.read_file(path)))74def hotplug(block):75 """76 Online the memory for the given block id.77 :param block: memory block id or or memory19878 :type string: like 19879 """80 block = get_blk_string(block)81 with open('/sys/devices/system/memory/%s/state' % block, 'w') as state_file: # pylint: disable=W151482 state_file.write('online')83 if not _check_memory_state(block):84 raise MemError(85 "unable to hot-plug %s block, not supported ?" % block)86def hotunplug(block):87 """88 Offline the memory for the given block id.89 :param block: memory block id.90 :type string: like 198 or memory19891 """92 block = get_blk_string(block)93 with open('/sys/devices/system/memory/%s/state' % block, 'w') as state_file: # pylint: disable=W151494 state_file.write('offline')95 if _check_memory_state(block):96 raise MemError(97 "unable to hot-unplug %s block. Device busy?" % block)98def read_from_meminfo(key):99 """100 Retrieve key from meminfo.101 :param key: Key name, such as ``MemTotal``.102 """103 for line in genio.read_file("/proc/meminfo").splitlines():104 if key in line:105 return int(re.search(r"(\d+)\s*(?:kB)?$", line).group(1))106def memtotal():...

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