Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. # All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14.  
  15. from rally.task import scenario
  16.  
  17. from xrally_kubernetes.tasks import scenario as common_scenario
  18.  
  19.  
  20. class BaseCreateAndDeletePodWithVolume(common_scenario.BaseKubernetesScenario):
  21.  
  22. def run(self, image, volume, name=None, command=None, status_wait=True):
  23. """Create pod with emptyDir volume, wait it readiness and delete then.
  24.  
  25. :param image: pod's image
  26. :param mount_path: path to mount volume in pod
  27. :param name: custom pod's name
  28. :param command: array of strings representing container command
  29. :param status_wait: wait pod status for success if True
  30. """
  31. namespace = self.choose_namespace()
  32.  
  33. name = self.client.create_pod(
  34. name,
  35. image=image,
  36. volume=volume,
  37. namespace=namespace,
  38. command=command,
  39. status_wait=status_wait
  40. )
  41.  
  42. self.client.delete_pod(
  43. name,
  44. namespace=namespace,
  45. status_wait=status_wait
  46. )
  47.  
  48.  
  49. class BaseCreateCheckDeletePodWithVolume(common_scenario.BaseKubernetesScenario):
  50.  
  51. def run(self, image, volume, check_cmd, name=None, command=None, error_regexp=None, status_wait=True):
  52. """Create pod with emptyDir volume, wait it readiness and delete then.
  53.  
  54. :param image: pod's image
  55. :param mount_path: path to mount volume in pod
  56. :param check_cmd: check command to exec in pod
  57. :param name: pod's custom name
  58. :param command: array of strings representing container command
  59. :param error_regexp: regexp string to search error in pod exec response
  60. :param status_wait: wait pod status for success if True
  61. """
  62. namespace = self.choose_namespace()
  63.  
  64. name = self.client.create_pod(
  65. name,
  66. image=image,
  67. volume=volume,
  68. namespace=namespace,
  69. command=command,
  70. status_wait=status_wait
  71. )
  72.  
  73. self.client.check_volume_pod(
  74. name,
  75. namespace=namespace,
  76. check_cmd=check_cmd,
  77. error_regexp=error_regexp
  78. )
  79.  
  80. self.client.delete_pod(
  81. name,
  82. namespace=namespace,
  83. status_wait=status_wait
  84. )
  85.  
  86.  
  87. @scenario.configure(name="Kubernetes.create_and_delete_pod_with_emptydir_volume",
  88. platform="kubernetes")
  89. class CreateAndDeletePodWithEmptyDirVolume(BaseCreateAndDeletePodWithVolume):
  90. def run(self, image, mount_path, name=None, command=None,
  91. status_wait=True):
  92. name = name or self.generate_random_name()
  93. namespace = self.choose_namespace()
  94.  
  95. volume = {
  96. "mount_path": [
  97. {
  98. "mountPath": mount_path,
  99. "name": name
  100. }
  101. ],
  102. "volume": [
  103. {
  104. "name": name,
  105. "emptyDir": {}
  106. }
  107. ]
  108. }
  109.  
  110. super(CreateAndDeletePodWithEmptyDirVolume, self).run(
  111. image,
  112. name=name,
  113. volume=volume,
  114. command=command,
  115. status_wait=status_wait
  116. )
  117.  
  118.  
  119. @scenario.configure(name="Kubernetes.create_check_and_delete_pod_with_emptydir_volume",
  120. platform="kubernetes")
  121. class CreateCheckAndDeletePodWithEmptyDirVolume(BaseCreateCheckAndDeletePodWithVolume):
  122. def run(self, image, mount_path, check_cmd, name=None, command=None, error_regexp=None, status_wait=True):
  123. name = name or self.generate_random_name()
  124.  
  125. volume = {
  126. "mount_path": [
  127. {
  128. "mountPath": mount_path,
  129. "name": name
  130. }
  131. ],
  132. "volume": [
  133. {
  134. "name": name,
  135. "emptyDir": {}
  136. }
  137. ]
  138. }
  139.  
  140. super(CreateAndDeletePodWithEmptyDirVolume, self).run(
  141. image,
  142. name=name,
  143. volume=volume,
  144. command=command,
  145. status_wait=status_wait
  146. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement