1
0

test_keystone.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for the Keystone states
  4. """
  5. # Import python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import logging
  8. # Import Salt Testing libs
  9. from tests.support.case import ModuleCase
  10. from tests.support.helpers import destructiveTest
  11. from tests.support.mixins import SaltReturnAssertsMixin
  12. from tests.support.unit import skipIf
  13. log = logging.getLogger(__name__)
  14. NO_KEYSTONE = False
  15. try:
  16. import keystoneclient # pylint: disable=import-error,unused-import
  17. except ImportError:
  18. NO_KEYSTONE = True
  19. @skipIf(
  20. NO_KEYSTONE,
  21. "Please install keystoneclient and a keystone server before running"
  22. "keystone integration tests.",
  23. )
  24. class KeystoneStateTest(ModuleCase, SaltReturnAssertsMixin):
  25. """
  26. Validate the keystone state
  27. """
  28. endpoint = "http://localhost:35357/v2.0"
  29. token = "administrator"
  30. @destructiveTest
  31. def setUp(self):
  32. ret = self.run_state(
  33. "keystone.service_present",
  34. name="keystone",
  35. description="OpenStack Identity",
  36. service_type="identity",
  37. connection_endpoint=self.endpoint,
  38. connection_token=self.token,
  39. )
  40. self.assertTrue(
  41. ret["keystone_|-keystone_|-keystone_|-service_present"]["result"]
  42. )
  43. ret = self.run_state(
  44. "keystone.endpoint_present",
  45. name="keystone",
  46. region="RegionOne",
  47. publicurl="http://localhost:5000/v2.0",
  48. internalurl="http://localhost:5000/v2.0",
  49. adminurl="http://localhost:35357/v2.0",
  50. connection_endpoint=self.endpoint,
  51. connection_token=self.token,
  52. )
  53. self.assertTrue(
  54. ret["keystone_|-keystone_|-keystone_|-endpoint_present"]["result"]
  55. )
  56. ret = self.run_state(
  57. "keystone.tenant_present",
  58. name="admin",
  59. description="Admin Project",
  60. connection_endpoint=self.endpoint,
  61. connection_token=self.token,
  62. )
  63. self.assertTrue(ret["keystone_|-admin_|-admin_|-tenant_present"]["result"])
  64. ret = self.run_state(
  65. "keystone.tenant_present",
  66. name="demo",
  67. description="Demo Project",
  68. connection_endpoint=self.endpoint,
  69. connection_token=self.token,
  70. )
  71. self.assertTrue(ret["keystone_|-demo_|-demo_|-tenant_present"]["result"])
  72. ret = self.run_state(
  73. "keystone.role_present",
  74. name="admin",
  75. connection_endpoint=self.endpoint,
  76. connection_token=self.token,
  77. )
  78. self.assertTrue(ret["keystone_|-admin_|-admin_|-role_present"]["result"])
  79. ret = self.run_state(
  80. "keystone.role_present",
  81. name="user",
  82. connection_endpoint=self.endpoint,
  83. connection_token=self.token,
  84. )
  85. self.assertTrue(ret["keystone_|-user_|-user_|-role_present"]["result"])
  86. ret = self.run_state(
  87. "keystone.user_present",
  88. name="admin",
  89. email="admin@example.com",
  90. password="adminpass",
  91. tenant="admin",
  92. roles={"admin": ["admin"]},
  93. connection_endpoint=self.endpoint,
  94. connection_token=self.token,
  95. )
  96. self.assertTrue(ret["keystone_|-admin_|-admin_|-user_present"]["result"])
  97. ret = self.run_state(
  98. "keystone.user_present",
  99. name="demo",
  100. email="demo@example.com",
  101. password="demopass",
  102. tenant="demo",
  103. roles={"demo": ["user"]},
  104. connection_endpoint=self.endpoint,
  105. connection_token=self.token,
  106. )
  107. self.assertTrue(ret["keystone_|-demo_|-demo_|-user_present"]["result"])
  108. @destructiveTest
  109. def test_keystone_v2(self):
  110. ret = self.run_state(
  111. "keystone.service_present",
  112. name="testv2",
  113. description="Nova Service",
  114. service_type="compute",
  115. profile="adminv2",
  116. )
  117. self.assertTrue(ret["keystone_|-testv2_|-testv2_|-service_present"]["result"])
  118. ret = self.run_state(
  119. "keystone.endpoint_present",
  120. name="nova",
  121. description="Nova Service",
  122. publicurl="http://localhost:8774/v2.1/%(tenant_id)s",
  123. internalurl="http://localhost:8774/v2.1/%(tenant_id)s",
  124. adminurl="http://localhost:8774/v2.1/%(tenant_id)s",
  125. region="RegionOne",
  126. profile="adminv2",
  127. )
  128. self.assertTrue(ret["keystone_|-nova_|-nova_|-endpoint_present"]["result"])
  129. # Region Two
  130. ret = self.run_state(
  131. "keystone.endpoint_present",
  132. name="nova",
  133. description="Nova Service",
  134. publicurl="http://localhost:8774/v2.1/%(tenant_id)s",
  135. internalurl="http://localhost:8774/v2.1/%(tenant_id)s",
  136. adminurl="http://localhost:8774/v2.1/%(tenant_id)s",
  137. region="RegionTwo",
  138. profile="adminv2",
  139. )
  140. self.assertTrue(ret["keystone_|-nova_|-nova_|-endpoint_present"]["result"])
  141. # Region One, change publicurl
  142. ret = self.run_state(
  143. "keystone.endpoint_present",
  144. name="nova",
  145. description="Nova Service",
  146. publicurl="http://127.0.0.1:8774/v2.1/%(tenant_id)s",
  147. internalurl="http://localhost:8774/v2.1/%(tenant_id)s",
  148. adminurl="http://localhost:8774/v2.1/%(tenant_id)s",
  149. region="RegionOne",
  150. profile="adminv2",
  151. )
  152. self.assertTrue(ret["keystone_|-nova_|-nova_|-endpoint_present"]["result"])
  153. ret = self.run_state(
  154. "keystone.endpoint_get", name="nova", region="RegionOne", profile="adminv2"
  155. )
  156. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  157. self.assertTrue(
  158. ret["keystone_|-testv3_|-testv3_|-endpoint_present"][
  159. "publicurl"
  160. ].start_with("http://127.0.0.1")
  161. )
  162. ret = self.run_state(
  163. "keystone.tenant_present",
  164. name="test",
  165. description="Test Tenant",
  166. profile="adminv2",
  167. )
  168. self.assertTrue(ret["keystone_|-test_|-test_|-tenant_present"]["result"])
  169. ret = self.run_state("keystone.role_present", name="user", profile="adminv2")
  170. self.assertTrue(ret["keystone_|-user_|-user_|-role_present"]["result"])
  171. ret = self.run_state(
  172. "keystone.user_present",
  173. name="test",
  174. email="test@example.com",
  175. tenant="test",
  176. password="testpass",
  177. roles={"test": ["user"]},
  178. profile="adminv2",
  179. )
  180. self.assertTrue(ret["keystone_|-test_|-test_|-user_present"]["result"])
  181. ret = self.run_state(
  182. "keystone.service_absent", name="testv2", profile="adminv2"
  183. )
  184. self.assertTrue(ret["keystone_|-testv2_|-testv2_|-service_absent"]["result"])
  185. @destructiveTest
  186. def test_keystone_v3(self):
  187. ret = self.run_state(
  188. "keystone.service_present",
  189. name="testv3",
  190. description="Image Service",
  191. service_type="image",
  192. profile="adminv3",
  193. )
  194. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-service_present"]["result"])
  195. ret = self.run_state(
  196. "keystone.endpoint_present",
  197. name="testv3",
  198. description="Glance Service",
  199. interface="public",
  200. url="http://localhost:9292",
  201. region="RegionOne",
  202. profile="adminv3",
  203. )
  204. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  205. ret = self.run_state(
  206. "keystone.endpoint_present",
  207. name="testv3",
  208. description="Glance Service",
  209. interface="internal",
  210. url="http://localhost:9292",
  211. region="RegionOne",
  212. profile="adminv3",
  213. )
  214. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  215. ret = self.run_state(
  216. "keystone.endpoint_present",
  217. name="testv3",
  218. description="Glance Service",
  219. interface="admin",
  220. url="http://localhost:9292",
  221. region="RegionOne",
  222. profile="adminv3",
  223. )
  224. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  225. # Region Two
  226. ret = self.run_state(
  227. "keystone.endpoint_present",
  228. name="testv3",
  229. description="Glance Service",
  230. interface="public",
  231. url="http://localhost:9292",
  232. region="RegionTwo",
  233. profile="adminv3",
  234. )
  235. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  236. ret = self.run_state(
  237. "keystone.endpoint_present",
  238. name="testv3",
  239. description="Glance Service",
  240. interface="internal",
  241. url="http://localhost:9292",
  242. region="RegionTwo",
  243. profile="adminv3",
  244. )
  245. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  246. ret = self.run_state(
  247. "keystone.endpoint_present",
  248. name="testv3",
  249. description="Glance Service",
  250. interface="admin",
  251. url="http://localhost:9292",
  252. region="RegionTwo",
  253. profile="adminv3",
  254. )
  255. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  256. # Region One, change
  257. ret = self.run_state(
  258. "keystone.endpoint_present",
  259. name="testv3",
  260. description="Glance Service",
  261. interface="public",
  262. url="http://127.0.0.1:9292",
  263. region="RegionOne",
  264. profile="adminv3",
  265. )
  266. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  267. ret = self.run_state(
  268. "keystone.endpoint_get",
  269. name="testv3",
  270. region="RegionOne",
  271. interface="public",
  272. profile="adminv3",
  273. )
  274. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["result"])
  275. self.assertTrue(
  276. ret["keystone_|-testv3_|-testv3_|-endpoint_present"]["endpoint"]["url"]
  277. == "http://127.0.0.1:9292"
  278. )
  279. ret = self.run_state(
  280. "keystone.project_present",
  281. name="testv3",
  282. description="Test v3 Tenant",
  283. profile="adminv3",
  284. )
  285. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-project_present"]["result"])
  286. ret = self.run_state("keystone.role_present", name="user", profile="adminv3")
  287. self.assertTrue(ret["keystone_|-user_|-user_|-role_present"]["result"])
  288. ret = self.run_state(
  289. "keystone.user_present",
  290. name="testv3",
  291. email="testv3@example.com",
  292. project="testv3",
  293. password="testv3pass",
  294. roles={"testv3": ["user"]},
  295. profile="adminv3",
  296. )
  297. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-user_present"]["result"])
  298. ret = self.run_state(
  299. "keystone.service_absent", name="testv3", profile="adminv3"
  300. )
  301. self.assertTrue(ret["keystone_|-testv3_|-testv3_|-service_absent"]["result"])