| 1 |
--- |
| 2 |
# __Test Outline__ |
| 3 |
# |
| 4 |
# __ec2_scaling_policy__ |
| 5 |
# create simplescaling scaling policy |
| 6 |
# update simplescaling scaling policy |
| 7 |
# remove simplescaling scaling policy |
| 8 |
# create stepscaling scaling policy |
| 9 |
# update stepscaling scaling policy |
| 10 |
# remove stepscaling scaling policy |
| 11 |
|
| 12 |
- module_defaults: |
| 13 |
group/aws: |
| 14 |
region: "{{ aws_region }}" |
| 15 |
access_key: "{{ aws_access_key }}" |
| 16 |
secret_key: "{{ aws_secret_key }}" |
| 17 |
session_token: "{{ security_token | default(omit) }}" |
| 18 |
collections: |
| 19 |
- amazon.aws |
| 20 |
block: |
| 21 |
|
| 22 |
- name: create trivial launch_configuration |
| 23 |
autoscaling_launch_config: |
| 24 |
name: "{{ scaling_policy_lc_name }}" |
| 25 |
state: present |
| 26 |
instance_type: t3.nano |
| 27 |
image_id: "{{ ec2_ami_id }}" |
| 28 |
|
| 29 |
- name: create trivial ASG |
| 30 |
autoscaling_group: |
| 31 |
name: "{{ scaling_policy_asg_name }}" |
| 32 |
state: present |
| 33 |
launch_config_name: "{{ scaling_policy_lc_name }}" |
| 34 |
min_size: 0 |
| 35 |
max_size: 1 |
| 36 |
desired_capacity: 0 |
| 37 |
|
| 38 |
- name: Create Simple Scaling policy using implicit defaults |
| 39 |
autoscaling_policy: |
| 40 |
name: "{{ resource_prefix }}_simplescaling_policy" |
| 41 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 42 |
state: present |
| 43 |
adjustment_type: ChangeInCapacity |
| 44 |
scaling_adjustment: 1 |
| 45 |
register: result |
| 46 |
|
| 47 |
- assert: |
| 48 |
that: |
| 49 |
- result.policy_name == resource_prefix ~ '_simplescaling_policy' |
| 50 |
- result.changed |
| 51 |
|
| 52 |
- name: Update Simple Scaling policy using explicit defaults |
| 53 |
autoscaling_policy: |
| 54 |
name: "{{ resource_prefix }}_simplescaling_policy" |
| 55 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 56 |
state: present |
| 57 |
adjustment_type: ChangeInCapacity |
| 58 |
scaling_adjustment: 1 |
| 59 |
policy_type: SimpleScaling |
| 60 |
register: result |
| 61 |
|
| 62 |
- assert: |
| 63 |
that: |
| 64 |
- result.policy_name == resource_prefix ~ '_simplescaling_policy' |
| 65 |
- not result.changed |
| 66 |
|
| 67 |
- name: min_adjustment_step is ignored with ChangeInCapacity |
| 68 |
autoscaling_policy: |
| 69 |
name: "{{ resource_prefix }}_simplescaling_policy" |
| 70 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 71 |
state: present |
| 72 |
adjustment_type: ChangeInCapacity |
| 73 |
scaling_adjustment: 1 |
| 74 |
min_adjustment_step: 1 |
| 75 |
policy_type: SimpleScaling |
| 76 |
register: result |
| 77 |
|
| 78 |
- assert: |
| 79 |
that: |
| 80 |
- result.policy_name == resource_prefix ~ '_simplescaling_policy' |
| 81 |
- not result.changed |
| 82 |
- result.adjustment_type == "ChangeInCapacity" |
| 83 |
|
| 84 |
- name: Change Simple Scaling policy adjustment_type to PercentChangeInCapacity |
| 85 |
autoscaling_policy: |
| 86 |
name: "{{ resource_prefix }}_simplescaling_policy" |
| 87 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 88 |
state: present |
| 89 |
adjustment_type: PercentChangeInCapacity |
| 90 |
scaling_adjustment: 1 |
| 91 |
min_adjustment_step: 1 |
| 92 |
policy_type: SimpleScaling |
| 93 |
register: result |
| 94 |
|
| 95 |
- assert: |
| 96 |
that: |
| 97 |
- result.policy_name == resource_prefix ~ '_simplescaling_policy' |
| 98 |
- result.changed |
| 99 |
- result.adjustment_type == "PercentChangeInCapacity" |
| 100 |
|
| 101 |
- name: Remove Simple Scaling policy |
| 102 |
autoscaling_policy: |
| 103 |
name: "{{ resource_prefix }}_simplescaling_policy" |
| 104 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 105 |
state: absent |
| 106 |
register: result |
| 107 |
|
| 108 |
- assert: |
| 109 |
that: |
| 110 |
- result.changed |
| 111 |
|
| 112 |
- name: Create Step Scaling policy |
| 113 |
autoscaling_policy: |
| 114 |
name: "{{ resource_prefix }}_stepscaling_policy" |
| 115 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 116 |
state: present |
| 117 |
policy_type: StepScaling |
| 118 |
metric_aggregation: Maximum |
| 119 |
step_adjustments: |
| 120 |
- upper_bound: 20 |
| 121 |
scaling_adjustment: 50 |
| 122 |
- lower_bound: 20 |
| 123 |
scaling_adjustment: 100 |
| 124 |
adjustment_type: "PercentChangeInCapacity" |
| 125 |
register: result |
| 126 |
|
| 127 |
- assert: |
| 128 |
that: |
| 129 |
- result.policy_name == resource_prefix ~ '_stepscaling_policy' |
| 130 |
- result.changed |
| 131 |
|
| 132 |
- name: Add another step |
| 133 |
autoscaling_policy: |
| 134 |
name: "{{ resource_prefix }}_stepscaling_policy" |
| 135 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 136 |
state: present |
| 137 |
policy_type: StepScaling |
| 138 |
metric_aggregation: Maximum |
| 139 |
step_adjustments: |
| 140 |
- upper_bound: 20 |
| 141 |
scaling_adjustment: 50 |
| 142 |
- lower_bound: 20 |
| 143 |
upper_bound: 40 |
| 144 |
scaling_adjustment: 75 |
| 145 |
- lower_bound: 40 |
| 146 |
scaling_adjustment: 100 |
| 147 |
adjustment_type: "PercentChangeInCapacity" |
| 148 |
register: result |
| 149 |
|
| 150 |
- assert: |
| 151 |
that: |
| 152 |
- result.policy_name == resource_prefix ~ '_stepscaling_policy' |
| 153 |
- result.changed |
| 154 |
- result.adjustment_type == "PercentChangeInCapacity" |
| 155 |
|
| 156 |
- name: Remove Step Scaling policy |
| 157 |
autoscaling_policy: |
| 158 |
name: "{{ resource_prefix }}_stepscaling_policy" |
| 159 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 160 |
state: absent |
| 161 |
register: result |
| 162 |
|
| 163 |
- assert: |
| 164 |
that: |
| 165 |
- result.changed |
| 166 |
|
| 167 |
- name: Remove Step Scaling policy (idemopotency) |
| 168 |
autoscaling_policy: |
| 169 |
name: "{{ resource_prefix }}_stepscaling_policy" |
| 170 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 171 |
state: absent |
| 172 |
register: result |
| 173 |
|
| 174 |
- assert: |
| 175 |
that: |
| 176 |
- result is not changed |
| 177 |
- result is successful |
| 178 |
|
| 179 |
- name: create TargetTracking predefined policy |
| 180 |
autoscaling_policy: |
| 181 |
name: "{{ resource_prefix }}_targettracking_predefined_policy" |
| 182 |
policy_type: TargetTrackingScaling |
| 183 |
target_tracking_config: |
| 184 |
predefined_metric_spec: |
| 185 |
predefined_metric_type: ASGAverageCPUUtilization |
| 186 |
target_value: 98.0 |
| 187 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 188 |
register: result |
| 189 |
|
| 190 |
- assert: |
| 191 |
that: |
| 192 |
- result.policy_name == resource_prefix ~ '_targettracking_predefined_policy' |
| 193 |
- result.changed |
| 194 |
- result is successful |
| 195 |
|
| 196 |
- name: create TargetTrackingScaling predefined policy (idempotency) |
| 197 |
autoscaling_policy: |
| 198 |
name: "{{ resource_prefix }}_targettracking_predefined_policy" |
| 199 |
policy_type: TargetTrackingScaling |
| 200 |
target_tracking_config: |
| 201 |
predefined_metric_spec: |
| 202 |
predefined_metric_type: ASGAverageCPUUtilization |
| 203 |
target_value: 98.0 |
| 204 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 205 |
register: result |
| 206 |
|
| 207 |
- assert: |
| 208 |
that: |
| 209 |
- result.policy_name == resource_prefix ~ '_targettracking_predefined_policy' |
| 210 |
- result is not changed |
| 211 |
|
| 212 |
# # It would be good to also test this but we would need an Target group and an ALB |
| 213 |
# - name: create TargetTracking predefined policy with resource_label |
| 214 |
# autoscaling_policy: |
| 215 |
# name: "{{ resource_prefix }}_targettracking_predefined_rl_policy" |
| 216 |
# policy_type: TargetTrackingScaling |
| 217 |
# target_tracking_config: |
| 218 |
# predefined_metric_spec: |
| 219 |
# predefined_metric_type: ALBRequestCountPerTarget |
| 220 |
# resource_label: "{{ alb_resource_label }}" |
| 221 |
# target_value: 98.0 |
| 222 |
# asg_name: "{{ scaling_policy_asg_name }}" |
| 223 |
# register: result |
| 224 |
# |
| 225 |
# - assert: |
| 226 |
# that: |
| 227 |
# - result.policy_name == "{{ resource_prefix }}_targettracking_predefined_rl_policy" |
| 228 |
# - result.changed |
| 229 |
# - result is successful |
| 230 |
# |
| 231 |
# - name: create TargetTracking predefined policy with resource_label (idempotency) |
| 232 |
# autoscaling_policy: |
| 233 |
# name: "{{ resource_prefix }}_targettracking_predefined_rl_policy" |
| 234 |
# policy_type: TargetTrackingScaling |
| 235 |
# target_tracking_config: |
| 236 |
# predefined_metric_spec: |
| 237 |
# predefined_metric_type: ALBRequestCountPerTarget |
| 238 |
# resource_label: "{{ alb_resource_label }}" |
| 239 |
# target_value: 98.0 |
| 240 |
# asg_name: "{{ scaling_policy_asg_name }}" |
| 241 |
# register: result |
| 242 |
# |
| 243 |
# - assert: |
| 244 |
# that: |
| 245 |
# - result.policy_name == "{{ resource_prefix }}_targettracking_predefined_rl_policy" |
| 246 |
# - result is not changed |
| 247 |
|
| 248 |
- name: create TargetTrackingScaling custom policy |
| 249 |
autoscaling_policy: |
| 250 |
name: "{{ resource_prefix }}_targettracking_custom_policy" |
| 251 |
policy_type: TargetTrackingScaling |
| 252 |
target_tracking_config: |
| 253 |
customized_metric_spec: |
| 254 |
metric_name: metric_1 |
| 255 |
namespace: namespace_1 |
| 256 |
statistic: Minimum |
| 257 |
unit: Gigabits |
| 258 |
dimensions: [{'Name': 'dimension1', 'Value': 'value1'}] |
| 259 |
disable_scalein: true |
| 260 |
target_value: 98.0 |
| 261 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 262 |
register: result |
| 263 |
|
| 264 |
- assert: |
| 265 |
that: |
| 266 |
- result.policy_name == resource_prefix ~ '_targettracking_custom_policy' |
| 267 |
- result.changed |
| 268 |
- result is successful |
| 269 |
|
| 270 |
- name: create TargetTrackingScaling custom policy (idempotency) |
| 271 |
autoscaling_policy: |
| 272 |
name: "{{ resource_prefix }}_targettracking_custom_policy" |
| 273 |
policy_type: TargetTrackingScaling |
| 274 |
target_tracking_config: |
| 275 |
customized_metric_spec: |
| 276 |
metric_name: metric_1 |
| 277 |
namespace: namespace_1 |
| 278 |
statistic: Minimum |
| 279 |
unit: Gigabits |
| 280 |
dimensions: [{'Name': 'dimension1', 'Value': 'value1'}] |
| 281 |
disable_scalein: true |
| 282 |
target_value: 98.0 |
| 283 |
asg_name: "{{ scaling_policy_asg_name }}" |
| 284 |
register: result |
| 285 |
|
| 286 |
- assert: |
| 287 |
that: |
| 288 |
- result.policy_name == resource_prefix ~ '_targettracking_custom_policy' |
| 289 |
- result is not changed |
| 290 |
|
| 291 |
always: |
| 292 |
|
| 293 |
# ============================================================ |
| 294 |
- name: Remove the scaling policies |
| 295 |
autoscaling_policy: |
| 296 |
name: "{{ item }}" |
| 297 |
state: absent |
| 298 |
register: result |
| 299 |
with_items: |
| 300 |
- "{{ resource_prefix }}_simplescaling_policy" |
| 301 |
- "{{ resource_prefix }}_stepscaling_policy" |
| 302 |
- "{{ resource_prefix }}_targettracking_predefined_policy" |
| 303 |
- "{{ resource_prefix }}_targettracking_predefined_rl_policy" |
| 304 |
- "{{ resource_prefix }}_targettracking_custom_policy" |
| 305 |
ignore_errors: yes |
| 306 |
|
| 307 |
- name: remove the ASG |
| 308 |
autoscaling_group: |
| 309 |
name: "{{ scaling_policy_asg_name }}" |
| 310 |
state: absent |
| 311 |
ignore_errors: yes |
| 312 |
|
| 313 |
- name: remove the Launch Configuration |
| 314 |
autoscaling_launch_config: |
| 315 |
name: "{{ scaling_policy_lc_name }}" |
| 316 |
state: absent |
| 317 |
ignore_errors: yes |