A collection of plugins for Rally framework designed for the OpenStack platform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

167 lines
7.0 KiB

  1. # Copyright 2013: Mirantis Inc.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. import json
  16. import re
  17. import unittest
  18. from tests.functional import utils
  19. class DeploymentTestCase(unittest.TestCase):
  20. def setUp(self):
  21. super(DeploymentTestCase, self).setUp()
  22. def test_create_fromenv_list_show(self):
  23. rally = utils.Rally()
  24. rally.env.update(utils.TEST_ENV)
  25. rally("deployment create --name t_create_env --fromenv")
  26. self.assertIn("t_create_env", rally("deployment list"))
  27. self.assertIn(utils.TEST_ENV["OS_AUTH_URL"],
  28. rally("deployment show"))
  29. def test_create_fromfile(self):
  30. rally = utils.Rally()
  31. rally.env.update(utils.TEST_ENV)
  32. rally("deployment create --name t_create_env --fromenv")
  33. with open("/tmp/.tmp.deployment", "w") as f:
  34. f.write(rally("deployment config"))
  35. rally("deployment create --name t_create_file "
  36. "--filename /tmp/.tmp.deployment")
  37. self.assertIn("t_create_file", rally("deployment list"))
  38. @unittest.skip("It started failing due to broken launching script. "
  39. "Requires investigation.")
  40. def test_create_empty(self):
  41. rally = utils.Rally()
  42. rally("deployment create --name t_empty")
  43. self.assertEqual("{}", rally("deployment config"))
  44. @unittest.skip("It started failing due to broken launching script. "
  45. "Requires investigation.")
  46. def test_config(self):
  47. rally = utils.Rally()
  48. rally.env.update(utils.TEST_ENV)
  49. rally("deployment create --name t_create_env --fromenv")
  50. config = json.loads(rally("deployment config"))
  51. self.assertIn("creds", config)
  52. self.assertIn("openstack", config["creds"])
  53. oscreds = config["creds"]["openstack"]
  54. self.assertEqual(utils.TEST_ENV["OS_USERNAME"],
  55. oscreds["admin"]["username"])
  56. self.assertEqual(utils.TEST_ENV["OS_PASSWORD"],
  57. oscreds["admin"]["password"])
  58. if "project_name" in oscreds["admin"]:
  59. # keystone v3
  60. self.assertEqual(utils.TEST_ENV["OS_TENANT_NAME"],
  61. oscreds["admin"]["project_name"])
  62. else:
  63. # keystone v2
  64. self.assertEqual(utils.TEST_ENV["OS_TENANT_NAME"],
  65. oscreds["admin"]["tenant_name"])
  66. self.assertEqual(utils.TEST_ENV["OS_AUTH_URL"],
  67. oscreds["auth_url"])
  68. def test_destroy(self):
  69. rally = utils.Rally()
  70. rally.env.update(utils.TEST_ENV)
  71. rally("deployment create --name t_create_env --fromenv")
  72. self.assertIn("t_create_env", rally("deployment list"))
  73. rally("deployment destroy")
  74. self.assertNotIn("t_create_env", rally("deployment list"))
  75. def test_check_success(self):
  76. rally = utils.Rally()
  77. self.assertTrue(rally("deployment check"))
  78. def test_check_fail(self):
  79. rally = utils.Rally()
  80. rally.env.update(utils.TEST_ENV)
  81. rally("deployment create --name t_create_env --fromenv")
  82. self.assertRaises(utils.RallyCliError, rally, "deployment check")
  83. @unittest.skip("It started failing due to broken launching script. "
  84. "Requires investigation.")
  85. def test_check_debug(self):
  86. rally = utils.Rally()
  87. rally.env.update(utils.TEST_ENV)
  88. rally("deployment create --name t_create_env --fromenv")
  89. config = json.loads(rally("deployment config"))
  90. config["creds"]["openstack"]["admin"]["password"] = "fakepassword"
  91. file = utils.JsonTempFile(config)
  92. rally("deployment create --name t_create_file_debug "
  93. "--filename %s" % file.filename)
  94. self.assertIn("t_create_file_debug", rally("deployment list"))
  95. self.assertEqual(config,
  96. json.loads(rally("deployment config")))
  97. self.assertRaises(utils.RallyCliError, rally, "deployment check")
  98. try:
  99. rally("--debug deployment check")
  100. except utils.RallyCliError as e:
  101. self.assertIn(
  102. "[-] Unable to authenticate for user %(username)s in"
  103. " project %(tenant_name)s" %
  104. {"username": utils.TEST_ENV["OS_USERNAME"],
  105. "tenant_name": utils.TEST_ENV["OS_TENANT_NAME"]},
  106. str(e))
  107. self.assertIn(
  108. "AuthenticationFailed: Failed to authenticate to %(auth_url)s"
  109. " for user '%(username)s' in project '%(tenant_name)s'" %
  110. {"auth_url": utils.TEST_ENV["OS_AUTH_URL"],
  111. "username": utils.TEST_ENV["OS_USERNAME"],
  112. "tenant_name": utils.TEST_ENV["OS_TENANT_NAME"]},
  113. str(e))
  114. else:
  115. self.fail("rally deployment fails to raise error for wrong"
  116. " authentication info")
  117. def test_recreate(self):
  118. rally = utils.Rally()
  119. rally.env.update(utils.TEST_ENV)
  120. rally("deployment create --name t_create_env --fromenv")
  121. rally("deployment recreate --deployment t_create_env")
  122. self.assertIn("t_create_env", rally("deployment list"))
  123. @unittest.skip("It started failing due to broken launching script. "
  124. "Requires investigation.")
  125. def test_recreate_from_file(self):
  126. rally = utils.Rally()
  127. rally.env.update(utils.TEST_ENV)
  128. rally("deployment create --name t_create_env --fromenv")
  129. config = json.loads(rally("deployment config"))
  130. config["creds"]["openstack"]["auth_url"] = "http://foo/"
  131. file = utils.JsonTempFile(config)
  132. rally("deployment recreate --deployment t_create_env "
  133. "--filename %s" % file.filename)
  134. self.assertIn("t_create_env", rally("deployment list"))
  135. self.assertEqual(config,
  136. json.loads(rally("deployment config")))
  137. self.assertIn("http://foo/", rally("deployment show"))
  138. def test_use(self):
  139. rally = utils.Rally()
  140. rally.env.update(utils.TEST_ENV)
  141. output = rally(
  142. "deployment create --name t_create_env1 --fromenv")
  143. uuid = re.search(r"Using deployment: (?P<uuid>[0-9a-f\-]{36})",
  144. output).group("uuid")
  145. rally("deployment create --name t_create_env2 --fromenv")
  146. rally("deployment use --deployment %s" % uuid)
  147. current_deployment = utils.get_global("RALLY_DEPLOYMENT",
  148. rally.env)
  149. self.assertEqual(uuid, current_deployment)