File: 09.autoscaling.t

package info (click to toggle)
libvm-ec2-perl 1.28-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,556 kB
  • sloc: perl: 12,047; makefile: 8
file content (117 lines) | stat: -rw-r--r-- 3,270 bytes parent folder | download | duplicates (4)
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
#-*-Perl-*-

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.t'

use strict;
use ExtUtils::MakeMaker;
use File::Temp qw(tempfile);
use FindBin '$Bin';
use lib "$Bin/lib","$Bin/../lib","$Bin/../blib/lib","$Bin/../blib/arch";

use constant TEST_COUNT => 18;
use Test::More tests => TEST_COUNT;
use EC2TestSupport;

$SIG{TERM} = $SIG{INT} = sub { exit 0 };  # run the termination

use constant LC_NAME  => 'VM-EC2-Launch-test';
use constant ASG_NAME => 'VM-EC2-ASG-test';
use constant POLICY_NAME => 'VM-EC2-Policy-test';

# this script tests the autoscaling groups
my ($ec2);

use_ok('VM::EC2',':standard',':scaling');
SKIP: {

skip "account information unavailable",TEST_COUNT-1 unless setup_environment();

$ec2 = VM::EC2->new(-region=>'eu-west-1') or BAIL_OUT("Can't load VM::EC2 module");

# in case it was here from a previous invocation
$ec2->delete_launch_configuration(-name => LC_NAME);
$ec2->delete_autoscaling_group(-name => ASG_NAME);
$ec2->delete_policy(
    -name => POLICY_NAME,
    -auto_scaling_group_name => ASG_NAME,
);

$ec2->print_error(1);

my $s = $ec2->create_launch_configuration(
    -name => LC_NAME,
    -image_id => 'ami-3a0f034e', # ubuntu 12.04 in eu-west-1
    -instance_type => 't1.micro',
    -security_groups => ['default'],
    -instance_monitoring => 0,
);
ok($s, 'create_launch_configuration');

my @l = $ec2->describe_launch_configurations();
ok(scalar @l, 'describe_launch_configurations');
is($l[0]->launch_configuration_name, LC_NAME, 'created name is correct');

$s = $ec2->create_autoscaling_group(
    -name => ASG_NAME,
    -min_size => 0,
    -max_size => 0,
    -launch_config => LC_NAME,
    -desired_capacity => 0,
    -availability_zones => [qw/eu-west-1a/],
);
ok($s, 'create_autoscaling_group');

my @a = $ec2->describe_autoscaling_groups();
ok(scalar @a, 'describe_autoscaling_group');
is($a[0]->max_size, 0, 'correct max size');

$s = $ec2->update_autoscaling_group(
    -name => ASG_NAME,
    -max_size => 1,
);
ok($s, 'update_autoscaling_group');

@a = $ec2->describe_autoscaling_groups();
is($a[0]->max_size, 1, 'correctly updated max size');

my $p = $ec2->put_scaling_policy(
    -name => POLICY_NAME,
    -auto_scaling_group_name => ASG_NAME,
    -scaling_adjustment => 1,
    -adjustment_type => 'ChangeInCapacity',
    -cooldown => 30,
);
ok($p, 'Policy created without errors');

my @r = $ec2->describe_policies;
my $policy = $r[0];
is(ref $policy, 'VM::EC2::ScalingPolicy', 'Policy returned as an object');
is($policy->name, POLICY_NAME, 'Correct name');
is($policy->auto_scaling_group_name, ASG_NAME, 'Correct asg');
is($policy->adjustment_type, 'ChangeInCapacity', 'Correct adj type');
is($policy->scaling_adjustment, 1, 'Correct scaling adj');
is($policy->cooldown, 30, 'Correct cooldown');

$p = $ec2->delete_policy(
    -name => POLICY_NAME,
    -auto_scaling_group_name => ASG_NAME,
);
ok($p, 'Policy deleted');

is($ec2->describe_policies, undef, 'No policies left');

# END SKIP
}

exit 0;

END {
    print STDERR "# cleaning up...\n";
	if ($ec2) {
        $ec2->print_error(0);
        $ec2->delete_launch_configuration(-name => LC_NAME);
        $ec2->delete_autoscaling_group(-name => ASG_NAME);
    }
};