provider.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. """
  2. Provider implementation based on the moto library (mock boto). This mock
  3. provider is useful for running tests against cloudbridge but should not
  4. be used in tandem with other providers, in particular the AWS provider.
  5. This is because instantiating this provider will result in all calls to
  6. boto being hijacked, which will cause AWS to malfunction.
  7. See notes below.
  8. """
  9. from moto import mock_ec2
  10. from moto import mock_route53
  11. from moto import mock_s3
  12. import responses
  13. from ..aws import AWSCloudProvider
  14. from ...interfaces.provider import TestMockHelperMixin
  15. class MockAWSCloudProvider(AWSCloudProvider, TestMockHelperMixin):
  16. """
  17. Using this mock driver will result in all boto communications being
  18. hijacked. As a result, this mock driver and the AWS driver cannot be used
  19. at the same time. Do not instantiate the mock driver if you plan to use
  20. the AWS provider within the same python process. Alternatively, call
  21. provider.tearDownMock() to stop the hijacking.
  22. """
  23. PROVIDER_ID = 'mock'
  24. def __init__(self, config):
  25. self.setUpMock()
  26. super(MockAWSCloudProvider, self).__init__(config)
  27. def setUpMock(self):
  28. """
  29. Let Moto take over all socket communications
  30. """
  31. self.ec2mock = mock_ec2()
  32. self.ec2mock.start()
  33. self.s3mock = mock_s3()
  34. self.s3mock.start()
  35. self.route53mock = mock_route53()
  36. self.route53mock.start()
  37. responses.add(
  38. responses.GET,
  39. self.AWS_INSTANCE_DATA_DEFAULT_URL,
  40. body=u"""
  41. [
  42. {
  43. "family": "General Purpose",
  44. "enhanced_networking": false,
  45. "vCPU": 1,
  46. "generation": "current",
  47. "ebs_iops": 0,
  48. "network_performance": "Low",
  49. "ebs_throughput": 0,
  50. "vpc": {
  51. "ips_per_eni": 2,
  52. "max_enis": 2
  53. },
  54. "arch": [
  55. "x86_64"
  56. ],
  57. "linux_virtualization_types": [
  58. "HVM"
  59. ],
  60. "pricing": {
  61. "us-east-1": {
  62. "linux": {
  63. "ondemand": "0.0058",
  64. "reserved": {
  65. "yrTerm1Convertible.allUpfront": "0.003881",
  66. "yrTerm1Convertible.noUpfront": "0.0041",
  67. "yrTerm1Convertible.partialUpfront": "0.003941",
  68. "yrTerm1Standard.allUpfront": "0.003311",
  69. "yrTerm1Standard.noUpfront": "0.0036",
  70. "yrTerm1Standard.partialUpfront": "0.003412",
  71. "yrTerm3Convertible.allUpfront": "0.002626",
  72. "yrTerm3Convertible.noUpfront": "0.0029",
  73. "yrTerm3Convertible.partialUpfront": "0.002632",
  74. "yrTerm3Standard.allUpfront": "0.002169",
  75. "yrTerm3Standard.noUpfront": "0.0025",
  76. "yrTerm3Standard.partialUpfront": "0.002342"
  77. }
  78. }
  79. }
  80. },
  81. "ebs_optimized": false,
  82. "storage": null,
  83. "max_bandwidth": 0,
  84. "instance_type": "t2.nano",
  85. "ECU": "variable",
  86. "memory": 0.5,
  87. "ebs_max_bandwidth": 0
  88. },
  89. {
  90. "family": "General Purpose",
  91. "enhanced_networking": false,
  92. "vCPU": 96,
  93. "generation": "current",
  94. "ebs_iops": 80000.0,
  95. "network_performance": "25 Gigabit",
  96. "ebs_throughput": 1750.0,
  97. "vpc": {
  98. "ips_per_eni": 50,
  99. "max_enis": 15
  100. },
  101. "arch": [
  102. "x86_64"
  103. ],
  104. "linux_virtualization_types": [
  105. "HVM"
  106. ],
  107. "ebs_optimized": false,
  108. "storage": null,
  109. "max_bandwidth": 0,
  110. "instance_type": "m5.24xlarge",
  111. "ECU": 345.0,
  112. "memory": 384.0,
  113. "ebs_max_bandwidth": 14000.0
  114. },
  115. {
  116. "family": "General Purpose",
  117. "enhanced_networking": false,
  118. "vCPU": 96,
  119. "generation": "current",
  120. "ebs_iops": 80000.0,
  121. "network_performance": "25 Gigabit",
  122. "ebs_throughput": 1750.0,
  123. "vpc": {
  124. "ips_per_eni": 50,
  125. "max_enis": 15
  126. },
  127. "arch": [
  128. "x86_64"
  129. ],
  130. "linux_virtualization_types": [
  131. "HVM"
  132. ],
  133. "ebs_optimized": false,
  134. "storage": null,
  135. "max_bandwidth": 0,
  136. "instance_type": "m5.24xlarge",
  137. "ECU": 345.0,
  138. "memory": 384.0,
  139. "ebs_max_bandwidth": 14000.0
  140. },
  141. {
  142. "family": "Memory optimized",
  143. "enhanced_networking": false,
  144. "vCPU": 96,
  145. "generation": "current",
  146. "ebs_iops": 80000.0,
  147. "network_performance": "25 Gigabit",
  148. "ebs_throughput": 1750.0,
  149. "vpc": {
  150. "ips_per_eni": 50,
  151. "max_enis": 15
  152. },
  153. "arch": [
  154. "x86_64"
  155. ],
  156. "linux_virtualization_types": [
  157. "HVM"
  158. ],
  159. "ebs_optimized": false,
  160. "storage": null,
  161. "max_bandwidth": 0,
  162. "instance_type": "r5.24xlarge",
  163. "ECU": 347.0,
  164. "memory": 768.0,
  165. "ebs_max_bandwidth": 14000.0
  166. },
  167. {
  168. "family": "Memory optimized",
  169. "enhanced_networking": false,
  170. "vCPU": 96,
  171. "generation": "current",
  172. "ebs_iops": 80000.0,
  173. "network_performance": "25 Gigabit",
  174. "ebs_throughput": 1750.0,
  175. "vpc": {
  176. "ips_per_eni": 50,
  177. "max_enis": 15
  178. },
  179. "arch": [
  180. "x86_64"
  181. ],
  182. "linux_virtualization_types": [
  183. "HVM"
  184. ],
  185. "ebs_optimized": false,
  186. "storage": null,
  187. "max_bandwidth": 0,
  188. "instance_type": "r5d.24xlarge",
  189. "ECU": 347.0,
  190. "memory": 768.0,
  191. "ebs_max_bandwidth": 14000.0
  192. }
  193. ]
  194. """)
  195. def tearDownMock(self):
  196. """
  197. Stop Moto intercepting all socket communications
  198. """
  199. self.s3mock.stop()
  200. self.ec2mock.stop()
  201. self.route53mock.stop()