solutious-rudy 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/CHANGES.txt +19 -1
  2. data/README.rdoc +66 -35
  3. data/Rakefile +1 -0
  4. data/Rudyfile +97 -6
  5. data/bin/ird +7 -4
  6. data/bin/rudy +120 -212
  7. data/bin/rudy-ec2 +240 -0
  8. data/bin/rudy-s3 +76 -0
  9. data/bin/rudy-sdb +67 -0
  10. data/lib/annoy.rb +61 -18
  11. data/lib/console.rb +10 -5
  12. data/lib/rudy/aws/ec2/address.rb +76 -40
  13. data/lib/rudy/aws/ec2/group.rb +138 -78
  14. data/lib/rudy/aws/ec2/image.rb +134 -12
  15. data/lib/rudy/aws/ec2/instance.rb +116 -89
  16. data/lib/rudy/aws/ec2/keypair.rb +26 -14
  17. data/lib/rudy/aws/ec2/snapshot.rb +23 -12
  18. data/lib/rudy/aws/ec2/volume.rb +198 -202
  19. data/lib/rudy/aws/ec2/zone.rb +77 -0
  20. data/lib/rudy/aws/ec2.rb +56 -25
  21. data/lib/rudy/aws/s3.rb +54 -0
  22. data/lib/rudy/aws/sdb/error.rb +46 -0
  23. data/lib/rudy/aws/sdb.rb +298 -0
  24. data/lib/rudy/aws.rb +29 -57
  25. data/lib/rudy/{metadata/backup.rb → backup.rb} +8 -8
  26. data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
  27. data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
  28. data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
  29. data/lib/rudy/cli/aws/ec2/images.rb +196 -0
  30. data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
  31. data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
  32. data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
  33. data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
  34. data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
  35. data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
  36. data/lib/rudy/cli/aws/s3/store.rb +22 -0
  37. data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
  38. data/lib/rudy/cli/{deploy.rb → candy.rb} +2 -6
  39. data/lib/rudy/cli/config.rb +25 -20
  40. data/lib/rudy/cli/disks.rb +18 -108
  41. data/lib/rudy/cli/machines.rb +94 -0
  42. data/lib/rudy/cli/routines.rb +47 -70
  43. data/lib/rudy/cli.rb +104 -89
  44. data/lib/rudy/config/objects.rb +5 -43
  45. data/lib/rudy/config.rb +8 -24
  46. data/lib/rudy/disks.rb +248 -0
  47. data/lib/rudy/global.rb +121 -0
  48. data/lib/rudy/huxtable.rb +232 -147
  49. data/lib/rudy/machines.rb +245 -0
  50. data/lib/rudy/metadata.rb +136 -0
  51. data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
  52. data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
  53. data/lib/rudy/routines/release.rb +27 -8
  54. data/lib/rudy/routines/shutdown.rb +47 -32
  55. data/lib/rudy/routines/startup.rb +47 -37
  56. data/lib/rudy/routines.rb +30 -37
  57. data/lib/rudy/scm/svn.rb +1 -1
  58. data/lib/rudy/utils.rb +262 -4
  59. data/lib/rudy.rb +76 -248
  60. data/lib/storable.rb +19 -16
  61. data/lib/sysinfo.rb +1 -1
  62. data/rudy.gemspec +88 -68
  63. data/support/rudy-ec2-startup +5 -5
  64. data/test/05_config/00_setup_test.rb +3 -7
  65. data/test/20_sdb/00_setup_test.rb +2 -17
  66. data/test/20_sdb/10_domains_test.rb +18 -16
  67. data/test/25_ec2/00_setup_test.rb +5 -10
  68. data/test/25_ec2/10_keypairs_test.rb +13 -5
  69. data/test/25_ec2/20_groups_test.rb +48 -56
  70. data/test/25_ec2/30_addresses_test.rb +13 -10
  71. data/test/25_ec2/40_volumes_test.rb +11 -8
  72. data/test/25_ec2/50_snapshots_test.rb +17 -12
  73. data/test/26_ec2_instances/00_setup_test.rb +3 -8
  74. data/test/26_ec2_instances/10_instances_test.rb +21 -19
  75. data/test/30_sdb_metadata/00_setup_test.rb +2 -9
  76. data/test/30_sdb_metadata/10_disks_test.rb +47 -37
  77. data/test/30_sdb_metadata/20_backups_test.rb +9 -9
  78. data/test/helper.rb +5 -3
  79. data/vendor/highline-1.5.1/CHANGELOG +222 -0
  80. data/vendor/highline-1.5.1/INSTALL +35 -0
  81. data/vendor/highline-1.5.1/LICENSE +7 -0
  82. data/vendor/highline-1.5.1/README +63 -0
  83. data/vendor/highline-1.5.1/Rakefile +82 -0
  84. data/vendor/highline-1.5.1/TODO +6 -0
  85. data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
  86. data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
  87. data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
  88. data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
  89. data/vendor/highline-1.5.1/examples/limit.rb +12 -0
  90. data/vendor/highline-1.5.1/examples/menus.rb +65 -0
  91. data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
  92. data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
  93. data/vendor/highline-1.5.1/examples/password.rb +7 -0
  94. data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
  95. data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
  96. data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
  97. data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
  98. data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
  99. data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
  100. data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
  101. data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
  102. data/vendor/highline-1.5.1/lib/highline.rb +758 -0
  103. data/vendor/highline-1.5.1/setup.rb +1360 -0
  104. data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
  105. data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
  106. data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
  107. data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
  108. data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
  109. metadata +81 -69
  110. data/lib/aws_sdb/error.rb +0 -42
  111. data/lib/aws_sdb/service.rb +0 -215
  112. data/lib/aws_sdb.rb +0 -3
  113. data/lib/rudy/aws/simpledb.rb +0 -71
  114. data/lib/rudy/cli/addresses.rb +0 -85
  115. data/lib/rudy/cli/backups.rb +0 -175
  116. data/lib/rudy/cli/domains.rb +0 -17
  117. data/lib/rudy/cli/groups.rb +0 -77
  118. data/lib/rudy/cli/images.rb +0 -111
  119. data/lib/rudy/cli/instances.rb +0 -142
  120. data/lib/rudy/cli/keypairs.rb +0 -47
  121. data/lib/rudy/cli/manager.rb +0 -51
  122. data/lib/rudy/cli/release.rb +0 -174
  123. data/lib/rudy/cli/volumes.rb +0 -121
  124. data/lib/rudy/command/addresses.rb +0 -69
  125. data/lib/rudy/command/backups.rb +0 -65
  126. data/lib/rudy/command/disks-old.rb +0 -322
  127. data/lib/rudy/command/disks.rb +0 -9
  128. data/lib/rudy/command/domains.rb +0 -34
  129. data/lib/rudy/command/groups.rb +0 -118
  130. data/lib/rudy/command/instances.rb +0 -278
  131. data/lib/rudy/command/keypairs.rb +0 -149
  132. data/lib/rudy/command/manager.rb +0 -65
  133. data/lib/rudy/command/volumes.rb +0 -127
  134. data/lib/rudy/metadata/disk.rb +0 -149
  135. data/lib/rudy/metadata/machine.rb +0 -34
  136. data/lib/rudy/routines/disk_handler.rb +0 -190
  137. data/lib/rudy/routines/script_runner.rb +0 -65
  138. data/test/50_commands/00_setup_test.rb +0 -11
  139. data/test/50_commands/10_keypairs_test.rb +0 -79
  140. data/test/50_commands/20_groups_test.rb +0 -77
  141. data/test/50_commands/40_volumes_test.rb +0 -55
  142. data/test/50_commands/50_instances_test.rb +0 -110
  143. data/tryouts/console_tryout.rb +0 -91
  144. data/tryouts/disks.rb +0 -55
  145. data/tryouts/nested_methods.rb +0 -36
  146. data/tryouts/session_tryout.rb +0 -46
@@ -1,149 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module MetaData
5
- class Disk < Storable
6
- include Rudy::Huxtable
7
-
8
- # This is a flag used internally to specify that a volume has been
9
- # created for this disk, but not yet formated.
10
- attr_accessor :raw_volume
11
-
12
- field :rtype
13
- field :awsid
14
-
15
- field :environment
16
- field :role
17
- field :path
18
- field :position
19
-
20
- field :zone
21
- field :region
22
- field :device
23
- #field :backups => Array
24
- field :size
25
-
26
- def initialize
27
- @backups = []
28
- @raw_volume = false
29
- @rtype = Disk.rtype
30
- end
31
-
32
- def self.rtype
33
- 'disk'
34
- end
35
-
36
- def name
37
- Disk.generate_name(@zone, @environment, @role, @position, @path)
38
- end
39
-
40
- def Disk.generate_name(zon, env, rol, pos, pat, sep=File::SEPARATOR)
41
- pos = pos.to_s.rjust 2, '0'
42
- dirs = pat.split sep if pat
43
- dirs.shift while dirs && (dirs[0].nil? || dirs[0].empty?)
44
- ["disk", zon, env, rol, pos, *dirs].join(RUDY_DELIM)
45
- end
46
-
47
- def valid?
48
- @zone && @environment && @role && @position && @path && @size && @device
49
- end
50
-
51
- def to_query(more=[], remove=[])
52
- criteria = [:rtype, :zone, :environment, :role, :position, :path, *more]
53
- criteria -= [*remove].flatten
54
- query = []
55
- criteria.each do |n|
56
- val = self.send(n.to_sym)
57
- query << "['#{n}' = '#{self.send(n.to_sym)}'] " if val # Only add attributes with values
58
- end
59
- query.join(" intersection ")
60
- end
61
-
62
- def to_select
63
-
64
- end
65
-
66
- def save
67
- @@sdb.store(RUDY_DOMAIN, name, self.to_hash, :replace) # Always returns nil
68
- true
69
- end
70
-
71
- def destroy
72
- @@sdb.destroy(RUDY_DOMAIN, name)
73
- true
74
- end
75
-
76
- def refresh
77
- h = @@sdb.get(RUDY_DOMAIN, name) || {}
78
- from_hash(h)
79
- end
80
-
81
- def Disk.get(dname)
82
- h = @@sdb.get(RUDY_DOMAIN, dname) || {}
83
- from_hash(h)
84
- end
85
-
86
- def is_mounted?
87
-
88
- end
89
-
90
-
91
- def format(instance)
92
- raise "No instance supplied" unless instance
93
- raise "Disk not valid" unless self.valid?
94
-
95
- begin
96
- puts "Creating the filesystem (mkfs.ext3 -F #{disk.device})".bright
97
- ssh_command instance.dns_name_public, current_user_keypairpath, @global.user, "mkfs.ext3 -F #{disk.device}"
98
- sleep 1
99
- rescue => ex
100
- @logger.puts ex.backtrace if debug?
101
- raise "Error formatting #{disk.path}: #{ex.message}"
102
- end
103
- true
104
- end
105
- def mount(instance)
106
- raise "No instance supplied" unless instance
107
- disk = find_disk(opts[:disk] || opts[:path])
108
- raise "Disk #{opts[:disk] || opts[:path]} cannot be found" unless disk
109
- switch_user(:root)
110
- begin
111
- puts "Mounting #{disk.device} to #{disk.path}".bright
112
- ssh_command instance.dns_name_public, current_user_keypairpath, @global.user, "mkdir -p #{disk.path} && mount -t ext3 #{disk.device} #{disk.path}"
113
- rescue => ex
114
- @logger.puts ex.backtrace if debug?
115
- raise "Error mounting #{disk.path}: #{ex.message}"
116
- end
117
- true
118
- end
119
-
120
- def unmount(instance)
121
- raise "No instance supplied" unless instance
122
- disk = find_disk(opts[:disk] || opts[:path])
123
- raise "Disk #{opts[:disk] || opts[:path]} cannot be found" unless disk
124
- switch_user(:root)
125
- begin
126
- puts "Unmounting #{disk.path}...".bright
127
- ssh_command instance.dns_name_public, current_user_keypairpath, global.user, "umount #{disk.path}"
128
- sleep 1
129
- rescue => ex
130
- @logger.puts ex.backtrace if debug?
131
- raise "Error unmounting #{disk.path}: #{ex.message}"
132
- end
133
- true
134
- end
135
-
136
- def to_s
137
- str = ""
138
- field_names.each do |key|
139
- str << sprintf(" %22s: %s#{$/}", key, self.send(key.to_sym))
140
- end
141
- str
142
- end
143
-
144
-
145
- end
146
-
147
- end
148
-
149
- end
@@ -1,34 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module MetaData
5
- class Machine < Storable
6
-
7
- @@rtype = 'machine'
8
-
9
- field :rtype
10
- field :awsid
11
-
12
- field :environment
13
- field :role
14
- field :path
15
- field :position
16
-
17
- field :zone
18
- field :region
19
-
20
- def initialize
21
- @rtype = @@rtype.to_s
22
- end
23
-
24
- def rtype
25
- @@rtype.to_s
26
- end
27
-
28
- def rtype=(val)
29
- end
30
-
31
-
32
- end
33
- end
34
- end
@@ -1,190 +0,0 @@
1
-
2
-
3
- module Rudy::Routines
4
- class DiskHandler
5
- include Rudy::Huxtable # @config, @global come from here
6
-
7
-
8
- # +machine+ is a Rudy::AWS::EC2::Instance object
9
- # +routines+ is a Hash config contain the disk routines.
10
- def execute(machine, routines)
11
-
12
- @logger.puts "Running DISK routines".bright
13
-
14
-
15
- unless routines
16
- @logger.puts "No #{action} disk routines."
17
- return
18
- end
19
-
20
- unless machine.awsid
21
- @logger.puts "Machine given has no instance ID. Skipping disk routines."
22
- return
23
- end
24
-
25
- unless machine.dns_name_public
26
- @logger.puts "Machine given has no DNS name: #{machine.awsid}. Skipping disk routines."
27
- return
28
- end
29
-
30
- # The order is important. We could be destroying and recreating
31
- # a disk on the same machine.
32
- destroy(machine, routines.destroy) if routines.destroy
33
- mount(machine, routines.mount) if routines.mount
34
- restore(machine, routines.restore) if routines.restore
35
- create(machine, routines.create) if routines.create
36
-
37
- end
38
-
39
-
40
- def create(machine, disk_routine)
41
-
42
- disk_routine.each_pair do |path,props|
43
-
44
- begin
45
- puts "Creating disk for #{path}"
46
-
47
- disk = Rudy::MetaData::Disk.new
48
- disk.path = path
49
- [:region, :zone, :environment, :role, :position].each do |n|
50
- disk.send("#{n}=", @global.send(n)) if @global.send(n)
51
- end
52
- [:device, :size].each do |n|
53
- disk.send("#{n}=", props[n]) if props.has_key?(n)
54
- end
55
-
56
-
57
- puts "Creating volume... (#{disk.size}GB in #{@global.zone})".bright
58
- volume = @ec2.volumes.create(disk.size, @global.zone)
59
-
60
- puts "Attaching #{volume[:aws_id]} to #{machine.awsid}".bright
61
- @ec2.volumes.attach(machine.awsid, volume[:aws_id], disk.device)
62
- sleep 6
63
-
64
- puts "Creating the filesystem (mkfs.ext3 -F #{disk.device})".bright
65
- ssh_command machine.dns_name_public, keypairpath, @global.user, "mkfs.ext3 -F #{disk.device}"
66
- sleep 3
67
-
68
- puts "Mounting #{disk.device} to #{disk.path}".bright
69
- ssh_command machine.dns_name_public, keypairpath, @global.user, "mkdir -p #{disk.path} && mount -t ext3 #{disk.device} #{disk.path}"
70
-
71
- puts "Creating disk metadata for #{disk.name}"
72
- disk.awsid = volume[:aws_id]
73
- Rudy::MetaData::Disk.save(@sdb, disk)
74
-
75
- sleep 1
76
- rescue => ex
77
- @logger.puts "There was an error creating #{path}: #{ex.message}".color(:red)
78
- @logger.puts ex.backtrace
79
- # NOTE: This isn't necessary right? B/c saving happens last so if there
80
- # is an exception, the disk metadata would never be saved.
81
- #if disk
82
- # puts "Removing metadata for #{disk.name}"
83
- # Rudy::MetaData::Disk.destroy(@sdb, disk)
84
- #end
85
- end
86
- puts
87
- end
88
- end
89
-
90
-
91
-
92
- def destroy(machine, disk_routine)
93
- disk_paths = disk_routine.keys
94
-
95
- vols = @ec2.instances.volumes(machine.awsid) || []
96
- puts "No volumes to destroy for (#{machine.awsid})" if vols.empty?
97
- vols.each do |vol|
98
- disk = Rudy::MetaData::Disk.find_from_volume(@sdb, vol[:aws_id])
99
- if disk
100
- this_path = disk.path
101
- else
102
- puts "No disk metadata for volume #{vol[:aws_id]}. Going old school..."
103
- this_path = device_to_path(machine, vol[:aws_device])
104
- end
105
-
106
- if disk_paths.member?(this_path)
107
-
108
-
109
- begin
110
- puts "Unmounting #{this_path}..."
111
- ssh_command machine.dns_name_public, keypairpath, @global.user, "umount #{this_path}"
112
- sleep 3
113
- rescue => ex
114
- puts "Error while unmounting #{this_path}: #{ex.message}"
115
- puts ex.backtrace if Drydock.debug?
116
- puts "We'll keep going..."
117
- end
118
-
119
- begin
120
-
121
- if @ec2.volumes.attached?(disk.awsid)
122
- puts "Detaching #{vol[:aws_id]}"
123
- @ec2.volumes.detach(vol[:aws_id])
124
- sleep 3 # TODO: replace with something like wait_for_machine
125
- end
126
-
127
- puts "Destroying #{this_path} (#{vol[:aws_id]})"
128
- if @ec2.volumes.available?(disk.awsid)
129
- @ec2.volumes.destroy(vol[:aws_id])
130
- else
131
- puts "Volume is still attached (maybe a web server of database is running?)"
132
- end
133
-
134
- if disk
135
- puts "Deleteing metadata for #{disk.name}"
136
- Rudy::MetaData::Disk.destroy(@sdb, disk)
137
- end
138
-
139
- rescue => ex
140
- puts "Error while detaching volume #{vol[:aws_id]}: #{ex.message}"
141
- puts ex.backtrace if Drydock.debug?
142
- puts "Continuing..."
143
- end
144
-
145
- end
146
- puts
147
-
148
- end
149
-
150
- end
151
-
152
-
153
- def mount(machine, disk_routine)
154
- disk_paths = disk_routine.keys
155
- vols = @ec2.instances.volumes(machine.awsid) || []
156
- puts "No volumes to mount for (#{machine.awsid})" if vols.empty?
157
- vols.each do |vol|
158
- disk = Rudy::MetaData::Disk.find_from_volume(@sdb, vol[:aws_id])
159
- if disk
160
- this_path = disk.path
161
- else
162
- puts "No disk metadata for volume #{vol[:aws_id]}. Going old school..."
163
- this_path = device_to_path(machine, vol[:aws_device])
164
- end
165
-
166
- next unless disk_paths.member?(this_path)
167
-
168
- begin
169
- unless @ec2.instances.attached_volume?(machine.awsid, vol[:aws_device])
170
- puts "Attaching #{vol[:aws_id]} to #{machine.awsid}".bright
171
- @ec2.volumes.attach(machine.awsid, vol[:aws_id],vol[:aws_device])
172
- sleep 3
173
- end
174
-
175
- puts "Mounting #{this_path} to #{vol[:aws_device]}".bright
176
- ssh_command machine.dns_name_public, keypairpath, @global.user, "mkdir -p #{this_path} && mount -t ext3 #{vol[:aws_device]} #{this_path}"
177
-
178
- sleep 1
179
- rescue => ex
180
- puts "There was an error mounting #{this_path}: #{ex.message}"
181
- puts ex.backtrace if Drydock.debug?
182
- end
183
- puts
184
- end
185
- end
186
-
187
-
188
-
189
- end
190
- end
@@ -1,65 +0,0 @@
1
-
2
- require 'tempfile'
3
-
4
- module Rudy::Routines
5
- class ScriptRunner
6
- include Rudy::Huxtable
7
-
8
- def execute(instance, routine, before_or_after)
9
- return false unless instance
10
-
11
- rscripts = @config.routines.find_deferred(@global.environment, @global.role, routine, before_or_after) || []
12
- rscripts &&= [rscripts].flatten # Make sure it's an Array
13
- if !rscripts || rscripts.empty?
14
- @logger.puts "No scripts defined."
15
- return
16
- end
17
-
18
- # The config file will contain settings from ~/.rudy/config
19
- script_config = @config.routines.find_deferred(@global.environment, @global.role, :config) || {}
20
- script_config[:global] = @global.marshal_dump
21
- script_config[:global].reject! { |n,v| n == :cert || n == :privatekey }
22
- script_config_filename = "#{routine}_config.yaml"
23
-
24
- tf = Tempfile.new(script_config_filename)
25
- Rudy::Utils.write_to_file(tf.path, script_config.to_hash.to_yaml, 'w')
26
-
27
- rscripts.each do |rscript|
28
- user, script = rscript.shift
29
-
30
- @logger.puts "User: #{user} (#{user_keypairpath(user)})"
31
- begin
32
- Net::SCP.start(instance.dns_name_public, user, :keys => [user_keypairpath(user)]) do |scp|
33
- scp.upload!(tf.path, "~/#{script_config_filename}") do |ch, name, sent, total|
34
- "#{name}: #{sent}/#{total}"
35
- end
36
- end
37
- rescue => ex
38
- raise "Error transfering #{script_config_filename}: #{ex.message} "
39
- end
40
-
41
- begin
42
- Net::SSH.start(instance.dns_name_public, user, :keys => [user_keypairpath(user)]) do |session|
43
-
44
- puts "Running #{script}...".bright
45
- session.exec!("chmod 700 ~/#{script_config_filename}")
46
- session.exec!("chmod 700 #{script}")
47
- puts session.exec!("#{script}")
48
-
49
- puts "Removing remote copy of #{script_filename}..."
50
- session.exec!("rm ~/#{script_config_filename}")
51
- end
52
- rescue => ex
53
- raise "Error executing #{script}: #{ex.message}"
54
- end
55
- end
56
-
57
-
58
- tf.delete # remove local copy of config_file
59
- #switch_user # return to the requested user
60
- end
61
-
62
-
63
-
64
- end
65
- end
@@ -1,11 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'helper')
2
-
3
- module Rudy::Test
4
- class Case_50_Commands < Test::Unit::TestCase
5
- include Rudy::AWS
6
-
7
- @@logger = StringIO.new
8
-
9
-
10
- end
11
- end
@@ -1,79 +0,0 @@
1
-
2
- module Rudy::Test
3
- class Case_50_Commands
4
-
5
-
6
- context "#{name}_10 KeyPairs" do
7
- setup do
8
- @rkey = Rudy::KeyPairs.new(:logger => @@logger)
9
- # So we can test with and without user specified keypairs
10
- # (stage should have keypairs configured in ./.rudy/config or Rudyfile)
11
- @rkey.global.environment = :test
12
- stop_test !@rkey.is_a?(Rudy::KeyPairs), "We need Rudy::KeyPairs (#{@rkey})"
13
- end
14
-
15
- teardown do
16
- #if @@logger && @@logger.is_a?(StringIO)
17
- # @@logger.rewind
18
- # puts @@logger.read
19
- #end
20
- end
21
-
22
- should "(10) create a keypair" do
23
- stop_test @rkey.any?, "Delete existing keypairs"
24
- kp = @rkey.create
25
- assert kp.is_a?(Rudy::AWS::EC2::KeyPair)
26
- assert @rkey.exists?(kp.name), "KeyPair not registered with Amazon"
27
- assert File.exists?(@rkey.path), "No private key: #{@rkey.path}"
28
- assert File.exists?(@rkey.public_path), "No public key: #{@rkey.public_path}"
29
- end
30
-
31
- should "(11) create a keypair with an arbitrary name" do
32
- n = "test-%s" % Rudy::Utils.strand
33
- kp = @rkey.create(n)
34
- assert kp.is_a?(Rudy::AWS::EC2::KeyPair)
35
- assert @rkey.exists?(kp.name), "KeyPair not registered with Amazon"
36
- assert File.exists?(@rkey.path(n)), "No private key: #{@rkey.path(n)}"
37
- assert File.exists?(@rkey.public_path(n)), "No public key: #{@rkey.public_path(n)}"
38
- end
39
-
40
- should "(12) not create keypair if one exists" do
41
- assert @rkey.exists?, "No #{@rkey.name} KeyPair"
42
- begin; kp = @rkey.create; rescue; end # Quiet, you!
43
- assert kp.nil?, "Keypair was still created"
44
- end
45
-
46
- should "(13) not create keypair if a root keypair is defined in config" do
47
- assert_equal (@rkey.global.environment = :keypairtest), :keypairtest # stage needs keypairs configured
48
- assert @rkey.has_root_keypair?, "No root keypair path defined in config"
49
- begin; kp = @rkey.create; rescue => ex; end
50
- assert kp.nil?, "Keypair was still created"
51
- end
52
-
53
- should "(20) list keypairs" do
54
- # We assume we've created more than one keypair before this point
55
- assert @rkey.any?, "No keypairs"
56
- assert (kp_list = @rkey.list).is_a?(Array), "List not an Array"
57
- assert kp_list.size > 1, "List not greater than 1 (#{kp_list.size})"
58
- assert (kp_hash = @rkey.list_as_hash).is_a?(Hash), "List not a Hash"
59
- end
60
-
61
- should "(30) find existing keypair for current machine group" do
62
- assert !(test_kp = @rkey.user_keypairpath(:root)).nil?, "Test keypair is nil"
63
- @rkey.global.environment = :keypairtest # user_keypairpath will now look at the stage
64
- assert !(stage_kp = @rkey.user_keypairpath(:root)).nil?, "keypairtest keypair is nil"
65
- assert test_kp != stage_kp, "Test and Stage keypairs are the same (#{test_kp}, #{stage_kp})"
66
- end
67
-
68
- should "(99) destroy keypairs" do
69
- assert @rkey.any?, "No keypairs registered"
70
- @rkey.list.each { |kp| assert @rkey.destroy(kp.name), "Not destroyed #{kp.name}" }
71
- assert !File.exists?(@rkey.path), "Still exists: #{@rkey.path}"
72
- assert !File.exists?(@rkey.public_path), "Still exists: #{@rkey.public_path}"
73
- end
74
-
75
-
76
- end
77
-
78
- end
79
- end
@@ -1,77 +0,0 @@
1
-
2
- module Rudy::Test
3
- class Case_50_Commands
4
-
5
-
6
- context "#{name}_20 Groups" do
7
- setup do
8
- @rgroup = Rudy::Groups.new(:logger => @@logger)
9
- stop_test !@rgroup.is_a?(Rudy::Groups), "We need Rudy::Groups (#{@rgroup})"
10
- end
11
-
12
- teardown do
13
- #if @@logger && @@logger.is_a?(StringIO)
14
- # @@logger.rewind
15
- # puts @@logger.read
16
- #end
17
- end
18
-
19
- should "(10) create a group" do
20
- stop_test @rgroup.any?, "Delete existing Groups"
21
- group = @rgroup.create
22
- assert group.is_a?(Rudy::AWS::EC2::Group)
23
- assert @rgroup.exists?(group.name), "Group not registered with Amazon"
24
- assert_equal group.name, @rgroup.name
25
- # We don't check the rules because we do that in the lower
26
- # level tests for Rudy::AWS::EC2::Groups.
27
- end
28
-
29
- should "(11) create a group with an arbitrary name" do
30
- n = "test-%s" % Rudy::Utils.strand
31
- group = @rgroup.create(n)
32
-
33
- assert group.is_a?(Rudy::AWS::EC2::Group)
34
- assert @rgroup.exists?(group.name), "Group #{group.name} not registered with Amazon"
35
- assert_equal group.name, n
36
- end
37
-
38
-
39
- should "(20) list groups" do
40
- assert @rgroup.any?, "No groups"
41
- assert @rgroup.exists?, "No #{@rgroup.name} group"
42
-
43
- kp_list = @rgroup.list
44
- assert kp_list.is_a?(Array), "List not an Array"
45
-
46
- kp_hash = @rgroup.list_as_hash
47
- assert kp_hash.is_a?(Hash), "List not a Hash"
48
- end
49
-
50
- should "(30) not create group if one exists" do
51
- assert @rgroup.exists?, "No #{@rgroup.name} Group"
52
- begin
53
- group = @rgroup.create
54
- rescue # Quiet, you!
55
- end
56
- assert group.nil?, "Group was still created"
57
- end
58
-
59
- xshould "(40) modify group rules" do
60
-
61
- end
62
-
63
- should "(99) destroy groups" do
64
- assert @rgroup.exists?, "Group #{@rgroup.name} doesn't exist"
65
- @rgroup.list.each do |group|
66
- next if group.name == 'default'
67
- assert @rgroup.destroy(group.name), "Did not destroy #{group.name}"
68
- end
69
- assert !@rgroup.exists?, "Group #{@rgroup.name} still exists"
70
- end
71
-
72
-
73
- end
74
-
75
-
76
- end
77
- end
@@ -1,55 +0,0 @@
1
-
2
-
3
- module Rudy::Test
4
- class Case_50_Commands
5
-
6
- context "#{name}_40 Volumes" do
7
-
8
- setup do
9
- @rvol = Rudy::Volumes.new(:logger => @@logger)
10
- stop_test !@rvol.is_a?(Rudy::Volumes), "We need Rudy::Volumes (#{@rvol})"
11
- end
12
-
13
- should "(10) create a volume" do
14
- volume_size = 2
15
- #stop_test @rvol.any?(:available), "Destroy existing volumes"
16
- volume = @rvol.create(volume_size)
17
- assert volume.is_a?(Rudy::AWS::EC2::Volume), "Not a Volume"
18
- # Should use the global zone by default
19
- assert_equal @rvol.global.zone.to_s, volume.zone, "Zone incorrect: #{volume.zone}"
20
- assert_equal volume_size.to_i, volume.size.to_i, "Size incorrect: #{volume.size}"
21
- # Rudy::Volume should wait until the volume is available before returning
22
- assert volume.available?, "Volume not available (#{volume.status})"
23
- end
24
-
25
- should "(11) list a volume as available" do
26
-
27
- end
28
-
29
- should "(20) list volumes" do
30
- volume_list = @rvol.list
31
- assert volume_list.is_a?(Array), "Not an Array"
32
- assert volume_list.size > 0, "No Volumes in Array"
33
-
34
- volume_hash = @rvol.list_as_hash
35
- assert volume_hash.is_a?(Hash), "Not a Hash"
36
- assert volume_hash.keys.size > 0, "No Volumes in Hash"
37
-
38
- assert_equal volume_list.size.to_i, volume_hash.keys.size.to_i, "Hash and Array not equal size"
39
- end
40
-
41
- should "(90) destroy volumes" do
42
- assert @rvol.any?, "No volumes"
43
- volume_list = @rvol.list
44
- volume_list.each do |vol|
45
- next unless vol.available?
46
- ret = @rvol.destroy(vol.awsid)
47
- assert ret, "Not destroyed (#{ret} for #{vol.awsid})"
48
- assert @rvol.deleting?(vol.awsid), "Volume not in deleting state (#{vol.awsid}: #{vol.state})"
49
- end
50
- end
51
- end
52
-
53
- end
54
- end
55
-