test_grafana.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. # Copyright 2022 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. # Testcase OMNIA_1.2_Grafana_TC_005
  16. # Test case to Validate syslog.log on grafana loki
  17. - name: OMNIA_1.2_Grafana_TC_005
  18. hosts: localhost
  19. connection: local
  20. tags: TC_005
  21. gather_subset:
  22. - 'min'
  23. vars_files:
  24. - ../input_params/base_vars.yml
  25. - test_vars/test_grafana_vars.yml
  26. tasks:
  27. - name: Check login_vars file is encrypted
  28. command: cat {{ login_vars_path }}
  29. changed_when: false
  30. register: config_content
  31. no_log: true
  32. tags: always
  33. - name: Validate login file is encypted or not
  34. assert:
  35. that: "'$ANSIBLE_VAULT;' in config_content.stdout"
  36. fail_msg: "{{ login_vars_fail_msg }}"
  37. success_msg: "{{ login_vars_success_msg }}"
  38. - name: Installing jq (JSON Query)
  39. package:
  40. name: "{{ test_package }}"
  41. state: present
  42. - name: Decrpyt login_vars.yml
  43. command: >-
  44. ansible-vault decrypt {{ login_vars_path }}
  45. --vault-password-file {{ login_vars_vault_path }}
  46. changed_when: false
  47. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  48. no_log: true
  49. tags: always
  50. - name: Include variable file login_vars.yml
  51. include_vars: "{{ login_vars_path }}"
  52. no_log: true
  53. tags: always
  54. - name: Get auth string
  55. shell: echo -n {{ grafana_username }}_{{ grafana_password }} | sha256sum
  56. register: auth_string_output
  57. changed_when: false
  58. failed_when: false
  59. no_log: true
  60. tags: always
  61. - name: Set the grafana username and password
  62. set_fact:
  63. grafana_username: "{{ grafana_username }}"
  64. grafana_password: "{{ grafana_password }}"
  65. auth_string: "{{ auth_string_output }}"
  66. no_log: true
  67. tags: always
  68. - name: Encypt login file
  69. command: >-
  70. ansible-vault encrypt {{ login_vars_path }}
  71. --vault-password-file {{ login_vars_vault_path }}
  72. changed_when: false
  73. no_log: true
  74. tags: always
  75. - name: Fetch Grafana Cluster IP
  76. shell: |
  77. kubectl get svc -n grafana -o json | jq '.items[] | select(.metadata.name == "loki") | "\(.spec.clusterIP)"'
  78. register: grafanaloki_ip_info
  79. - name: Ping the grafana device to validate connectivity
  80. command: ping -c1 {{ grafanaloki_ip_info.stdout[1:-1] }}
  81. register: validate_grafanaloki
  82. changed_when: false
  83. failed_when: false
  84. - name: Validate the Grafana Loki connectivity
  85. assert:
  86. that:
  87. - "'ping' in validate_grafanaloki.stdout"
  88. success_msg: "{{ connectivity_success_msg }}"
  89. fail_msg: "{{ connectivity_failure_msg }}"
  90. # Testcase OMNIA_1.2_Grafana_TC_005
  91. # Test case to Validate syslog.log on grafana loki
  92. - name: Execute get syslog
  93. shell: |
  94. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="syslog"}' | jq
  95. register: syslog_info
  96. when: "'ping' in validate_grafanaloki.stdout"
  97. - name: Verify if syslog status is success or not
  98. assert:
  99. that:
  100. - syslog_info.stdout.status | regex_search( "{{ success }}" )
  101. success_msg: "{{ syslog_success_msg }}"
  102. fail_msg: "{{ syslog_fail_msg }}"
  103. # Testcase OMNIA_1.2_Grafana_TC_006
  104. # Test case to Validate Grafana omnia.log
  105. - name: Execute get job is omnia
  106. shell: |
  107. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="Omnia"}' | jq
  108. register: omnia_info
  109. when: "'ping' in validate_grafanaloki.stdout"
  110. - name: Verify if omnia log status is success or not
  111. assert:
  112. that:
  113. - omnia_info.stdout.status | regex_search( "{{ success }}" )
  114. success_msg: "{{ omnia_success_msg }}"
  115. fail_msg: "{{ omnia_fail_msg }}"
  116. # Testcase OMNIA_1.2_Grafana_TC_007(-)
  117. # Test case to Validate Rocky OS package log
  118. - name: Execute get job is Package Rocky
  119. shell: |
  120. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="Package Rocky.log"}' | jq
  121. register: package_rocky_info
  122. when: "'ping' in validate_grafanaloki.stdout"
  123. - name: Verify if Package Rocky log status is success or not
  124. assert:
  125. that:
  126. - package_rocky_info.stdout.status | regex_search( "{{ success }}" )
  127. - package_rocky_info.stdout.data.result != None
  128. success_msg: "{{ package_rocky_success_msg }}"
  129. fail_msg: "{{ package_rocky_fail_msg }}"
  130. # Testcase OMNIA_1.2_Grafana_TC_007
  131. # Test case to Validate Rocky OS package log
  132. - name: Execute get job is Package Rocky
  133. shell: |
  134. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="Package Rocky"}' | jq
  135. register: package_rocky_info
  136. when: "'ping' in validate_grafanaloki.stdout"
  137. - name: Verify if Package Rocky log status is success or not
  138. assert:
  139. that:
  140. - package_rocky_info.stdout.status | regex_search( "{{ success }}" )
  141. success_msg: "{{ package_rocky_success_msg }}"
  142. fail_msg: "{{ package_rocky_fail_msg }}"
  143. # Testcase OMNIA_1.2_Grafana_TC_008
  144. # Test case to Validate K8s pods log
  145. - name: Execute get job is K8s pods
  146. shell: |
  147. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="K8s pods"}' | jq
  148. register: k8s_pods_info
  149. when: "'ping' in validate_grafanaloki.stdout"
  150. - name: Verify if k8s pods log status is success or not
  151. assert:
  152. that:
  153. - k8s_pods_info.stdout.status | regex_search( "{{ success }}" )
  154. success_msg: "{{ k8s_pods_success_msg }}"
  155. fail_msg: "{{ k8s_pods_fail_msg }}"
  156. # Testcase OMNIA_1.2_Grafana_TC_009
  157. # Test case to Validate cron log
  158. - name: Execute get job is cron logs
  159. shell: |
  160. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="cron"}' | jq
  161. register: cron_info
  162. when: "'ping' in validate_grafanaloki.stdout"
  163. - name: Verify if cron log status is success or not
  164. assert:
  165. that:
  166. - cron_info.stdout.status | regex_search( "{{ success }}" )
  167. success_msg: "{{ cron_success_msg }}"
  168. fail_msg: "{{ cron_fail_msg }}"
  169. # Testcase OMNIA_1.2_Grafana_TC_010
  170. # Test case to Validate Vars log
  171. - name: Execute get job is var logs
  172. shell: |
  173. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="varlogs"}' | jq
  174. register: varlogs_info
  175. when: "'ping' in validate_grafanaloki.stdout"
  176. - name: Verify if var log status is success or not
  177. assert:
  178. that:
  179. - varlogs_info.stdout.status | regex_search( "{{ success }}" )
  180. success_msg: "{{ varlogs_success_msg }}"
  181. fail_msg: "{{ varlogs_fail_msg }}"
  182. # Testcase OMNIA_1.2_Grafana_TC_011
  183. # Test case to Validate Secure log
  184. - name: Execute get job is secure logs
  185. shell: |
  186. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="secure"}' | jq
  187. register: secure_info
  188. when: "'ping' in validate_grafanaloki.stdout"
  189. - name: Verify if secure log status is success or not
  190. assert:
  191. that:
  192. - secure_info.stdout.status | regex_search( "{{ success }}" )
  193. success_msg: "{{ secure_success_msg }}"
  194. fail_msg: "{{ secure_fail_msg }}"
  195. # Testcase OMNIA_1.2_Grafana_TC_012
  196. # Test case to Validate audit log
  197. - name: Execute get job is audit logs
  198. shell: |
  199. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="audit"}' | jq
  200. register: audit_info
  201. when: "'ping' in validate_grafanaloki.stdout"
  202. - name: Verify if audit log status is success or not
  203. assert:
  204. that:
  205. - audit_info.stdout.status | regex_search( "{{ success }}" )
  206. success_msg: "{{ audit_success_msg }}"
  207. fail_msg: "{{ audit_fail_msg }}"
  208. # Testcase OMNIA_1.2_Grafana_TC_013
  209. # Test case to Validate sssd log
  210. - name: Execute get job is sssd logs
  211. shell: |
  212. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="sssd"}' | jq
  213. register: sssd_info
  214. when: "'ping' in validate_grafanaloki.stdout"
  215. - name: Verify if sssd log status is success or not
  216. assert:
  217. that:
  218. - sssd_info.stdout.status | regex_search( "{{ success }}" )
  219. success_msg: "{{ sssd_success_msg }}"
  220. fail_msg: "{{ sssd_fail_msg }}"
  221. # Testcase OMNIA_1.2_Grafana_TC_014
  222. # Test case to Validate Grafana - /var/log/omnia.log
  223. - name: Execute get job is Grafana - /var/log/omnia.log logs
  224. shell: |
  225. curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="varlogs",filename="/var/log/omnia.log"}' | jq
  226. register: varlog_omnia_info
  227. when: "'ping' in validate_grafanaloki.stdout"
  228. - name: Verify if varlog for file omnio.log status is success or not
  229. assert:
  230. that:
  231. - varlog_omnia_info.stdout.status | regex_search( "{{ success }}" )
  232. success_msg: "{{ varlog_omnia_success_msg }}"
  233. fail_msg: "{{ varlog_omnia_fail_msg }}"