How to use apply_patches method in tempest

Best Python code snippet using tempest_python

test_nocloud.py

Source:test_nocloud.py Github

copy

Full Screen

...10 self.tmp = self.makeDir()11 self.paths = helpers.Paths({'cloud_dir': self.tmp})12 self.cmdline = "root=TESTCMDLINE"13 self.unapply = []14 self.apply_patches([(util, 'get_cmdline', self._getcmdline)])15 super(TestNoCloudDataSource, self).setUp()16 def tearDown(self):17 apply_patches([i for i in reversed(self.unapply)])18 super(TestNoCloudDataSource, self).tearDown()19 def apply_patches(self, patches):20 ret = apply_patches(patches)21 self.unapply += ret22 def _getcmdline(self):23 return self.cmdline24 def test_nocloud_seed_dir(self):25 md = {'instance-id': 'IID', 'dsmode': 'local'}26 ud = "USER_DATA_HERE"27 populate_dir(os.path.join(self.paths.seed_dir, "nocloud"),28 {'user-data': ud, 'meta-data': yaml.safe_dump(md)})29 sys_cfg = {30 'datasource': {'NoCloud': {'fs_label': None}}31 }32 ds = DataSourceNoCloud.DataSourceNoCloud33 dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)34 ret = dsrc.get_data()35 self.assertEqual(dsrc.userdata_raw, ud)36 self.assertEqual(dsrc.metadata, md)37 self.assertTrue(ret)38 def test_fs_label(self):39 #find_devs_with should not be called ff fs_label is None40 ds = DataSourceNoCloud.DataSourceNoCloud41 class PsuedoException(Exception):42 pass43 def my_find_devs_with(*args, **kwargs):44 _f = (args, kwargs)45 raise PsuedoException46 self.apply_patches([(util, 'find_devs_with', my_find_devs_with)])47 # by default, NoCloud should search for filesystems by label48 sys_cfg = {'datasource': {'NoCloud': {}}}49 dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)50 self.assertRaises(PsuedoException, dsrc.get_data)51 # but disabling searching should just end up with None found52 sys_cfg = {'datasource': {'NoCloud': {'fs_label': None}}}53 dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)54 ret = dsrc.get_data()55 self.assertFalse(ret)56 def test_no_datasource_expected(self):57 #no source should be found if no cmdline, config, and fs_label=None58 sys_cfg = {'datasource': {'NoCloud': {'fs_label': None}}}59 ds = DataSourceNoCloud.DataSourceNoCloud60 dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)61 self.assertFalse(dsrc.get_data())62 def test_seed_in_config(self):63 ds = DataSourceNoCloud.DataSourceNoCloud64 data = {65 'fs_label': None,66 'meta-data': {'instance-id': 'IID'},67 'user-data': "USER_DATA_RAW",68 }69 sys_cfg = {'datasource': {'NoCloud': data}}70 dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)71 ret = dsrc.get_data()72 self.assertEqual(dsrc.userdata_raw, "USER_DATA_RAW")73 self.assertEqual(dsrc.metadata.get('instance-id'), 'IID')74 self.assertTrue(ret)75 def test_nocloud_seed_with_vendordata(self):76 md = {'instance-id': 'IID', 'dsmode': 'local'}77 ud = "USER_DATA_HERE"78 vd = "THIS IS MY VENDOR_DATA"79 populate_dir(os.path.join(self.paths.seed_dir, "nocloud"),80 {'user-data': ud, 'meta-data': yaml.safe_dump(md),81 'vendor-data': vd})82 sys_cfg = {83 'datasource': {'NoCloud': {'fs_label': None}}84 }85 ds = DataSourceNoCloud.DataSourceNoCloud86 dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)87 ret = dsrc.get_data()88 self.assertEqual(dsrc.userdata_raw, ud)89 self.assertEqual(dsrc.metadata, md)90 self.assertEqual(dsrc.vendordata, vd)91 self.assertTrue(ret)92 def test_nocloud_no_vendordata(self):93 populate_dir(os.path.join(self.paths.seed_dir, "nocloud"),94 {'user-data': "ud", 'meta-data': "instance-id: IID\n"})95 sys_cfg = {'datasource': {'NoCloud': {'fs_label': None}}}96 ds = DataSourceNoCloud.DataSourceNoCloud97 dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)98 ret = dsrc.get_data()99 self.assertEqual(dsrc.userdata_raw, "ud")100 self.assertFalse(dsrc.vendordata)101 self.assertTrue(ret)102class TestParseCommandLineData(MockerTestCase):103 def test_parse_cmdline_data_valid(self):104 ds_id = "ds=nocloud"105 pairs = (106 ("root=/dev/sda1 %(ds_id)s", {}),107 ("%(ds_id)s; root=/dev/foo", {}),108 ("%(ds_id)s", {}),109 ("%(ds_id)s;", {}),110 ("%(ds_id)s;s=SEED", {'seedfrom': 'SEED'}),111 ("%(ds_id)s;seedfrom=SEED;local-hostname=xhost",112 {'seedfrom': 'SEED', 'local-hostname': 'xhost'}),113 ("%(ds_id)s;h=xhost",114 {'local-hostname': 'xhost'}),115 ("%(ds_id)s;h=xhost;i=IID",116 {'local-hostname': 'xhost', 'instance-id': 'IID'}),117 )118 for (fmt, expected) in pairs:119 fill = {}120 cmdline = fmt % {'ds_id': ds_id}121 ret = DataSourceNoCloud.parse_cmdline_data(ds_id=ds_id, fill=fill,122 cmdline=cmdline)123 self.assertEqual(expected, fill)124 self.assertTrue(ret)125 def test_parse_cmdline_data_none(self):126 ds_id = "ds=foo"127 cmdlines = (128 "root=/dev/sda1 ro",129 "console=/dev/ttyS0 root=/dev/foo",130 "",131 "ds=foocloud",132 "ds=foo-net",133 "ds=nocloud;s=SEED",134 )135 for cmdline in cmdlines:136 fill = {}137 ret = DataSourceNoCloud.parse_cmdline_data(ds_id=ds_id, fill=fill,138 cmdline=cmdline)139 self.assertEqual(fill, {})140 self.assertFalse(ret)141def apply_patches(patches):142 ret = []143 for (ref, name, replace) in patches:144 if replace is None:145 continue146 orig = getattr(ref, name)147 setattr(ref, name, replace)148 ret.append((ref, name, orig))149 return ret...

Full Screen

Full Screen

set_flags.py

Source:set_flags.py Github

copy

Full Screen

...52 line = line.replace('LDFLAGS_FOR_BENCH_SUITE', ldflags)53 output += line54 with open('modified.diff', 'w') as f:55 f.write(output)56def apply_patches(bench):57 bench_dir = os.path.join(config.android_home, config.bench_dict[bench])58 bench_diff = 'modified.diff'59 flags_patch = os.path.join(60 os.path.dirname(os.path.realpath(__file__)), bench_diff)61 try:62 subprocess.check_call(['git', '-C', bench_dir, 'apply', flags_patch])63 except subprocess.CalledProcessError:64 raise OSError('Patch for adding flags for %s does not succeed.' % bench)65def replace_flags_in_dir(bench, cflags, ldflags):66 bench_mk = os.path.join(config.android_home, config.bench_dict[bench],67 'Android.mk')68 if not cflags:69 cflags = ''70 if not ldflags:71 ldflags = ''72 output = ''73 with open(bench_mk) as f:74 for line in f:75 line = line.replace('$(CFLAGS_FOR_BENCH_SUITE)', cflags)76 line = line.replace('$(LDFLAGS_FOR_BENCH_SUITE)', ldflags)77 output += line78 with open(bench_mk, 'w') as f:79 f.write(output)80def add_flags_Panorama(cflags, ldflags):81 backup_file('Panorama', 'mk')82 replace_flags_in_dir('Panorama', cflags, ldflags)83def add_flags_Synthmark(cflags, ldflags):84 backup_file('Synthmark', 'mk')85 replace_flags_in_dir('Synthmark', cflags, ldflags)86def add_flags_Skia(cflags, ldflags):87 backup_file('Skia', 'bp')88 replace_flags('Skia', config.android_type, 'bp', cflags, ldflags)89 apply_patches('Skia')90def add_flags_Binder(cflags, ldflags):91 backup_file('Binder', 'bp')92 replace_flags('Binder', config.android_type, 'bp', cflags, ldflags)93 apply_patches('Binder')94def add_flags_Hwui(cflags, ldflags):95 backup_file('Hwui', 'bp')96 replace_flags('Hwui', config.android_type, 'bp', cflags, ldflags)97 apply_patches('Hwui')98def add_flags_Dex2oat(cflags, ldflags):99 backup_file('Dex2oat', 'bp')100 replace_flags('Dex2oat', config.android_type, 'bp', cflags, ldflags)...

Full Screen

Full Screen

hash_patch.py

Source:hash_patch.py Github

copy

Full Screen

...12 def add_hash_candidate(self, mut):13 if mut.addr in self.blacklisted or mut.addr in self.patched:14 return15 self.patched.add(mut.addr)16 self.apply_patches()17 def blacklist_hash_candidate(self, addr):18 self.blacklisted.add(addr)19 if addr in self.patched:20 self.patched.remove(addr)21 self.apply_patches()22 def apply_patches(self):23 with open("/tmp/redqueen_whitelist", "w") as w:24 with open("/tmp/rq_patches", "w") as f:25 for addr in self.patched:26 hexaddr = hex(addr).rstrip("L").lstrip("0x")27 if hexaddr:28 w.write(hexaddr + "\n")...

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 tempest 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