How to use launch_instance method in tempest

Best Python code snippet using tempest_python

schema.py

Source:schema.py Github

copy

Full Screen

1import graphene2import json3from datetime import datetime4from graphene_django.types import DjangoObjectType5from .models import Launch, Rocket, Payload, LaunchSite, Norad6import time7class LaunchSiteType(DjangoObjectType):8 class Meta:9 model = LaunchSite10class NoradType(DjangoObjectType):11 class Meta:12 model = Norad13class PayloadType(DjangoObjectType):14 15 class Meta:16 model = Payload17class RocketType(DjangoObjectType):18 class Meta:19 model = Rocket20 21class LaunchType(DjangoObjectType):22 23 class Meta:24 model = Launch25class Query(graphene.ObjectType):26 27 launch = graphene.Field(LaunchType, id=graphene.Int())28 launch_by_mission_name = graphene.List(LaunchType, mission_name=graphene.String())29 launches_by_launch_date_unix = graphene.List(LaunchType, launch_date_unix=graphene.Float())30 all_launches = graphene.List(LaunchType)31 rocket = graphene.Field(RocketType, id=graphene.Int())32 all_rockets = graphene.List(RocketType)33 payload = graphene.Field(PayloadType, id=graphene.Int())34 all_payloads = graphene.List(PayloadType)35 norad = graphene.Field(NoradType, id=graphene.Int())36 all_norads = graphene.List(NoradType)37 norads_by_payload_id = graphene.List(NoradType, payload_id=graphene.String())38 launchsite = graphene.Field(LaunchSiteType, id=graphene.Int())39 all_launchsites = graphene.List(LaunchSiteType)40 def resolve_launch_by_mission_name(self, info, **kwargs):41 mission_name = kwargs.get('mission_name')42 if mission_name:43 return Launch.objects.filter(mission_name=mission_name)44 return None45 def resolve_launches_by_launch_date_unix(self, info, **kwargs):46 launch_date = kwargs.get('launch_date_unix')47 print(launch_date)48 if launch_date:49 return Launch.objects.filter(launch_date_unix=launch_date)50 return None51 def resolve_norads_by_payload_id(self, info, **kwargs):52 norad_payload_id = kwargs.get('payload_id')53 if norad_payload_id:54 payload_list = Payload.objects.filter(payload_id=norad_payload_id)55 for payload in payload_list:56 if norad_payload_id == payload.payload_id:57 return Norad.objects.filter(payload_id=payload.id)58 return None59 def resolve_all_norads(self, info, **kwargs):60 return Norad.objects.all()61 62 def resolve_all_launchsites(self, info, **kwargs):63 return LaunchSite.objects.all()64 def resolve_all_payloads(self, info, **kwargs):65 return Payload.objects.all()66 def resolve_all_rockets(self, info, **kwargs):67 return Rocket.objects.all()68 def resolve_all_launches(self, info, **kwargs):69 return Launch.objects.all()70 71 def resolve_norad(self, info, **kwargs):72 id = kwargs.get('id')73 if id:74 return Norad.objects.get(id=id)75 return None76 def resolve_launchsite(self, info, **kwargs):77 id = kwargs.get('id')78 if id:79 return LaunchSite.objects.get(id=id)80 return None81 def resolve_payload(self, info, **kwargs):82 id = kwargs.get('id')83 if id:84 return Payload.objects.get(id=id)85 return None86 def resolve_rocket(self, info, **kwargs):87 id = kwargs.get('id')88 if id:89 return Rocket.objects.get(id=id)90 return None91 def resolve_launch(self, info, **kwargs):92 id = kwargs.get('id')93 if id:94 return Launch.objects.get(id=id)95 return None96class NoradInput(graphene.InputObjectType):97 id = graphene.ID()98 norad_id = graphene.Int()99 payload_id = graphene.Int()100class PayloadInput(graphene.InputObjectType):101 id = graphene.ID()102 payload_id = graphene.String()103 rocket_id = graphene.Int()104class LaunchSiteInput(graphene.InputObjectType):105 id = graphene.ID()106 site_id = graphene.String()107 site_name = graphene.String()108 site_name_long = graphene.String()109class RocketInput(graphene.InputObjectType):110 id = graphene.ID()111 rocket_id = graphene.String()112class LaunchInput(graphene.InputObjectType):113 id = graphene.ID()114 flight_number = graphene.Int()115 mission_name = graphene.String()116 launch_date_unix = graphene.Float()117 launch_success = graphene.Boolean()118 launchsite_id = graphene.Int()119 rocket_id = graphene.Int()120class CreateNorad(graphene.Mutation):121 class Arguments:122 input = NoradInput(required=True)123 124 ok = graphene.Boolean()125 norad = graphene.Field(NoradType)126 @staticmethod127 def mutate(root, info, input=None):128 ok = True129 payload = Payload.objects.get(id=input.payload_id)130 norad_instance = Norad( 131 norad_id = input.norad_id132 )133 norad_instance.save()134 norad_instance.payload = payload135 norad_instance.save()136 return CreateNorad(norad=norad_instance, ok=ok)137class CreateLaunchSite(graphene.Mutation):138 class Arguments:139 input = LaunchSiteInput(required=True)140 141 ok = graphene.Boolean()142 launchsite = graphene.Field(LaunchSiteType)143 @staticmethod144 def mutate(root, info, input=None):145 ok = True146 launchsite_instance = LaunchSite( 147 site_id = input.site_id,148 site_name = input.site_name,149 site_name_long = input.site_name_long150 )151 launchsite_instance.save()152 return CreateLaunchSite(launchsite=launchsite_instance, ok=ok)153class CreatePayload(graphene.Mutation):154 class Arguments:155 input = PayloadInput(required=True)156 ok = graphene.Boolean()157 payload = graphene.Field(PayloadType)158 @staticmethod159 def mutate(root, info, input=None):160 ok = True161 rocket = Rocket.objects.get(id=input.rocket_id)162 payload_instance = Payload(163 payload_id = input.payload_id164 )165 payload_instance.save()166 payload_instance.rocket = rocket167 payload_instance.save()168 return CreatePayload(ok=ok,payload=payload_instance)169class CreateRocket(graphene.Mutation):170 class Arguments:171 input = RocketInput(required=True)172 ok = graphene.Boolean()173 rocket = graphene.Field(RocketType)174 @staticmethod175 def mutate(root, info, input=None):176 ok = True177 rocket_instance = Rocket(178 rocket_id = input.rocket_id179 )180 rocket_instance.save()181 return CreateRocket(ok=ok,rocket=rocket_instance)182class CreateLaunch(graphene.Mutation):183 class Arguments:184 input = LaunchInput(required=True)185 186 ok = graphene.Boolean()187 launch = graphene.Field(LaunchType)188 @staticmethod189 def mutate(root, info, input=None):190 ok = True191 192 launch_instance = Launch( 193 flight_number = input.flight_number,194 mission_name = input.mission_name,195 launch_date_unix = input.launch_date_unix,196 launch_success = input.launch_success197 )198 launch_instance.save()199 launch_site = LaunchSite.objects.get(id=input.launchsite_id)200 launch_instance.launch_site = launch_site201 rocket = Rocket.objects.get(id=input.rocket_id)202 launch_instance.rocket = rocket203 launch_instance.save()204 return CreateLaunch(launch=launch_instance, ok=ok)205class UpdateRocket(graphene.Mutation):206 class Arguments:207 id = graphene.Int(required=True)208 input = RocketInput(required=True)209 ok = graphene.Boolean()210 rocket = graphene.Field(RocketType)211 @staticmethod212 def mutate(root, info, id, input=None):213 ok = False214 rocket_instance = Rocket.objects.get(id=id)215 print(rocket_instance)216 if rocket_instance:217 ok = True218 rocket_instance.rocket_id = input.rocket_id219 rocket_instance.save()220 return UpdateRocket(ok=ok, rocket=rocket_instance)221 return UpdateRocket(ok=ok, rocket=None)222class UpdateLaunchSite(graphene.Mutation):223 class Arguments:224 id = graphene.Int(required=True)225 input = LaunchSiteInput(required=True)226 ok = graphene.Boolean()227 launchsite = graphene.Field(LaunchSiteType)228 @staticmethod229 def mutate(root, info, id, input=None):230 ok = False231 launchsite_instance = LaunchSite.objects.get(id=id)232 if launchsite_instance:233 ok = True234 launchsite_instance.site_id = input.site_id,235 launchsite_instance.site_name = input.site_name,236 launchsite_instance.site_name_long = input.site_name_long237 launchsite_instance.save()238 return UpdateLaunchSite(ok=ok, launchsite=launchsite_instance)239 return UpdateLaunchSite(ok=ok, launchsite=None)240class UpdateNorad(graphene.Mutation):241 class Arguments:242 id = graphene.Int(required=True)243 input = NoradInput(required=True)244 ok = graphene.Boolean()245 norad = graphene.Field(NoradType)246 @staticmethod247 def mutate(root, info, id, input=None):248 ok = False249 norad_instance = Norad.objects.get(id=id)250 if norad_instance:251 ok = True252 norad_instance.norad_id = input.norad_id253 norad_instance.save()254 payload = Payload.objects.get(id=input.payload_id)255 norad_instance.payload = payload256 norad_instance.save()257 return UpdateNorad(ok=ok, norad=norad_instance)258 return UpdateNorad(ok=ok, norad=None)259class UpdatePayload(graphene.Mutation):260 class Arguments:261 id = graphene.Int(required=True)262 input = PayloadInput(required=True)263 ok = graphene.Boolean()264 payload = graphene.Field(PayloadType)265 @staticmethod266 def mutate(root, info, id, input=None):267 ok = False268 payload_instance = Payload.objects.get(id=id)269 if payload_instance:270 ok = True271 payload_instance.payload_id = input.payload_id272 payload_instance.save()273 rocket = Rocket.objects.get(id=input.rocket_id)274 payload_instance.rocket = rocket275 payload_instance.save()276 return UpdatePayload(ok=ok, payload=payload_instance)277 return UpdatePayload(ok=ok, payload=None)278class UpdateLaunch(graphene.Mutation):279 class Arguments:280 id = graphene.Int(required=True)281 input = LaunchInput(required=True)282 ok = graphene.Boolean()283 launch = graphene.Field(LaunchType)284 @staticmethod285 def mutate(root, info, id, input=None):286 ok = False287 launch_instance = Launch.objects.get(id=id)288 if launch_instance:289 ok = True290 if input.flight_number:291 launch_instance.flight_number = input.flight_number,292 launch_instance.mission_name = input.mission_name,293 if input.launch_date_unix:294 launch_instance.launch_date_unix = input.launch_date_unix,295 launch_instance.launch_success = input.launch_success296 launch_instance.save()297 launch_site = LaunchSite.objects.get(id=input.launchsite_id)298 launch_instance.launch_site = launch_site299 rocket = Rocket.objects.get(id=input.rocket_id)300 launch_instance.rocket = rocket301 launch_instance.save()302 return UpdateLaunch(ok=ok, launch=launch_instance)303 return UpdateLaunch(ok=ok, launch=None)304class DeleteNorad(graphene.Mutation):305 class Arguments:306 id = graphene.ID()307 308 ok = graphene.Boolean()309 norad = graphene.Field(NoradType)310 @staticmethod311 def mutate(root, info, id):312 norad_instance = Norad.objects.get(id=id) 313 norad_instance.delete()314 return DeleteNorad(ok=True)315 316 return None317class DeletePayload(graphene.Mutation):318 class Arguments:319 id = graphene.ID()320 321 ok = graphene.Boolean()322 launch = graphene.Field(PayloadType)323 @staticmethod324 def mutate(root, info, id):325 launch_instance = Payload.objects.get(id=id) 326 launch_instance.delete()327 return DeletePayload(ok=True)328 329 return None330class DeleteLaunchSite(graphene.Mutation):331 class Arguments:332 id = graphene.ID()333 334 ok = graphene.Boolean()335 launchsite = graphene.Field(LaunchSiteType)336 @staticmethod337 def mutate(root, info, id):338 launchsite_instance = LaunchSite.objects.get(id=id) 339 launchsite_instance.delete()340 return DeleteLaunchSite(ok=True)341 342 return None343class DeleteRocket(graphene.Mutation):344 class Arguments:345 id = graphene.ID()346 347 ok = graphene.Boolean()348 launch = graphene.Field(RocketType)349 @staticmethod350 def mutate(root, info, id):351 rocket_instance = Rocket.objects.get(id=id) 352 rocket_instance.delete()353 return DeleteRocket(ok=True)354 355 return None356class DeleteLaunch(graphene.Mutation):357 class Arguments:358 id = graphene.ID()359 360 ok = graphene.Boolean()361 launch = graphene.Field(LaunchType)362 @staticmethod363 def mutate(root, info, id):364 launch_instance = Launch.objects.get(id=id) 365 launch_instance.delete()366 return DeleteLaunch(ok=True)367 368 return None369class Mutation(graphene.ObjectType):370 create_launch = CreateLaunch.Field()371 update_launch = UpdateLaunch.Field()372 delete_launch = DeleteLaunch.Field()373 create_rocket = CreateRocket.Field()374 update_rocket = UpdateRocket.Field()375 delete_rocket = DeleteRocket.Field()376 create_launchsite = CreateLaunchSite.Field()377 update_launchsite = UpdateLaunchSite.Field()378 delete_launchsite = DeleteLaunchSite.Field()379 create_payload = CreatePayload.Field()380 update_payload = UpdatePayload.Field()381 delete_payload = DeletePayload.Field()382 create_norad = CreateNorad.Field()383 update_norad = UpdateNorad.Field()384 delete_norad = DeleteNorad.Field()385 ...

Full Screen

Full Screen

test_aws_ec2.py

Source:test_aws_ec2.py Github

copy

Full Screen

...24 def runTest(self):25 self.assertIsNotNone(self.aws_ec2)26class AwsEc2Launch(AwsEc2TestCase):27 def runTest(self):28 code, ret = self.aws_ec2.launch_instance(29 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,30 security_groups=self.security_groups, tags=self.tags)31 self.assertEqual(0, code, ret)32 self.launched_instances.append(ret.instance_id)33 code, ret = self.aws_ec2.launch_instance(34 ami=self.ami, block_devices={"xvde": 5, "xvdf": 10}, instance_type=self.instance_type,35 key_name=self.key_name, security_groups=self.security_groups, tags=self.tags)36 self.assertEqual(0, code, ret)37 self.launched_instances.append(ret.instance_id)38 code, ret = self.aws_ec2.launch_instance(39 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,40 security_groups=self.security_groups, tags=self.tags, DryRun=True)41 self.assertEqual(1, code, ret)42 code, ret = self.aws_ec2.launch_instance(43 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,44 security_groups=self.security_groups, tags=self.tags, InvalidParam=True)45 self.assertEqual(1, code, ret)46 code, ret = self.aws_ec2.launch_instance(47 ami="ami-bad_ami", instance_type=self.instance_type, key_name=self.key_name,48 security_groups=self.security_groups, tags=self.tags)49 self.assertNotEqual(0, code, ret)50 code, ret = self.aws_ec2.launch_instance(51 ami=self.ami, instance_type="bad_instance_type", key_name=self.key_name,52 security_groups=self.security_groups, tags=self.tags)53 self.assertNotEqual(0, code, ret)54 code, ret = self.aws_ec2.launch_instance(55 ami=self.ami, instance_type=self.instance_type, key_name="bad_key_name",56 security_groups=self.security_groups, tags=self.tags)57 self.assertNotEqual(0, code, ret)58class AwsEc2LaunchStatus(AwsEc2TestCase):59 def runTest(self):60 code, ret = self.aws_ec2.launch_instance(61 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,62 security_groups=self.security_groups, tags=self.tags)63 self.assertEqual(0, code, ret)64 self.launched_instances.append(ret.instance_id)65 self.assertEqual(self.ami, ret.image_id, ret)66 self.assertEqual(self.instance_type, ret.instance_type, ret)67 self.assertTrue(ret.state["Name"] in ["pending", "running"], ret)68 for tag in ret.tags:69 self.assertTrue(tag in self.tags, ret)70 for tag in self.tags:71 self.assertTrue(tag in ret.tags, ret)72 code, ret = self.aws_ec2.launch_instance(73 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,74 security_groups=self.security_groups, tags=self.tags, wait_time_secs=300,75 show_progress=True)76 self.assertEqual("running", ret.state["Name"], ret)77 self.assertIsNotNone(ret.public_ip_address, ret)78 self.assertIsNotNone(ret.private_ip_address, ret)79 self.launched_instances.append(ret.instance_id)80class AwsEc2ControlStatus(AwsEc2TestCase):81 def runTest(self):82 code, ret = self.aws_ec2.launch_instance(83 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,84 security_groups=self.security_groups, tags=self.tags)85 self.assertEqual(0, code, ret)86 self.launched_instances.append(ret.instance_id)87 code, ret = self.aws_ec2.control_instance(mode="status", image_id=ret.instance_id)88 self.assertEqual(0, code, ret)89 self.assertEqual(self.ami, ret.image_id, ret)90 self.assertEqual(self.instance_type, ret.instance_type, ret)91 self.assertTrue(ret.state["Name"] in ["pending", "running"], ret)92 for tag in ret.tags:93 self.assertTrue(tag in self.tags, ret)94 for tag in self.tags:95 self.assertTrue(tag in ret.tags, ret)96 self.assertIsNotNone(ret.instance_id, ret)97 self.assertIsNotNone(ret.image_id, ret)98 self.assertIsNotNone(ret.instance_type, ret)99 self.assertIsNotNone(ret.state["Name"], ret)100 self.assertIsNotNone(ret.tags, ret)101 self.assertRaises(ValueError, self.aws_ec2.control_instance, mode="bad_mode",102 image_id=ret.instance_id)103 code, ret = self.aws_ec2.control_instance(mode="status", image_id="bad_id")104 self.assertNotEqual(0, code, ret)105 self.assertRegex(ret, "Invalid", ret)106class AwsEc2ControlStart(AwsEc2TestCase):107 def runTest(self):108 code, ret = self.aws_ec2.launch_instance(109 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,110 security_groups=self.security_groups, tags=self.tags)111 self.assertEqual(0, code, ret)112 self.launched_instances.append(ret.instance_id)113 code, ret = self.aws_ec2.control_instance(mode="start", image_id=ret.instance_id)114 self.assertEqual(0, code, ret)115 self.assertTrue(ret.state["Name"] in ["starting", "running"], ret)116class AwsEc2ControlStartReboot(AwsEc2TestCase):117 def runTest(self):118 code, ret = self.aws_ec2.launch_instance(119 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,120 security_groups=self.security_groups, tags=self.tags)121 self.assertEqual(0, code, ret)122 self.launched_instances.append(ret.instance_id)123 code, ret = self.aws_ec2.control_instance(mode="start", image_id=ret.instance_id)124 self.assertEqual(0, code, ret)125 self.assertTrue(ret.state["Name"] in ["running"], ret)126 code, ret = self.aws_ec2.control_instance(mode="reboot", image_id=ret.instance_id)127 self.assertEqual(0, code, ret)128 self.assertTrue(ret.state["Name"] in ["rebooting", "running"], ret)129class AwsEc2ControlStop(AwsEc2TestCase):130 def runTest(self):131 code, ret = self.aws_ec2.launch_instance(132 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,133 security_groups=self.security_groups, tags=self.tags, wait_time_secs=60)134 self.assertEqual(0, code, ret)135 self.launched_instances.append(ret.instance_id)136 code, ret = self.aws_ec2.control_instance(mode="stop", image_id=ret.instance_id)137 self.assertEqual(0, code, ret)138 self.assertTrue(ret.state["Name"] in ["stopping", "stopped"], ret)139 code, ret = self.aws_ec2.control_instance(mode="start", image_id=ret.instance_id)140 self.assertEqual(0, code, ret)141 self.assertTrue(ret.state["Name"] in ["pending", "running"], ret)142 code, ret = self.aws_ec2.control_instance(mode="force-stop", image_id=ret.instance_id)143 self.assertEqual(0, code, ret)144 self.assertTrue(ret.state["Name"] in ["stopping", "stopped"], ret)145class AwsEc2ControlTerminate(AwsEc2TestCase):146 def runTest(self):147 code, ret = self.aws_ec2.launch_instance(148 ami=self.ami, instance_type=self.instance_type, key_name=self.key_name,149 security_groups=self.security_groups, tags=self.tags)150 self.assertEqual(0, code, ret)151 self.launched_instances.append(ret.instance_id)152 code, ret = self.aws_ec2.control_instance(mode="terminate", image_id=ret.instance_id)153 self.assertEqual(0, code, ret)154 self.assertTrue(ret.state["Name"] in ["shutting-down", "terminated"], ret)155 code, ret = self.aws_ec2.control_instance(mode="start", image_id=ret.instance_id)156 self.assertNotEqual(0, code, ret)157class AwsEc2TagInstance(AwsEc2TestCase):158 def runTest(self):159 code, ret = self.aws_ec2.launch_instance(ami=self.ami, instance_type=self.instance_type,160 key_name=self.key_name,161 security_groups=self.security_groups, tags=[])162 self.assertEqual(0, code, ret)163 self.launched_instances.append(ret.instance_id)164 self.aws_ec2.tag_instance(image_id=ret.instance_id, tags=self.tags)165 code, ret = self.aws_ec2.control_instance(mode="status", image_id=ret.instance_id)166 self.assertEqual(0, code, ret)167 for tag in ret.tags:168 self.assertTrue(tag in self.tags, ret)169 for tag in self.tags:...

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