PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/BRI_RNAseq_truseq_optimized/pymodules/python2.7/lib/python/apache_libcloud-0.15.1-py2.7.egg/libcloud/test/compute/test_hostvirtual.py

https://gitlab.com/pooja043/Globus_Docker_1
Python | 188 lines | 139 code | 34 blank | 15 comment | 1 complexity | b1b0ddc75e03c79812e588ca92381eb6 MD5 | raw file
  1. # Licensed to the Apache Software Foundation (ASF) under one or more
  2. # contributor license agreements. See the NOTICE file distributed with
  3. # this work for additional information regarding copyright ownership.
  4. # The ASF licenses this file to You under the Apache License, Version 2.0
  5. # (the "License"); you may not use this file except in compliance with
  6. # the License. You may obtain 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,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import sys
  16. import unittest
  17. from libcloud.utils.py3 import httplib
  18. from libcloud.compute.drivers.hostvirtual import HostVirtualNodeDriver
  19. from libcloud.compute.types import NodeState
  20. from libcloud.compute.base import NodeAuthPassword
  21. from libcloud.test import MockHttp
  22. from libcloud.test.file_fixtures import ComputeFileFixtures
  23. from libcloud.test.secrets import HOSTVIRTUAL_PARAMS
  24. class HostVirtualTest(unittest.TestCase):
  25. def setUp(self):
  26. HostVirtualNodeDriver.connectionCls.conn_classes = (
  27. None, HostVirtualMockHttp)
  28. self.driver = HostVirtualNodeDriver(*HOSTVIRTUAL_PARAMS)
  29. def test_list_nodes(self):
  30. nodes = self.driver.list_nodes()
  31. self.assertEqual(len(nodes), 4)
  32. self.assertEqual(len(nodes[0].public_ips), 1)
  33. self.assertEqual(len(nodes[1].public_ips), 1)
  34. self.assertEqual(len(nodes[0].private_ips), 0)
  35. self.assertEqual(len(nodes[1].private_ips), 0)
  36. self.assertTrue('208.111.39.118' in nodes[1].public_ips)
  37. self.assertTrue('208.111.45.250' in nodes[0].public_ips)
  38. self.assertEqual(nodes[3].state, NodeState.RUNNING)
  39. self.assertEqual(nodes[1].state, NodeState.TERMINATED)
  40. def test_list_sizes(self):
  41. sizes = self.driver.list_sizes()
  42. self.assertEqual(len(sizes), 14)
  43. self.assertEqual(sizes[0].id, '31')
  44. self.assertEqual(sizes[4].id, '71')
  45. self.assertEqual(sizes[2].ram, '512MB')
  46. self.assertEqual(sizes[2].disk, '20GB')
  47. self.assertEqual(sizes[3].bandwidth, '600GB')
  48. self.assertEqual(sizes[1].price, '15.00')
  49. def test_list_images(self):
  50. images = self.driver.list_images()
  51. self.assertEqual(len(images), 8)
  52. self.assertEqual(images[0].id, '1739')
  53. self.assertEqual(images[0].name, 'Gentoo 2012 (0619) i386')
  54. def test_list_locations(self):
  55. locations = self.driver.list_locations()
  56. self.assertEqual(locations[0].id, '3')
  57. self.assertEqual(locations[0].name, 'SJC - San Jose, CA')
  58. self.assertEqual(locations[1].id, '13')
  59. self.assertEqual(locations[1].name, 'IAD2- Reston, VA')
  60. def test_reboot_node(self):
  61. node = self.driver.list_nodes()[0]
  62. self.assertTrue(self.driver.reboot_node(node))
  63. def test_ex_get_node(self):
  64. node = self.driver.ex_get_node(node_id='62291')
  65. self.assertEqual(node.id, '62291')
  66. self.assertEqual(node.name, 'server1.vr-cluster.org')
  67. self.assertEqual(node.state, NodeState.TERMINATED)
  68. self.assertTrue('208.111.45.250' in node.public_ips)
  69. def test_ex_stop_node(self):
  70. node = self.driver.list_nodes()[0]
  71. self.assertTrue(self.driver.ex_stop_node(node))
  72. def test_ex_start_node(self):
  73. node = self.driver.list_nodes()[0]
  74. self.assertTrue(self.driver.ex_start_node(node))
  75. def test_destroy_node(self):
  76. node = self.driver.list_nodes()[0]
  77. self.assertTrue(self.driver.destroy_node(node))
  78. def test_ex_delete_node(self):
  79. node = self.driver.list_nodes()[0]
  80. self.assertTrue(self.driver.ex_delete_node(node))
  81. def test_create_node(self):
  82. auth = NodeAuthPassword('vr!@#hosted#@!')
  83. size = self.driver.list_sizes()[0]
  84. image = self.driver.list_images()[0]
  85. node = self.driver.create_node(
  86. name='test.com',
  87. image=image,
  88. size=size,
  89. auth=auth
  90. )
  91. self.assertEqual('62291', node.id)
  92. self.assertEqual('server1.vr-cluster.org', node.name)
  93. def test_ex_provision_node(self):
  94. node = self.driver.list_nodes()[0]
  95. auth = NodeAuthPassword('vr!@#hosted#@!')
  96. self.assertTrue(self.driver.ex_provision_node(
  97. node=node,
  98. auth=auth
  99. ))
  100. def test_create_node_in_location(self):
  101. auth = NodeAuthPassword('vr!@#hosted#@!')
  102. size = self.driver.list_sizes()[0]
  103. image = self.driver.list_images()[0]
  104. location = self.driver.list_locations()[1]
  105. node = self.driver.create_node(
  106. name='test.com',
  107. image=image,
  108. size=size,
  109. auth=auth,
  110. location=location
  111. )
  112. self.assertEqual('62291', node.id)
  113. self.assertEqual('server1.vr-cluster.org', node.name)
  114. class HostVirtualMockHttp(MockHttp):
  115. fixtures = ComputeFileFixtures('hostvirtual')
  116. def _cloud_servers(self, method, url, body, headers):
  117. body = self.fixtures.load('list_nodes.json')
  118. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  119. def _cloud_server(self, method, url, body, headers):
  120. body = self.fixtures.load('get_node.json')
  121. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  122. def _cloud_sizes(self, method, url, body, headers):
  123. body = self.fixtures.load('list_sizes.json')
  124. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  125. def _cloud_images(self, method, url, body, headers):
  126. body = self.fixtures.load('list_images.json')
  127. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  128. def _cloud_locations(self, method, url, body, headers):
  129. body = self.fixtures.load('list_locations.json')
  130. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  131. def _cloud_cancel(self, method, url, body, headers):
  132. body = self.fixtures.load('node_destroy.json')
  133. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  134. def _cloud_server_reboot(self, method, url, body, headers):
  135. body = self.fixtures.load('node_reboot.json')
  136. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  137. def _cloud_server_shutdown(self, method, url, body, headers):
  138. body = self.fixtures.load('node_stop.json')
  139. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  140. def _cloud_server_start(self, method, url, body, headers):
  141. body = self.fixtures.load('node_start.json')
  142. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  143. def _cloud_buy(self, method, url, body, headers):
  144. body = self.fixtures.load('create_node.json')
  145. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  146. def _cloud_server_build(self, method, url, body, headers):
  147. body = self.fixtures.load('create_node.json')
  148. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  149. def _cloud_server_delete(self, method, url, body, headers):
  150. body = self.fixtures.load('node_destroy.json')
  151. return (httplib.OK, body, {}, httplib.responses[httplib.OK])
  152. if __name__ == '__main__':
  153. sys.exit(unittest.main())
  154. # vim:autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python