aboutsummaryrefslogtreecommitdiffstats
path: root/roles/onap-chaos-tests/tasks/node-cpu-hog.yaml
blob: c70f339fc902dc8cc1ed2da92f3ed51f3533617b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
- name: create directory for cpu hog scenario
  ansible.builtin.file:
    path: /tmp/resiliency/node-cpu-hog
    state: directory
    mode: '0755'
  tags: prepare

- name: Get compute node list
  community.kubernetes.k8s_info:
    kind: Node
    label_selectors: "! node-role.kubernetes.io/master"
  register: kubernetes_computer_node_list
  tags: prepare

- name: Set Fact first compute node Internal IP
  ansible.builtin.set_fact:
    first_node_ip: "{{ item.address }}"
  when: "'Hostname' in item.type"
  with_items:
    "{{ (kubernetes_computer_node_list.resources | first).status.addresses }}"
  tags: prepare

- name: Set Compute for the node cpu hog
  ansible.builtin.set_fact:
    compute_chaos: "{{ first_node_ip }}"
  when: compute_chaos is not defined
  tags: prepare

- name: Prepare rbac file for node cpu hog experiment
  ansible.builtin.template:
    src: node-cpu-hog-rbac.yaml.j2
    dest: /tmp/resiliency/node-cpu-hog/node-cpu-hog-rbac.yaml
    mode: 0600
  tags: prepare

- name: Prepare chaos file for node cpu hog experiment
  ansible.builtin.template:
    src: node-cpu-hog-chaos.yaml.j2
    dest: /tmp/resiliency/node-cpu-hog/node-cpu-hog-chaos.yaml
    mode: 0600
  tags: prepare

- name: Apply  node cpu hog  rbac
  community.kubernetes.k8s:
    state: present
    src: /tmp/resiliency/node-cpu-hog/node-cpu-hog-rbac.yaml

- name: Apply node cpu hog experiment
  community.kubernetes.k8s:
    state: present
    src: /tmp/resiliency/node-cpu-hog/node-cpu-hog-chaos.yaml

- name: wait for the end of chaos
  run_once: true
  community.kubernetes.k8s_info:
    kind: ChaosEngine
    api_version: litmuschaos.io/v1alpha1
    name: onap-chaos-cpu
    namespace: "{{ onap_namespace }}"
  register: chaosengine_status
  changed_when:
    &chaos_test chaosengine_status is defined and
    chaosengine_status.resources[0].status.engineStatus == "completed"
  until: *chaos_test
  retries: 5
  delay: 120

- name: get results
  run_once: true
  community.kubernetes.k8s_info:
    kind: ChaosResult
    api_version: litmuschaos.io/v1alpha1
    name: onap-chaos-cpu-node-cpu-hog
    namespace: "{{ onap_namespace }}"
  register: chaosresult_drain
  changed_when:
    &chaos_result chaosresult_drain is defined and
     (chaosresult_drain.resources[0].status.experimentStatus.verdict == "Pass" or
     chaosresult_drain.resources[0].status.experimentStatus.verdict == "Fail" )
  until: *chaos_result
  retries: 5
  delay: 20
- name: Print the chaos result verdict
  ansible.builtin.debug:
    msg: " The test is {{ chaosresult_drain.resources[0].status.experimentStatus.verdict}}-ed"