Best Python code snippet using lisa_python
lvm_utils.py
Source:lvm_utils.py
...5 return vg_name6def lvcreate(osd, lv_name, vg_name, size):7 osd.exec_command(cmd="sudo lvcreate -n %s -l %s %s " % (lv_name, size, vg_name))8 return lv_name9def make_partition(osd, device, start=None, end=None, gpt=False):10 osd.exec_command(11 cmd="sudo parted --script %s mklabel gpt" % device12 ) if gpt else osd.exec_command(13 cmd="sudo parted --script %s mkpart primary %s %s" % (device, start, end)14 )15def osd_scenario1(osd, devices_dict, dmcrypt=False):16 """17 OSD scenario type1 generator18 Args:19 osd: osd node20 devices_dict: dict of devices of the osd node supplied21 dmcrypt: False by default22 Returns:23 generated scenario, dmcrypt24 """25 pvcreate(osd, devices_dict.get("devices"))26 vgname = vgcreate(27 osd, osd.LvmConfig.vg_name % "1", devices_dict.get("devices")28 ) # all /dev/vd{b,c,d,e}29 data_lv1 = lvcreate(30 osd,31 osd.LvmConfig.data_lv % "1",32 osd.LvmConfig.vg_name % "1",33 osd.LvmConfig.size.format(20),34 )35 data_lv2 = lvcreate(36 osd,37 osd.LvmConfig.data_lv % "2",38 osd.LvmConfig.vg_name % "1",39 osd.LvmConfig.size.format(20),40 )41 data_lv3 = lvcreate(42 osd,43 osd.LvmConfig.data_lv % "3",44 osd.LvmConfig.vg_name % "1",45 osd.LvmConfig.size.format(20),46 )47 data_lv4 = lvcreate(48 osd,49 osd.LvmConfig.data_lv % "4",50 osd.LvmConfig.vg_name % "1",51 osd.LvmConfig.size.format(20),52 )53 db_lv1 = lvcreate(54 osd,55 osd.LvmConfig.db_lv % "1",56 osd.LvmConfig.vg_name % "1",57 osd.LvmConfig.size.format(8),58 )59 db_lv2 = lvcreate(60 osd,61 osd.LvmConfig.db_lv % "2",62 osd.LvmConfig.vg_name % "1",63 osd.LvmConfig.size.format(8),64 )65 wal_lv1 = lvcreate(66 osd,67 osd.LvmConfig.wal_lv % "1",68 osd.LvmConfig.vg_name % "1",69 osd.LvmConfig.size.format(2),70 )71 wal_lv2 = lvcreate(72 osd,73 osd.LvmConfig.wal_lv % "2",74 osd.LvmConfig.vg_name % "1",75 osd.LvmConfig.size.format(2),76 )77 scenario = (78 "{{'data':'{datalv1}','data_vg':'{vg_name}'}},"79 "{{'data':'{datalv2}','data_vg':'{vg_name}',"80 "'db':'{dblv1}','db_vg':'{vg_name}'}},"81 "{{'data':'{datalv3}','data_vg':'{vg_name}',"82 "'wal':'{wallv1}','wal_vg':'{vg_name}'}},"83 "{{'data':'{datalv4}','data_vg':'{vg_name}',"84 "'db':'{dblv2}','db_vg':'{vg_name}','wal':'{wallv2}',"85 "'wal_vg':'{vg_name}'}}".format(86 vg_name=vgname,87 datalv1=data_lv1,88 datalv2=data_lv2,89 dblv1=db_lv1,90 datalv3=data_lv3,91 wallv1=wal_lv1,92 datalv4=data_lv4,93 dblv2=db_lv2,94 wallv2=wal_lv2,95 )96 )97 return {"scenario": scenario, "dmcrypt": dmcrypt}98def osd_scenario1_dmcrypt(osd, devices_dict):99 """100 OSD scenario type2 generator101 Args:102 osd: osd node103 devices_dict: dict of devices of the osd node supplied104 dmcrypt: False by default105 Returns:106 generated scenario, dmcrypt(overridden to True)107 """108 generated_sce_dict = osd_scenario1(osd, devices_dict, dmcrypt=True)109 return {110 "scenario": generated_sce_dict.get("scenario"),111 "dmcrypt": generated_sce_dict.get("dmcrypt"),112 }113def osd_scenario2(osd, devices_dict, dmcrypt=False):114 """115 OSD scenario type3 generator116 Args:117 osd: osd node118 devices_dict: dict of devices of the osd node supplied119 dmcrypt: False by default120 Returns:121 generated scenario, dmcrypt122 """123 make_partition(osd, devices_dict.get("device1"), gpt=True)124 make_partition(osd, devices_dict.get("device1"), "1", "80%")125 make_partition(osd, devices_dict.get("device1"), "80%", "85%")126 make_partition(osd, devices_dict.get("device1"), "85%", "90%")127 make_partition(osd, devices_dict.get("device1"), "90%", "95%")128 make_partition(osd, devices_dict.get("device1"), "95%", "100%")129 scenario = (130 "{{'data':'{vdb1}','db':'{vdb2}','wal':'{vdb3}'}},"131 "{{'data':'{vdc}','db':'{vdb4}','wal':'{vdb5}'}},"132 "{{'data':'{vdd}'}}".format(133 vdb1=devices_dict.get("device1") + "1",134 vdb2=devices_dict.get("device1") + "2",135 vdb3=devices_dict.get("device1") + "3",136 vdc=devices_dict.get("device2"),137 vdb4=devices_dict.get("device1") + "4",138 vdb5=devices_dict.get("device1") + "5",139 vdd=devices_dict.get("device3"),140 )141 )142 return {"scenario": scenario, "dmcrypt": dmcrypt}143def osd_scenario2_dmcrypt(osd, devices_dict):144 """145 OSD scenario type4 generator146 Args:147 osd: osd node148 devices_dict: dict of devices of the osd node supplied149 dmcrypt: False by default150 Returns:151 generated scenario, dmcrypt(overridden to True)152 """153 generated_sce_dict = osd_scenario2(osd, devices_dict, dmcrypt=True)154 return {155 "scenario": generated_sce_dict.get("scenario"),156 "dmcrypt": generated_sce_dict.get("dmcrypt"),157 }158def osd_scenario3(osd, devices_dict, dmcrypt=False):159 """160 OSD scenario type5 generator161 Args:162 osd: osd node163 devices_dict: dict of devices of the osd node supplied164 dmcrypt: False by default165 Returns:166 generated scenario, dmcrypt167 """168 pvcreate(osd, devices_dict.get("devices"))169 devs = "{a} {b}".format(170 a=devices_dict.get("device0"), b=devices_dict.get("device2")171 ) # vdb vdd172 vgname = vgcreate(osd, osd.LvmConfig.vg_name % "1", devs)173 make_partition(osd, devices_dict.get("device3"), gpt=True) # vde174 make_partition(osd, devices_dict.get("device3"), "1", "80%")175 make_partition(osd, devices_dict.get("device3"), "80%", "90%")176 make_partition(osd, devices_dict.get("device3"), "90%", "100%")177 data_lv1 = lvcreate(178 osd,179 osd.LvmConfig.data_lv % "1",180 osd.LvmConfig.vg_name % "1",181 osd.LvmConfig.size.format(80),182 )183 db_lv1 = lvcreate(184 osd,185 osd.LvmConfig.db_lv % "1",186 osd.LvmConfig.vg_name % "1",187 osd.LvmConfig.size.format(10),188 )189 wal_lv1 = lvcreate(190 osd,...
p06_smallest_difference.py
Source:p06_smallest_difference.py
1import sys2# Function to sort the arrays in O(nlog(n))3def merge_sort(arr):4 # function to create the partitions5 def make_partition(_arr):6 if len(_arr) <= 1:7 return _arr8 middle = len(_arr) // 29 left = make_partition(_arr[:middle])10 right = make_partition(_arr[middle:])11 return merge_partition(left, right)12 # function to merge the array partitions13 def merge_partition(left, right):14 result = []15 i, j = 0, 016 while i < len(left) and j < len(right):17 if left[i] <= right[j]:18 result.append(left[i])19 i += 120 else:21 result.append(right[j])22 j += 123 result += left[i:]24 result += right[j:]25 return result26 return make_partition(arr)27# Function to find the smallest difference28def find_smallest_difference(array1, array2):29 array1 = merge_sort(array1)30 array2 = merge_sort(array2)31 a, b, difference = 0, 0, sys.maxsize32 pair = []33 while a < len(array1) and b < len(array2):34 if abs(array1[a] - array2[b]) < difference:35 difference = abs(array1[a] - array2[b])36 pair = [array1[a], array2[b]]37 if difference == 0:38 break39 if array1[a] < array2[b]:40 a += 1...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!