How to use ext_mkfs_options method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...111 tune2fs_dict[option] = int(value)112 else:113 tune2fs_dict[option] = value114 return tune2fs_dict115def ext_mkfs_options(tune2fs_dict, mkfs_option):116 """Map the tune2fs options to mkfs options."""117 def __inode_count(tune_dict, k):118 return (tune_dict['Block count']/tune_dict[k] + 1) * (119 tune_dict['Block size'])120 def __block_count(tune_dict, k):121 return int(100*tune_dict[k]/tune_dict['Block count'] + 1)122 def __volume_name(tune_dict, k):123 if tune_dict[k] != '<none>':124 return tune_dict[k]125 else:126 return ''127 # mappings between fs features and mkfs options128 ext_mapping = {'Blocks per group': '-g',129 'Block size': '-b',130 'Filesystem features': '-O',131 'Filesystem OS type': '-o',132 'Filesystem revision #': '-r',133 'Filesystem volume name': '-L',134 'Flex block group size': '-G',135 'Fragment size': '-f',136 'Inode count': '-i',137 'Inode size': '-I',138 'Journal inode': '-j',139 'Reserved block count': '-m'}140 conversions = {141 'Journal inode': lambda d, k: None,142 'Filesystem volume name': __volume_name,143 'Reserved block count': __block_count,144 'Inode count': __inode_count,145 'Filesystem features': lambda d, k: re.sub(' ', ',', d[k]),146 'Filesystem revision #': lambda d, k: d[k][0]}147 for key, value in ext_mapping.iteritems():148 if key not in tune2fs_dict:149 continue150 if key in conversions:151 mkfs_option[value] = conversions[key](tune2fs_dict, key)152 else:153 mkfs_option[value] = tune2fs_dict[key]154def xfs_tunables(dev):155 """Call xfs_grow -n to get filesystem tunables."""156 # Have to mount the filesystem to call xfs_grow.157 tmp_mount_dir = tempfile.mkdtemp()158 cmd = 'mount %s %s' % (dev, tmp_mount_dir)159 utils.system_output(cmd)160 xfs_growfs = os.path.join(os.environ['AUTODIR'], 'tools', 'xfs_growfs')161 cmd = '%s -n %s' % (xfs_growfs, dev)162 try:163 out = utils.system_output(cmd)164 finally:165 # Clean.166 cmd = 'umount %s' % dev167 utils.system_output(cmd, ignore_status=True)168 os.rmdir(tmp_mount_dir)169 ## The output format is given in report_info (xfs_growfs.c)170 ## "meta-data=%-22s isize=%-6u agcount=%u, agsize=%u blks\n"171 ## " =%-22s sectsz=%-5u attr=%u\n"172 ## "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"173 ## " =%-22s sunit=%-6u swidth=%u blks\n"174 ## "naming =version %-14u bsize=%-6u\n"175 ## "log =%-22s bsize=%-6u blocks=%u, version=%u\n"176 ## " =%-22s sectsz=%-5u sunit=%u blks, lazy-count=%u\n"177 ## "realtime =%-22s extsz=%-6u blocks=%llu, rtextents=%llu\n"178 tune2fs_dict = {}179 # Flag for extracting naming version number180 keep_version = False181 for line in out.splitlines():182 m ='^([-\w]+)', line)183 if m:184 main_tag = pairs = line.split()186 for pair in pairs:187 # naming: version needs special treatment188 if pair == '=version':189 # 1 means the next pair is the version number we want190 keep_version = True191 continue192 if keep_version:193 tune2fs_dict['naming: version'] = pair194 # Resets the flag since we have logged the version195 keep_version = False196 continue197 # Ignores the strings without '=', such as 'blks'198 if '=' not in pair:199 continue200 key, value = pair.split('=')201 tagged_key = '%s: %s' % (main_tag, key)202 if re.match('[0-9]+', value):203 tune2fs_dict[tagged_key] = int(value.rstrip(','))204 else:205 tune2fs_dict[tagged_key] = value.rstrip(',')206 return tune2fs_dict207def xfs_mkfs_options(tune2fs_dict, mkfs_option):208 """Maps filesystem tunables to their corresponding mkfs options."""209 # Mappings210 xfs_mapping = {'meta-data: isize': '-i size',211 'meta-data: agcount': '-d agcount',212 'meta-data: sectsz': '-s size',213 'meta-data: attr': '-i attr',214 'data: bsize': '-b size',215 'data: imaxpct': '-i maxpct',216 'data: sunit': '-d sunit',217 'data: swidth': '-d swidth',218 'data: unwritten': '-d unwritten',219 'naming: version': '-n version',220 'naming: bsize': '-n size',221 'log: version': '-l version',222 'log: sectsz': '-l sectsize',223 'log: sunit': '-l sunit',224 'log: lazy-count': '-l lazy-count',225 'realtime: extsz': '-r extsize',226 'realtime: blocks': '-r size',227 'realtime: rtextents': '-r rtdev'}228 mkfs_option['-l size'] = tune2fs_dict['log: bsize'] * (229 tune2fs_dict['log: blocks'])230 for key, value in xfs_mapping.iteritems():231 mkfs_option[value] = tune2fs_dict[key]232def compare_features(needed_feature, current_feature):233 """Compare two ext* feature lists."""234 if len(needed_feature) != len(current_feature):235 return False236 for feature in current_feature:237 if feature not in needed_feature:238 return False239 return True240def match_ext_options(fs_type, dev, needed_options):241 """Compare the current ext* filesystem tunables with needed ones."""242 # mkfs.ext* will load default options from /etc/mke2fs.conf243 conf_opt = parse_mke2fs_conf(fs_type)244 # We need to convert the conf options to mkfs options.245 conf_mkfs_opt = convert_conf_opt(conf_opt)246 # Breaks user mkfs option string to dictionary.247 needed_opt_dict = opt_string2dict(needed_options)248 # Removes ignored options.249 ignored_option = ['-c', '-q', '-E', '-F']250 for opt in ignored_option:251 if opt in needed_opt_dict:252 del needed_opt_dict[opt]253 # User options override config options.254 needed_opt = conf_mkfs_opt255 for key, value in needed_opt_dict.iteritems():256 if key == '-N' or key == '-T':257 raise Exception('-N/T is not allowed.')258 elif key == '-O':259 needed_opt[key] = merge_ext_features(needed_opt[key], value)260 else:261 needed_opt[key] = value262 # '-j' option will add 'has_journal' feature.263 if '-j' in needed_opt and 'has_journal' not in needed_opt['-O']:264 needed_opt['-O'].append('has_journal')265 # 'extents' will be shown as 'extent' in the outcome of tune2fs266 if 'extents' in needed_opt['-O']:267 needed_opt['-O'].append('extent')268 needed_opt['-O'].remove('extents')269 # large_file is a byproduct of resize_inode.270 if 'large_file' not in needed_opt['-O'] and (271 'resize_inode' in needed_opt['-O']):272 needed_opt['-O'].append('large_file')273 current_opt = {}274 tune2fs_dict = ext_tunables(dev)275 ext_mkfs_options(tune2fs_dict, current_opt)276 # Does the match277 for key, value in needed_opt.iteritems():278 if key == '-O':279 if not compare_features(value, current_opt[key].split(',')):280 return False281 elif key not in current_opt or value != current_opt[key]:282 return False283 return True284def match_xfs_options(dev, needed_options):285 """Compare the current ext* filesystem tunables with needed ones."""286 tmp_mount_dir = tempfile.mkdtemp()287 cmd = 'mount %s %s' % (dev, tmp_mount_dir)288 utils.system_output(cmd)289 xfs_growfs = os.path.join(os.environ['AUTODIR'], 'tools', 'xfs_growfs')...

Full Screen

Full Screen Github


Full Screen

...11 self.god.unstub_all()12 def create_test_file(self, filename, contents):13 test_file = StringIO.StringIO(contents)14, 'r').and_return(test_file)15 def test_ext_mkfs_options(self):16 tune2fs_dict = {'Filesystem volume name': '<none>',17 'Last mounted on': '<not available>',18 'Filesystem revision #': '1 (dynamic)',19 'Block size': 4096,20 'Block count': 263056,21 'Fragment size': 4096,22 'Blocks per group': 32768,23 'Journal inode': 8,24 'Reserved block count': 2630,25 'Inode count': 131616,26 'Filesystem features': 'filetype sparse_super',27 'Filesystem OS type': 'Linux'}28 expected_option = {'-b': 4096,29 '-f': 4096,30 '-g': 32768,31 '-j': None,32 '-m': 1,33 '-O': 'filetype,sparse_super',34 '-o': 'Linux',35 '-r': '1'}36 mkfs_option = {}37 fsinfo.ext_mkfs_options(tune2fs_dict, mkfs_option)38 for option, value in expected_option.iteritems():39 self.assertEqual(value, mkfs_option[option])40 def test_xfs_mkfs_options(self):41 tune2fs_dict = {'meta-data: isize': 256,42 'meta-data: agcount': 8,43 'meta-data: agsize': 32882,44 'meta-data: sectsz': 512,45 'meta-data: attr': 0,46 'data: bsize': 4096,47 'data: imaxpct': 25,48 'data: sunit': 0,49 'data: swidth': 0,50 'data: unwritten': 1,51 'naming: version': 2,...

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:


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

Run autotest 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?