test_control_plane_validation.yml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. # Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain 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,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - block:
  16. - name: Fetch Package info
  17. package_facts:
  18. manager: auto
  19. - name: Verify all packages are installed
  20. assert:
  21. that: "'{{ item }}' in ansible_facts.packages"
  22. success_msg: "{{ install_package_success_msg }}"
  23. fail_msg: "{{ install_package_fail_msg }}"
  24. when: "'python-docker' not in item"
  25. with_items: "{{ common_packages }}"
  26. ignore_errors: true
  27. - name: Check login_vars is encrypted
  28. command: cat {{ login_vars_filename }}
  29. changed_when: false
  30. register: config_content
  31. - name: Validate login file is encypted or not
  32. assert:
  33. that: "'$ANSIBLE_VAULT;' in config_content.stdout"
  34. fail_msg: "{{ login_vars_fail_msg }}"
  35. success_msg: "{{ login_vars_success_msg }}"
  36. # Installing a required package : JQ
  37. - name: Installing jq (JSON Query)
  38. package:
  39. name: "{{ test_package }}"
  40. state: present
  41. # Checking if all the required pods are working
  42. - name: Get pods info
  43. shell: kubectl get pods --all-namespaces
  44. register: all_pods_info
  45. - name: Check the count of pods
  46. set_fact:
  47. count: "{{ all_pods_info.stdout_lines|length - 1 }}"
  48. - name: Check if all the pods are running
  49. assert:
  50. that:
  51. - "'Running' in all_pods_info.stdout_lines[{{ item }}]"
  52. fail_msg: "{{ check_pods_fail_msg }}"
  53. success_msg: "{{ check_pods_success_msg }}"
  54. with_sequence: start=1 end={{ count }}
  55. # Checking if NFS Server is running and Custom ISO is created
  56. - name: Get NFS Stat
  57. shell: systemctl status nfs-idmapd
  58. register: nfstat_info
  59. - name: Verify NFS Stat is running
  60. assert:
  61. that:
  62. - "'Active: active (running)' in nfstat_info.stdout"
  63. success_msg: "{{ nfs_share_success_msg }}"
  64. fail_msg: "{{ nfs_share_fail_msg }}"
  65. - name: Check nfs mount point
  66. stat:
  67. path: "{{ nfs_mount_Path }}"
  68. register: nfs_mount_info
  69. - name: Verify nfs share is mounted
  70. assert:
  71. that:
  72. - "{{ nfs_mount_info.stat.exists }}"
  73. success_msg: "{{ nfs_mount_success_msg }}"
  74. fail_msg: "{{ nfs_mount_fail_msg }}"
  75. - name: Check Custom ISO
  76. stat:
  77. path: "{{ check_iso_path }}"
  78. register: check_iso_info
  79. - name: Verify Custom ISO is created in the NFS repo
  80. assert:
  81. that:
  82. - "{{ check_iso_info.stat.exists }}"
  83. success_msg: "{{ check_iso_success_msg }}"
  84. fail_msg: "{{ check_iso_fail_msg }}"
  85. # Checking if network-config container is running
  86. - name: Get Pod info for network-config
  87. shell: |
  88. crictl ps -o json | jq '.containers[] | select(.labels."io.kubernetes.pod.namespace" == "network-config" and .labels."io.kubernetes.container.name" == "mngmnt-network-container") | "\(.id) \(.metadata.name) \(.state)"'
  89. register: network_config_pod_info
  90. - name: Get Pod Status for network-config
  91. assert:
  92. that:
  93. - network_config_pod_info.stdout_lines | regex_search( "{{ container_info }}")
  94. success_msg: "{{ network_config_pod_success_msg }}"
  95. fail_msg: "{{ network_config_pod_fail_msg }}"
  96. - name: Get Pod facts
  97. shell: |
  98. crictl ps -o json | jq '.containers[] | select(.labels."io.kubernetes.pod.namespace" == "network-config" and .labels."io.kubernetes.container.name" == "mngmnt-network-container") | "\(.id)"'
  99. register: network_config_pod_fact
  100. - name: Parse container id for the pods
  101. set_fact:
  102. container_id: "{{ network_config_pod_fact.stdout[1:-1] }}"
  103. - name: Check dhcpd,xinetd service is running
  104. command: crictl exec {{ container_id }} systemctl is-active {{ item }}
  105. changed_when: false
  106. ignore_errors: yes
  107. register: pod_service_check
  108. with_items:
  109. - dhcpd
  110. - xinetd
  111. - name: Verify dhcpd, xinetd service is running
  112. assert:
  113. that:
  114. - "'active' in pod_service_check.results[{{ item }}].stdout"
  115. - "'inactive' not in pod_service_check.results[{{ item }}].stdout"
  116. - "'unknown' not in pod_service_check.results[{{ item }}].stdout"
  117. fail_msg: "{{ pod_service_check_fail_msg }}"
  118. success_msg: "{{ pod_service_check_success_msg }}"
  119. with_sequence: start=0 end={{ pod_service_check.results|length - 1 }}
  120. # Checking if cobbler-container is running
  121. - name: Get Pod info for cobbler
  122. shell: |
  123. crictl ps -o json | jq '.containers[] | select(.labels."io.kubernetes.pod.namespace" == "cobbler") | "\(.id) \(.metadata.name) \(.state)"'
  124. register: network_config_pod_info
  125. - name: Get Pod Status for cobbler
  126. assert:
  127. that:
  128. - network_config_pod_info.stdout_lines | regex_search( "{{ container_info }}")
  129. success_msg: "{{ cobbler_pod_success_msg }}"
  130. fail_msg: "{{ cobbler_pod_fail_msg }}"
  131. - name: Get Pod facts for cobbler
  132. shell: |
  133. crictl ps -o json | jq '.containers[] | select(.labels."io.kubernetes.pod.namespace" == "cobbler") | "\(.id)"'
  134. register: network_config_pod_fact
  135. - name: Extract cobbler pod id
  136. set_fact:
  137. cobbler_id: "{{ network_config_pod_fact.stdout[1:-1] }}"
  138. - name: Check tftp,dhcpd,xinetd,cobblerd service is running
  139. command: crictl exec {{ cobbler_id }} systemctl is-active {{ item }}
  140. changed_when: false
  141. ignore_errors: yes
  142. register: pod_service_check
  143. with_items:
  144. - dhcpd
  145. - tftp
  146. - xinetd
  147. - cobblerd
  148. - name: Verify tftp,dhcpd,xinetd,cobblerd service is running
  149. assert:
  150. that:
  151. - "'active' in pod_service_check.results[{{ item }}].stdout"
  152. - "'inactive' not in pod_service_check.results[{{ item }}].stdout"
  153. - "'unknown' not in pod_service_check.results[{{ item }}].stdout"
  154. fail_msg: "{{pod_service_check_fail_msg}}"
  155. success_msg: "{{pod_service_check_success_msg}}"
  156. with_sequence: start=0 end=3
  157. # Checking Cron-Jobs
  158. - name: Check crontab list
  159. command: crictl exec {{ cobbler_id }} crontab -l
  160. changed_when: false
  161. register: crontab_list
  162. - name: Verify crontab list
  163. assert:
  164. that:
  165. - "'* * * * * /usr/bin/ansible-playbook /root/tftp.yml' in crontab_list.stdout"
  166. - "'*/5 * * * * /usr/bin/ansible-playbook /root/inventory_creation.yml' in crontab_list.stdout"
  167. fail_msg: "{{cron_jobs_fail_msg}}"
  168. success_msg: "{{cron_jobs_success_msg}}"
  169. # Checking subnet-manger pod is running and open sm is running
  170. # Comment if infiniband is not connected
  171. - name: Fetch subnet-manager stats
  172. shell: kubectl get pods -n subnet-manager
  173. register: sm_manager_info
  174. - name: Verify subnet_manager container is running
  175. assert:
  176. that:
  177. - "'Running' in sm_manager_info.stdout_lines[1]"
  178. fail_msg: "{{subnet_manager_fail_msg}}"
  179. success_msg: "{{subnet_manager_success_msg}}"
  180. # Checking awx pod is running
  181. - name: Get Pod info for awx
  182. shell: |
  183. crictl ps -o json | jq '.containers[] | select(.labels."io.kubernetes.pod.namespace" == "awx") | "\(.id) \(.metadata.name) \(.state)"'
  184. register: awx_config_pod_info
  185. - name: Get Pod Status for awx
  186. assert:
  187. that:
  188. - network_config_pod_info.stdout_lines[{{ item }}] | regex_search( "{{ container_info }}")
  189. success_msg: "{{ awx_pod_success_msg }}"
  190. fail_msg: "{{ awx_pod_fail_msg }}"
  191. ignore_errors: yes
  192. with_sequence: start=0 end={{ network_config_pod_info.stdout_lines |length - 1 }}
  193. - name: Get pvc stats
  194. shell: |
  195. kubectl get pvc -n awx -o json |jq '.items[] | "\(.status.phase)"'
  196. register: pvc_stats_info
  197. - name: Verify if pvc stats is running
  198. assert:
  199. that:
  200. - "'Bound' in pvc_stats_info.stdout"
  201. fail_msg: "{{ pvc_stat_fail_msg }}"
  202. success_msg: "{{ pvc_stat_success_msg }}"
  203. with_sequence: start=0 end={{ pvc_stats_info.stdout_lines |length|int - 1 }}
  204. - name: Get svc stats
  205. shell: kubectl get svc -n awx awx-service -o json
  206. register: svc_stats_info
  207. - name: Verify if svc is up and running
  208. assert:
  209. that:
  210. - "'Error from server (NotFound):' not in svc_stats_info.stdout"
  211. success_msg: "{{ svc_stat_success_msg }}"
  212. fail_msg: "{{ svc_stat_fail_msg }}"
  213. - name: Fetch Cluster IP from svc
  214. shell: |
  215. kubectl get svc -n awx -o json | jq '.items[] | select(.metadata.name == "awx-service") | "\(.spec.clusterIP)"'
  216. register: cluster_ip_info
  217. - name: Check if connection to svc Cluster IP is enabled
  218. uri:
  219. url: http://{{ cluster_ip_info.stdout[1:-1] }}
  220. follow_redirects: none
  221. method: GET
  222. ignore_errors: yes
  223. register: cluster_ip_conn
  224. - name: Verify connection to svc cluster is working
  225. assert:
  226. that:
  227. - cluster_ip_conn.status == 200
  228. success_msg: "{{ svc_conn_success_msg }} : {{ cluster_ip_info.stdout[1:-1] }}"
  229. fail_msg: "{{ svc_conn_fail_msg }} : {{ cluster_ip_info.stdout[1:-1] }}"