-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathshutdown-and-terminate.yml
140 lines (118 loc) · 4.23 KB
/
shutdown-and-terminate.yml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
- name: Install agent linux (HNR)
hosts: testing_hosts_linux
gather_facts: true
become: true
vars:
agent_user: root
pre_tasks:
- name: Initial cleanup
ansible.builtin.include_role:
name: caos.ansible_roles.infra_agent
vars:
uninstall: true
fips_enabled: "{{ '-fips' in inventory_hostname }}"
tasks:
- name: Install agent
ansible.builtin.include_role:
name: caos.ansible_roles.infra_agent
vars:
display_name: "{{ iid }}:{{ inventory_hostname }}"
repo_endpoint: "http://nr-downloads-ohai-staging.s3-website-us-east-1.amazonaws.com/infrastructure_agent"
fips_enabled: "{{ '-fips' in inventory_hostname }}"
- name: Install agent windows (HNR)
hosts: testing_hosts_windows
gather_facts: true
pre_tasks:
- name: Initial cleanup
ansible.builtin.include_role:
name: caos.ansible_roles.infra_agent
vars:
uninstall: true
tasks:
- name: Install agent
ansible.builtin.include_role:
name: caos.ansible_roles.infra_agent
vars:
display_name: "{{ iid }}:{{ inventory_hostname }}"
- name: Test agent behaviour on host shutdown
hosts: testing_hosts
vars:
# Add here hosts of the instances that doesn't support Smart HNR (shutdown detection) e.g. - "amd64:ubuntu14.04"
instances_not_supporting_shutdown_detection: {
"amd64:debian-jessie"
}
host_supports_shutdown_detection: >-
{{
true if inventory_hostname not in instances_not_supporting_shutdown_detection
else false
}}
tasks:
- name: Pause a bit to let the agent send some data
ansible.builtin.pause:
minutes: 1
- name: Restart the agent
ansible.builtin.include_role:
name: caos.ansible_roles.service_status
vars:
service_name: "newrelic-infra"
action: "restart"
- name: Pause for a bit to let the agent initialize
ansible.builtin.pause:
seconds: 30
- name: Get entity id
ansible.builtin.include_role:
name: caos.ansible_roles.infra_agent_get_entity_id
- name: Assert agent restart don't trigger shutdown event
ansible.builtin.include_role:
name: caos.ansible_roles.assert_host_status_event
vars:
host_status: "shutdown"
expect_change_event: false
since_sec_ago: 30
- name: Stop instances
ansible.builtin.include_role:
name: caos.ansible_roles.ec2_instance
vars:
action: stop
instance_id: "{{ iid }}"
- name: Pause for a bit to let the event fire
ansible.builtin.pause:
seconds: 30
- name: Assert that the agent detecteded host shutdown and disconnected from the backend (only on hosts that support shutdown detection)
ansible.builtin.include_role:
name: caos.ansible_roles.assert_host_status_event
vars:
host_status: "shutdown"
expect_change_event: "{{ host_supports_shutdown_detection }}"
timestamp_ref: "{{ ec2_stop_time_sec | int }}"
- name: Start instances
ansible.builtin.include_role:
name: caos.ansible_roles.ec2_instance
vars:
action: start
instance_id: "{{ iid }}"
- name: Assert the agent performed connect to the backend (only on hosts that support shutdown detection)
ansible.builtin.include_role:
name: caos.ansible_roles.assert_host_status_event
vars:
host_status: "running"
expect_change_event: "{{ host_supports_shutdown_detection }}"
timestamp_ref: "{{ ec2_start_time_sec | int }}"
- name: Terminate instances
ansible.builtin.include_role:
name: caos.ansible_roles.ec2_instance
vars:
action: terminate
instance_id: "{{ iid }}"
- name: Pause for a bit to let the event fire
ansible.builtin.pause:
seconds: 30
- name: Assert that the agent detecteded host termination and disconnected from the backend (only on hosts that support shutdown detection)
ansible.builtin.include_role:
name: caos.ansible_roles.assert_host_status_event
vars:
host_status: "shutdown"
expect_change_event: "{{ host_supports_shutdown_detection }}"
timestamp_ref: "{{ ec2_terminate_time_sec | int }}"
...