rudy 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +54 -30
- data/README.rdoc +100 -12
- data/Rakefile +103 -8
- data/Rudyfile +119 -0
- data/bin/ird +175 -0
- data/bin/rudy +259 -156
- data/bin/rudy-ec2 +228 -95
- data/bin/rudy-s3 +76 -0
- data/bin/rudy-sdb +67 -0
- data/lib/annoy.rb +270 -0
- data/lib/console.rb +30 -9
- data/lib/escape.rb +305 -0
- data/lib/rudy.rb +151 -182
- data/lib/rudy/aws.rb +56 -49
- data/lib/rudy/aws/ec2.rb +47 -292
- data/lib/rudy/aws/ec2/address.rb +157 -0
- data/lib/rudy/aws/ec2/group.rb +301 -0
- data/lib/rudy/aws/ec2/image.rb +168 -0
- data/lib/rudy/aws/ec2/instance.rb +434 -0
- data/lib/rudy/aws/ec2/keypair.rb +104 -0
- data/lib/rudy/aws/ec2/snapshot.rb +98 -0
- data/lib/rudy/aws/ec2/volume.rb +230 -0
- data/lib/rudy/aws/ec2/zone.rb +77 -0
- data/lib/rudy/aws/s3.rb +54 -0
- data/lib/rudy/aws/sdb.rb +298 -0
- data/lib/rudy/aws/sdb/error.rb +46 -0
- data/lib/rudy/{metadata/backup.rb → backup.rb} +26 -51
- data/lib/rudy/cli.rb +157 -0
- data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
- data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
- data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
- data/lib/rudy/cli/aws/ec2/images.rb +196 -0
- data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
- data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
- data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
- data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
- data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
- data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
- data/lib/rudy/cli/aws/s3/store.rb +22 -0
- data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
- data/lib/rudy/cli/candy.rb +8 -0
- data/lib/rudy/{command → cli}/config.rb +34 -24
- data/lib/rudy/cli/disks.rb +35 -0
- data/lib/rudy/cli/machines.rb +94 -0
- data/lib/rudy/cli/routines.rb +57 -0
- data/lib/rudy/config.rb +77 -72
- data/lib/rudy/config/objects.rb +29 -0
- data/lib/rudy/disks.rb +248 -0
- data/lib/rudy/global.rb +121 -0
- data/lib/rudy/huxtable.rb +340 -0
- data/lib/rudy/machines.rb +245 -0
- data/lib/rudy/metadata.rb +123 -13
- data/lib/rudy/routines.rb +47 -0
- data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
- data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
- data/lib/rudy/routines/release.rb +34 -0
- data/lib/rudy/routines/shutdown.rb +57 -0
- data/lib/rudy/routines/startup.rb +58 -0
- data/lib/rudy/scm/svn.rb +1 -1
- data/lib/rudy/utils.rb +322 -4
- data/lib/storable.rb +26 -17
- data/lib/sysinfo.rb +274 -0
- data/lib/tryouts.rb +6 -13
- data/rudy.gemspec +128 -42
- data/support/randomize-root-password +45 -0
- data/support/rudy-ec2-startup +9 -9
- data/support/update-ec2-ami-tools +20 -0
- data/test/05_config/00_setup_test.rb +20 -0
- data/test/05_config/30_machines_test.rb +69 -0
- data/test/20_sdb/00_setup_test.rb +16 -0
- data/test/20_sdb/10_domains_test.rb +115 -0
- data/test/25_ec2/00_setup_test.rb +29 -0
- data/test/25_ec2/10_keypairs_test.rb +41 -0
- data/test/25_ec2/20_groups_test.rb +131 -0
- data/test/25_ec2/30_addresses_test.rb +38 -0
- data/test/25_ec2/40_volumes_test.rb +49 -0
- data/test/25_ec2/50_snapshots_test.rb +74 -0
- data/test/26_ec2_instances/00_setup_test.rb +28 -0
- data/test/26_ec2_instances/10_instances_test.rb +83 -0
- data/test/26_ec2_instances/50_images_test.rb +13 -0
- data/test/30_sdb_metadata/00_setup_test.rb +21 -0
- data/test/30_sdb_metadata/10_disks_test.rb +109 -0
- data/test/30_sdb_metadata/20_backups_test.rb +102 -0
- data/test/coverage.txt +51 -0
- data/test/helper.rb +36 -0
- data/vendor/highline-1.5.1/CHANGELOG +222 -0
- data/vendor/highline-1.5.1/INSTALL +35 -0
- data/vendor/highline-1.5.1/LICENSE +7 -0
- data/vendor/highline-1.5.1/README +63 -0
- data/vendor/highline-1.5.1/Rakefile +82 -0
- data/vendor/highline-1.5.1/TODO +6 -0
- data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
- data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
- data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
- data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
- data/vendor/highline-1.5.1/examples/limit.rb +12 -0
- data/vendor/highline-1.5.1/examples/menus.rb +65 -0
- data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
- data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
- data/vendor/highline-1.5.1/examples/password.rb +7 -0
- data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
- data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
- data/vendor/highline-1.5.1/lib/highline.rb +758 -0
- data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
- data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
- data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
- data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
- data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
- data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
- data/vendor/highline-1.5.1/setup.rb +1360 -0
- data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
- data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
- data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
- data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
- data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
- metadata +141 -38
- data/lib/aws_sdb.rb +0 -3
- data/lib/aws_sdb/error.rb +0 -42
- data/lib/aws_sdb/service.rb +0 -215
- data/lib/rudy/aws/simpledb.rb +0 -53
- data/lib/rudy/command/addresses.rb +0 -46
- data/lib/rudy/command/backups.rb +0 -175
- data/lib/rudy/command/base.rb +0 -841
- data/lib/rudy/command/deploy.rb +0 -12
- data/lib/rudy/command/disks.rb +0 -213
- data/lib/rudy/command/environment.rb +0 -73
- data/lib/rudy/command/groups.rb +0 -61
- data/lib/rudy/command/images.rb +0 -91
- data/lib/rudy/command/instances.rb +0 -85
- data/lib/rudy/command/machines.rb +0 -161
- data/lib/rudy/command/metadata.rb +0 -41
- data/lib/rudy/command/release.rb +0 -174
- data/lib/rudy/command/volumes.rb +0 -66
- data/lib/rudy/metadata/disk.rb +0 -138
- data/tryouts/console_tryout.rb +0 -91
@@ -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
|
data/support/rudy-ec2-startup
CHANGED
@@ -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::
|
12
|
+
# See Rudy::CLI::Machines#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
|
@@ -33,8 +33,8 @@ METADATA = 'http://169.254.169.254/2008-02-01/meta-data'
|
|
33
33
|
|
34
34
|
METADATAPARAMS = ['instance-id', 'instance-type']
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
Rudy::CONFIG_DIR=File.join('.rudy')
|
37
|
+
Rudy::CONFIG_FILE=File.join('config')
|
38
38
|
|
39
39
|
module Rudy
|
40
40
|
module EC2Startup
|
@@ -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}"
|
@@ -91,9 +91,9 @@ module Rudy
|
|
91
91
|
# (when we're not running as that user.)
|
92
92
|
config[:userdata].each_pair do |n,hash|
|
93
93
|
fileparts = (n == :root) ? ['/root'] : [user_home_dir(n)]
|
94
|
-
fileparts <<
|
94
|
+
fileparts << Rudy::CONFIG_DIR
|
95
95
|
dirpath = File.join(fileparts)
|
96
|
-
filepath = File.join(dirpath,
|
96
|
+
filepath = File.join(dirpath, Rudy::CONFIG_FILE)
|
97
97
|
|
98
98
|
# Backwards compatability
|
99
99
|
if !File.directory?(dirpath)
|
@@ -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,20 @@
|
|
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::Huxtable
|
7
|
+
|
8
|
+
@@logger = STDERR #StringIO.new
|
9
|
+
@@zone = @@global.zone.to_s
|
10
|
+
|
11
|
+
context "#{name}_00 Setup" do
|
12
|
+
should "(00) have class variables setup" do
|
13
|
+
stop_test !@@global.is_a?(Rudy::Global), "We don't have global (#{@@global})"
|
14
|
+
stop_test !@@config.is_a?(Rudy::Config), "We don't have an instance of Rudy::Config (#{@@config})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
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,16 @@
|
|
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_AWS_SDB < Test::Unit::TestCase
|
12
|
+
include Rudy::Huxtable
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Rudy::Test
|
2
|
+
class Case_20_AWS_SDB
|
3
|
+
|
4
|
+
|
5
|
+
def get_domain
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
context "#{name}_10 Domains" do
|
10
|
+
|
11
|
+
setup do
|
12
|
+
@sdb = Rudy::AWS::SDB.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
13
|
+
@domain_list = @sdb.list_domains || []
|
14
|
+
@domain = @domain_list.first
|
15
|
+
end
|
16
|
+
|
17
|
+
should "(10) create domain" do
|
18
|
+
dname = 'test_' << Rudy::Utils.strand
|
19
|
+
assert @sdb.create_domain(dname), "Domain not created (#{dname})"
|
20
|
+
end
|
21
|
+
|
22
|
+
should "(20) list domains" do
|
23
|
+
domain_list = @sdb.list_domains
|
24
|
+
assert domain_list.is_a?(Array), "Not an Array"
|
25
|
+
assert !domain_list.empty?, "No Domains"
|
26
|
+
end
|
27
|
+
|
28
|
+
should "(30) store objects" do
|
29
|
+
|
30
|
+
assert !@domain.nil?, "No domain"
|
31
|
+
|
32
|
+
produce = lambda {
|
33
|
+
{
|
34
|
+
'orange' => rand(100) * 10,
|
35
|
+
'celery' => rand(100) * 100,
|
36
|
+
'grapes' => :green
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
@sdb.put(@domain, 'produce1', produce.call, :replace)
|
41
|
+
@sdb.put(@domain, 'produce2', produce.call, :replace)
|
42
|
+
|
43
|
+
# TODO: Need assertion here!
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
should "(40) get objects" do
|
48
|
+
assert !@domain.nil?, "No domain"
|
49
|
+
item = @sdb.get(@domain, 'produce1')
|
50
|
+
assert_equal Hash, item.class # good stuff
|
51
|
+
assert_equal ['green'], item['grapes']
|
52
|
+
end
|
53
|
+
|
54
|
+
should "(50) query objects" do
|
55
|
+
|
56
|
+
assert !@domain.nil?, "No domain"
|
57
|
+
|
58
|
+
items = @sdb.query(@domain, "[ 'grapes' = 'green' ]")
|
59
|
+
assert items.is_a?(Array), "Not an Array"
|
60
|
+
assert_equal 2, items.size, "More than 2 objects"
|
61
|
+
end
|
62
|
+
|
63
|
+
should "(51) query objects with attributes" do
|
64
|
+
|
65
|
+
assert !@domain.nil?, "No domain"
|
66
|
+
|
67
|
+
items = @sdb.query_with_attributes(@domain, "[ 'grapes' = 'green' ]")
|
68
|
+
assert items.is_a?(Hash), "Not a Hash"
|
69
|
+
assert_equal 2, items.keys.size, "More than 2 objects"
|
70
|
+
assert items['produce1']['celery'].first.to_i > 1000, "Celery less than 1000"
|
71
|
+
end
|
72
|
+
|
73
|
+
should "(60) select objects" do
|
74
|
+
assert !@domain.nil?, "No domain"
|
75
|
+
q = "select * from #{@domain}"
|
76
|
+
|
77
|
+
items = @sdb.select(q)
|
78
|
+
assert items.is_a?(Hash), "Not a Hash"
|
79
|
+
assert_equal 2, items.keys.size, "More than 2 objects"
|
80
|
+
|
81
|
+
# {"produce1"=>{"celery"=>["5200"], "grapes"=>["green"], "orange"=>["550"]}}
|
82
|
+
assert items['produce1']['celery'].first.to_i > 1000, "Celery less than 1000"
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
should "(70) destroy objects" do
|
87
|
+
assert !@domain.nil?, "No domain"
|
88
|
+
q = "select * from #{@domain}"
|
89
|
+
items = @sdb.select(q)
|
90
|
+
assert items.is_a?(Hash), "Not a Hash"
|
91
|
+
items.keys.each do |item|
|
92
|
+
assert @sdb.destroy(@domain, item), "Not destroyed (#{item})"
|
93
|
+
end
|
94
|
+
sleep 1 # Eventual consistency. Items may still appear.
|
95
|
+
q = "select * from #{@domain}"
|
96
|
+
items = @sdb.select(q)
|
97
|
+
assert items.nil?, "Some items not destroyed (#{items})"
|
98
|
+
end
|
99
|
+
|
100
|
+
should "(99) destroy domains" do
|
101
|
+
|
102
|
+
assert !@domain.nil?, "No domain"
|
103
|
+
|
104
|
+
@domain_list.each do |domain|
|
105
|
+
assert @sdb.destroy_domain(domain), "Not destroyed (#{domain})"
|
106
|
+
end
|
107
|
+
|
108
|
+
domain_list = @sdb.list_domains
|
109
|
+
assert domain_list.empty?, "Not empty"
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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::Huxtable
|
13
|
+
|
14
|
+
@@zone = @@global.zone.to_s
|
15
|
+
|
16
|
+
|
17
|
+
context "#{name}_00 Setup" do
|
18
|
+
should "(10) have class variables setup" do
|
19
|
+
stop_test !@@global.is_a?(Rudy::Global), "We don't have global (#{@@global})"
|
20
|
+
stop_test !@@config.is_a?(Rudy::Config), "We don't have an instance of Rudy::Config (#{@@config})"
|
21
|
+
stop_test !@@global.accountnum, "No account number"
|
22
|
+
end
|
23
|
+
should "(11) be zone" do
|
24
|
+
stop_test !@@zone, "No zone"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
module Rudy::Test
|
3
|
+
|
4
|
+
class Case_25_EC2
|
5
|
+
|
6
|
+
context "#{name}_10 KeyPairs" do
|
7
|
+
setup do
|
8
|
+
@@test_name ||= 'test-' << Rudy::Utils.strand
|
9
|
+
@ec2key = Rudy::AWS::EC2::KeyPairs.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
10
|
+
#@ami = @@config.machines.find(@@zone.to_sym, :ami)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
should "(10) create keypair" do
|
15
|
+
keypair = @ec2key.create(@@test_name)
|
16
|
+
assert keypair.is_a?(Rudy::AWS::EC2::KeyPair), "Not a KeyPair"
|
17
|
+
assert !keypair.name.empty?, "No name"
|
18
|
+
assert !keypair.fingerprint.empty?, "No fingerprint"
|
19
|
+
assert !keypair.private_key.empty?, "No private key"
|
20
|
+
end
|
21
|
+
|
22
|
+
should "(20) list keypairs" do
|
23
|
+
keypairs = @ec2key.list || []
|
24
|
+
assert keypairs.size > 0, "No keypairs"
|
25
|
+
end
|
26
|
+
|
27
|
+
should "(21) get specific keypair" do
|
28
|
+
assert @ec2key.get(@@test_name).is_a?(Rudy::AWS::EC2::KeyPair), "Not a KeyPair (#{@@test_name})"
|
29
|
+
end
|
30
|
+
|
31
|
+
should "(50) destroy keypairs" do
|
32
|
+
keypairs = @ec2key.list || []
|
33
|
+
assert keypairs.size > 0, "No keypairs"
|
34
|
+
keypairs.each do |kp|
|
35
|
+
@ec2key.destroy(kp.name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,131 @@
|
|
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 = @ec2group.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
|
+
setup do
|
17
|
+
@ec2group = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
18
|
+
@accountnum = @@config.accounts.aws.accountnum
|
19
|
+
end
|
20
|
+
|
21
|
+
should "(00) not be existing groups" do
|
22
|
+
|
23
|
+
group_list = get_groups
|
24
|
+
stop_test !group_list.empty?, "Destroy the existing groups (#{group_list.keys.join(', ')})"
|
25
|
+
stop_test !@accountnum, "Need an account number for group authorization"
|
26
|
+
end
|
27
|
+
|
28
|
+
should "(01) create group with name" do
|
29
|
+
group_list = get_groups
|
30
|
+
test_name ||= 'test-' << Rudy::Utils.strand
|
31
|
+
str = Rudy::Utils.strand
|
32
|
+
group = @ec2group.create(test_name)
|
33
|
+
assert group.is_a?(Rudy::AWS::EC2::Group), "Not a Group object (#{group.class.to_s})"
|
34
|
+
assert_equal group.name, test_name, "Group name not set"
|
35
|
+
assert_equal group.description, "Security Group #{test_name}", "Group description not 'Security Group #{test_name}'"
|
36
|
+
assert @ec2group.exists?(test_name), "Group #{test_name} doesn't exist"
|
37
|
+
end
|
38
|
+
|
39
|
+
should "(02) create group with name and description" do
|
40
|
+
test_name ||= 'test-' << Rudy::Utils.strand
|
41
|
+
str = Rudy::Utils.strand
|
42
|
+
desc = "Description for #{test_name}"
|
43
|
+
group = @ec2group.create(test_name, desc)
|
44
|
+
assert group.is_a?(Rudy::AWS::EC2::Group), "Not a Group object"
|
45
|
+
assert_equal group.name, test_name, "Group name not set"
|
46
|
+
assert_equal group.description, desc, "Group description not set"
|
47
|
+
assert @ec2group.exists?(test_name), "Group #{test_name} doesn't exist"
|
48
|
+
end
|
49
|
+
|
50
|
+
should "(10) list available groups" do
|
51
|
+
group_list = @ec2group.list
|
52
|
+
assert group_list.is_a?(Array), "Group list is not an Array"
|
53
|
+
|
54
|
+
group_list_hash = @ec2group.list_as_hash
|
55
|
+
assert group_list_hash.is_a?(Hash), "Group list is not an Hash"
|
56
|
+
|
57
|
+
group_list.each do |group|
|
58
|
+
assert group.is_a?(Rudy::AWS::EC2::Group), "Not a group"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
should "(20) authorize/revoke group rules for address" do
|
63
|
+
external_ip_address = Rudy::Utils::external_ip_address
|
64
|
+
external_ip_address ||= '192.168.0.1/32'
|
65
|
+
|
66
|
+
test_name ||= 'test-' << Rudy::Utils.strand
|
67
|
+
|
68
|
+
group = @ec2group.create(test_name)
|
69
|
+
protocols = ['tcp', 'udp']
|
70
|
+
addresses = [external_ip_address]
|
71
|
+
ports = [[3100,3150],[3200,3250]]
|
72
|
+
|
73
|
+
ret = @ec2group.authorize(test_name, addresses, ports, protocols)
|
74
|
+
assert ret, "Authorize did not return true"
|
75
|
+
|
76
|
+
group = @ec2group.get(test_name)
|
77
|
+
|
78
|
+
assert group.is_a?(Rudy::AWS::EC2::Group), "Not a group (#{group})"
|
79
|
+
assert group.addresses.is_a?(Hash), "Addresses is not a hash (#{group.addresses})"
|
80
|
+
|
81
|
+
group.addresses.each_pair do |address,rules|
|
82
|
+
assert rules.is_a?(Array), "Not an Array"
|
83
|
+
assert_equal 7, rules.size, "Not 7 rules"
|
84
|
+
puts "TODO: Check port ranges"
|
85
|
+
end
|
86
|
+
|
87
|
+
ret = @ec2group.revoke(test_name, addresses, ports, protocols)
|
88
|
+
assert ret, "Revoke did not return true"
|
89
|
+
sleep 1 # Wait for eventual consistency
|
90
|
+
group = @ec2group.get(test_name)
|
91
|
+
assert group.addresses.is_a?(Hash), "Addresses is not a hash"
|
92
|
+
assert group.addresses.empty?, "Some addresses not revoked #{group.addresses.to_s}"
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
should "(21) authorize/revoke group permissions for account/group" do
|
97
|
+
test_name ||= 'test-' << Rudy::Utils.strand
|
98
|
+
group = @ec2group.create(test_name)
|
99
|
+
should_have = "#{@accountnum}:#{test_name}"
|
100
|
+
|
101
|
+
ret = @ec2group.authorize_group(test_name, test_name, @accountnum)
|
102
|
+
assert ret, "Authorize failed (#{should_have})"
|
103
|
+
group = @ec2group.get(test_name)
|
104
|
+
assert group.is_a?(Rudy::AWS::EC2::Group), "Not a Group object"
|
105
|
+
assert group.groups.is_a?(Hash), "Groups is not a Hash (#{group.groups.class})"
|
106
|
+
assert_equal should_have, group.groups.keys.first, "Authorized group is not #{should_have}"
|
107
|
+
# TODO: Check port ranges
|
108
|
+
|
109
|
+
ret = @ec2group.revoke_group(test_name, test_name, @accountnum)
|
110
|
+
assert ret, "Revoke failed (#{should_have})"
|
111
|
+
group = @ec2group.get(test_name)
|
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 !group.groups.has_key?(should_have), "Still authorized for #{should_have}"
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
should "(50) destroy groups" do
|
119
|
+
group_list = get_groups
|
120
|
+
assert !group_list.empty?, "No groups"
|
121
|
+
group_list.each_pair do |gname,group|
|
122
|
+
assert @ec2group.destroy(group.name), "Not destroyed (#{group.name})"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|