solusvm 1.0.0.beta3 → 1.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +10 -4
  3. data/LICENSE +1 -1
  4. data/README.markdown +1 -1
  5. data/lib/solusvm.rb +2 -2
  6. data/lib/solusvm/base.rb +10 -32
  7. data/lib/solusvm/cli/base_cli.rb +30 -5
  8. data/lib/solusvm/cli/client_cli.rb +9 -9
  9. data/lib/solusvm/cli/general_cli.rb +5 -5
  10. data/lib/solusvm/cli/node_cli.rb +8 -8
  11. data/lib/solusvm/cli/reseller_cli.rb +7 -7
  12. data/lib/solusvm/cli/server_cli.rb +31 -31
  13. data/lib/solusvm/solusvm_errors.rb +22 -0
  14. data/lib/solusvm/version.rb +1 -1
  15. data/solusvm.gemspec +2 -0
  16. data/test/cli/test_base_cli.rb +32 -0
  17. data/test/cli/test_client_cli.rb +38 -21
  18. data/test/cli/test_general_cli.rb +13 -4
  19. data/test/cli/test_node_cli.rb +28 -14
  20. data/test/cli/test_reseller_cli.rb +69 -58
  21. data/test/cli/test_server_cli.rb +128 -39
  22. data/test/solusvm/test_base.rb +103 -0
  23. data/test/{test_cli.rb → solusvm/test_cli.rb} +1 -1
  24. data/test/solusvm/test_client.rb +109 -0
  25. data/test/solusvm/test_general.rb +69 -0
  26. data/test/{test_hash.rb → solusvm/test_hash.rb} +1 -1
  27. data/test/solusvm/test_node.rb +120 -0
  28. data/test/solusvm/test_reseller.rb +93 -0
  29. data/test/solusvm/test_server.rb +253 -0
  30. data/test/{helper.rb → test_helper.rb} +19 -4
  31. data/test/test_solusvm.rb +1 -1
  32. data/test/vcr_cassettes/base/invalid_key.yml +19 -0
  33. data/test/vcr_cassettes/base/invalid_status.yml +19 -0
  34. data/test/vcr_cassettes/base/nonexistent_node.yml +19 -0
  35. data/test/vcr_cassettes/base/parse_response.yml +28 -0
  36. data/test/vcr_cassettes/base/statusmsg.yml +28 -0
  37. data/test/vcr_cassettes/base/successful.yml +45 -0
  38. data/test/vcr_cassettes/base/unauthorized_ip.yml +19 -0
  39. data/test/vcr_cassettes/client/authenticate.yml +37 -0
  40. data/test/vcr_cassettes/client/change_password.yml +39 -0
  41. data/test/vcr_cassettes/client/create.yml +42 -0
  42. data/test/vcr_cassettes/client/delete.yml +37 -0
  43. data/test/vcr_cassettes/client/exists.yml +20 -0
  44. data/test/vcr_cassettes/client/list.yml +66 -0
  45. data/test/vcr_cassettes/general/isos.yml +38 -0
  46. data/test/vcr_cassettes/general/plans.yml +38 -0
  47. data/test/vcr_cassettes/general/templates.yml +38 -0
  48. data/test/vcr_cassettes/node/available_ips.yml +41 -0
  49. data/test/vcr_cassettes/node/ids.yml +21 -0
  50. data/test/vcr_cassettes/node/list.yml +38 -0
  51. data/test/vcr_cassettes/node/statistics.yml +32 -0
  52. data/test/vcr_cassettes/node/virtualservers.yml +67 -0
  53. data/test/vcr_cassettes/node/xenresources.yml +22 -0
  54. data/test/vcr_cassettes/reseller/change_resources.yml +27 -0
  55. data/test/vcr_cassettes/reseller/create.yml +27 -0
  56. data/test/vcr_cassettes/reseller/delete.yml +15 -0
  57. data/test/vcr_cassettes/reseller/info.yml +27 -0
  58. data/test/vcr_cassettes/reseller/list.yml +27 -0
  59. data/test/vcr_cassettes/server/.yml +1017 -0
  60. data/test/vcr_cassettes/server/boot.yml +15 -0
  61. data/test/vcr_cassettes/server/change_bootorder.yml +15 -0
  62. data/test/vcr_cassettes/server/change_consolepass.yml +16 -0
  63. data/test/vcr_cassettes/server/change_hostname.yml +15 -0
  64. data/test/vcr_cassettes/server/change_owner.yml +15 -0
  65. data/test/vcr_cassettes/server/change_plan.yml +15 -0
  66. data/test/vcr_cassettes/server/change_rootpassword.yml +15 -0
  67. data/test/vcr_cassettes/server/change_vncpass.yml +15 -0
  68. data/test/vcr_cassettes/server/console.yml +15 -0
  69. data/test/vcr_cassettes/server/create.yml +27 -0
  70. data/test/vcr_cassettes/server/exists.yml +15 -0
  71. data/test/vcr_cassettes/server/info.yml +27 -0
  72. data/test/vcr_cassettes/server/info_all.yml +15 -0
  73. data/test/vcr_cassettes/server/mountiso.yml +15 -0
  74. data/test/vcr_cassettes/server/network_disable.yml +15 -0
  75. data/test/vcr_cassettes/server/network_enable.yml +15 -0
  76. data/test/vcr_cassettes/server/pae_disable.yml +15 -0
  77. data/test/vcr_cassettes/server/pae_enable.yml +15 -0
  78. data/test/vcr_cassettes/server/reboot.yml +15 -0
  79. data/test/vcr_cassettes/server/rebuild.yml +15 -0
  80. data/test/vcr_cassettes/server/resume.yml +15 -0
  81. data/test/vcr_cassettes/server/shutdown.yml +15 -0
  82. data/test/vcr_cassettes/server/status.yml +15 -0
  83. data/test/vcr_cassettes/server/suspend.yml +15 -0
  84. data/test/vcr_cassettes/server/terminate.yml +27 -0
  85. data/test/vcr_cassettes/server/tun_disable.yml +15 -0
  86. data/test/vcr_cassettes/server/tun_enable.yml +15 -0
  87. data/test/vcr_cassettes/server/unmountiso.yml +15 -0
  88. data/test/vcr_cassettes/server/vnc.yml +15 -0
  89. metadata +220 -156
  90. data/.rbenv-version +0 -1
  91. data/.rvmrc +0 -47
  92. data/test/fixtures/base_bad_key.txt +0 -1
  93. data/test/fixtures/base_node_does_not_exist.txt +0 -1
  94. data/test/fixtures/base_unauthorized_ip.txt +0 -1
  95. data/test/fixtures/client_authenticate_error.txt +0 -2
  96. data/test/fixtures/client_authenticate_success.txt +0 -2
  97. data/test/fixtures/client_change_password_error.txt +0 -2
  98. data/test/fixtures/client_change_password_success.txt +0 -4
  99. data/test/fixtures/client_create_error.txt +0 -2
  100. data/test/fixtures/client_create_success.txt +0 -7
  101. data/test/fixtures/client_delete_success.txt +0 -2
  102. data/test/fixtures/client_exists_success.txt +0 -2
  103. data/test/fixtures/client_list_success.txt +0 -14
  104. data/test/fixtures/client_list_success_empty.txt +0 -2
  105. data/test/fixtures/error.txt +0 -2
  106. data/test/fixtures/general_isos_success.txt +0 -3
  107. data/test/fixtures/general_plans_success.txt +0 -3
  108. data/test/fixtures/general_templates_success.txt +0 -3
  109. data/test/fixtures/node_list_all_ips_available.txt +0 -4
  110. data/test/fixtures/node_list_all_ips_not_available.txt +0 -4
  111. data/test/fixtures/node_statistics_success.txt +0 -14
  112. data/test/fixtures/node_virtualservers_success.txt +0 -15
  113. data/test/fixtures/node_virtualservers_success_empty.txt +0 -2
  114. data/test/fixtures/node_xenresources_success.txt +0 -4
  115. data/test/fixtures/nodes_ids_success.txt +0 -3
  116. data/test/fixtures/nodes_list_success.txt +0 -3
  117. data/test/fixtures/reseller_change_resources_success.txt +0 -16
  118. data/test/fixtures/reseller_create_success.txt +0 -23
  119. data/test/fixtures/reseller_delete_success.txt +0 -2
  120. data/test/fixtures/reseller_info_success.txt +0 -23
  121. data/test/fixtures/reseller_list_success.txt +0 -3
  122. data/test/fixtures/server_boot_success.txt +0 -2
  123. data/test/fixtures/server_bootorder_success.txt +0 -2
  124. data/test/fixtures/server_change_consolepass_success.txt +0 -3
  125. data/test/fixtures/server_change_owner_success.txt +0 -2
  126. data/test/fixtures/server_change_success.txt +0 -2
  127. data/test/fixtures/server_change_vncpass_success.txt +0 -3
  128. data/test/fixtures/server_console_success.txt +0 -7
  129. data/test/fixtures/server_create_success.txt +0 -10
  130. data/test/fixtures/server_exists_success.txt +0 -2
  131. data/test/fixtures/server_hostname_success.txt +0 -3
  132. data/test/fixtures/server_info_success.txt +0 -10
  133. data/test/fixtures/server_infoall_success.txt +0 -13
  134. data/test/fixtures/server_mountiso_success.txt +0 -2
  135. data/test/fixtures/server_network_disable_success.txt +0 -2
  136. data/test/fixtures/server_network_enable_success.txt +0 -2
  137. data/test/fixtures/server_pae_success.txt +0 -2
  138. data/test/fixtures/server_reboot_success.txt +0 -2
  139. data/test/fixtures/server_rebuild_success.txt +0 -2
  140. data/test/fixtures/server_resume_success.txt +0 -2
  141. data/test/fixtures/server_rootpassword_success.txt +0 -3
  142. data/test/fixtures/server_shutdown_success.txt +0 -2
  143. data/test/fixtures/server_status_success.txt +0 -2
  144. data/test/fixtures/server_suspend_success.txt +0 -2
  145. data/test/fixtures/server_terminate_success.txt +0 -2
  146. data/test/fixtures/server_tun_disable_success.txt +0 -2
  147. data/test/fixtures/server_tun_enable_success.txt +0 -2
  148. data/test/fixtures/server_unmountiso_success.txt +0 -2
  149. data/test/fixtures/server_vnc_success.txt +0 -6
  150. data/test/test_base.rb +0 -115
  151. data/test/test_client.rb +0 -98
  152. data/test/test_general.rb +0 -70
  153. data/test/test_node.rb +0 -112
  154. data/test/test_reseller.rb +0 -80
  155. data/test/test_server.rb +0 -227
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
  require 'solusvm/cli'
3
3
 
4
4
  class TestCli < Test::Unit::TestCase
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class TestClient < Test::Unit::TestCase
4
+
5
+ def setup
6
+ setup_solusvm
7
+ @client = Solusvm::Client.new
8
+ end
9
+
10
+ def test_create
11
+ options = {:username => 'vps123', :password=> '123456', :email=> 'email@address.com', :firstname => 'phill', :lastname => 'smith'}
12
+ VCR.use_cassette "client/create" do
13
+ @client.create(options)
14
+ end
15
+ params = @client.returned_parameters
16
+ assert_equal options[:username], params['username']
17
+ assert_equal options[:firstname], params['firstname']
18
+ assert_equal options[:lastname], params['lastname']
19
+ assert_equal options[:password], params['password']
20
+ assert_equal options[:email], params['email']
21
+ assert_equal 'Successfully added client', params['statusmsg']
22
+ assert_equal 'success', params['status']
23
+ end
24
+
25
+ def test_create_fail
26
+ VCR.use_cassette "client/create" do
27
+ assert ! @client.create
28
+ end
29
+ assert_equal 'Empty username field', @client.statusmsg
30
+ end
31
+
32
+ def test_exists
33
+ VCR.use_cassette "client/exists" do
34
+ assert @client.exists?("vps123")
35
+ end
36
+ assert_equal 'Client exists', @client.statusmsg
37
+ end
38
+
39
+ def test_change_password
40
+ VCR.use_cassette "client/change_password" do
41
+ assert @client.change_password("vps123","123456")
42
+ end
43
+ end
44
+
45
+ def test_change_password_fail
46
+ VCR.use_cassette "client/change_password" do
47
+ assert ! @client.change_password("vps13","thecake")
48
+ end
49
+ end
50
+
51
+ def test_authenticate
52
+ VCR.use_cassette "client/authenticate" do
53
+ assert @client.authenticate('u', 'p')
54
+ end
55
+ end
56
+
57
+ def test_authenticate_fail
58
+ VCR.use_cassette "client/authenticate" do
59
+ assert ! @client.authenticate('u', 'notp')
60
+ end
61
+ assert_equal 'invalid username or password', @client.statusmsg
62
+ end
63
+
64
+ def test_delete
65
+ VCR.use_cassette "client/delete" do
66
+ assert @client.delete("vps123")
67
+ end
68
+ end
69
+
70
+ def test_delete_fail
71
+ VCR.use_cassette "client/delete" do
72
+ assert !@client.delete("novps")
73
+ end
74
+ end
75
+
76
+ def test_list
77
+ Solusvm.config("api_id1", api_login[:key], :url => 'http://www.example.com/api')
78
+ VCR.use_cassette "client/list" do
79
+ @client.list
80
+ end
81
+
82
+ client = @client.returned_parameters["clients"]["client"].first
83
+
84
+ assert_equal "1", client["id"]
85
+ assert_equal "vps123", client["username"]
86
+ assert_equal "vps123@email.com", client["email"]
87
+ assert_equal "phill", client["firstname"]
88
+ assert_equal "smith", client["lastname"]
89
+ assert_equal "VPS Co", client["company"]
90
+ assert_equal "Client", client["level"]
91
+ assert_equal "Active", client["status"]
92
+ assert_equal "2009-01-01", client["created"]
93
+ assert_equal "2010-04-23", client["lastlogin"]
94
+ end
95
+
96
+ def test_list_empty
97
+ Solusvm.config("api_id2", api_login[:key], :url => 'http://www.example.com/api')
98
+ VCR.use_cassette "client/list" do
99
+ assert @client.list.empty?
100
+ end
101
+ end
102
+
103
+ def test_list_fail
104
+ Solusvm.config("api_id3", api_login[:key], :url => 'http://www.example.com/api')
105
+ VCR.use_cassette "client/list" do
106
+ assert_nil @client.list
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class TestGeneral < Test::Unit::TestCase
4
+ def setup
5
+ setup_solusvm
6
+ @general = Solusvm::General.new
7
+ end
8
+
9
+ def test_templates
10
+ VCR.use_cassette "general/templates" do
11
+ assert_equal %w(template1 template2 template3), @general.templates('xen')
12
+ end
13
+ end
14
+
15
+ # TODO: Refactor so that the lib is not validating server types
16
+ def test_templates_empty
17
+ VCR.use_cassette "general/templates" do
18
+ assert !@general.templates('openvz')
19
+ end
20
+ end
21
+
22
+ def test_templates_with_invalid_type
23
+ VCR.use_cassette "general/templates" do
24
+ assert_raise Solusvm::SolusvmError do
25
+ @general.templates('badserver')
26
+ end
27
+ end
28
+ end
29
+
30
+ def test_plans
31
+ VCR.use_cassette "general/plans" do
32
+ assert_equal %w(plan1 plan2 plan3 plan4), @general.plans('xen')
33
+ end
34
+ end
35
+
36
+ def test_plans_empty
37
+ VCR.use_cassette "general/plans" do
38
+ assert !@general.plans('openvz')
39
+ end
40
+ end
41
+
42
+ def test_plans_with_invalid_type
43
+ VCR.use_cassette "general/plans" do
44
+ assert_raise Solusvm::SolusvmError do
45
+ @general.plans('whatever')
46
+ end
47
+ end
48
+ end
49
+
50
+ def test_isos
51
+ VCR.use_cassette "general/isos" do
52
+ assert_equal %w(iso1 iso2 iso3), @general.isos('xen')
53
+ end
54
+ end
55
+
56
+ def test_isos_empty
57
+ VCR.use_cassette "general/isos" do
58
+ assert !@general.isos('openvz')
59
+ end
60
+ end
61
+
62
+ def test_isos_with_invalid_type
63
+ VCR.use_cassette "general/isos" do
64
+ assert_raise Solusvm::SolusvmError do
65
+ @general.isos('whatever')
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
 
3
3
  class TestHash < Test::Unit::TestCase
4
4
  def test_reverse_merge
@@ -0,0 +1,120 @@
1
+ require 'test_helper'
2
+
3
+ class TestNode < Test::Unit::TestCase
4
+ def setup
5
+ setup_solusvm
6
+ @nodes = Solusvm::Node.new
7
+ end
8
+
9
+ def test_list
10
+ VCR.use_cassette "node/list" do
11
+ assert_equal %w(node1 node2 node3 node4), @nodes.list('xen')
12
+ end
13
+ end
14
+
15
+ def test_list_empty
16
+ VCR.use_cassette "node/list" do
17
+ assert !@nodes.list('openvz')
18
+ end
19
+ end
20
+
21
+ def test_nodes_with_invalid_type
22
+ assert_raise Solusvm::SolusvmError do
23
+ @nodes.list('whatever')
24
+ end
25
+ end
26
+
27
+ def test_statistics
28
+ VCR.use_cassette "node/statistics" do
29
+ @nodes.statistics(1)
30
+ end
31
+
32
+ node_statistics = @nodes.returned_parameters
33
+
34
+ assert_equal '1000', node_statistics['freedisk']
35
+ assert_equal '22', node_statistics['sshport']
36
+ assert_equal 'city', node_statistics['city']
37
+ assert_equal 'name', node_statistics['name']
38
+ assert_equal '0', node_statistics['freeips']
39
+ assert_equal 'country', node_statistics['country']
40
+ assert_equal 'x86_64', node_statistics['arch']
41
+ assert_equal '1', node_statistics['id']
42
+ assert_equal '10', node_statistics['freememory']
43
+ assert_equal '2', node_statistics['virtualservers']
44
+ assert_equal '127.0.0.1', node_statistics['ip']
45
+ assert_equal 'hostname.com', node_statistics['hostname']
46
+ assert_equal 'success', node_statistics['status']
47
+ end
48
+
49
+ def test_list_all_ips_available
50
+ Solusvm.config("api_id1", api_login[:key], :url => 'http://www.example.com/api')
51
+ VCR.use_cassette "node/available_ips" do
52
+ assert_equal %w(123.123.123.123 124.124.124.124 125.125.125.125).sort, @nodes.available_ips(1).sort
53
+ end
54
+ end
55
+
56
+ def test_list_all_ips_not_available
57
+ Solusvm.config("api_id2", api_login[:key], :url => 'http://www.example.com/api')
58
+ VCR.use_cassette "node/available_ips" do
59
+ assert @nodes.available_ips(1).empty?
60
+ end
61
+ end
62
+
63
+ def test_ids
64
+ VCR.use_cassette "node/ids" do
65
+ assert_equal %w(nodeid1 nodeid2 nodeid3 nodeid4), @nodes.ids('xen')
66
+ end
67
+ end
68
+
69
+ def test_nodes_ids_error
70
+ assert_raise Solusvm::SolusvmError do
71
+ @nodes.ids('whatever')
72
+ end
73
+ end
74
+
75
+ def test_virtualservers
76
+ Solusvm.config("api_id1", api_login[:key], :url => 'http://www.example.com/api')
77
+ VCR.use_cassette "node/virtualservers" do
78
+ @nodes.virtualservers(1)
79
+ end
80
+
81
+ server = @nodes.returned_parameters["virtualservers"]["virtualserver"].first
82
+
83
+ assert_equal "theid", server["vserverid"]
84
+ assert_equal "thexid", server["ctid-xid"]
85
+ assert_equal "theclientid", server["clientid"]
86
+ assert_equal "theip", server["ipaddress"]
87
+ assert_equal "thehostname", server["hostname"]
88
+ assert_equal "thetemplate", server["template"]
89
+ assert_equal "thediskspace", server["hdd"]
90
+ assert_equal "thememory", server["memory"]
91
+ assert_equal "theswap", server["swap-burst"]
92
+ assert_equal "thetype", server["type"]
93
+ assert_equal "themac", server["mac"]
94
+ end
95
+
96
+ def test_virtualservers_empty
97
+ Solusvm.config("api_id2", api_login[:key], :url => 'http://www.example.com/api')
98
+ VCR.use_cassette "node/virtualservers" do
99
+ assert @nodes.virtualservers(1).empty?
100
+ end
101
+ end
102
+
103
+ def test_virtualservers_fail
104
+ Solusvm.config("api_id3", api_login[:key], :url => 'http://www.example.com/api')
105
+ VCR.use_cassette "node/virtualservers" do
106
+ assert_nil @nodes.virtualservers(1)
107
+ end
108
+ end
109
+
110
+ def test_xenresources
111
+ VCR.use_cassette "node/xenresources" do
112
+ @nodes.xenresources(1)
113
+ end
114
+
115
+ node_resources = @nodes.returned_parameters
116
+
117
+ assert_equal 'thefreememory', node_resources['freememory']
118
+ assert_equal 'thefreehdd', node_resources['freehdd']
119
+ end
120
+ end
@@ -0,0 +1,93 @@
1
+ require 'test_helper'
2
+
3
+ class TestReseller < Test::Unit::TestCase
4
+
5
+ def setup
6
+ setup_solusvm
7
+ @reseller = Solusvm::Reseller.new
8
+ end
9
+
10
+ def test_create
11
+ options = {:username => 'reseller123', :password=> '123456', :email=> 'reseller3@email.com', :firstname => 'Phill', :lastname => 'Smith'}
12
+
13
+ VCR.use_cassette "reseller/create" do
14
+ @reseller.create(options)
15
+ end
16
+
17
+ params = @reseller.returned_parameters
18
+
19
+ assert params
20
+ assert_equal options[:username], params['username']
21
+ assert_equal options[:firstname], params['firstname']
22
+ assert_equal options[:lastname], params['lastname']
23
+ assert_equal options[:password], params['password']
24
+ assert_equal options[:email], params['email']
25
+ end
26
+
27
+ def test_create_fail
28
+ VCR.use_cassette "reseller/create" do
29
+ assert ! @reseller.create
30
+ end
31
+ assert_equal 'error message', @reseller.statusmsg
32
+ end
33
+
34
+ def test_change_resources
35
+ options = {:maxvps => 10}
36
+ VCR.use_cassette "reseller/change_resources" do
37
+ @reseller.change_resources("vps123", options)
38
+ end
39
+
40
+ params = @reseller.returned_parameters
41
+
42
+ assert params
43
+ assert "10", params['maxvps']
44
+ end
45
+
46
+ def test_change_resources_fail
47
+ VCR.use_cassette "reseller/change_resources" do
48
+ assert !@reseller.change_resources("vps13")
49
+ end
50
+ end
51
+
52
+ def test_info
53
+ VCR.use_cassette "reseller/info" do
54
+ @reseller.info("vps123")
55
+ end
56
+
57
+ params = @reseller.returned_parameters
58
+
59
+ assert params
60
+ assert_equal "reseller123", params['username']
61
+ assert_equal "Phill", params['firstname']
62
+ assert_equal "Smith", params['lastname']
63
+ assert_equal "123456", params['password']
64
+ assert_equal "reseller3@email.com", params['email']
65
+ end
66
+
67
+ def test_info_fail
68
+ VCR.use_cassette "reseller/info" do
69
+ assert !@reseller.info("vps13")
70
+ end
71
+ end
72
+
73
+ def test_list
74
+ Solusvm.config("api_id1", api_login[:key], :url => 'http://www.example.com/api')
75
+ VCR.use_cassette "reseller/list" do
76
+ assert_equal %w(username1 username2 username3), @reseller.list
77
+ end
78
+ end
79
+
80
+ def test_list_empty
81
+ Solusvm.config("api_id2", api_login[:key], :url => 'http://www.example.com/api')
82
+ VCR.use_cassette "reseller/list" do
83
+ assert !@reseller.list
84
+ end
85
+ end
86
+
87
+ def test_delete
88
+ VCR.use_cassette "reseller/delete" do
89
+ assert @reseller.delete("vps123")
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,253 @@
1
+ require 'test_helper'
2
+
3
+ class TestServer < Test::Unit::TestCase
4
+ def setup
5
+ setup_solusvm
6
+ @server = Solusvm::Server.new
7
+ end
8
+
9
+ def test_create
10
+ options = {:hostname => 'server.hostname.com', :type => 'xen', :username => 'bob', :password => '123456',
11
+ :node => 'node1', :plan => 'plan1', :template => 'mytpl', :ips => 1}
12
+ hostname = options.delete(:hostname)
13
+ password = options.delete(:password)
14
+ VCR.use_cassette "server/create" do
15
+ @server.create(hostname, password, options)
16
+ end
17
+ actual = @server.returned_parameters
18
+ assert_equal hostname, actual['hostname']
19
+ assert_equal options[:password], actual['rootpassword']
20
+ assert_equal '100', actual['vserverid']
21
+ assert_equal 'console-123', actual['consoleuser']
22
+ assert_equal '123456', actual['consolepassword']
23
+ assert_equal '123.123.123.123', actual['mainipaddress']
24
+ assert_equal 'vm101|101', actual['virtid']
25
+ end
26
+
27
+ def test_create_error
28
+ VCR.use_cassette "server/create" do
29
+ @server.create('', '')
30
+ end
31
+ assert ! @server.successful?
32
+ end
33
+
34
+ def test_rebuild
35
+ VCR.use_cassette "server/rebuild" do
36
+ assert @server.rebuild(1, "mytpl")
37
+ end
38
+ assert_equal 'Virtual server is being rebuilt', @server.statusmsg
39
+ end
40
+
41
+ def test_boot
42
+ VCR.use_cassette "server/boot" do
43
+ assert @server.boot(1)
44
+ end
45
+ assert_equal 'Virtual server booted', @server.statusmsg
46
+ end
47
+
48
+ def test_reboot
49
+ VCR.use_cassette "server/reboot" do
50
+ assert @server.reboot(1)
51
+ end
52
+ assert_equal 'Virtual server rebooted', @server.statusmsg
53
+ end
54
+
55
+ def test_suspend
56
+ VCR.use_cassette "server/suspend" do
57
+ assert @server.suspend(1)
58
+ end
59
+ assert_equal 'Virtual server suspended', @server.statusmsg
60
+ end
61
+
62
+ def test_resume
63
+ VCR.use_cassette "server/resume" do
64
+ assert @server.resume(1)
65
+ end
66
+ assert_equal 'Virtual server unsuspended', @server.statusmsg
67
+ end
68
+
69
+ def test_shutdown
70
+ VCR.use_cassette "server/shutdown" do
71
+ assert @server.shutdown(1)
72
+ end
73
+ assert_equal 'Virtual server shutdown', @server.statusmsg
74
+ end
75
+
76
+ def test_terminate
77
+ VCR.use_cassette "server/terminate" do
78
+ assert @server.terminate(1)
79
+ assert_equal 'Virtual server terminated', @server.statusmsg
80
+
81
+ assert @server.terminate(1, true)
82
+ assert_equal 'Virtual server terminated', @server.statusmsg
83
+ end
84
+ end
85
+
86
+ def test_tun_enable
87
+ VCR.use_cassette "server/tun_enable" do
88
+ assert @server.tun_enable(1)
89
+ end
90
+ end
91
+
92
+ def test_tun_disable
93
+ VCR.use_cassette "server/tun_disable" do
94
+ assert @server.tun_disable(1)
95
+ end
96
+ end
97
+
98
+ def test_network_enable
99
+ VCR.use_cassette "server/network_enable" do
100
+ assert @server.network_enable(1)
101
+ end
102
+ end
103
+
104
+ def test_network_disable
105
+ VCR.use_cassette "server/network_disable" do
106
+ assert @server.network_disable(1)
107
+ end
108
+ end
109
+
110
+ def test_pae_enable
111
+ VCR.use_cassette "server/pae_enable" do
112
+ assert @server.pae_enable(1)
113
+ end
114
+ end
115
+
116
+ def test_pae_disable
117
+ VCR.use_cassette "server/pae_disable" do
118
+ assert @server.pae_disable(1)
119
+ end
120
+ end
121
+
122
+ def test_exists
123
+ VCR.use_cassette "server/exists" do
124
+ assert @server.exists?(1)
125
+ end
126
+ assert_equal 'Virtual server exists', @server.statusmsg
127
+ end
128
+
129
+ def test_status
130
+ VCR.use_cassette "server/status" do
131
+ assert_equal 'online', @server.status(1)
132
+ end
133
+ end
134
+
135
+ def test_add_ip
136
+ #flunk "This is broken on the SolusVM API Level"
137
+ end
138
+
139
+ def test_change_plan
140
+ VCR.use_cassette "server/change_plan" do
141
+ assert @server.change_plan(1, 'newplan')
142
+ end
143
+ assert_equal 'Virtual server updated', @server.statusmsg
144
+ end
145
+
146
+ def test_change_owner
147
+ VCR.use_cassette "server/change_owner" do
148
+ assert @server.change_owner(1, 2)
149
+ end
150
+ end
151
+
152
+ def test_change_consolepass
153
+ VCR.use_cassette "server/change_consolepass" do
154
+ assert @server.change_consolepass(1, "thepassword")
155
+ end
156
+ end
157
+
158
+ def test_change_vncpass
159
+ VCR.use_cassette "server/change_vncpass" do
160
+ assert @server.change_vncpass(1, "thepassword")
161
+ end
162
+ end
163
+
164
+ def test_change_rootpassword
165
+ VCR.use_cassette "server/change_rootpassword" do
166
+ assert @server.change_rootpassword(1, "thepassword")
167
+ end
168
+ end
169
+
170
+ def test_change_bootorder
171
+ VCR.use_cassette "server/change_bootorder" do
172
+ assert @server.change_bootorder(1, :c)
173
+ end
174
+ end
175
+
176
+ def test_change_hostname
177
+ VCR.use_cassette "server/change_hostname" do
178
+ assert @server.change_hostname(1, "thehostname")
179
+ end
180
+ end
181
+
182
+ def test_info
183
+ VCR.use_cassette "server/info" do
184
+ assert @server.info(1, true)
185
+ end
186
+ VCR.use_cassette "server/info" do
187
+ @server.info(1)
188
+ end
189
+ info = @server.returned_parameters
190
+ assert_equal '1', info['vserverid']
191
+ assert_equal '1', info['ctid-xid']
192
+ assert_equal '1', info['clientid']
193
+ assert_equal 'host.example.com', info['hostname']
194
+ assert_equal '123.123.123.123', info['ipaddress']
195
+ assert_equal 'vps1', info['template']
196
+ assert_equal '123456', info['hdd']
197
+ assert_equal '123456', info['memory']
198
+ assert_equal 'swp', info['swap-burst']
199
+ assert_equal 'xenhvm', info['type']
200
+ end
201
+
202
+ def test_vnc
203
+ VCR.use_cassette "server/vnc" do
204
+ @server.vnc(1)
205
+ end
206
+ info = @server.returned_parameters
207
+ assert_equal 'thetype', info['type']
208
+ assert_equal 'thevncip', info['vncip']
209
+ assert_equal 'thevncport', info['vncport']
210
+ assert_equal 'thevncpassword', info['vncpassword']
211
+ end
212
+
213
+ def test_console
214
+ VCR.use_cassette "server/console" do
215
+ @server.console(1)
216
+ end
217
+ info = @server.returned_parameters
218
+ assert_equal 'thetype', info['type']
219
+ assert_equal 'theconsoleip', info['consoleip']
220
+ assert_equal 'theconsoleport', info['consoleport']
221
+ assert_equal 'theconsolepassword', info['consolepassword']
222
+ assert_equal 'theconsoleusername', info['consoleusername']
223
+ end
224
+
225
+ def test_info_all
226
+ VCR.use_cassette "server/info_all" do
227
+ @server.info_all(1)
228
+ end
229
+ info = @server.returned_parameters
230
+ assert_equal "success", info["status"]
231
+ assert_equal "123.123.123.123", info["mainipaddress"]
232
+ assert_equal "tydeus", info["node"]
233
+ assert_equal "openvz", info["type"]
234
+ assert_equal "16106127360000,5370261749139,10735865610861,33", info["bandwidth"]
235
+ assert_equal "1073741824,187097088,886644736,17", info["memory"]
236
+ assert_equal "236223201280,103640707072,132582494208,44", info["hdd"]
237
+ assert_equal "/graphs/9/214/214-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["trafficgraph"]
238
+ assert_equal "/graphs/9/214/214-load-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["loadgraph"]
239
+ assert_equal "/graphs/9/214/214-mem-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["memorygraph"]
240
+ end
241
+
242
+ def test_mountiso
243
+ VCR.use_cassette "server/mountiso" do
244
+ assert @server.mountiso(1, "theiso")
245
+ end
246
+ end
247
+
248
+ def test_unmountiso
249
+ VCR.use_cassette "server/unmountiso" do
250
+ assert @server.unmountiso(1)
251
+ end
252
+ end
253
+ end