Best Python code snippet using localstack_python
aws_ds_info.py
Source:aws_ds_info.py
...245 return paginator.paginate(246 DirectoryId=module.params['id'],247 ), True248 else:249 return client.describe_snapshots(250 DirectoryId=module.params['id'],251 ), False252 elif module.params['describe_trusts']:253 if client.can_paginate('describe_trusts'):254 paginator = client.get_paginator('describe_trusts')255 return paginator.paginate(256 DirectoryId=module.params['id'],257 ), True258 else:259 return client.describe_trusts(260 DirectoryId=module.params['id'],261 ), False262 else:263 return None, False...
test_cli.py
Source:test_cli.py
...36 ]37 )38 for i in vol["Volumes"]:39 self.conn.delete_volume(VolumeId=i["VolumeId"])40 snaps = self.conn.describe_snapshots(41 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]42 )43 for i in snaps["Snapshots"]:44 self.conn.delete_snapshot(SnapshotId=i["SnapshotId"])45 vms = self.conn.describe_instances(46 Filters=[47 {"Name": "tag:Name", "Values": ["osc_bsu_backup_27aaade4"]},48 {"Name": "instance-state-name", "Values": ["running"]},49 ]50 )51 for reservation in vms["Reservations"]:52 if reservation.get("Instances"):53 for instance in reservation["Instances"]:54 self.conn.terminate_instances(InstanceIds=[instance["InstanceId"]])55 self.conn.stop_instances(56 InstanceIds=[instance["InstanceId"]], Force=True57 )58 logging.disable(logging.NOTSET)59 def setUpVolumes(self):60 self.vol1 = self.conn.create_volume(61 AvailabilityZone=self.region + "a", Size=10, VolumeType="standard"62 )63 self.conn.get_waiter("volume_available").wait(VolumeIds=[self.vol1["VolumeId"]])64 self.conn.create_tags(65 Resources=[self.vol1["VolumeId"]],66 Tags=[67 {"Key": "Name", "Value": "osc_bsu_backup_27aaade4"},68 {"Key": "test2", "Value": "osc_bsu_backup_27aaade4"},69 ],70 )71 self.vol2 = self.conn.create_volume(72 AvailabilityZone=self.region + "a", Size=10, VolumeType="standard"73 )74 self.conn.get_waiter("volume_available").wait(VolumeIds=[self.vol2["VolumeId"]])75 self.conn.create_tags(76 Resources=[self.vol2["VolumeId"]],77 Tags=[78 {"Key": "Name", "Value": "osc_bsu_backup_27aaade4"},79 {"Key": "test2", "Value": "osc_bsu_backup_27aaade4"},80 ],81 )82 def setUpInstances(self, count=1):83 centos = self.conn.describe_images(84 Filters=[85 {"Name": "owner-alias", "Values": ["Outscale"]},86 {"Name": "name", "Values": ["CentOS-*"]},87 ]88 )89 self.vm1 = self.conn.run_instances(90 InstanceType="tinav4.c1r1p3",91 ImageId=centos["Images"][0]["ImageId"],92 KeyName="osc_bsu_backup_27aaade4",93 MinCount=1,94 MaxCount=count,95 )96 self.conn.get_waiter("instance_running").wait(97 InstanceIds=[i["InstanceId"] for i in self.vm1["Instances"]]98 )99 self.conn.create_tags(100 Resources=[i["InstanceId"] for i in self.vm1["Instances"]],101 Tags=[102 {"Key": "Name", "Value": "osc_bsu_backup_27aaade4"},103 {"Key": "test2", "Value": "osc_bsu_backup_27aaade4"},104 ],105 )106 def test_integration_volume_id(self):107 self.setUpVolumes()108 class args(object):109 volume_id = self.vol1["VolumeId"]110 instance_id = None111 instances_tags = None112 volumes_tags = None113 profile = None114 region = "eu-west-2"115 endpoint = None116 rotate = 1117 client_cert = None118 rotate_only = False119 rotate_days = None120 copy_tags = False121 with patch("osc_bsu_backup.bsu_backup.DESCRIPTION", "osc_bsu_backup_27aaade4"):122 self.assertIsNone(cli.backup(args()))123 snaps = self.conn.describe_snapshots(124 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]125 )126 self.assertEqual(len(snaps["Snapshots"]), 1)127 self.assertIsNone(cli.backup(args()))128 snaps = self.conn.describe_snapshots(129 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]130 )131 self.assertEqual(len(snaps["Snapshots"]), 2)132 self.assertIsNone(cli.backup(args()))133 snaps = self.conn.describe_snapshots(134 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]135 )136 self.assertEqual(len(snaps["Snapshots"]), 2)137 def test_integration_volume_tags1(self):138 self.setUpVolumes()139 class args(object):140 volume_id = None141 instance_id = None142 instances_tags = None143 volumes_tags = [144 "test2:osc_bsu_backup_27aaade4",145 "Name:osc_bsu_backup_27aaade4",146 ]147 profile = None148 region = "eu-west-2"149 endpoint = None150 rotate = 1151 client_cert = None152 rotate_only = False153 rotate_days = None154 copy_tags = False155 with patch("osc_bsu_backup.bsu_backup.DESCRIPTION", "osc_bsu_backup_27aaade4"):156 self.assertIsNone(cli.backup(args()))157 snaps = self.conn.describe_snapshots(158 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]159 )160 self.assertEqual(len(snaps["Snapshots"]), 2)161 self.assertIsNone(cli.backup(args()))162 snaps = self.conn.describe_snapshots(163 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]164 )165 self.assertEqual(len(snaps["Snapshots"]), 4)166 self.assertIsNone(cli.backup(args()))167 snaps = self.conn.describe_snapshots(168 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]169 )170 self.assertEqual(len(snaps["Snapshots"]), 4)171 def test_integration_instance_id(self):172 self.setUpInstances(count=1)173 class args(object):174 volume_id = None175 instance_id = self.vm1["Instances"][0]["InstanceId"]176 instances_tags = None177 volumes_tags = None178 profile = None179 region = "eu-west-2"180 endpoint = None181 rotate = 1182 client_cert = None183 rotate_only = False184 rotate_days = None185 copy_tags = False186 with patch("osc_bsu_backup.bsu_backup.DESCRIPTION", "osc_bsu_backup_27aaade4"):187 self.assertIsNone(cli.backup(args()))188 snaps = self.conn.describe_snapshots(189 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]190 )191 self.assertEqual(len(snaps["Snapshots"]), 1)192 self.assertIsNone(cli.backup(args()))193 snaps = self.conn.describe_snapshots(194 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]195 )196 self.assertEqual(len(snaps["Snapshots"]), 2)197 self.assertIsNone(cli.backup(args()))198 snaps = self.conn.describe_snapshots(199 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]200 )201 self.assertEqual(len(snaps["Snapshots"]), 2)202 def test_integration_instance_tags(self):203 self.setUpInstances(count=4)204 class args(object):205 volume_id = None206 instance_id = None207 instances_tags = ["test2:osc_bsu_backup_27aaade4"]208 volumes_tags = None209 profile = None210 region = "eu-west-2"211 endpoint = None212 rotate = 1213 client_cert = None214 rotate_only = False215 rotate_days = None216 copy_tags = False217 with patch("osc_bsu_backup.bsu_backup.DESCRIPTION", "osc_bsu_backup_27aaade4"):218 self.assertIsNone(cli.backup(args()))219 snaps = self.conn.describe_snapshots(220 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]221 )222 self.assertEqual(len(snaps["Snapshots"]), 4)223 self.assertIsNone(cli.backup(args()))224 snaps = self.conn.describe_snapshots(225 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]226 )227 self.assertEqual(len(snaps["Snapshots"]), 8)228 self.assertIsNone(cli.backup(args()))229 snaps = self.conn.describe_snapshots(230 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]231 )232 self.assertEqual(len(snaps["Snapshots"]), 8)233 def test_integration_copy_tags(self):234 self.setUpVolumes()235 class args(object):236 volume_id = None237 instance_id = None238 instances_tags = None239 volumes_tags = [240 "test2:osc_bsu_backup_27aaade4",241 "Name:osc_bsu_backup_27aaade4",242 ]243 profile = None244 region = "eu-west-2"245 endpoint = None246 rotate = 1247 client_cert = None248 rotate_only = False249 rotate_days = None250 copy_tags = True251 with patch("osc_bsu_backup.bsu_backup.DESCRIPTION", "osc_bsu_backup_27aaade4"):252 self.assertIsNone(cli.backup(args()))253 snaps = self.conn.describe_snapshots(254 Filters=[{"Name": "description", "Values": ["osc_bsu_backup_27aaade4"]}]255 )256 self.assertEqual(len(snaps["Snapshots"]), 2)257 self.assertEqual(258 snaps["Snapshots"][0]["Tags"],259 [260 {"Key": "Name", "Value": "osc_bsu_backup_27aaade4"},261 {"Key": "test2", "Value": "osc_bsu_backup_27aaade4"},262 ],263 )264if __name__ == "__main__":...
describe_snapshots.py
Source:describe_snapshots.py
1from chinac_way_v3.core.profile.profile import Profile2from chinac_way_v3.core.client import Client3from chinac_way_v3.cbs.v10.describe_snapshots import DescribeSnapshots4import json5from datebase.save_mongo import save_Mongo67def Describe_Snapshots(region_id, access_key_id, access_secret):8 profile = Profile(region_id,access_key_id,access_secret)9 client = Client(profile)10 request=DescribeSnapshots()11 request.set_method('GET')12 # è°ç¨æ§çrequest.set_old_version()13 # è°ç¨v2æ°çrequest.set_v2_version(),é»è®¤æ¯æ°ç14 response = client.get_response(request)15 print(response)16 dict = json.loads(response)17 Action = request.get_action()18 save_Mongo(dict, Action)
...
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!!