test_azure_security_service.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import azure_test.helpers as helpers
  2. from azure_test.helpers import ProviderTestBase
  3. class AzureSecurityServiceTestCase(ProviderTestBase):
  4. @helpers.skipIfNoService(['security.security_groups'])
  5. def test_azure_security_key_paires(self):
  6. with self.assertRaises(NotImplementedError):
  7. self.key_pairs = self.provider.security.key_pairs
  8. @helpers.skipIfNoService(['security.security_groups'])
  9. def test_azure_security_group_create(self):
  10. name = "testCreateSecGroup3"
  11. sg = self.provider.security.security_groups.create(
  12. name=name, description=name, network_id="")
  13. print("Create( " + "Name-" + sg.name + " Id-" + sg.id + " Rules - " + str(sg.rules) + " )")
  14. self.assertEqual(name, sg.name)
  15. @helpers.skipIfNoService(['security.security_groups'])
  16. def test_azure_security_group_find_exists(self):
  17. sgl = self.provider.security.security_groups.find("sg")
  18. for sg in sgl:
  19. self.assertTrue("sg" in sg.name)
  20. self.assertTrue(sgl.total_results > 0)
  21. @helpers.skipIfNoService(['security.security_groups'])
  22. def test_azure_security_group_find_not_exists(self):
  23. sgl = self.provider.security.security_groups.find('dontfindme')
  24. self.assertTrue(sgl.total_results == 0)
  25. @helpers.skipIfNoService(['security.security_groups'])
  26. def test_azure_security_group_list(self):
  27. sgl = self.provider.security.security_groups.list()
  28. found_sg = [g.name for g in sgl]
  29. for group in sgl:
  30. print("List( " + "Name-" + group.name + " Id-" + group.id + " Rules - " + " )")
  31. self.assertTrue(
  32. len(sgl) == 3,
  33. "Count should be 3")
  34. @helpers.skipIfNoService(['security.security_groups'])
  35. def test_azure_security_group_get_found(self):
  36. sgl = self.provider.security.security_groups.get(
  37. "/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/CloudBridge-Azure'\
  38. '/providers/Microsoft.Network/networkSecurityGroups/sg3")
  39. print("Get ( " + "Name - " + sgl.name + " Id - " + sgl.id + " )")
  40. self.assertTrue(
  41. sgl.name == "sg3",
  42. "SG name should be sg3")
  43. @helpers.skipIfNoService(['security.security_groups'])
  44. def test_azure_security_group_get_not_found(self):
  45. sgl = self.provider.security.security_groups.get(
  46. "/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/CloudBridge-Azure'\
  47. '/providers/Microsoft.Network/networkSecurityGroups/sg4")
  48. print(str(sgl))
  49. self.assertTrue(
  50. sgl is None,
  51. "Security group does not exist. Should return None.")
  52. @helpers.skipIfNoService(['security.security_groups'])
  53. def test_azure_security_group_delete_IdExists(self):
  54. sg = self.provider.security.security_groups.delete(
  55. "/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/CloudBridge-Azure'\
  56. '/providers/Microsoft.Network/networkSecurityGroups/sg2")
  57. print("Delete - ")
  58. self.assertEqual(sg, True)
  59. @helpers.skipIfNoService(['security.security_groups'])
  60. def test_azure_security_group_delete_IdNotExist(self):
  61. sg = self.provider.security.security_groups.delete(
  62. "/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/CloudBridge-Azure'\
  63. '/providers/Microsoft.Network/networkSecurityGroups/sg5")
  64. self.assertEqual(sg, False)
  65. @helpers.skipIfNoService(['security.security_groups'])
  66. def test_azure_security_group_rule_create(self):
  67. list = self.provider.security.security_groups.list()
  68. cb = list.data[0]
  69. rules = cb.rules
  70. for rule in rules:
  71. print(str(rule))
  72. print("Before creating Rule - " + str(rules[0]) + " length - " + str(len(rules)))
  73. cb.add_rule('*', '25', '100', '*')
  74. rules = cb.rules
  75. print("After creating Rule - " + str(rules[0]) + " length - " + str(len(rules)))
  76. self.assertEqual(len(rules), 3)
  77. @helpers.skipIfNoService(['security.security_groups'])
  78. def test_azure_security_group_rule_delete(self):
  79. list = self.provider.security.security_groups.list()
  80. cb = list.data[0]
  81. rules = cb.rules
  82. print("Before deleting Rule - " + str(rules[0]) + " length - " + str(len(rules)))
  83. rules[1].delete()
  84. rules = cb.rules
  85. print("After deleting Rule - " + str(rules[0]) + " length - " + str(len(rules)))
  86. self.assertEqual(len(rules), 2)
  87. @helpers.skipIfNoService(['security.security_groups'])
  88. def test_azure_security_group_rule_get_exist(self):
  89. list = self.provider.security.security_groups.list()
  90. cb = list.data[0]
  91. rule = cb.get_rule('*', '25', '1', '100')
  92. print("Get Rule - " + str(rule))
  93. self.assertIsNotNone(rule)
  94. @helpers.skipIfNoService(['security.security_groups'])
  95. def test_azure_security_group_rule_get_notExist(self):
  96. list = self.provider.security.security_groups.list()
  97. cb = list.data[0]
  98. rule = cb.get_rule('*', '25', '1', '1')
  99. print("Get Rule - " + str(rule))
  100. self.assertEqual(str(rule), 'None')
  101. @helpers.skipIfNoService(['security.security_groups'])
  102. def test_azure_security_group_to_json(self):
  103. list = self.provider.security.security_groups.list()
  104. cb = list.data[0]
  105. rule = cb.to_json()
  106. print("Get Rule - " + str(rule))
  107. self.assertIsNotNone(rule)
  108. @helpers.skipIfNoService(['security.security_groups'])
  109. def test_azure_security_group_rule_to_json(self):
  110. list = self.provider.security.security_groups.list()
  111. cb = list.data[0]
  112. rules = cb.rules
  113. rule = rules[0]
  114. json = rule.to_json()
  115. print("Get Rule - " + str(json))
  116. self.assertEqual(json[2:9], "cidr_ip")