rudy 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/CHANGES.txt +54 -30
  2. data/README.rdoc +100 -12
  3. data/Rakefile +103 -8
  4. data/Rudyfile +119 -0
  5. data/bin/ird +175 -0
  6. data/bin/rudy +259 -156
  7. data/bin/rudy-ec2 +228 -95
  8. data/bin/rudy-s3 +76 -0
  9. data/bin/rudy-sdb +67 -0
  10. data/lib/annoy.rb +270 -0
  11. data/lib/console.rb +30 -9
  12. data/lib/escape.rb +305 -0
  13. data/lib/rudy.rb +151 -182
  14. data/lib/rudy/aws.rb +56 -49
  15. data/lib/rudy/aws/ec2.rb +47 -292
  16. data/lib/rudy/aws/ec2/address.rb +157 -0
  17. data/lib/rudy/aws/ec2/group.rb +301 -0
  18. data/lib/rudy/aws/ec2/image.rb +168 -0
  19. data/lib/rudy/aws/ec2/instance.rb +434 -0
  20. data/lib/rudy/aws/ec2/keypair.rb +104 -0
  21. data/lib/rudy/aws/ec2/snapshot.rb +98 -0
  22. data/lib/rudy/aws/ec2/volume.rb +230 -0
  23. data/lib/rudy/aws/ec2/zone.rb +77 -0
  24. data/lib/rudy/aws/s3.rb +54 -0
  25. data/lib/rudy/aws/sdb.rb +298 -0
  26. data/lib/rudy/aws/sdb/error.rb +46 -0
  27. data/lib/rudy/{metadata/backup.rb → backup.rb} +26 -51
  28. data/lib/rudy/cli.rb +157 -0
  29. data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
  30. data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
  31. data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
  32. data/lib/rudy/cli/aws/ec2/images.rb +196 -0
  33. data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
  34. data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
  35. data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
  36. data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
  37. data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
  38. data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
  39. data/lib/rudy/cli/aws/s3/store.rb +22 -0
  40. data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
  41. data/lib/rudy/cli/candy.rb +8 -0
  42. data/lib/rudy/{command → cli}/config.rb +34 -24
  43. data/lib/rudy/cli/disks.rb +35 -0
  44. data/lib/rudy/cli/machines.rb +94 -0
  45. data/lib/rudy/cli/routines.rb +57 -0
  46. data/lib/rudy/config.rb +77 -72
  47. data/lib/rudy/config/objects.rb +29 -0
  48. data/lib/rudy/disks.rb +248 -0
  49. data/lib/rudy/global.rb +121 -0
  50. data/lib/rudy/huxtable.rb +340 -0
  51. data/lib/rudy/machines.rb +245 -0
  52. data/lib/rudy/metadata.rb +123 -13
  53. data/lib/rudy/routines.rb +47 -0
  54. data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
  55. data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
  56. data/lib/rudy/routines/release.rb +34 -0
  57. data/lib/rudy/routines/shutdown.rb +57 -0
  58. data/lib/rudy/routines/startup.rb +58 -0
  59. data/lib/rudy/scm/svn.rb +1 -1
  60. data/lib/rudy/utils.rb +322 -4
  61. data/lib/storable.rb +26 -17
  62. data/lib/sysinfo.rb +274 -0
  63. data/lib/tryouts.rb +6 -13
  64. data/rudy.gemspec +128 -42
  65. data/support/randomize-root-password +45 -0
  66. data/support/rudy-ec2-startup +9 -9
  67. data/support/update-ec2-ami-tools +20 -0
  68. data/test/05_config/00_setup_test.rb +20 -0
  69. data/test/05_config/30_machines_test.rb +69 -0
  70. data/test/20_sdb/00_setup_test.rb +16 -0
  71. data/test/20_sdb/10_domains_test.rb +115 -0
  72. data/test/25_ec2/00_setup_test.rb +29 -0
  73. data/test/25_ec2/10_keypairs_test.rb +41 -0
  74. data/test/25_ec2/20_groups_test.rb +131 -0
  75. data/test/25_ec2/30_addresses_test.rb +38 -0
  76. data/test/25_ec2/40_volumes_test.rb +49 -0
  77. data/test/25_ec2/50_snapshots_test.rb +74 -0
  78. data/test/26_ec2_instances/00_setup_test.rb +28 -0
  79. data/test/26_ec2_instances/10_instances_test.rb +83 -0
  80. data/test/26_ec2_instances/50_images_test.rb +13 -0
  81. data/test/30_sdb_metadata/00_setup_test.rb +21 -0
  82. data/test/30_sdb_metadata/10_disks_test.rb +109 -0
  83. data/test/30_sdb_metadata/20_backups_test.rb +102 -0
  84. data/test/coverage.txt +51 -0
  85. data/test/helper.rb +36 -0
  86. data/vendor/highline-1.5.1/CHANGELOG +222 -0
  87. data/vendor/highline-1.5.1/INSTALL +35 -0
  88. data/vendor/highline-1.5.1/LICENSE +7 -0
  89. data/vendor/highline-1.5.1/README +63 -0
  90. data/vendor/highline-1.5.1/Rakefile +82 -0
  91. data/vendor/highline-1.5.1/TODO +6 -0
  92. data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
  93. data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
  94. data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
  95. data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
  96. data/vendor/highline-1.5.1/examples/limit.rb +12 -0
  97. data/vendor/highline-1.5.1/examples/menus.rb +65 -0
  98. data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
  99. data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
  100. data/vendor/highline-1.5.1/examples/password.rb +7 -0
  101. data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
  102. data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
  103. data/vendor/highline-1.5.1/lib/highline.rb +758 -0
  104. data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
  105. data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
  106. data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
  107. data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
  108. data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
  109. data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
  110. data/vendor/highline-1.5.1/setup.rb +1360 -0
  111. data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
  112. data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
  113. data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
  114. data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
  115. data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
  116. metadata +141 -38
  117. data/lib/aws_sdb.rb +0 -3
  118. data/lib/aws_sdb/error.rb +0 -42
  119. data/lib/aws_sdb/service.rb +0 -215
  120. data/lib/rudy/aws/simpledb.rb +0 -53
  121. data/lib/rudy/command/addresses.rb +0 -46
  122. data/lib/rudy/command/backups.rb +0 -175
  123. data/lib/rudy/command/base.rb +0 -841
  124. data/lib/rudy/command/deploy.rb +0 -12
  125. data/lib/rudy/command/disks.rb +0 -213
  126. data/lib/rudy/command/environment.rb +0 -73
  127. data/lib/rudy/command/groups.rb +0 -61
  128. data/lib/rudy/command/images.rb +0 -91
  129. data/lib/rudy/command/instances.rb +0 -85
  130. data/lib/rudy/command/machines.rb +0 -161
  131. data/lib/rudy/command/metadata.rb +0 -41
  132. data/lib/rudy/command/release.rb +0 -174
  133. data/lib/rudy/command/volumes.rb +0 -66
  134. data/lib/rudy/metadata/disk.rb +0 -138
  135. data/tryouts/console_tryout.rb +0 -91
@@ -0,0 +1,38 @@
1
+
2
+ module Rudy::Test
3
+
4
+ class Case_25_EC2
5
+
6
+ context "#{name}_30 Addresses" do
7
+ setup do
8
+ @ec2add = Rudy::AWS::EC2::Addresses.new(@@global.accesskey, @@global.secretkey, @@global.region)
9
+ end
10
+
11
+ should "(00) not be existing addresses" do
12
+ stop_test @ec2add.any?, "Destroy the existing addresses"
13
+ end
14
+
15
+ should "(01) create address" do
16
+ address = @ec2add.create
17
+ assert address.is_a?(Rudy::AWS::EC2::Address), "Did not create"
18
+ assert address.ipaddress.size > 0, "Address length is 0"
19
+ end
20
+
21
+ should "(10) list available addresses" do
22
+ assert @ec2add.any?, "No addresses"
23
+ assert @ec2add.list_as_hash.is_a?(Hash), "Not a Hash"
24
+ assert @ec2add.list.is_a?(Array), "Not an Array"
25
+ assert_equal 1, @ec2add.list.size, "More than one address"
26
+ end
27
+
28
+ should "(50) destroy address" do
29
+ assert @ec2add.any?, "No addresses"
30
+ @ec2add.list.each do |address|
31
+ assert @ec2add.destroy(address), "Did not destroy"
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+
2
+ module Rudy::Test
3
+ class Case_25_EC2
4
+
5
+ context "#{name}_40 Volumes" do
6
+ setup do
7
+ @ec2vol = Rudy::AWS::EC2::Volumes.new(@@global.accesskey, @@global.secretkey, @@global.region)
8
+ end
9
+
10
+ should "(00) not be existing volumes" do
11
+ volume_hash = @ec2vol.list_as_hash
12
+ volume_hash.reject! { |volid, vol| !vol.available? }
13
+ stop_test !volume_hash.empty?, "Destroy the existing volumes"
14
+ end
15
+
16
+ should "(10) create volume" do
17
+ volume_size = 2
18
+ volume = @ec2vol.create(volume_size, @@zone)
19
+ assert volume.is_a?(Rudy::AWS::EC2::Volume), "Not a Volume"
20
+ assert_equal @@zone, volume.zone, "Zone incorrect: #{volume.zone}"
21
+ assert_equal volume_size.to_i, volume.size.to_i, "Size incorrect: #{volume.size}"
22
+ assert volume.creating? || volume.available?, "Volume not creating or available (#{volume.status})"
23
+ end
24
+
25
+ should "(20) list volumes" do
26
+ volume_list = @ec2vol.list
27
+ assert volume_list.is_a?(Array), "Not an Array"
28
+ assert volume_list.size > 0, "No Volumes in Array"
29
+
30
+ volume_hash = @ec2vol.list_as_hash
31
+ assert volume_hash.is_a?(Hash), "Not a Hash"
32
+ assert volume_hash.keys.size > 0, "No Volumes in Hash"
33
+
34
+ assert_equal volume_list.size.to_i, volume_hash.keys.size.to_i, "Hash and Array not equal size"
35
+ end
36
+
37
+ should "(50) destroy volumes" do
38
+ assert @ec2vol.any?, "No volumes"
39
+ volume_list = @ec2vol.list
40
+ volume_list.each do |vol|
41
+ next unless vol.available?
42
+ assert @ec2vol.destroy(vol.awsid), "Not destroyed (#{vol.awsid})"
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,74 @@
1
+
2
+ module Rudy::Test
3
+ class Case_25_EC2
4
+
5
+
6
+
7
+ context "#{name}_50 Snapshots" do
8
+ setup do
9
+ @ec2vol = Rudy::AWS::EC2::Volumes.new(@@global.accesskey, @@global.secretkey, @@global.region)
10
+ @ec2snap = Rudy::AWS::EC2::Snapshots.new(@@global.accesskey, @@global.secretkey, @@global.region)
11
+ end
12
+
13
+
14
+ should "(00) be no snapshots" do
15
+ stop_test @ec2snap.any?, "Destroy existing snapshots"
16
+ end
17
+
18
+ should "(01) create a volume to work off of" do
19
+ @@volumes ||= []
20
+ @@volumes << @ec2vol.create(1, @@zone)
21
+ stop_test !@@volumes.first.is_a?(Rudy::AWS::EC2::Volume), "No volume to work off of."
22
+ end
23
+
24
+ should "(01) create snapshot" do
25
+ stop_test !@@volumes.first.is_a?(Rudy::AWS::EC2::Volume), "No volume to work off of."
26
+ assert !@@volumes.first.awsid.empty?, "No volume ID"
27
+ @ec2snap.create(@@volumes.first.awsid)
28
+ end
29
+
30
+ should "(10) list snapshots" do
31
+ snap_list = @ec2snap.list
32
+ assert snap_list.is_a?(Array), "Not an Array"
33
+ assert snap_list.size > 0, "No Snapshots in Array"
34
+
35
+ snap_hash = @ec2snap.list_as_hash
36
+ assert snap_hash.is_a?(Hash), "Not an Hash"
37
+ assert snap_hash.keys.size > 0, "No Snapshots in Hash"
38
+ end
39
+
40
+ should "(20) create volume from snapshot" do
41
+ volume_size = 2
42
+ snap_list = @ec2snap.list || []
43
+ assert !snap_list.empty?, "No snapshots"
44
+
45
+ volume = @ec2vol.create(volume_size, @@zone, snap_list.first.awsid)
46
+ #puts "#{volume.awsid} #{snap_list.first.awsid}"
47
+
48
+ assert volume.is_a?(Rudy::AWS::EC2::Volume), "Not a Volume"
49
+ assert_equal @@zone, volume.zone, "Zone incorrect: #{volume.zone}"
50
+ assert_equal snap_list.first.awsid, volume.snapid, "Snapshot mismatch: #{volume.snapid}"
51
+ assert_equal volume_size.to_i, volume.size.to_i, "Size incorrect: #{volume.size}"
52
+ assert volume.creating? || volume.available?, "Volume not creating or available (#{volume.status})"
53
+
54
+ @@volumes << volume # We put it here so it will be destoryed in teardown
55
+ end
56
+
57
+ should "(90) destroy snapshots" do
58
+ assert @ec2snap.any?, "No snapshots"
59
+ snap_list = @ec2snap.list
60
+ snap_list.each do |snap|
61
+ next unless snap.completed?
62
+ assert @ec2snap.destroy(snap.awsid), "Not destroyed (#{snap.awsid})"
63
+ end
64
+ end
65
+
66
+ should "(99) cleanup created volumes" do
67
+ (@@volumes || []).each do |vol|
68
+ assert @ec2vol.destroy(vol), "Volume not destoryed (#{vol.awsid})"
69
+ end
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,28 @@
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_26_EC2 < Test::Unit::TestCase
12
+ include Rudy::Huxtable
13
+
14
+ @@logger = STDERR #StringIO.new
15
+ @@zone = @@global.zone.to_s
16
+
17
+ context "#{name}_10 Setup" do
18
+ should "(10) have class variables setup" do
19
+ stop_test !@@global.is_a?(Rudy::Global), "We don't have Rudy::Global (#{@@global})"
20
+ stop_test !@@config.is_a?(Rudy::Config), "We don't have an instance of Rudy::Config (#{@@config})"
21
+ end
22
+ should "(11) be zone" do
23
+ stop_test !@@zone, "No zone"
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,83 @@
1
+
2
+ module Rudy::Test
3
+ class Case_26_EC2
4
+
5
+ context "#{name}_10 Instances" do
6
+
7
+ setup do
8
+ @ec2inst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
9
+ @ec2add = Rudy::AWS::EC2::Addresses.new(@@global.accesskey, @@global.secretkey, @@global.region)
10
+ @us_ami = @@config.machines.find(:"us-east-1b", :ami)
11
+ @eu_ami = @@config.machines.find(:"eu-west-1b", :ami)
12
+ end
13
+
14
+ should "(10) create instance" do
15
+ stop_test @ec2inst.any?(:running), "Destroy the existing instances"
16
+ instances = @ec2inst.create(:ami => 'ami-235fba4a', :group => "default") # Amazon Getting Started AMI
17
+ assert instances.is_a?(Array), "Not an Array of instances"
18
+ instances.each do |instance|
19
+ Rudy::Utils.waiter(2, 120, @@logger) { @ec2inst.running?(instance) }
20
+ assert instance.is_a?(Rudy::AWS::EC2::Instance), "Not an Rudy::AWS::EC2::Instance object"
21
+ end
22
+ end
23
+
24
+ testnum = 20
25
+ Rudy::AWS::EC2::Instances::KNOWN_STATES.each do |state|
26
+ should "(#{testnum}) know instance is #{state}" do
27
+ instances = @ec2inst.list(state) || []
28
+ return skip("No instances are in #{state} state") if instances.empty?
29
+ instances.each do |inst|
30
+ assert @ec2inst.send("#{state}?", inst) # running?(inst)
31
+ end
32
+ end
33
+ testnum += 1
34
+ end
35
+
36
+ should "(30) list instance" do
37
+ assert @ec2inst.list.is_a?(Array), "Not an Array of instances"
38
+ assert @ec2inst.list_as_hash.is_a?(Hash), "Not a Hash of instances"
39
+ end
40
+
41
+ should "(31) console" do
42
+ @ec2inst.list.each do |inst|
43
+ assert @ec2inst.console_output(inst).is_a?(String), "No console output for (#{inst.awsid})"
44
+ end
45
+ end
46
+
47
+ should "(40) assign IP address to instance" do
48
+ assigned = 0
49
+ @ec2inst.list.each do |instance|
50
+ next if instance.terminated? || instance.shutting_down?
51
+ assigned += 1
52
+ address = @ec2add.create
53
+ assert @ec2add.associate(address, instance), "Did not assign"
54
+ end
55
+ assert assigned > 0, "No machine running"
56
+ end
57
+
58
+
59
+ should "(60) restart instance" do
60
+ instances = @ec2inst.list(:running)
61
+ instances.each do |instance|
62
+ assert @ec2inst.restart(instance), "Did not restart"
63
+ end
64
+ end
65
+
66
+ should "(99) destroy instance" do
67
+ assert @ec2inst.any?(:running), "No instances running"
68
+ instances = @ec2inst.list(:running)
69
+ return skip("No running instances") unless instances
70
+ instances.each do |instance|
71
+ assert @ec2inst.destroy(instance), "Did not destroy"
72
+ end
73
+ end
74
+
75
+ should "(99) clean created addresses" do
76
+ (@ec2add.list || []).each do |address|
77
+ assert @ec2add.destroy(address), "Address not destroyed (#{address})"
78
+ end
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,13 @@
1
+ module Rudy::Test
2
+ class Case_26_EC2
3
+
4
+ context "#{name} Images" do
5
+ should "nothing" do
6
+ assert true
7
+ end
8
+
9
+ end
10
+
11
+
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'helper')
2
+
3
+ module Rudy::Test
4
+ class Case_30_MetaData < Test::Unit::TestCase
5
+ include Rudy::Huxtable
6
+
7
+ @@logger = StringIO.new
8
+
9
+ context "#{name}_00 Setup" do
10
+ should "(00) have class variables setup" do
11
+ stop_test !@@global.is_a?(Rudy::Global), "We don't have global (#{@@global})"
12
+ stop_test !@@config.is_a?(Rudy::Config), "We don't have an instance of Rudy::Config (#{@@config})"
13
+ end
14
+ end
15
+
16
+ at_exit {
17
+ @@logger.rewind
18
+ puts @@logger.read
19
+ }
20
+ end
21
+ end
@@ -0,0 +1,109 @@
1
+ module Rudy::Test
2
+ class Case_30_MetaData
3
+
4
+
5
+ context "#{name}_10 Disks" do
6
+
7
+ setup do
8
+ @sdb = Rudy::AWS::SDB.new(@@global.accesskey, @@global.secretkey, @@global.region)
9
+ #@ami = @@config.machines.find(@@zone.to_sym, :ami)
10
+ end
11
+
12
+
13
+ should "(00) have global setup" do
14
+ [:region, :zone, :environment, :role, :position].each do |n|
15
+ assert @@global.respond_to?(n), "No global #{n}"
16
+ end
17
+ end
18
+
19
+ should "(01) have domain" do
20
+ assert @sdb.create_domain(Rudy::DOMAIN), "Domain not created (#{Rudy::DOMAIN})"
21
+ end
22
+
23
+
24
+ should "(10) create a disk object" do
25
+ disk = Rudy::Disk.new('/rudy/disk', 1, '/dev/sdh')
26
+
27
+ disk_name_elements = []
28
+ [:zone, :environment, :role, :position].each do |n|
29
+ disk_name_elements << @@global.send(n)
30
+ end
31
+
32
+ # disk-us-east-1b-stage-app-01-rudy-disk
33
+ disk_name = ['disk', disk_name_elements, 'rudy', 'disk'].join(Rudy::DELIM)
34
+
35
+ assert_equal disk_name, disk.name, "Unexpected disk name #{disk.name}"
36
+ assert disk.valid?, "Disk not valid"
37
+
38
+ end
39
+
40
+ should "(11) save a disk object" do
41
+ disk = Rudy::Disk.new('/rudy/disk', 1, '/dev/sdh')
42
+ assert disk.is_a?(Rudy::Disk), "Not a Rudy::Disk (#{disk})"
43
+ assert disk.save, "Did not save #{disk.name}"
44
+ end
45
+
46
+ should "(20) list metadata with select" do
47
+ q = "select * from #{Rudy::DOMAIN}"
48
+
49
+ items = @sdb.select(q)
50
+ #p items
51
+ assert_equal Hash, items.class
52
+ assert items.size > 0, "No disks"
53
+ assert_equal @@global.zone.to_s, items.values.first['zone'].first.to_s
54
+ end
55
+
56
+ should "(22) list disk metadata with select" do
57
+ q = "select * from #{Rudy::DOMAIN} where rtype = 'disk'"
58
+ items = @sdb.select(q)
59
+ assert_equal Hash, items.class
60
+ assert items.size > 0, "No disks"
61
+ assert_equal @@global.zone.to_s, items.values.first['zone'].first.to_s
62
+ end
63
+
64
+ should "(23) list disk metadata with query" do
65
+ q = "select * from #{Rudy::DOMAIN} where rtype = 'disk'"
66
+
67
+ items = @sdb.query_with_attributes(Rudy::DOMAIN, "['rtype' = 'disk']")
68
+ assert_equal Hash, items.class
69
+ assert items.size > 0, "No disks"
70
+ assert_equal @@global.zone.to_s, items.values.first['zone'].first.to_s
71
+ end
72
+
73
+ should "(30) get disk from Rudy::Disks, modify, and save" do
74
+ disk_tmp = Rudy::Disk.new('/rudy/disk', 1, '/dev/sdh')
75
+ rdisk = Rudy::Disks.new
76
+ disk_orig = rdisk.get(disk_tmp.name)
77
+ assert_equal Rudy::Disk, disk_orig.class, "Not a Rudy::Disk #{disk_orig}"
78
+ assert_equal @@global.zone.to_s, disk_orig.zone.to_s, "Unexpected zone #{disk_orig.zone}"
79
+ sleep 1
80
+ disk_orig.size = 2
81
+ assert disk_orig.save, "Did not save #{disk_orig.name}"
82
+ disk_new = rdisk.get(disk_orig.name)
83
+ assert_equal disk_orig.size, disk_new.size, "Different size #{disk_new.size}"
84
+ assert disk_new.destroy, "Did not destroy #{disk_new.name}"
85
+ end
86
+
87
+
88
+ xshould "(90) destroy all disk metadata" do
89
+ # disabled b/c there are disks at this point. Previous tests delete them.
90
+ q = "select * from #{Rudy::DOMAIN} where rtype = 'disk'"
91
+ items = @sdb.select(q)
92
+ p items
93
+ assert_equal Hash, items.class
94
+ items.keys.each do |item|
95
+ @sdb.destroy(Rudy::DOMAIN, item)
96
+ end
97
+ end
98
+
99
+ should "(99) destroy domain" do
100
+ assert @sdb.destroy_domain(Rudy::DOMAIN), "Domain not destroyed (#{Rudy::DOMAIN})"
101
+ end
102
+
103
+ end
104
+
105
+
106
+
107
+
108
+ end
109
+ end
@@ -0,0 +1,102 @@
1
+ module Rudy::Test
2
+ class Case_30_MetaData
3
+
4
+ def create_backup
5
+ back = Rudy::MetaData::Backup.new
6
+ [:region, :zone, :environment, :role, :position].each do |n|
7
+ back.send("#{n}=", @@global.send(n))
8
+ end
9
+
10
+ back.path = "/rudy/disk"
11
+ back.size = 10
12
+
13
+ back
14
+ end
15
+
16
+ def format_timestamp(dat)
17
+ mon, day, hour, min, sec = [dat.mon, dat.day, dat.hour, dat.min, dat.sec].collect { |v| v.to_s.rjust(2, "0") }
18
+ [dat.year, mon, day, Rudy::DELIM, hour, min, Rudy::DELIM, sec].join
19
+ end
20
+
21
+ context "#{name}_20 Backups" do
22
+
23
+ should "(00) have global setup" do
24
+ [:region, :zone, :environment, :role, :position].each do |n|
25
+ assert @@global.respond_to?(n), "No global #{n}"
26
+ end
27
+ end
28
+
29
+ should "(01) have domain" do
30
+ #assert @@sdb.domains.create(Rudy::DOMAIN), "Domain not created (#{Rudy::DOMAIN})"
31
+ end
32
+
33
+
34
+ should "(10) create a backup object" do
35
+ back = create_backup
36
+
37
+ back_name = []
38
+ [:region, :zone, :environment, :role, :position].each do |n|
39
+ back_name << @@global.send(n)
40
+ end
41
+
42
+ back_time = format_timestamp(Time.now.utc)
43
+
44
+ back_name.shift # don't use region in backup name, but add the backup identifier and path
45
+ back_name = ['back', back_name, 'rudy', 'disk', back_time].join(Rudy::DELIM)
46
+ assert_equal back_name, back.name
47
+
48
+ assert back.valid?, "Bcakup not valid"
49
+
50
+ back.save
51
+ end
52
+
53
+ should "(20) list metadata" do
54
+ q = "select * from #{Rudy::DOMAIN}"
55
+
56
+ items = @@sdb.select(q)
57
+ assert_equal Hash, items.class
58
+ assert items.size > 0, "No backups"
59
+ assert_equal @@global.zone.to_s, items.values.first['zone'].first.to_s
60
+ end
61
+
62
+ should "(22) list backup metadata with select" do
63
+ q = "select * from #{Rudy::DOMAIN} where rtype = 'back'"
64
+ items = @@sdb.select(q)
65
+ assert_equal Hash, items.class
66
+ assert items.size > 0, "No backups"
67
+ assert_equal @@global.zone.to_s, items.values.first['zone'].first.to_s
68
+ end
69
+
70
+ should "(23) list backup metadata with query" do
71
+ q = "select * from #{Rudy::DOMAIN} where rtype = 'back'"
72
+
73
+ items = @@sdb.query_with_attributes(Rudy::DOMAIN, "['rtype' = 'back']")
74
+ assert_equal Hash, items.class
75
+ assert items.size > 0, "No backups"
76
+ assert_equal @@global.zone.to_s, items.values.first['zone'].first.to_s
77
+ end
78
+
79
+ should "(30) get backup metadata" do
80
+ back_tmp = create_backup
81
+ back = Rudy::MetaData::Backup.get(back_tmp.name)
82
+ assert_equal Rudy::MetaData::Backup, back.class
83
+ assert_equal @@global.zone.to_s, back.zone.to_s
84
+
85
+ end
86
+
87
+ should "(40) destroy backup metadata" do
88
+ q = "select * from #{Rudy::DOMAIN} where rtype = 'back'"
89
+ items = @@sdb.select(q)
90
+ assert_equal Hash, items.class
91
+ items.keys.each do |item|
92
+ @@sdb.destroy(Rudy::DOMAIN, item)
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+
99
+
100
+
101
+ end
102
+ end