filtered-azure-security.res 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. cloudbridge.test.test_security_service.CloudSecurityServiceTestCase
  2. Test output
  3. ..........
  4. ----------------------------------------------------------------------
  5. Ran 10 tests in 848.776s
  6. OK
  7. Wrote profile results to run_single.py.lprof
  8. Timer unit: 1e-06 s
  9. Total time: 491.5 s
  10. Function: create at line 113
  11. Line # Hits Time Per Hit % Time Line Contents
  12. ==============================================================
  13. 113 @cb_helpers.deprecated_alias(network_id='network')
  14. 114 @dispatch(event="provider.security.vm_firewalls.create",
  15. 115 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  16. 116 @profile
  17. 117 def create(self, label, network, description=None):
  18. 118 16 219.0 13.7 0.0 AzureVMFirewall.assert_valid_resource_label(label)
  19. 119 6 304.0 50.7 0.0 name = AzureVMFirewall._generate_name_from_label(label, "cb-fw")
  20. 120 6 17.0 2.8 0.0 net = network.id if isinstance(network, Network) else network
  21. 121 6 15.0 2.5 0.0 parameters = {"location": self.provider.region_name,
  22. 122 6 5.0 0.8 0.0 "tags": {'Label': label,
  23. 123 6 12.0 2.0 0.0 'network_id': net}}
  24. 124
  25. 125 6 4.0 0.7 0.0 if description:
  26. 126 6 12.0 2.0 0.0 parameters['tags'].update(Description=description)
  27. 127
  28. 128 6 32.0 5.3 0.0 fw = self.provider.azure_client.create_vm_firewall(name,
  29. 129 6 28271830.0 4711971.7 5.8 parameters)
  30. 130
  31. 131 # Add default rules to negate azure default rules.
  32. 132 # See: https://github.com/CloudVE/cloudbridge/issues/106
  33. 133 # pylint:disable=protected-access
  34. 134 42 125.0 3.0 0.0 for rule in fw.default_security_rules:
  35. 135 36 70.0 1.9 0.0 rule_name = "cb-override-" + rule.name
  36. 136 # Transpose rules to priority 4001 onwards, because
  37. 137 # only 0-4096 are allowed for custom rules
  38. 138 36 68.0 1.9 0.0 rule.priority = rule.priority - 61440
  39. 139 36 47.0 1.3 0.0 rule.access = "Deny"
  40. 140 36 320.0 8.9 0.0 self.provider.azure_client.create_vm_firewall_rule(
  41. 141 36 396826984.0 11022971.8 80.7 fw.id, rule_name, rule)
  42. 142
  43. 143 # Add a new custom rule allowing all outbound traffic to the internet
  44. 144 6 6.0 1.0 0.0 parameters = {"priority": 3000,
  45. 145 6 6.0 1.0 0.0 "protocol": "*",
  46. 146 6 6.0 1.0 0.0 "source_port_range": "*",
  47. 147 6 6.0 1.0 0.0 "source_address_prefix": "*",
  48. 148 6 6.0 1.0 0.0 "destination_port_range": "*",
  49. 149 6 7.0 1.2 0.0 "destination_address_prefix": "Internet",
  50. 150 6 6.0 1.0 0.0 "access": "Allow",
  51. 151 6 24.0 4.0 0.0 "direction": "Outbound"}
  52. 152 6 56.0 9.3 0.0 result = self.provider.azure_client.create_vm_firewall_rule(
  53. 153 6 66399658.0 11066609.7 13.5 fw.id, "cb-default-internet-outbound", parameters)
  54. 154 6 23.0 3.8 0.0 fw.security_rules.append(result)
  55. 155
  56. 156 6 181.0 30.2 0.0 cb_fw = AzureVMFirewall(self.provider, fw)
  57. 157 6 7.0 1.2 0.0 return cb_fw
  58. Total time: 179.261 s
  59. Function: delete at line 159
  60. Line # Hits Time Per Hit % Time Line Contents
  61. ==============================================================
  62. 159 @dispatch(event="provider.security.vm_firewalls.delete",
  63. 160 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  64. 161 @profile
  65. 162 def delete(self, vm_firewall):
  66. 163 6 23.0 3.8 0.0 fw_id = (vm_firewall.id if isinstance(vm_firewall, AzureVMFirewall)
  67. 164 else vm_firewall)
  68. 165 6 179261294.0 29876882.3 100.0 self.provider.azure_client.delete_vm_firewall(fw_id)
  69. Total time: 67.5466 s
  70. Function: label at line 81
  71. Line # Hits Time Per Hit % Time Line Contents
  72. ==============================================================
  73. 81 @label.setter
  74. 82 @profile
  75. 83 def label(self, value):
  76. 84 11 137.0 12.5 0.0 self.assert_valid_resource_label(value)
  77. 85 3 12.0 4.0 0.0 self._vm_firewall.tags.update(Label=value or "")
  78. 86 3 20.0 6.7 0.0 self._provider.azure_client.update_vm_firewall_tags(
  79. 87 3 67546411.0 22515470.3 100.0 self.id, self._vm_firewall.tags)
  80. Total time: 55.53 s
  81. Function: create at line 187
  82. Line # Hits Time Per Hit % Time Line Contents
  83. ==============================================================
  84. 187 @dispatch(event="provider.security.vm_firewall_rules.create",
  85. 188 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  86. 189 @profile
  87. 190 def create(self, firewall, direction, protocol=None, from_port=None,
  88. 191 to_port=None, cidr=None, src_dest_fw=None):
  89. 192 5 8.0 1.6 0.0 if protocol and from_port and to_port:
  90. 193 5 6.0 1.2 0.0 return self._create_rule(firewall, direction, protocol, from_port,
  91. 194 5 55529974.0 11105994.8 100.0 to_port, cidr)
  92. 195 elif src_dest_fw:
  93. 196 result = None
  94. 197 fw = (self.provider.security.vm_firewalls.get(src_dest_fw)
  95. 198 if isinstance(src_dest_fw, str) else src_dest_fw)
  96. 199 for rule in fw.rules:
  97. 200 result = self._create_rule(
  98. 201 rule.direction, rule.protocol, rule.from_port,
  99. 202 rule.to_port, rule.cidr)
  100. 203 return result
  101. 204 else:
  102. 205 return None
  103. Total time: 32.3408 s
  104. Function: delete at line 238
  105. Line # Hits Time Per Hit % Time Line Contents
  106. ==============================================================
  107. 238 @dispatch(event="provider.security.vm_firewall_rules.delete",
  108. 239 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  109. 240 @profile
  110. 241 def delete(self, firewall, rule):
  111. 242 3 9.0 3.0 0.0 rule_id = rule.id if isinstance(rule, AzureVMFirewallRule) else rule
  112. 243 3 7.0 2.3 0.0 fw_name = firewall.name
  113. 244 3 14.0 4.7 0.0 self.provider.azure_client. \
  114. 245 3 32340706.0 10780235.3 100.0 delete_vm_firewall_rule(rule_id, fw_name)
  115. 246 4 35.0 8.8 0.0 for i, o in enumerate(firewall._vm_firewall.security_rules):
  116. 247 4 10.0 2.5 0.0 if o.id == rule_id:
  117. 248 # pylint:disable=protected-access
  118. 249 3 6.0 2.0 0.0 del firewall._vm_firewall.security_rules[i]
  119. 250 3 3.0 1.0 0.0 break
  120. Total time: 9.13897 s
  121. Function: get_or_create_default at line 320
  122. Line # Hits Time Per Hit % Time Line Contents
  123. ==============================================================
  124. 320 @profile
  125. 321 def get_or_create_default(self, zone):
  126. 322 # Look for a CB-default subnet
  127. 323 6 9138951.0 1523158.5 100.0 matches = self.find(label=BaseSubnet.CB_DEFAULT_SUBNET_LABEL)
  128. 324 6 6.0 1.0 0.0 if matches:
  129. 325 6 14.0 2.3 0.0 return matches[0]
  130. 326
  131. 327 # No provider-default Subnet exists, try to create it (net + subnets)
  132. 328 network = self.provider.networking.networks.get_or_create_default()
  133. 329 subnet = self.create(BaseSubnet.CB_DEFAULT_SUBNET_LABEL, network,
  134. 330 BaseSubnet.CB_DEFAULT_SUBNET_IPV4RANGE, zone)
  135. 331 return subnet
  136. Total time: 9.07843 s
  137. Function: find at line 1272
  138. Line # Hits Time Per Hit % Time Line Contents
  139. ==============================================================
  140. 1272 @dispatch(event="provider.networking.subnets.find",
  141. 1273 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  142. 1274 @profile
  143. 1275 def find(self, network=None, **kwargs):
  144. 1276 6 5803094.0 967182.3 63.9 obj_list = self._list_subnets(network)
  145. 1277 6 15.0 2.5 0.0 filters = ['label']
  146. 1278 6 3275043.0 545840.5 36.1 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  147. 1279
  148. 1280 6 40.0 6.7 0.0 return ClientPagedResultList(self.provider,
  149. 1281 6 234.0 39.0 0.0 matches if matches else [])
  150. Total time: 6.12621 s
  151. Function: create at line 306
  152. Line # Hits Time Per Hit % Time Line Contents
  153. ==============================================================
  154. 306 @dispatch(event="provider.security.key_pairs.create",
  155. 307 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  156. 308 @profile
  157. 309 def create(self, name, public_key_material=None):
  158. 310 14 165.0 11.8 0.0 AzureKeyPair.assert_valid_resource_name(name)
  159. 311 4 5249153.0 1312288.2 85.7 key_pair = self.get(name)
  160. 312
  161. 313 4 5.0 1.2 0.0 if key_pair:
  162. 314 1 1.0 1.0 0.0 raise DuplicateResourceException(
  163. 315 1 4.0 4.0 0.0 'Keypair already exists with name {0}'.format(name))
  164. 316
  165. 317 3 2.0 0.7 0.0 private_key = None
  166. 318 3 3.0 1.0 0.0 if not public_key_material:
  167. 319 2 109145.0 54572.5 1.8 public_key_material, private_key = cb_helpers.generate_key_pair()
  168. 320
  169. 321 entity = {
  170. 322 3 15.0 5.0 0.0 'PartitionKey': AzureKeyPairService.PARTITION_KEY,
  171. 323 3 135.0 45.0 0.0 'RowKey': str(uuid.uuid4()),
  172. 324 3 2.0 0.7 0.0 'Name': name,
  173. 325 3 7.0 2.3 0.0 'Key': public_key_material
  174. 326 }
  175. 327
  176. 328 3 372582.0 124194.0 6.1 self.provider.azure_client.create_public_key(entity)
  177. 329 3 394977.0 131659.0 6.4 key_pair = self.get(name)
  178. 330 3 12.0 4.0 0.0 key_pair.material = private_key
  179. 331 3 2.0 0.7 0.0 return key_pair
  180. Total time: 6.12568 s
  181. Function: get at line 259
  182. Line # Hits Time Per Hit % Time Line Contents
  183. ==============================================================
  184. 259 @dispatch(event="provider.security.key_pairs.get",
  185. 260 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  186. 261 @profile
  187. 262 def get(self, key_pair_id):
  188. 263 11 13.0 1.2 0.0 try:
  189. 264 11 1125460.0 102314.5 18.4 key_pair = self.provider.azure_client.\
  190. 265 11 5000048.0 454549.8 81.6 get_public_key(key_pair_id)
  191. 266
  192. 267 11 23.0 2.1 0.0 if key_pair:
  193. 268 7 135.0 19.3 0.0 return AzureKeyPair(self.provider, key_pair)
  194. 269 4 3.0 0.8 0.0 return None
  195. 270 except AzureException as error:
  196. 271 log.debug("KeyPair %s was not found.", key_pair_id)
  197. 272 log.debug(error)
  198. 273 return None
  199. Total time: 4.61747 s
  200. Function: get at line 1168
  201. Line # Hits Time Per Hit % Time Line Contents
  202. ==============================================================
  203. 1168 @dispatch(event="provider.networking.networks.get",
  204. 1169 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  205. 1170 @profile
  206. 1171 def get(self, network_id):
  207. 1172 18 23.0 1.3 0.0 try:
  208. 1173 18 4616908.0 256494.9 100.0 network = self.provider.azure_client.get_network(network_id)
  209. 1174 18 542.0 30.1 0.0 return AzureNetwork(self.provider, network)
  210. 1175 except (CloudError, InvalidValueException) as cloud_error:
  211. 1176 # Azure raises the cloud error if the resource not available
  212. 1177 log.exception(cloud_error)
  213. 1178 return None
  214. Total time: 4.32446 s
  215. Function: list at line 1180
  216. Line # Hits Time Per Hit % Time Line Contents
  217. ==============================================================
  218. 1180 @dispatch(event="provider.networking.networks.list",
  219. 1181 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  220. 1182 @profile
  221. 1183 def list(self, limit=None, marker=None):
  222. 1184 6 10.0 1.7 0.0 networks = [AzureNetwork(self.provider, network)
  223. 1185 6 4324209.0 720701.5 100.0 for network in self.provider.azure_client.list_networks()]
  224. 1186 6 20.0 3.3 0.0 return ClientPagedResultList(self.provider, networks,
  225. 1187 6 221.0 36.8 0.0 limit=limit, marker=marker)
  226. Total time: 1.84706 s
  227. Function: list at line 105
  228. Line # Hits Time Per Hit % Time Line Contents
  229. ==============================================================
  230. 105 @dispatch(event="provider.security.vm_firewalls.list",
  231. 106 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  232. 107 @profile
  233. 108 def list(self, limit=None, marker=None):
  234. 109 7 13.0 1.9 0.0 fws = [AzureVMFirewall(self.provider, fw)
  235. 110 7 1846776.0 263825.1 100.0 for fw in self.provider.azure_client.list_vm_firewall()]
  236. 111 7 274.0 39.1 0.0 return ClientPagedResultList(self.provider, fws, limit, marker)
  237. Total time: 0.751486 s
  238. Function: list at line 275
  239. Line # Hits Time Per Hit % Time Line Contents
  240. ==============================================================
  241. 275 @dispatch(event="provider.security.key_pairs.list",
  242. 276 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  243. 277 @profile
  244. 278 def list(self, limit=None, marker=None):
  245. 279 6 39.0 6.5 0.0 key_pairs, resume_marker = self.provider.azure_client.list_public_keys(
  246. 280 6 7.0 1.2 0.0 AzureKeyPairService.PARTITION_KEY, marker=marker,
  247. 281 6 751263.0 125210.5 100.0 limit=limit or self.provider.config.default_result_limit)
  248. 282 6 19.0 3.2 0.0 results = [AzureKeyPair(self.provider, key_pair)
  249. 283 6 82.0 13.7 0.0 for key_pair in key_pairs]
  250. 284 6 6.0 1.0 0.0 return ServerPagedResultList(is_truncated=resume_marker,
  251. 285 6 4.0 0.7 0.0 marker=resume_marker,
  252. 286 6 4.0 0.7 0.0 supports_total=False,
  253. 287 6 62.0 10.3 0.0 data=results)
  254. Total time: 0.726115 s
  255. Function: get at line 93
  256. Line # Hits Time Per Hit % Time Line Contents
  257. ==============================================================
  258. 93 @dispatch(event="provider.security.vm_firewalls.get",
  259. 94 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  260. 95 @profile
  261. 96 def get(self, vm_firewall_id):
  262. 97 3 2.0 0.7 0.0 try:
  263. 98 3 725867.0 241955.7 100.0 fws = self.provider.azure_client.get_vm_firewall(vm_firewall_id)
  264. 99 2 45.0 22.5 0.0 return AzureVMFirewall(self.provider, fws)
  265. 100 1 4.0 4.0 0.0 except (CloudError, InvalidValueException) as cloud_error:
  266. 101 # Azure raises the cloud error if the resource not available
  267. 102 1 196.0 196.0 0.0 log.exception(cloud_error)
  268. 103 1 1.0 1.0 0.0 return None
  269. Total time: 0.553877 s
  270. Function: find at line 81
  271. Line # Hits Time Per Hit % Time Line Contents
  272. ==============================================================
  273. 81 @dispatch(event="provider.security.vm_firewalls.find",
  274. 82 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  275. 83 @profile
  276. 84 def find(self, **kwargs):
  277. 85 3 4.0 1.3 0.0 obj_list = self
  278. 86 3 4.0 1.3 0.0 filters = ['label']
  279. 87 3 553824.0 184608.0 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  280. 88
  281. 89 # All kwargs should have been popped at this time.
  282. 90 2 2.0 1.0 0.0 if len(kwargs) > 0:
  283. 91 raise InvalidParamException(
  284. 92 "Unrecognised parameters for search: %s. Supported "
  285. 93 "attributes: %s" % (kwargs, ", ".join(filters)))
  286. 94
  287. 95 2 2.0 1.0 0.0 return ClientPagedResultList(self.provider,
  288. 96 2 41.0 20.5 0.0 matches if matches else [])
  289. Total time: 0.527011 s
  290. Function: delete at line 333
  291. Line # Hits Time Per Hit % Time Line Contents
  292. ==============================================================
  293. 333 @dispatch(event="provider.security.key_pairs.delete",
  294. 334 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  295. 335 @profile
  296. 336 def delete(self, key_pair):
  297. 337 3 4.0 1.3 0.0 key_pair = (key_pair if isinstance(key_pair, AzureKeyPair) else
  298. 338 1 128431.0 128431.0 24.4 self.get(key_pair))
  299. 339 3 1.0 0.3 0.0 if key_pair:
  300. 340 # pylint:disable=protected-access
  301. 341 3 398575.0 132858.3 75.6 self.provider.azure_client.delete_public_key(key_pair._key_pair)
  302. Total time: 0.263378 s
  303. Function: find at line 289
  304. Line # Hits Time Per Hit % Time Line Contents
  305. ==============================================================
  306. 289 @dispatch(event="provider.security.key_pairs.find",
  307. 290 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  308. 291 @profile
  309. 292 def find(self, **kwargs):
  310. 293 3 4.0 1.3 0.0 obj_list = self
  311. 294 3 2.0 0.7 0.0 filters = ['name']
  312. 295 3 263278.0 87759.3 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  313. 296
  314. 297 # All kwargs should have been popped at this time.
  315. 298 2 2.0 1.0 0.0 if len(kwargs) > 0:
  316. 299 raise InvalidParamException(
  317. 300 "Unrecognised parameters for search: %s. Supported "
  318. 301 "attributes: %s" % (kwargs, ", ".join(filters)))
  319. 302
  320. 303 2 9.0 4.5 0.0 return ClientPagedResultList(self.provider,
  321. 304 2 83.0 41.5 0.0 matches if matches else [])
  322. Total time: 0.177344 s
  323. Function: refresh at line 105
  324. Line # Hits Time Per Hit % Time Line Contents
  325. ==============================================================
  326. 105 @profile
  327. 106 def refresh(self):
  328. 107 """
  329. 108 Refreshes the security group with tags if required.
  330. 109 """
  331. 110 1 1.0 1.0 0.0 try:
  332. 111 1 9.0 9.0 0.0 self._vm_firewall = self._provider.azure_client. \
  333. 112 1 177332.0 177332.0 100.0 get_vm_firewall(self.id)
  334. 113 1 2.0 2.0 0.0 if not self._vm_firewall.tags:
  335. 114 self._vm_firewall.tags = {}
  336. 115 except (CloudError, ValueError) as cloud_error:
  337. 116 log.exception(cloud_error.message)
  338. Total time: 0.0011 s
  339. Function: find at line 121
  340. Line # Hits Time Per Hit % Time Line Contents
  341. ==============================================================
  342. 121 @dispatch(event="provider.security.vm_firewall_rules.find",
  343. 122 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  344. 123 @profile
  345. 124 def find(self, firewall, **kwargs):
  346. 125 3 7.0 2.3 0.6 obj_list = firewall.rules
  347. 126 3 3.0 1.0 0.3 filters = ['name', 'direction', 'protocol', 'from_port', 'to_port',
  348. 127 3 2.0 0.7 0.2 'cidr', 'src_dest_fw', 'src_dest_fw_id']
  349. 128 3 1047.0 349.0 95.2 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  350. 129 2 41.0 20.5 3.7 return ClientPagedResultList(self._provider, list(matches))
  351. Total time: 0.001076 s
  352. Function: list at line 173
  353. Line # Hits Time Per Hit % Time Line Contents
  354. ==============================================================
  355. 173 @dispatch(event="provider.security.vm_firewall_rules.list",
  356. 174 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  357. 175 @profile
  358. 176 def list(self, firewall, limit=None, marker=None):
  359. 177 # Filter out firewall rules with priority < 3500 because values
  360. 178 # between 3500 and 4096 are assumed to be owned by cloudbridge
  361. 179 # default rules.
  362. 180 # pylint:disable=protected-access
  363. 181 15 19.0 1.3 1.8 rules = [AzureVMFirewallRule(firewall, rule) for rule
  364. 182 15 661.0 44.1 61.4 in firewall._vm_firewall.security_rules
  365. 183 if rule.priority < 3500]
  366. 184 15 32.0 2.1 3.0 return ClientPagedResultList(self.provider, rules,
  367. 185 15 364.0 24.3 33.8 limit=limit, marker=marker)
  368. Total time: 0.000267 s
  369. Function: get at line 111
  370. Line # Hits Time Per Hit % Time Line Contents
  371. ==============================================================
  372. 111 @dispatch(event="provider.security.vm_firewall_rules.get",
  373. 112 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  374. 113 @profile
  375. 114 def get(self, firewall, rule_id):
  376. 115 2 264.0 132.0 98.9 matches = [rule for rule in firewall.rules if rule.id == rule_id]
  377. 116 2 2.0 1.0 0.7 if matches:
  378. 117 1 0.0 0.0 0.0 return matches[0]
  379. 118 else:
  380. 119 1 1.0 1.0 0.4 return None