OpenStack in a snap!
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.
 
 
 
 

146 lines
4.7 KiB

  1. #!/usr/bin/env python
  2. """
  3. basic_test.py
  4. This is a basic test of microstack functionality. We verify that:
  5. 1) We can install the snap.
  6. 2) We can launch a cirros image.
  7. 3) Horizon is running, and we can hit the landing page.
  8. 4) We can login to Horizon successfully.
  9. The Horizon testing bits were are based on code generated by the Selinum
  10. Web IDE.
  11. """
  12. import json
  13. import os
  14. import sys
  15. import time
  16. import unittest
  17. import xvfbwrapper
  18. from selenium import webdriver
  19. from selenium.webdriver.common.by import By
  20. sys.path.append(os.getcwd())
  21. from tests.framework import Framework, check, check_output, call # noqa E402
  22. class TestBasics(Framework):
  23. def setUp(self):
  24. super(TestBasics, self).setUp()
  25. # Setup Selenium Driver
  26. self.display = xvfbwrapper.Xvfb(width=1280, height=720)
  27. self.display.start()
  28. self.driver = webdriver.PhantomJS()
  29. def tearDown(self):
  30. # Tear down selenium driver
  31. self.driver.quit()
  32. self.display.stop()
  33. super(TestBasics, self).tearDown()
  34. def test_basics(self):
  35. """Basic test
  36. Install microstack, and verify that we can launch a machine and
  37. open the Horizon GUI.
  38. """
  39. launch = '/snap/bin/microstack.launch'
  40. openstack = '/snap/bin/microstack.openstack'
  41. print("Testing microstack.launch ...")
  42. check(*self.PREFIX, launch, 'breakfast')
  43. endpoints = check_output(
  44. *self.PREFIX, '/snap/bin/microstack.openstack', 'endpoint', 'list')
  45. # Endpoints should be listening on 10.20.20.1
  46. self.assertTrue("10.20.20.1" in endpoints)
  47. # Endpoints should not contain localhost
  48. self.assertFalse("localhost" in endpoints)
  49. # Verify that microstack.launch completed successfully
  50. # Ping the instance
  51. ip = None
  52. servers = check_output(*self.PREFIX, openstack,
  53. 'server', 'list', '--format', 'json')
  54. servers = json.loads(servers)
  55. for server in servers:
  56. if server['Name'] == 'breakfast':
  57. ip = server['Networks'].split(",")[1].strip()
  58. break
  59. self.assertTrue(ip)
  60. pings = 1
  61. max_pings = 40
  62. while not call(*self.PREFIX, 'ping', '-c', '1', ip):
  63. pings += 1
  64. if pings > max_pings:
  65. self.assertFalse(True, msg='Max pings reached!')
  66. print("Testing instances' ability to connect to the Internet")
  67. # Test Internet connectivity
  68. attempts = 1
  69. max_attempts = 40
  70. username = check_output(*self.PREFIX, 'whoami')
  71. while not call(
  72. *self.PREFIX,
  73. 'ssh',
  74. '-oStrictHostKeyChecking=no',
  75. '-i', '/home/{}/.ssh/id_microstack'.format(username),
  76. 'cirros@{}'.format(ip),
  77. '--', 'ping', '-c', '1', '91.189.94.250'):
  78. attempts += 1
  79. if attempts > max_attempts:
  80. self.assertFalse(True, msg='Unable to access the Internet!')
  81. time.sleep(5)
  82. if 'multipass' in self.PREFIX:
  83. print("Opening {}:80 up to the outside world".format(
  84. self.HORIZON_IP))
  85. with open('/tmp/_10_hosts.py', 'w') as hosts:
  86. hosts.write("""\
  87. # Allow all hosts to connect to this machine
  88. ALLOWED_HOSTS = ['*',]
  89. """)
  90. check('multipass', 'copy-files', '/tmp/_10_hosts.py',
  91. '{}:/tmp/_10_hosts.py'.format(self.MACHINE))
  92. check(
  93. *self.PREFIX, 'sudo', 'cp', '/tmp/_10_hosts.py',
  94. '/var/snap/microstack/common/etc/horizon/local_settings.d/'
  95. )
  96. check(*self.PREFIX, 'sudo', 'snap', 'restart', 'microstack')
  97. print('Verifying GUI for (IP: {})'.format(self.HORIZON_IP))
  98. # Verify that our GUI is working properly
  99. self.driver.get("http://{}/".format(self.HORIZON_IP))
  100. # Login to horizon!
  101. self.driver.find_element(By.ID, "id_username").click()
  102. self.driver.find_element(By.ID, "id_username").send_keys("admin")
  103. self.driver.find_element(By.ID, "id_password").send_keys("keystone")
  104. self.driver.find_element(By.CSS_SELECTOR, "#loginBtn > span").click()
  105. # Verify that we can click something on the dashboard -- e.g.,
  106. # we're still not sitting at the login screen.
  107. self.driver.find_element(By.LINK_TEXT, "Images").click()
  108. self.passed = True
  109. if __name__ == '__main__':
  110. # Run our tests, ignoring deprecation warnings and warnings about
  111. # unclosed sockets. (TODO: setup a selenium server so that we can
  112. # move from PhantomJS, which is deprecated, to to Selenium headless.)
  113. unittest.main(warnings='ignore')