solutious-rudy 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/CHANGES.txt +8 -9
  2. data/README.rdoc +48 -7
  3. data/Rakefile +102 -7
  4. data/Rudyfile +28 -0
  5. data/bin/ird +162 -0
  6. data/bin/rudy +287 -93
  7. data/lib/annoy.rb +227 -0
  8. data/lib/aws_sdb/service.rb +1 -1
  9. data/lib/console.rb +20 -4
  10. data/lib/escape.rb +305 -0
  11. data/lib/rudy.rb +265 -125
  12. data/lib/rudy/aws.rb +61 -26
  13. data/lib/rudy/aws/ec2.rb +20 -296
  14. data/lib/rudy/aws/ec2/address.rb +121 -0
  15. data/lib/rudy/aws/ec2/group.rb +241 -0
  16. data/lib/rudy/aws/ec2/image.rb +46 -0
  17. data/lib/rudy/aws/ec2/instance.rb +407 -0
  18. data/lib/rudy/aws/ec2/keypair.rb +92 -0
  19. data/lib/rudy/aws/ec2/snapshot.rb +87 -0
  20. data/lib/rudy/aws/ec2/volume.rb +234 -0
  21. data/lib/rudy/aws/simpledb.rb +33 -15
  22. data/lib/rudy/cli.rb +142 -0
  23. data/lib/rudy/cli/addresses.rb +85 -0
  24. data/lib/rudy/cli/backups.rb +175 -0
  25. data/lib/rudy/{command → cli}/config.rb +18 -13
  26. data/lib/rudy/cli/deploy.rb +12 -0
  27. data/lib/rudy/cli/disks.rb +125 -0
  28. data/lib/rudy/cli/domains.rb +17 -0
  29. data/lib/rudy/cli/groups.rb +77 -0
  30. data/lib/rudy/{command → cli}/images.rb +18 -6
  31. data/lib/rudy/cli/instances.rb +142 -0
  32. data/lib/rudy/cli/keypairs.rb +47 -0
  33. data/lib/rudy/cli/manager.rb +51 -0
  34. data/lib/rudy/{command → cli}/release.rb +10 -10
  35. data/lib/rudy/cli/routines.rb +80 -0
  36. data/lib/rudy/cli/volumes.rb +121 -0
  37. data/lib/rudy/command/addresses.rb +62 -39
  38. data/lib/rudy/command/backups.rb +60 -170
  39. data/lib/rudy/command/disks-old.rb +322 -0
  40. data/lib/rudy/command/disks.rb +5 -209
  41. data/lib/rudy/command/domains.rb +34 -0
  42. data/lib/rudy/command/groups.rb +105 -48
  43. data/lib/rudy/command/instances.rb +263 -70
  44. data/lib/rudy/command/keypairs.rb +149 -0
  45. data/lib/rudy/command/manager.rb +65 -0
  46. data/lib/rudy/command/volumes.rb +110 -49
  47. data/lib/rudy/config.rb +90 -70
  48. data/lib/rudy/config/objects.rb +67 -0
  49. data/lib/rudy/huxtable.rb +253 -0
  50. data/lib/rudy/metadata/backup.rb +23 -48
  51. data/lib/rudy/metadata/disk.rb +79 -68
  52. data/lib/rudy/metadata/machine.rb +34 -0
  53. data/lib/rudy/routines.rb +54 -0
  54. data/lib/rudy/routines/disk_handler.rb +190 -0
  55. data/lib/rudy/routines/release.rb +15 -0
  56. data/lib/rudy/routines/script_runner.rb +65 -0
  57. data/lib/rudy/routines/shutdown.rb +42 -0
  58. data/lib/rudy/routines/startup.rb +48 -0
  59. data/lib/rudy/utils.rb +57 -2
  60. data/lib/storable.rb +11 -5
  61. data/lib/sysinfo.rb +274 -0
  62. data/rudy.gemspec +84 -20
  63. data/support/randomize-root-password +45 -0
  64. data/support/rudy-ec2-startup +5 -5
  65. data/support/update-ec2-ami-tools +20 -0
  66. data/test/05_config/00_setup_test.rb +24 -0
  67. data/test/05_config/30_machines_test.rb +69 -0
  68. data/test/20_sdb/00_setup_test.rb +31 -0
  69. data/test/20_sdb/10_domains_test.rb +113 -0
  70. data/test/25_ec2/00_setup_test.rb +34 -0
  71. data/test/25_ec2/10_keypairs_test.rb +33 -0
  72. data/test/25_ec2/20_groups_test.rb +139 -0
  73. data/test/25_ec2/30_addresses_test.rb +35 -0
  74. data/test/25_ec2/40_volumes_test.rb +46 -0
  75. data/test/25_ec2/50_snapshots_test.rb +69 -0
  76. data/test/26_ec2_instances/00_setup_test.rb +33 -0
  77. data/test/26_ec2_instances/10_instances_test.rb +81 -0
  78. data/test/26_ec2_instances/50_images_test.rb +13 -0
  79. data/test/30_sdb_metadata/00_setup_test.rb +28 -0
  80. data/test/30_sdb_metadata/10_disks_test.rb +99 -0
  81. data/test/30_sdb_metadata/20_backups_test.rb +102 -0
  82. data/test/50_commands/00_setup_test.rb +11 -0
  83. data/test/50_commands/10_keypairs_test.rb +79 -0
  84. data/test/50_commands/20_groups_test.rb +77 -0
  85. data/test/50_commands/40_volumes_test.rb +55 -0
  86. data/test/50_commands/50_instances_test.rb +110 -0
  87. data/test/coverage.txt +51 -0
  88. data/test/helper.rb +35 -0
  89. data/tryouts/disks.rb +55 -0
  90. data/tryouts/nested_methods.rb +36 -0
  91. data/tryouts/session_tryout.rb +48 -0
  92. metadata +94 -25
  93. data/bin/rudy-ec2 +0 -108
  94. data/lib/rudy/command/base.rb +0 -839
  95. data/lib/rudy/command/deploy.rb +0 -12
  96. data/lib/rudy/command/environment.rb +0 -74
  97. data/lib/rudy/command/machines.rb +0 -170
  98. data/lib/rudy/command/metadata.rb +0 -41
  99. data/lib/rudy/metadata.rb +0 -26
@@ -0,0 +1,45 @@
1
+ #!/bin/sh
2
+
3
+ #
4
+ # Randomizes the root password on first boot
5
+ #
6
+ # * When the file /root/firstboot is present, this script will
7
+ # randomize the root password.
8
+ #
9
+ # who: delano@solutious.com
10
+ # when: 2009-03-13
11
+ #
12
+
13
+ # NOTE: Works on Gentoo
14
+ # TODO: Fix for debian
15
+
16
+ if [ -f "/root/firstrun" ] ; then
17
+ dd if=/dev/urandom count=50|md5sum|passwd --stdin root
18
+ rm -f /root/firstrun
19
+ else
20
+ echo "* Firstrun *" && touch /root/firstrun
21
+ fi
22
+
23
+ # New Gentoo (to be tested)
24
+ #if [ -f "/root/firstrun" ] ; then
25
+ # pword=`dd if=/dev/urandom count=51 | sha1sum`
26
+ # echo $pword | passwd --stdin root
27
+ # rm -f /root/firstrun
28
+ #else
29
+ # echo "* Firstrun *" && touch /root/firstrun
30
+ #fi
31
+
32
+ # Fix for debian
33
+ #if [ -f "/root/firstrun" ] ; then
34
+ # pword=`dd if=/dev/urandom count=51 | sha1sum`
35
+ # echo "root:$pword" | chpasswd
36
+ # rm -f /root/firstrun
37
+ #else
38
+ # echo "* Firstrun *" && touch /root/firstrun
39
+ #fi
40
+
41
+ # Random root password for Gentoo:
42
+ #dd if=/dev/urandom count=51 | sha1sum | passwd --stdin root
43
+
44
+ # Random root password for Debian/Ubuntu:
45
+ #echo "root:`dd if=/dev/urandom count=51 | sha1sum`" | chpasswd
@@ -9,7 +9,7 @@
9
9
 
10
10
  # Runs when an ec2 instance startups up.
11
11
  # Grabs configuration from the run time user data and stores it locally.
12
- # See Rudy::Command::Instances#start_instance for the expected yaml format.
12
+ # See Rudy::CLI::Instances#start_instance for the expected yaml format.
13
13
 
14
14
  # Put this in /etc/init.d. Then:
15
15
  # * chmod 755 rudy-ec2-startup
@@ -74,10 +74,10 @@ module Rudy
74
74
  # We don't want sensitive config values available in the log
75
75
  puts "CONFIG: " << config_yaml
76
76
 
77
- zone = config[:zone] ? config[:zone].downcase : "zone"
78
- environment = config[:environment] ? config[:environment].downcase : "env"
79
- role = config[:role] ? config[:role].downcase : "role"
80
- position = config[:position] ? config[:position].downcase : "00"
77
+ zone = config[:zone] ? config[:zone].to_s.downcase : "zone"
78
+ environment = config[:environment] ? config[:environment].to_s.downcase : "env"
79
+ role = config[:role] ? config[:role].to_s.downcase : "role"
80
+ position = config[:position] ? config[:position].to_s.downcase : "00"
81
81
 
82
82
  hostname = [zone, environment, role, position].join('-')
83
83
  log "Setting hostname: #{hostname}"
@@ -0,0 +1,20 @@
1
+ #!/bin/sh
2
+
3
+ #
4
+ # Installs the latest EC2 AMI Tools
5
+ #
6
+ # * Downloads zip to /tmp
7
+ # * Unzips and removes /usr/ec2 (if it exists)
8
+ # * Moves tools to /usr/ec2
9
+ #
10
+ # who: delano@solutious.com
11
+ # when: 2009-03-13
12
+ #
13
+
14
+ cd /tmp
15
+ echo " + Updating ec2-ami-tools"
16
+ wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip && \
17
+ unzip ec2-ami-tools.zip && rm ec2*.zip* && rm -rf /usr/ec2 && \
18
+ mv ec2-* ec2 && mv ec2 /usr/ && \
19
+ echo " + Updated ec2-ami-tools"
20
+
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ module Rudy::Test
4
+
5
+ class Case_05_Config < Test::Unit::TestCase
6
+ include Rudy::AWS # If we include Huxtable, we won't need to grab global and config form rmach
7
+
8
+ @@logger = STDERR #StringIO.new
9
+ @@rmach = Rudy::Instances.new(:logger => @@logger)
10
+ @@global = @@rmach.global
11
+ @@config = @@rmach.config
12
+ @@zone = @@rmach.global.zone.to_s
13
+
14
+ context "#{name}_00 Setup" do
15
+ should "(00) have class variables setup" do
16
+ stop_test !@@rmach.is_a?(Rudy::Instances), "We don't have an instance ofRudy::Instancess (#{@@rmach})"
17
+ stop_test !@@global.is_a?(OpenStruct), "We don't have global (#{@@global})"
18
+ stop_test !@@config.is_a?(Rudy::Config), "We don't have an instance of Rudy::Config (#{@@config})"
19
+ end
20
+ end
21
+
22
+
23
+ end
24
+ end
@@ -0,0 +1,69 @@
1
+
2
+ module Rudy::Test
3
+ class Case_05_Config
4
+
5
+ context "#{name}_30 Machines" do
6
+
7
+ should "(10) have accounts.aws" do
8
+ stop_test !@@config.accounts.is_a?(Rudy::Config::Accounts), "Not an Accounts class"
9
+
10
+ stop_test @@config.accounts.aws.accountnum.nil?, "No account"
11
+ stop_test @@config.accounts.aws.accesskey.nil?, "No accesskey"
12
+ stop_test @@config.accounts.aws.secretkey.nil?, "No secretkey"
13
+ end
14
+
15
+ should "(20) have defaults" do
16
+ assert @@config.defaults.is_a?(Rudy::Config::Defaults), "Not a Defaults class"
17
+ assert !@@config.defaults.region.nil?, "No default region"
18
+ assert !@@config.defaults.zone.nil?, "No default zone"
19
+ assert !@@config.defaults.environment.nil?, "No default environment"
20
+ assert !@@config.defaults.role.nil?, "No default role"
21
+ end
22
+
23
+ should "(30) have machines" do
24
+ assert @@config.machines.is_a?(Rudy::Config::Machines), "Not a Machines class"
25
+ assert !@@config.machines.keys.empty?, "Nothing in machine config"
26
+ end
27
+
28
+ should "(31) have 2 disks" do
29
+ reg, zon = @@config.defaults.region, @@config.defaults.zone
30
+ env, rol = @@config.defaults.environment, @@config.defaults.role
31
+
32
+ end
33
+
34
+ # Disabled for 0.5.0 (routines config removed)
35
+ xshould "(40) have routines" do
36
+ assert @@config.routines.is_a?(Rudy::Config::Routines), "Not a Routines class"
37
+ end
38
+
39
+ # Disabled for 0.5.0 (most machines config removed)
40
+ xshould "(50) be able to find and find_deferred" do
41
+ reg, zon = @@config.defaults.region, @@config.defaults.zone
42
+ env, rol = @@config.defaults.environment, @@config.defaults.role
43
+
44
+ #Caesars.enable_debug
45
+
46
+ conf = @@config.machines[env][rol]
47
+ conf_find = @@config.machines.find(env, rol)
48
+ conf_find_def = @@config.machines.find_deferred(env, rol)
49
+
50
+ assert_equal conf, conf_find, "config hash and find not equal"
51
+ assert_equal conf_find_def, conf_find, "find and find_deferred not equal"
52
+ end
53
+
54
+ should "(51) find different config for each zone" do
55
+ reg, zon = @@config.defaults.region, @@config.defaults.zone
56
+ env, rol = @@config.defaults.environment, @@config.defaults.role
57
+
58
+ us_ami = @@config.machines.find(:"us-east-1b", :ami)
59
+ eu_ami = @@config.machines.find(:"eu-west-1b", :ami)
60
+
61
+ assert us_ami.is_a?(String), "No ami for us-east-1b zone"
62
+ assert eu_ami.is_a?(String), "No ami for eu-west-1b"
63
+ assert us_ami != eu_ami, "EU (#{eu_ami}) and US (#{us_ami}) AMIs are the same"
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ module Rudy::Test
4
+ # Expects:
5
+ # * There to be no pre-existing keypairs, addresses, etc... (except
6
+ # the default group)
7
+ # * It can destroy instances, images, etc...
8
+ #
9
+ # DO NOT RUN THIS TEST ON A PRODUCTION AWS ACCOUNT!!
10
+ #
11
+ class Case_20_SimpleDB < Test::Unit::TestCase
12
+ include Rudy::AWS
13
+
14
+ @@logger = STDERR #StringIO.new
15
+ @@rmach = Rudy::Instances.new(:logger => @@logger)
16
+ @@global = @@rmach.global
17
+ @@config = @@rmach.config
18
+ @@zone = @@rmach.global.zone.to_s
19
+
20
+ context "#{name}_00 Setup" do
21
+ should "(00) have class variables setup" do
22
+ stop_test !@@rmach.is_a?(Rudy::Instances), "We don't have an instance ofRudy::Instancess (#{@@rmach})"
23
+ stop_test !@@sdb.is_a?(Rudy::AWS::SimpleDB), "We don't have an instance of Rudy::AWS::EC2 (#{@@ec2})"
24
+ end
25
+ should "(01) be zone" do
26
+ stop_test !@@zone, "No zone"
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,113 @@
1
+ module Rudy::Test
2
+ class Case_20_SimpleDB
3
+
4
+
5
+ def get_domain
6
+
7
+ end
8
+
9
+ xcontext "#{name}_10 Domains" do
10
+
11
+ setup do
12
+ @domain_list = @@sdb.domains.list || []
13
+ @domain = @domain_list.first
14
+ end
15
+
16
+ should "(10) create domain" do
17
+ dname = 'test_' << Rudy::Utils.strand
18
+ assert @@sdb.domains.create(dname), "Domain not created (#{dname})"
19
+ end
20
+
21
+ should "(20) list domains" do
22
+ domain_list = @@sdb.domains.list
23
+ assert domain_list.is_a?(Array), "Not an Array"
24
+ assert !domain_list.empty?, "No Domains"
25
+ end
26
+
27
+ should "(30) store objects" do
28
+
29
+ assert !@domain.nil?, "No domain"
30
+
31
+ produce = lambda {
32
+ {
33
+ 'orange' => rand(100) * 10,
34
+ 'celery' => rand(100) * 100,
35
+ 'grapes' => :green
36
+ }
37
+ }
38
+
39
+ @@sdb.store(@domain, 'produce1', produce.call, :replace)
40
+ @@sdb.store(@domain, 'produce2', produce.call, :replace)
41
+
42
+ # TODO: Need assertion here!
43
+
44
+ end
45
+
46
+ should "(40) get objects" do
47
+ assert !@domain.nil?, "No domain"
48
+ item = @@sdb.get(@domain, 'produce1')
49
+ assert_equal Hash, item.class # good stuff
50
+ assert_equal ['green'], item['grapes']
51
+ end
52
+
53
+ should "(50) query objects" do
54
+
55
+ assert !@domain.nil?, "No domain"
56
+
57
+ items = @@sdb.query(@domain, "[ 'grapes' = 'green' ]")
58
+ assert items.is_a?(Array), "Not an Array"
59
+ assert_equal 2, items.size, "More than 2 objects"
60
+ end
61
+
62
+ should "(51) query objects with attributes" do
63
+
64
+ assert !@domain.nil?, "No domain"
65
+
66
+ items = @@sdb.query_with_attributes(@domain, "[ 'grapes' = 'green' ]")
67
+ assert items.is_a?(Hash), "Not a Hash"
68
+ assert_equal 2, items.keys.size, "More than 2 objects"
69
+ assert items['produce1']['celery'].first.to_i > 1000, "Celery less than 1000"
70
+ end
71
+
72
+ should "(60) select objects" do
73
+ assert !@domain.nil?, "No domain"
74
+ q = "select * from #{@domain}"
75
+
76
+ items = @@sdb.select(q)
77
+ assert items.is_a?(Hash), "Not a Hash"
78
+ assert_equal 2, items.keys.size, "More than 2 objects"
79
+
80
+ # {"produce1"=>{"celery"=>["5200"], "grapes"=>["green"], "orange"=>["550"]}}
81
+ assert items['produce1']['celery'].first.to_i > 1000, "Celery less than 1000"
82
+ end
83
+
84
+
85
+ should "(70) destroy objects" do
86
+ assert !@domain.nil?, "No domain"
87
+ q = "select * from #{@domain}"
88
+ items = @@sdb.select(q)
89
+ assert items.is_a?(Hash), "Not a Hash"
90
+ items.keys.each do |item|
91
+ assert @@sdb.destroy(@domain, item), "Not destroyed (#{item})"
92
+ end
93
+ q = "select * from #{@domain}"
94
+ items = @@sdb.select(q)
95
+ assert items.nil?, "Some items not destroyed (#{items})"
96
+ end
97
+
98
+ should "(99) destroy domains" do
99
+
100
+ assert !@domain.nil?, "No domain"
101
+
102
+ @domain_list.each do |domain|
103
+ assert @@sdb.domains.destroy(domain), "Not destroyed (#{domain})"
104
+ end
105
+
106
+ domain_list = @@sdb.domains.list
107
+ assert domain_list.empty?, "Not empty"
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ module Rudy::Test
4
+ # Expects:
5
+ # * There to be no pre-existing keypairs, addresses, etc... (except
6
+ # the default group)
7
+ # * It can destroy instances, images, etc...
8
+ #
9
+ # DO NOT RUN THIS TEST ON A PRODUCTION AWS ACCOUNT!!
10
+ #
11
+ class Case_25_EC2 < Test::Unit::TestCase
12
+ include Rudy::AWS
13
+
14
+ @@logger = STDERR #StringIO.new
15
+ @@rmach = Rudy::Instances.new(:logger => @@logger)
16
+ @@global = @@rmach.global
17
+ @@config = @@rmach.config
18
+ @@zone = @@rmach.global.zone.to_s
19
+
20
+ context "#{name}_00 Setup" do
21
+ should "(10) have class variables setup" do
22
+ stop_test !@@rmach.is_a?(Rudy::Instances), "We don't have an instance ofRudy::Instancess (#{@@rmach})"
23
+ stop_test !@@ec2.is_a?(Rudy::AWS::EC2), "We don't have an instance of Rudy::AWS::EC2 (#{@@ec2})"
24
+ stop_test !@@global.is_a?(OpenStruct), "We don't have global (#{@@global})"
25
+ stop_test !@@config.is_a?(Rudy::Config), "We don't have an instance of Rudy::Config (#{@@config})"
26
+ stop_test !@@rmach.config || !@@rmach.config.accounts || !@@rmach.config.accounts.aws || !@@rmach.config.accounts.aws.accountnum, "No account number"
27
+ end
28
+ should "(11) be zone" do
29
+ stop_test !@@zone, "No zone"
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,33 @@
1
+
2
+ module Rudy::Test
3
+
4
+ class Case_25_EC2
5
+
6
+ context "#{name}_10 KeyPairs" do
7
+
8
+
9
+ should "(10) create keypair" do
10
+ name = 'test-' << Rudy::Utils.strand
11
+ keypair = @@ec2.keypairs.create(name)
12
+ assert keypair.is_a?(Rudy::AWS::EC2::KeyPair), "Not a KeyPair"
13
+ assert !keypair.name.empty?, "No name"
14
+ assert !keypair.fingerprint.empty?, "No fingerprint"
15
+ assert !keypair.private_key.empty?, "No private key"
16
+ end
17
+
18
+ should "(20) list keypairs" do
19
+ keypairs = @@ec2.keypairs.list || []
20
+ assert keypairs.size > 0, "No keypairs"
21
+ end
22
+
23
+ should "(50) destroy keypairs" do
24
+ keypairs = @@ec2.keypairs.list || []
25
+ assert keypairs.size > 0, "No keypairs"
26
+ keypairs.each do |kp|
27
+ @@ec2.keypairs.destroy(kp.name)
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,139 @@
1
+
2
+ module Rudy::Test
3
+
4
+ class Case_25_EC2
5
+
6
+ def get_groups
7
+ # Ruby 1.8 throws an undefined method error when this is at the
8
+ # bottom of the class
9
+ group_list = @@ec2.groups.list_as_hash
10
+ # "default" cannot be deleted so we exempt it
11
+ group_list.reject { |gname,group| gname == "default" }
12
+ end
13
+
14
+
15
+ context "#{name}_20 Groups" do
16
+
17
+ should "(00) not be existing groups" do
18
+ group_list = get_groups
19
+ stop_test !group_list.empty?, "Destroy the existing groups (except \"default\")"
20
+ end
21
+
22
+ should "(01) create group with name" do
23
+ group_list = get_groups
24
+
25
+ str = Rudy::Utils.strand
26
+ gname = "test-name-#{str}"
27
+ group = @@ec2.groups.create(gname)
28
+ assert group.is_a?(Rudy::AWS::EC2::Group), "Not a Group object"
29
+ assert_equal group.name, gname, "Group name not set"
30
+ assert_equal group.description, "Group #{gname}", "Group description not 'Group #{gname}'"
31
+ assert @@ec2.groups.exists?(gname), "Group #{gname} doesn't exist"
32
+ end
33
+
34
+ should "(02) create group with name and description" do
35
+ group_list = get_groups
36
+
37
+ str = Rudy::Utils.strand
38
+ gname = "test-name-#{str}"
39
+ desc = "test-desc-#{str}"
40
+ group = @@ec2.groups.create(gname, desc)
41
+ assert group.is_a?(Rudy::AWS::EC2::Group), "Not a Group object"
42
+ assert_equal group.name, gname, "Group name not set"
43
+ assert_equal group.description, desc, "Group description not set"
44
+ assert @@ec2.groups.exists?(gname), "Group #{gname} doesn't exist"
45
+ end
46
+
47
+ should "(10) list available groups" do
48
+ group_list = @@ec2.groups.list
49
+ assert group_list.is_a?(Array), "Group list is not an Array"
50
+
51
+ group_list_hash = @@ec2.groups.list_as_hash
52
+ assert group_list_hash.is_a?(Hash), "Group list is not an Hash"
53
+
54
+ group_list.each do |group|
55
+ assert group.is_a?(Rudy::AWS::EC2::Group), "Not a group"
56
+ end
57
+ end
58
+
59
+ should "(20) authorize/revoke group rules for address" do
60
+ external_ip_address = Rudy::Utils::external_ip_address
61
+ external_ip_address ||= '192.168.0.1/32'
62
+
63
+ gname = "test-" << Rudy::Utils.strand
64
+ group = @@ec2.groups.create(gname)
65
+ protocols = ['tcp', 'udp']
66
+ addresses = [external_ip_address]
67
+ ports = [[3100,3150],[3200,3250]]
68
+ should_have = [] # The list of address keys we're expecting in Groups#addresses
69
+ protocols.each do |protocol|
70
+ addresses.each do |address|
71
+ ports.each do |port|
72
+ should_have << "#{address}/#{protocol}"
73
+ ret = @@ec2.groups.authorize(gname, port[0].to_i, (port[1] || port[0]).to_i, protocol, address)
74
+ assert ret, "Did not authorize: #{port[0]}:#{port[1]} (#{protocol}) for #{address}"
75
+ end
76
+ end
77
+ end
78
+ group = @@ec2.groups.get(gname)
79
+ assert group.addresses.is_a?(Hash), "Addresses is not a hash"
80
+ address_diff = group.addresses.keys - should_have
81
+ assert address_diff.empty?, "Some addresses not created (#{address_diff.join(', ')})"
82
+ group.addresses.each_pair do |address,rules|
83
+ assert rules.is_a?(Array), "Not an Array"
84
+ assert_equal 2, rules.size, "Not 2 rules"
85
+ # TODO: Check port ranges
86
+ end
87
+
88
+ protocols.each do |protocol|
89
+ addresses.each do |address|
90
+ ports.each do |port|
91
+ should_have << "#{address}/#{protocol}"
92
+ ret = @@ec2.groups.revoke(gname, port[0].to_i, (port[1] || port[0]).to_i, protocol, address)
93
+ assert ret, "Did not revoke: #{port[0]}:#{port[1]} (#{protocol}) for #{address}"
94
+ end
95
+ end
96
+ end
97
+
98
+ group = @@ec2.groups.get(gname)
99
+ assert group.addresses.is_a?(Hash), "Addresses is not a hash"
100
+ assert group.addresses.empty?, "Some addresses not revoked #{group.addresses.to_s}"
101
+ end
102
+
103
+
104
+ should "(21) authorize/revoke group permissions for account/group" do
105
+ gname = "test-" << Rudy::Utils.strand
106
+ group = @@ec2.groups.create(gname)
107
+ should_have = "#{@@rmach.config.accounts.aws.accountnum}:#{gname}"
108
+
109
+ ret = @@ec2.groups.authorize_group(gname, gname, @@rmach.config.accounts.aws.accountnum)
110
+ assert ret, "Authorize failed (#{should_have})"
111
+ group = @@ec2.groups.get(gname)
112
+ assert group.is_a?(Rudy::AWS::EC2::Group), "Not a Group object"
113
+ assert group.groups.is_a?(Hash), "Groups is not a Hash (#{group.groups.class})"
114
+ assert_equal should_have, group.groups.keys.first, "Authorized group is not #{should_have}"
115
+ # TODO: Check port ranges
116
+
117
+ ret = @@ec2.groups.revoke_group(gname, gname, @@rmach.config.accounts.aws.accountnum)
118
+ assert ret, "Revoke failed (#{should_have})"
119
+ group = @@ec2.groups.get(gname)
120
+ assert group.is_a?(Rudy::AWS::EC2::Group), "Not a Group object"
121
+ assert group.groups.is_a?(Hash), "Groups is not a Hash (#{group.groups.class})"
122
+ assert !group.groups.has_key?(should_have), "Still authorized for #{should_have}"
123
+ end
124
+
125
+
126
+ should "(50) destroy groups" do
127
+ group_list = get_groups
128
+ assert !group_list.empty?, "No groups"
129
+ group_list.each_pair do |gname,group|
130
+ assert @@ec2.groups.destroy(group.name), "Not destroyed (#{group.name})"
131
+ end
132
+ end
133
+
134
+
135
+ end
136
+
137
+
138
+ end
139
+ end