filtered-aws-image.res 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. cloudbridge.test.test_image_service.CloudImageServiceTestCase
  2. Test output
  3. ..
  4. ----------------------------------------------------------------------
  5. Ran 2 tests in 110.730s
  6. OK
  7. Wrote profile results to run_single.py.lprof
  8. Timer unit: 1e-06 s
  9. Total time: 9.5028 s
  10. Function: refresh at line 376
  11. Line # Hits Time Per Hit % Time Line Contents
  12. ==============================================================
  13. 376 @profile
  14. 377 def refresh(self):
  15. 378 65 304.0 4.7 0.0 try:
  16. 379 65 9502299.0 146189.2 100.0 self._ec2_instance.reload()
  17. 380 65 201.0 3.1 0.0 self._unknown_state = False
  18. 381 except ClientError:
  19. 382 # The instance no longer exists and cannot be refreshed.
  20. 383 # set the state to unknown
  21. 384 self._unknown_state = True
  22. Total time: 4.28092 s
  23. Function: create at line 769
  24. Line # Hits Time Per Hit % Time Line Contents
  25. ==============================================================
  26. 769 @dispatch(event="provider.compute.instances.create",
  27. 770 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  28. 771 @profile
  29. 772 def create(self, label, image, vm_type, subnet, zone,
  30. 773 key_pair=None, vm_firewalls=None, user_data=None,
  31. 774 launch_config=None, **kwargs):
  32. 775 2 24.0 12.0 0.0 AWSInstance.assert_valid_resource_label(label)
  33. 776 2 10.0 5.0 0.0 image_id = image.id if isinstance(image, MachineImage) else image
  34. 777 vm_size = vm_type.id if \
  35. 778 2 2.0 1.0 0.0 isinstance(vm_type, VMType) else vm_type
  36. 779 subnet = (self.provider.networking.subnets.get(subnet)
  37. 780 2 4.0 2.0 0.0 if isinstance(subnet, str) else subnet)
  38. 781 2 4.0 2.0 0.0 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  39. 782 2 0.0 0.0 0.0 key_pair_name = key_pair.name if isinstance(
  40. 783 2 1.0 0.5 0.0 key_pair,
  41. 784 2 4.0 2.0 0.0 KeyPair) else key_pair
  42. 785 2 1.0 0.5 0.0 if launch_config:
  43. 786 bdm = self._process_block_device_mappings(launch_config)
  44. 787 else:
  45. 788 2 1.0 0.5 0.0 bdm = None
  46. 789
  47. 790 subnet_id, zone_id, vm_firewall_ids = \
  48. 791 2 54.0 27.0 0.0 self._resolve_launch_options(subnet, zone_id, vm_firewalls)
  49. 792
  50. 793 2 2.0 1.0 0.0 placement = {'AvailabilityZone': zone_id} if zone_id else None
  51. 794 2 5.0 2.5 0.0 inst = self.svc.create('create_instances',
  52. 795 2 2.0 1.0 0.0 ImageId=image_id,
  53. 796 2 0.0 0.0 0.0 MinCount=1,
  54. 797 2 2.0 1.0 0.0 MaxCount=1,
  55. 798 2 2.0 1.0 0.0 KeyName=key_pair_name,
  56. 799 2 2.0 1.0 0.0 SecurityGroupIds=vm_firewall_ids or None,
  57. 800 2 4.0 2.0 0.0 UserData=str(user_data) or None,
  58. 801 2 1.0 0.5 0.0 InstanceType=vm_size,
  59. 802 2 1.0 0.5 0.0 Placement=placement,
  60. 803 2 2.0 1.0 0.0 BlockDeviceMappings=bdm,
  61. 804 2 3397811.0 1698905.5 79.4 SubnetId=subnet_id
  62. 805 )
  63. 806 2 6.0 3.0 0.0 if inst and len(inst) == 1:
  64. 807 # Wait until the resource exists
  65. 808 # pylint:disable=protected-access
  66. 809 2 446604.0 223302.0 10.4 inst[0]._wait_till_exists()
  67. 810 # Tag the instance w/ the name
  68. 811 2 436371.0 218185.5 10.2 inst[0].label = label
  69. 812 2 4.0 2.0 0.0 return inst[0]
  70. 813 raise ValueError(
  71. 814 'Expected a single object response, got a list: %s' % inst)
  72. Total time: 2.65148 s
  73. Function: find at line 638
  74. Line # Hits Time Per Hit % Time Line Contents
  75. ==============================================================
  76. 638 @profile
  77. 639 def find(self, **kwargs):
  78. 640 # Filter by name or label
  79. 641 3 5.0 1.7 0.0 label = kwargs.pop('label', None)
  80. 642 # Popped here, not used in the generic find
  81. 643 3 3.0 1.0 0.0 owner = kwargs.pop('owners', None)
  82. 644
  83. 645 # All kwargs should have been popped at this time.
  84. 646 3 3.0 1.0 0.0 if len(kwargs) > 0:
  85. 647 1 1.0 1.0 0.0 raise InvalidParamException(
  86. 648 1 1.0 1.0 0.0 "Unrecognised parameters for search: %s. Supported "
  87. 649 1 11.0 11.0 0.0 "attributes: %s" % (kwargs, 'label'))
  88. 650
  89. 651 2 0.0 0.0 0.0 extra_args = {}
  90. 652 2 2.0 1.0 0.0 if owner:
  91. 653 1 1.0 1.0 0.0 extra_args.update(Owners=owner)
  92. 654
  93. 655 # The original list is made by combining both searches by "tag:Name"
  94. 656 # and "AMI name" to allow for searches of public images
  95. 657 2 1.0 0.5 0.0 if label:
  96. 658 2 13.0 6.5 0.0 log.debug("Searching for AWS Image Service %s", label)
  97. 659 2 1.0 0.5 0.0 obj_list = []
  98. 660 2 3.0 1.5 0.0 obj_list.extend(self.svc.find(filter_name='name',
  99. 661 2 1225611.0 612805.5 46.2 filter_value=label, **extra_args))
  100. 662 2 5.0 2.5 0.0 obj_list.extend(self.svc.find(filter_name='tag:Name',
  101. 663 2 1425801.0 712900.5 53.8 filter_value=label, **extra_args))
  102. 664 2 22.0 11.0 0.0 return obj_list
  103. 665 else:
  104. 666 return []
  105. Total time: 2.61199 s
  106. Function: refresh at line 134
  107. Line # Hits Time Per Hit % Time Line Contents
  108. ==============================================================
  109. 134 @profile
  110. 135 def refresh(self):
  111. 136 22 2611990.0 118726.8 100.0 self._ec2_image.reload()
  112. Total time: 0.584476 s
  113. Function: delete at line 452
  114. Line # Hits Time Per Hit % Time Line Contents
  115. ==============================================================
  116. 452 @dispatch(event="provider.storage.snapshots.delete",
  117. 453 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  118. 454 @profile
  119. 455 def delete(self, snapshot):
  120. 456 1 2.0 2.0 0.0 snapshot = (snapshot if isinstance(snapshot, AWSSnapshot) else
  121. 457 self.get(snapshot))
  122. 458 1 0.0 0.0 0.0 if snapshot:
  123. 459 # pylint:disable=protected-access
  124. 460 1 584474.0 584474.0 100.0 snapshot._snapshot.delete()
  125. Total time: 0.565674 s
  126. Function: list at line 668
  127. Line # Hits Time Per Hit % Time Line Contents
  128. ==============================================================
  129. 668 @profile
  130. 669 def list(self, filter_by_owner=True, limit=None, marker=None):
  131. 670 5 16.0 3.2 0.0 return self.svc.list(Owners=['self'] if filter_by_owner else
  132. 671 ['amazon', 'self'],
  133. 672 5 565658.0 113131.6 100.0 limit=limit, marker=marker)
  134. Total time: 0.541265 s
  135. Function: label at line 88
  136. Line # Hits Time Per Hit % Time Line Contents
  137. ==============================================================
  138. 88 @label.setter
  139. 89 # pylint:disable=arguments-differ
  140. 90 @profile
  141. 91 def label(self, value):
  142. 92 12 162.0 13.5 0.0 self.assert_valid_resource_label(value)
  143. 93 4 6.0 1.5 0.0 self._ec2_image.create_tags(Tags=[{'Key': 'Name',
  144. 94 4 541097.0 135274.2 100.0 'Value': value or ""}])
  145. Total time: 0.436325 s
  146. Function: label at line 254
  147. Line # Hits Time Per Hit % Time Line Contents
  148. ==============================================================
  149. 254 @label.setter
  150. 255 # pylint:disable=arguments-differ
  151. 256 @profile
  152. 257 def label(self, value):
  153. 258 2 24.0 12.0 0.0 self.assert_valid_resource_label(value)
  154. 259 2 8.0 4.0 0.0 self._ec2_instance.create_tags(Tags=[{'Key': 'Name',
  155. 260 2 436293.0 218146.5 100.0 'Value': value or ""}])
  156. Total time: 0.353906 s
  157. Function: delete at line 842
  158. Line # Hits Time Per Hit % Time Line Contents
  159. ==============================================================
  160. 842 @dispatch(event="provider.compute.instances.delete",
  161. 843 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  162. 844 @profile
  163. 845 def delete(self, instance):
  164. 846 2 4.0 2.0 0.0 aws_inst = (instance if isinstance(instance, AWSInstance) else
  165. 847 self.get(instance))
  166. 848 2 2.0 1.0 0.0 if aws_inst:
  167. 849 # pylint:disable=protected-access
  168. 850 2 353900.0 176950.0 100.0 aws_inst._ec2_instance.terminate()
  169. Total time: 0.284701 s
  170. Function: get_or_create_default at line 1103
  171. Line # Hits Time Per Hit % Time Line Contents
  172. ==============================================================
  173. 1103 @profile
  174. 1104 def get_or_create_default(self, zone):
  175. 1105 1 6.0 6.0 0.0 zone_name = zone.name if isinstance(zone, AWSPlacementZone) else zone
  176. 1106
  177. 1107 # # Look for provider default subnet in current zone
  178. 1108 # if zone_name:
  179. 1109 # snl = self.svc.find('availabilityZone', zone_name)
  180. 1110 #
  181. 1111 # else:
  182. 1112 # snl = self.svc.list()
  183. 1113 # # Find first available default subnet by sorted order
  184. 1114 # # of availability zone. Prefer zone us-east-1a over 1e,
  185. 1115 # # because newer zones tend to have less compatibility
  186. 1116 # # with different instance types (e.g. c5.large not available
  187. 1117 # # on us-east-1e as of 14 Dec. 2017).
  188. 1118 # # pylint:disable=protected-access
  189. 1119 # snl.sort(key=lambda sn: sn._subnet.availability_zone)
  190. 1120 #
  191. 1121 # for sn in snl:
  192. 1122 # # pylint:disable=protected-access
  193. 1123 # if sn._subnet.default_for_az:
  194. 1124 # return sn
  195. 1125
  196. 1126 # If no provider-default subnet has been found, look for
  197. 1127 # cloudbridge-default by label. We suffix labels by availability zone,
  198. 1128 # thus we add the wildcard for the regular expression to find the
  199. 1129 # subnet
  200. 1130 1 284614.0 284614.0 100.0 snl = self.find(label=AWSSubnet.CB_DEFAULT_SUBNET_LABEL + "*")
  201. 1131
  202. 1132 1 2.0 2.0 0.0 if snl:
  203. 1133 # pylint:disable=protected-access
  204. 1134 1 49.0 49.0 0.0 snl.sort(key=lambda sn: sn._subnet.availability_zone)
  205. 1135 1 2.0 2.0 0.0 if not zone_name:
  206. 1136 return snl[0]
  207. 1137 1 1.0 1.0 0.0 for subnet in snl:
  208. 1138 1 26.0 26.0 0.0 if subnet.zone.name == zone_name:
  209. 1139 1 1.0 1.0 0.0 return subnet
  210. 1140
  211. 1141 # No default Subnet exists, try to create a CloudBridge-specific
  212. 1142 # subnet. This involves creating the network, subnets, internet
  213. 1143 # gateway, and connecting it all together so that the network has
  214. 1144 # Internet connectivity.
  215. 1145
  216. 1146 # Check if a default net already exists and get it or create on
  217. 1147 default_net = self.provider.networking.networks.get_or_create_default()
  218. 1148
  219. 1149 # Get/create an internet gateway for the default network and a
  220. 1150 # corresponding router if it does not already exist.
  221. 1151 # NOTE: Comment this out because the docs instruct users to setup
  222. 1152 # network connectivity manually. There's a bit of discrepancy here
  223. 1153 # though because the provider-default network will have Internet
  224. 1154 # connectivity (unlike the CloudBridge-default network with this
  225. 1155 # being commented) and is hence left in the codebase.
  226. 1156 # default_gtw = default_net.gateways.get_or_create()
  227. 1157 # router_label = "{0}-router".format(
  228. 1158 # AWSNetwork.CB_DEFAULT_NETWORK_LABEL)
  229. 1159 # default_routers = self.provider.networking.routers.find(
  230. 1160 # label=router_label)
  231. 1161 # if len(default_routers) == 0:
  232. 1162 # default_router = self.provider.networking.routers.create(
  233. 1163 # router_label, default_net)
  234. 1164 # default_router.attach_gateway(default_gtw)
  235. 1165 # else:
  236. 1166 # default_router = default_routers[0]
  237. 1167
  238. 1168 # Create a subnet in each of the region's zones
  239. 1169 region = self.provider.compute.regions.get(self.provider.region_name)
  240. 1170 default_sn = None
  241. 1171
  242. 1172 # Determine how many subnets we'll need for the default network and the
  243. 1173 # number of available zones. We need to derive a non-overlapping
  244. 1174 # network size for each subnet within the parent net so figure those
  245. 1175 # subnets here. `<net>.subnets` method will do this but we need to give
  246. 1176 # it a prefix. Determining that prefix depends on the size of the
  247. 1177 # network and should be incorporate the number of zones. So iterate
  248. 1178 # over potential number of subnets until enough can be created to
  249. 1179 # accommodate the number of available zones. That is where the fixed
  250. 1180 # number comes from in the for loop as that many iterations will yield
  251. 1181 # more potential subnets than any region has zones.
  252. 1182 ip_net = ipaddress.ip_network(AWSNetwork.CB_DEFAULT_IPV4RANGE)
  253. 1183 for x in range(5):
  254. 1184 if len(region.zones) <= len(list(ip_net.subnets(
  255. 1185 prefixlen_diff=x))):
  256. 1186 prefixlen_diff = x
  257. 1187 break
  258. 1188 subnets = list(ip_net.subnets(prefixlen_diff=prefixlen_diff))
  259. 1189
  260. 1190 for i, z in reversed(list(enumerate(region.zones))):
  261. 1191 sn_label = "{0}-{1}".format(AWSSubnet.CB_DEFAULT_SUBNET_LABEL,
  262. 1192 z.id[-1])
  263. 1193 log.info("Creating a default CloudBridge subnet %s: %s" %
  264. 1194 (sn_label, str(subnets[i])))
  265. 1195 sn = self.create(sn_label, default_net, str(subnets[i]), z)
  266. 1196 # Create a route table entry between the SN and the inet gateway
  267. 1197 # See note above about why this is commented
  268. 1198 # default_router.attach_subnet(sn)
  269. 1199 if zone and zone_name == z.name:
  270. 1200 default_sn = sn
  271. 1201 # No specific zone was supplied; return the last created subnet
  272. 1202 # The list was originally reversed to have the last subnet be in zone a
  273. 1203 if not default_sn:
  274. 1204 default_sn = sn
  275. 1205 return default_sn
  276. Total time: 0.243766 s
  277. Function: get at line 633
  278. Line # Hits Time Per Hit % Time Line Contents
  279. ==============================================================
  280. 633 @profile
  281. 634 def get(self, image_id):
  282. 635 2 12.0 6.0 0.0 log.debug("Getting AWS Image Service with the id: %s", image_id)
  283. 636 2 243754.0 121877.0 100.0 return self.svc.get(image_id)
  284. Total time: 0.225429 s
  285. Function: find at line 1061
  286. Line # Hits Time Per Hit % Time Line Contents
  287. ==============================================================
  288. 1061 @dispatch(event="provider.networking.subnets.find",
  289. 1062 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  290. 1063 @profile
  291. 1064 def find(self, network=None, **kwargs):
  292. 1065 1 2.0 2.0 0.0 label = kwargs.pop('label', None)
  293. 1066
  294. 1067 # All kwargs should have been popped at this time.
  295. 1068 1 1.0 1.0 0.0 if len(kwargs) > 0:
  296. 1069 raise InvalidParamException(
  297. 1070 "Unrecognised parameters for search: %s. Supported "
  298. 1071 "attributes: %s" % (kwargs, 'label'))
  299. 1072
  300. 1073 1 20.0 20.0 0.0 log.debug("Searching for AWS Subnet Service %s", label)
  301. 1074 1 225406.0 225406.0 100.0 return self.svc.find(filter_name='tag:Name', filter_value=label)
  302. Total time: 0.094928 s
  303. Function: get at line 406
  304. Line # Hits Time Per Hit % Time Line Contents
  305. ==============================================================
  306. 406 @dispatch(event="provider.storage.snapshots.get",
  307. 407 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  308. 408 @profile
  309. 409 def get(self, snapshot_id):
  310. 410 1 94928.0 94928.0 100.0 return self.svc.get(snapshot_id)