solusvm 1.4.0 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/LICENSE +1 -1
  4. data/README.markdown +159 -116
  5. data/Rakefile +3 -33
  6. data/bin/solusvm +3 -4
  7. data/lib/solusvm.rb +1 -3
  8. data/lib/solusvm/base.rb +101 -46
  9. data/lib/solusvm/cli.rb +8 -8
  10. data/lib/solusvm/cli/base_cli.rb +3 -3
  11. data/lib/solusvm/cli/client_cli.rb +3 -5
  12. data/lib/solusvm/cli/general_cli.rb +3 -5
  13. data/lib/solusvm/cli/node_cli.rb +3 -5
  14. data/lib/solusvm/cli/reseller_cli.rb +3 -5
  15. data/lib/solusvm/cli/server_cli.rb +4 -6
  16. data/lib/solusvm/client.rb +45 -27
  17. data/lib/solusvm/errors.rb +3 -0
  18. data/lib/solusvm/general.rb +11 -12
  19. data/lib/solusvm/hash.rb +1 -11
  20. data/lib/solusvm/node.rb +33 -21
  21. data/lib/solusvm/reseller.rb +53 -49
  22. data/lib/solusvm/server.rb +188 -52
  23. data/lib/solusvm/version.rb +2 -2
  24. data/test/cli/test_base_cli.rb +14 -4
  25. data/test/cli/test_client_cli.rb +13 -13
  26. data/test/cli/test_general_cli.rb +7 -7
  27. data/test/cli/test_node_cli.rb +13 -13
  28. data/test/cli/test_reseller_cli.rb +11 -11
  29. data/test/cli/test_server_cli.rb +61 -61
  30. data/test/sham_rack_stubs/base/parse-response.json +4 -0
  31. data/test/sham_rack_stubs/client/authenticate.json +4 -0
  32. data/test/sham_rack_stubs/client/change-password.json +6 -0
  33. data/test/sham_rack_stubs/client/create.json +9 -0
  34. data/test/sham_rack_stubs/client/delete.json +4 -0
  35. data/test/sham_rack_stubs/client/exists.json +4 -0
  36. data/test/sham_rack_stubs/client/list-empty.json +5 -0
  37. data/test/sham_rack_stubs/client/list.json +30 -0
  38. data/test/sham_rack_stubs/general/isos-empty.json +5 -0
  39. data/test/sham_rack_stubs/general/isos.json +5 -0
  40. data/test/sham_rack_stubs/general/plans-empty.json +5 -0
  41. data/test/sham_rack_stubs/general/plans.json +5 -0
  42. data/test/sham_rack_stubs/general/templates-empty.json +7 -0
  43. data/test/sham_rack_stubs/general/templates.json +7 -0
  44. data/test/sham_rack_stubs/generic/error.json +4 -0
  45. data/test/sham_rack_stubs/node/available-ips-empty.json +6 -0
  46. data/test/sham_rack_stubs/node/available-ips.json +6 -0
  47. data/test/sham_rack_stubs/node/ids.json +5 -0
  48. data/test/sham_rack_stubs/node/list-empty.json +5 -0
  49. data/test/sham_rack_stubs/node/list-groups.json +5 -0
  50. data/test/sham_rack_stubs/node/list.json +5 -0
  51. data/test/sham_rack_stubs/node/statistics.json +21 -0
  52. data/test/sham_rack_stubs/node/virtualservers-empty.json +5 -0
  53. data/test/sham_rack_stubs/node/virtualservers.json +19 -0
  54. data/test/sham_rack_stubs/node/xenresources.json +6 -0
  55. data/test/sham_rack_stubs/reseller/change-resources.json +18 -0
  56. data/test/sham_rack_stubs/reseller/create.json +25 -0
  57. data/test/sham_rack_stubs/reseller/delete.json +4 -0
  58. data/test/sham_rack_stubs/reseller/info.json +24 -0
  59. data/test/sham_rack_stubs/reseller/list-empty.json +5 -0
  60. data/test/sham_rack_stubs/reseller/list.json +5 -0
  61. data/test/sham_rack_stubs/server/add-ip.json +5 -0
  62. data/test/sham_rack_stubs/server/boot.json +4 -0
  63. data/test/sham_rack_stubs/server/change-bootorder.json +4 -0
  64. data/test/sham_rack_stubs/server/change-hostname.json +5 -0
  65. data/test/sham_rack_stubs/server/change-owner.json +4 -0
  66. data/test/sham_rack_stubs/server/change-plan.json +4 -0
  67. data/test/sham_rack_stubs/server/change-rootpassword.json +5 -0
  68. data/test/sham_rack_stubs/server/change-vncpass.json +5 -0
  69. data/test/sham_rack_stubs/server/console.json +13 -0
  70. data/test/sham_rack_stubs/server/create.json +13 -0
  71. data/test/sham_rack_stubs/server/del-ip.json +4 -0
  72. data/test/sham_rack_stubs/server/exists.json +4 -0
  73. data/test/sham_rack_stubs/server/info-all.json +16 -0
  74. data/test/sham_rack_stubs/server/info.json +15 -0
  75. data/test/sham_rack_stubs/server/mountiso.json +4 -0
  76. data/test/sham_rack_stubs/server/network-disable.json +4 -0
  77. data/test/sham_rack_stubs/server/network-enable.json +4 -0
  78. data/test/sham_rack_stubs/server/pae-disable.json +4 -0
  79. data/test/sham_rack_stubs/server/pae-enable.json +4 -0
  80. data/test/sham_rack_stubs/server/reboot.json +4 -0
  81. data/test/sham_rack_stubs/server/rebuild.json +4 -0
  82. data/test/sham_rack_stubs/server/resume.json +4 -0
  83. data/test/sham_rack_stubs/server/shutdown.json +4 -0
  84. data/test/sham_rack_stubs/server/status.json +4 -0
  85. data/test/sham_rack_stubs/server/suspend.json +4 -0
  86. data/test/sham_rack_stubs/server/terminate.json +4 -0
  87. data/test/sham_rack_stubs/server/tun-disable.json +4 -0
  88. data/test/sham_rack_stubs/server/tun-enable.json +4 -0
  89. data/test/sham_rack_stubs/server/unmountiso.json +4 -0
  90. data/test/sham_rack_stubs/server/vnc.json +8 -0
  91. data/test/solusvm/test_base.rb +34 -56
  92. data/test/solusvm/test_cli.rb +3 -3
  93. data/test/solusvm/test_client.rb +56 -66
  94. data/test/solusvm/test_general.rb +34 -19
  95. data/test/solusvm/test_hash.rb +0 -9
  96. data/test/solusvm/test_node.rb +66 -72
  97. data/test/solusvm/test_reseller.rb +47 -58
  98. data/test/solusvm/test_server.rb +149 -164
  99. data/test/test_helper.rb +43 -31
  100. metadata +173 -189
  101. data/.document +0 -5
  102. data/.gitignore +0 -25
  103. data/.travis.yml +0 -12
  104. data/solusvm.gemspec +0 -33
  105. data/test/vcr_cassettes/base/invalid_key.yml +0 -19
  106. data/test/vcr_cassettes/base/invalid_status.yml +0 -19
  107. data/test/vcr_cassettes/base/nonexistent_node.yml +0 -19
  108. data/test/vcr_cassettes/base/parse_response.yml +0 -28
  109. data/test/vcr_cassettes/base/statusmsg.yml +0 -28
  110. data/test/vcr_cassettes/base/successful.yml +0 -68
  111. data/test/vcr_cassettes/base/successful_instance_config.yml +0 -28
  112. data/test/vcr_cassettes/base/unauthorized_ip.yml +0 -19
  113. data/test/vcr_cassettes/client/authenticate.yml +0 -37
  114. data/test/vcr_cassettes/client/change_password.yml +0 -39
  115. data/test/vcr_cassettes/client/create.yml +0 -42
  116. data/test/vcr_cassettes/client/delete.yml +0 -37
  117. data/test/vcr_cassettes/client/exists.yml +0 -20
  118. data/test/vcr_cassettes/client/list.yml +0 -66
  119. data/test/vcr_cassettes/general/isos.yml +0 -38
  120. data/test/vcr_cassettes/general/plans.yml +0 -38
  121. data/test/vcr_cassettes/general/templates.yml +0 -38
  122. data/test/vcr_cassettes/node/available_ips.yml +0 -41
  123. data/test/vcr_cassettes/node/ids.yml +0 -21
  124. data/test/vcr_cassettes/node/list.yml +0 -38
  125. data/test/vcr_cassettes/node/list_groups.yml +0 -20
  126. data/test/vcr_cassettes/node/statistics.yml +0 -32
  127. data/test/vcr_cassettes/node/virtualservers.yml +0 -67
  128. data/test/vcr_cassettes/node/xenresources.yml +0 -22
  129. data/test/vcr_cassettes/reseller/change_resources.yml +0 -27
  130. data/test/vcr_cassettes/reseller/create.yml +0 -27
  131. data/test/vcr_cassettes/reseller/delete.yml +0 -15
  132. data/test/vcr_cassettes/reseller/info.yml +0 -27
  133. data/test/vcr_cassettes/reseller/list.yml +0 -27
  134. data/test/vcr_cassettes/server/.yml +0 -1017
  135. data/test/vcr_cassettes/server/add_ip.yml +0 -15
  136. data/test/vcr_cassettes/server/boot.yml +0 -15
  137. data/test/vcr_cassettes/server/change_bootorder.yml +0 -15
  138. data/test/vcr_cassettes/server/change_consolepass.yml +0 -16
  139. data/test/vcr_cassettes/server/change_hostname.yml +0 -15
  140. data/test/vcr_cassettes/server/change_owner.yml +0 -15
  141. data/test/vcr_cassettes/server/change_plan.yml +0 -15
  142. data/test/vcr_cassettes/server/change_rootpassword.yml +0 -15
  143. data/test/vcr_cassettes/server/change_vncpass.yml +0 -15
  144. data/test/vcr_cassettes/server/console.yml +0 -28
  145. data/test/vcr_cassettes/server/create.yml +0 -27
  146. data/test/vcr_cassettes/server/del_ip.yml +0 -15
  147. data/test/vcr_cassettes/server/exists.yml +0 -15
  148. data/test/vcr_cassettes/server/info.yml +0 -27
  149. data/test/vcr_cassettes/server/info_all.yml +0 -15
  150. data/test/vcr_cassettes/server/mountiso.yml +0 -15
  151. data/test/vcr_cassettes/server/network_disable.yml +0 -15
  152. data/test/vcr_cassettes/server/network_enable.yml +0 -15
  153. data/test/vcr_cassettes/server/pae_disable.yml +0 -15
  154. data/test/vcr_cassettes/server/pae_enable.yml +0 -15
  155. data/test/vcr_cassettes/server/reboot.yml +0 -15
  156. data/test/vcr_cassettes/server/rebuild.yml +0 -15
  157. data/test/vcr_cassettes/server/resume.yml +0 -15
  158. data/test/vcr_cassettes/server/shutdown.yml +0 -15
  159. data/test/vcr_cassettes/server/status.yml +0 -15
  160. data/test/vcr_cassettes/server/suspend.yml +0 -15
  161. data/test/vcr_cassettes/server/terminate.yml +0 -27
  162. data/test/vcr_cassettes/server/tun_disable.yml +0 -15
  163. data/test/vcr_cassettes/server/tun_enable.yml +0 -15
  164. data/test/vcr_cassettes/server/unmountiso.yml +0 -15
  165. data/test/vcr_cassettes/server/vnc.yml +0 -15
@@ -15,13 +15,4 @@ class TestHash < Test::Unit::TestCase
15
15
  assert_equal expected, merged.reverse_merge!(defaults)
16
16
  assert_equal expected, merged
17
17
  end
18
-
19
- def test_to_query
20
- defaults = { a: "x", b: "y", c: 10 }
21
- expected = "a=x&b=y&c=10".split('&').sort
22
- actual = defaults.to_query.split('&').sort
23
-
24
- assert defaults.to_query.is_a?(String)
25
- assert_equal expected, actual
26
- end
27
18
  end
@@ -2,120 +2,114 @@ require 'test_helper'
2
2
 
3
3
  class TestNode < Test::Unit::TestCase
4
4
  def setup
5
- @nodes = Solusvm::Node.new(solusvm_params)
5
+ @nodes = SolusVM::Node.new(solusvm_params)
6
6
  end
7
7
 
8
8
  def test_list
9
- VCR.use_cassette "node/list" do
10
- assert_equal %w(node1 node2 node3 node4), @nodes.list('xen')
11
- end
9
+ stub_response 'node/list'
10
+
11
+ list = @nodes.list('xen')
12
+
13
+ assert @nodes.successful?
14
+ assert list.is_a? Array
15
+ assert_not_empty list
12
16
  end
13
17
 
14
18
  def test_list_empty
15
- VCR.use_cassette "node/list" do
16
- assert !@nodes.list('openvz')
17
- end
19
+ stub_response 'node/list-empty'
20
+
21
+ assert !@nodes.list('openvz')
22
+ assert @nodes.successful?
18
23
  end
19
24
 
20
25
  def test_nodes_with_invalid_type
21
26
  assert !@nodes.list('whatever')
27
+ assert !@nodes.successful?
22
28
  end
23
29
 
24
30
  def test_list_groups
25
- VCR.use_cassette "node/list_groups" do
26
- assert_equal ['--none--', 'nodegroup1', 'nodegroup2', 'nodegroup3'], @nodes.list_groups
27
- end
31
+ stub_response 'node/list-groups'
32
+
33
+ list = @nodes.list_groups
34
+
35
+ assert @nodes.successful?
36
+ assert list.is_a? Array
37
+ assert_not_empty list
28
38
  end
29
39
 
30
40
  def test_statistics
31
- VCR.use_cassette "node/statistics" do
32
- @nodes.statistics(1)
33
- end
34
-
35
- node_statistics = @nodes.returned_parameters
36
-
37
- assert_equal '1000', node_statistics['freedisk']
38
- assert_equal '22', node_statistics['sshport']
39
- assert_equal 'city', node_statistics['city']
40
- assert_equal 'name', node_statistics['name']
41
- assert_equal '0', node_statistics['freeips']
42
- assert_equal 'country', node_statistics['country']
43
- assert_equal 'x86_64', node_statistics['arch']
44
- assert_equal '1', node_statistics['id']
45
- assert_equal '10', node_statistics['freememory']
46
- assert_equal '2', node_statistics['virtualservers']
47
- assert_equal '127.0.0.1', node_statistics['ip']
48
- assert_equal 'hostname.com', node_statistics['hostname']
49
- assert_equal 'success', node_statistics['status']
41
+ stub_response 'node/statistics'
42
+
43
+ stats = @nodes.statistics(1)
44
+
45
+ assert @nodes.successful?
46
+ assert stats.is_a? Hash
47
+ assert_not_empty stats
50
48
  end
51
49
 
52
50
  def test_list_all_ips_available
53
- @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id1", url: 'http://www.example.com/api'))
54
- VCR.use_cassette "node/available_ips" do
55
- assert_equal %w(123.123.123.123 124.124.124.124 125.125.125.125).sort, @nodes.available_ips(1).sort
56
- end
51
+ stub_response 'node/available-ips'
52
+
53
+ list = @nodes.available_ips(1)
54
+
55
+ assert @nodes.successful?
56
+ assert list.is_a? Array
57
+ assert_not_empty list
57
58
  end
58
59
 
59
60
  def test_list_all_ips_not_available
60
- @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id2", url: 'http://www.example.com/api'))
61
- VCR.use_cassette "node/available_ips" do
62
- assert @nodes.available_ips(1).empty?
63
- end
61
+ stub_response 'node/available-ips-empty'
62
+
63
+ assert_empty @nodes.available_ips(1)
64
+ assert @nodes.successful?
64
65
  end
65
66
 
66
67
  def test_ids
67
- VCR.use_cassette "node/ids" do
68
- assert_equal %w(nodeid1 nodeid2 nodeid3 nodeid4), @nodes.ids('xen')
69
- end
68
+ stub_response 'node/ids'
69
+
70
+ list = @nodes.ids('xen')
71
+
72
+ assert @nodes.successful?
73
+ assert list.is_a? Array
74
+ assert_not_empty list
70
75
  end
71
76
 
72
77
  def test_nodes_ids_error
73
78
  assert !@nodes.ids('whatever')
79
+ assert !@nodes.successful?
74
80
  end
75
81
 
76
82
  def test_virtualservers
77
- @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id1", url: 'http://www.example.com/api'))
78
- VCR.use_cassette "node/virtualservers" do
79
- @nodes.virtualservers(1)
80
- end
81
-
82
- server = @nodes.returned_parameters["virtualservers"]["virtualserver"].first
83
-
84
- assert_equal "theid", server["vserverid"]
85
- assert_equal "thexid", server["ctid-xid"]
86
- assert_equal "theclientid", server["clientid"]
87
- assert_equal "theip", server["ipaddress"]
88
- assert_equal "thehostname", server["hostname"]
89
- assert_equal "thetemplate", server["template"]
90
- assert_equal "thediskspace", server["hdd"]
91
- assert_equal "thememory", server["memory"]
92
- assert_equal "theswap", server["swap-burst"]
93
- assert_equal "thetype", server["type"]
94
- assert_equal "themac", server["mac"]
83
+ stub_response 'node/virtualservers'
84
+
85
+ servers = @nodes.virtualservers(1)
86
+
87
+ assert @nodes.successful?
88
+ assert servers.is_a? Array
89
+ assert servers.all? { |s| s.is_a? Hash }
95
90
  end
96
91
 
97
92
  def test_virtualservers_empty
98
- @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id2", url: 'http://www.example.com/api'))
99
- VCR.use_cassette "node/virtualservers" do
100
- assert @nodes.virtualservers(1).empty?
101
- end
93
+ stub_response 'node/virtualservers-empty'
94
+
95
+ assert_empty @nodes.virtualservers(1)
96
+ assert @nodes.successful?
102
97
  end
103
98
 
104
99
  def test_virtualservers_fail
105
- @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id3", url: 'http://www.example.com/api'))
106
- VCR.use_cassette "node/virtualservers" do
107
- assert_nil @nodes.virtualservers(1)
108
- end
100
+ stub_response 'generic/error'
101
+
102
+ assert_nil @nodes.virtualservers(1)
103
+ assert !@nodes.successful?
109
104
  end
110
105
 
111
106
  def test_xenresources
112
- VCR.use_cassette "node/xenresources" do
113
- @nodes.xenresources(1)
114
- end
107
+ stub_response 'node/xenresources'
115
108
 
116
- node_resources = @nodes.returned_parameters
109
+ node_resources = @nodes.xenresources(1)
117
110
 
118
- assert_equal 'thefreememory', node_resources['freememory']
119
- assert_equal 'thefreehdd', node_resources['freehdd']
111
+ assert @nodes.successful?
112
+ assert node_resources.is_a? Hash
113
+ assert_not_empty node_resources
120
114
  end
121
115
  end
@@ -1,92 +1,81 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestReseller < Test::Unit::TestCase
4
-
5
4
  def setup
6
- @reseller = Solusvm::Reseller.new(solusvm_params)
5
+ @reseller = SolusVM::Reseller.new(solusvm_params)
7
6
  end
8
7
 
9
8
  def test_create
10
- options = {username: 'reseller123', password: '123456', email: 'reseller3@email.com', firstname: 'Phill', lastname: 'Smith'}
11
-
12
- VCR.use_cassette "reseller/create" do
13
- @reseller.create(options)
14
- end
15
-
16
- params = @reseller.returned_parameters
17
-
18
- assert params
19
- assert_equal options[:username], params['username']
20
- assert_equal options[:firstname], params['firstname']
21
- assert_equal options[:lastname], params['lastname']
22
- assert_equal options[:password], params['password']
23
- assert_equal options[:email], params['email']
9
+ options = {
10
+ username: 'apitest3',
11
+ password: '123456',
12
+ email: 'email@address.com',
13
+ firstname: 'Phill',
14
+ lastname: 'Smith'
15
+ }
16
+
17
+ stub_response 'reseller/create'
18
+
19
+ assert @reseller.create(options).is_a? Hash
20
+ assert @reseller.successful?
24
21
  end
25
22
 
26
23
  def test_create_fail
27
- VCR.use_cassette "reseller/create" do
28
- assert ! @reseller.create
29
- end
30
- assert_equal 'error message', @reseller.statusmsg
24
+ stub_response 'generic/error'
25
+
26
+ assert !@reseller.create
27
+ assert !@reseller.successful?
31
28
  end
32
29
 
33
30
  def test_change_resources
34
- options = {maxvps: 10}
35
- VCR.use_cassette "reseller/change_resources" do
36
- @reseller.change_resources("vps123", options)
37
- end
38
-
39
- params = @reseller.returned_parameters
31
+ stub_response 'reseller/change-resources'
40
32
 
41
- assert params
42
- assert "10", params['maxvps']
33
+ assert @reseller.change_resources("vps123", maxvps: 10).is_a? Hash
34
+ assert @reseller.successful?
43
35
  end
44
36
 
45
37
  def test_change_resources_fail
46
- VCR.use_cassette "reseller/change_resources" do
47
- assert !@reseller.change_resources("vps13")
48
- end
38
+ stub_response 'generic/error'
39
+
40
+ assert !@reseller.change_resources("vps13")
41
+ assert !@reseller.successful?
49
42
  end
50
43
 
51
44
  def test_info
52
- VCR.use_cassette "reseller/info" do
53
- @reseller.info("vps123")
54
- end
55
-
56
- params = @reseller.returned_parameters
57
-
58
- assert params
59
- assert_equal "reseller123", params['username']
60
- assert_equal "Phill", params['firstname']
61
- assert_equal "Smith", params['lastname']
62
- assert_equal "123456", params['password']
63
- assert_equal "reseller3@email.com", params['email']
45
+ stub_response 'reseller/info'
46
+
47
+ assert @reseller.info("vps123").is_a? Hash
48
+ assert @reseller.successful?
64
49
  end
65
50
 
66
51
  def test_info_fail
67
- VCR.use_cassette "reseller/info" do
68
- assert !@reseller.info("vps13")
69
- end
52
+ stub_response 'generic/error'
53
+
54
+ assert !@reseller.info("vps13")
55
+ assert !@reseller.successful?
70
56
  end
71
57
 
72
58
  def test_list
73
- @reseller = Solusvm::Reseller.new(solusvm_params.merge(api_id: 'api_id1', url: 'http://www.example.com/api'))
74
- VCR.use_cassette "reseller/list" do
75
- assert_equal %w(username1 username2 username3), @reseller.list
76
- end
59
+ stub_response 'reseller/list'
60
+
61
+ list = @reseller.list
62
+
63
+ assert list.is_a? Array
64
+ assert_not_empty list
65
+ assert @reseller.successful?
77
66
  end
78
67
 
79
68
  def test_list_empty
80
- @reseller = Solusvm::Reseller.new(solusvm_params.merge(api_id: 'api_id2', url: 'http://www.example.com/api'))
81
- VCR.use_cassette "reseller/list" do
82
- assert !@reseller.list
83
- end
69
+ stub_response 'reseller/list-empty'
70
+
71
+ assert !@reseller.list
72
+ assert @reseller.successful?
84
73
  end
85
74
 
86
75
  def test_delete
87
- VCR.use_cassette "reseller/delete" do
88
- assert @reseller.delete("vps123")
89
- end
90
- end
76
+ stub_response 'reseller/delete'
91
77
 
78
+ assert @reseller.delete("vps123")
79
+ assert @reseller.successful?
80
+ end
92
81
  end
@@ -2,267 +2,252 @@ require 'test_helper'
2
2
 
3
3
  class TestServer < Test::Unit::TestCase
4
4
  def setup
5
- @server = Solusvm::Server.new(solusvm_params)
5
+ @server = SolusVM::Server.new(solusvm_params)
6
6
  end
7
7
 
8
8
  def test_create
9
- options = {hostname: 'server.hostname.com', type: 'xen', username: 'bob', password: '123456',
10
- node: 'node1', plan: 'plan1', template: 'mytpl', ips: 1}
11
- hostname = options.delete(:hostname)
12
- password = options.delete(:password)
13
- VCR.use_cassette "server/create" do
14
- @server.create(hostname, password, options)
15
- end
16
- actual = @server.returned_parameters
17
- assert_equal hostname, actual['hostname']
18
- assert_equal options[:password], actual['rootpassword']
19
- assert_equal '100', actual['vserverid']
20
- assert_equal 'console-123', actual['consoleuser']
21
- assert_equal '123456', actual['consolepassword']
22
- assert_equal '123.123.123.123', actual['mainipaddress']
23
- assert_equal 'vm101|101', actual['virtid']
9
+ stub_response 'server/create'
10
+
11
+ options = {
12
+ type: 'xen',
13
+ username: 'bob',
14
+ node: 'node1',
15
+ plan: 'plan1',
16
+ template: 'mytpl',
17
+ ips: 1
18
+ }
19
+
20
+ hostname = 'test.com'
21
+ password = '123456'
22
+
23
+ assert @server.create(hostname, password, options).is_a? Hash
24
+ assert @server.successful?
24
25
  end
25
26
 
26
27
  def test_create_error
27
- VCR.use_cassette "server/create" do
28
- @server.create('', '')
29
- end
30
- assert ! @server.successful?
28
+ stub_response 'generic/error'
29
+
30
+ assert !@server.create('', '')
31
+ assert !@server.successful?
31
32
  end
32
33
 
33
34
  def test_rebuild
34
- VCR.use_cassette "server/rebuild" do
35
- assert @server.rebuild(1, "mytpl")
36
- end
37
- assert_equal 'Virtual server is being rebuilt', @server.statusmsg
35
+ stub_response 'server/rebuild'
36
+
37
+ assert @server.rebuild(1, "mytpl")
38
+ assert @server.successful?
38
39
  end
39
40
 
40
41
  def test_boot
41
- VCR.use_cassette "server/boot" do
42
- assert @server.boot(1)
43
- end
44
- assert_equal 'Virtual server booted', @server.statusmsg
42
+ stub_response 'server/boot'
43
+
44
+ assert @server.boot(1)
45
+ assert @server.successful?
45
46
  end
46
47
 
47
48
  def test_reboot
48
- VCR.use_cassette "server/reboot" do
49
- assert @server.reboot(1)
50
- end
51
- assert_equal 'Virtual server rebooted', @server.statusmsg
49
+ stub_response 'server/reboot'
50
+
51
+ assert @server.reboot(1)
52
+ assert @server.successful?
52
53
  end
53
54
 
54
55
  def test_suspend
55
- VCR.use_cassette "server/suspend" do
56
- assert @server.suspend(1)
57
- end
58
- assert_equal 'Virtual server suspended', @server.statusmsg
56
+ stub_response 'server/suspend'
57
+
58
+ assert @server.suspend(1)
59
+ assert @server.successful?
59
60
  end
60
61
 
61
62
  def test_resume
62
- VCR.use_cassette "server/resume" do
63
- assert @server.resume(1)
64
- end
65
- assert_equal 'Virtual server unsuspended', @server.statusmsg
63
+ stub_response 'server/resume'
64
+
65
+ assert @server.resume(1)
66
+ assert @server.successful?
66
67
  end
67
68
 
68
69
  def test_shutdown
69
- VCR.use_cassette "server/shutdown" do
70
- assert @server.shutdown(1)
71
- end
72
- assert_equal 'Virtual server shutdown', @server.statusmsg
70
+ stub_response 'server/shutdown'
71
+
72
+ assert @server.shutdown(1)
73
+ assert @server.successful?
73
74
  end
74
75
 
75
76
  def test_terminate
76
- VCR.use_cassette "server/terminate" do
77
- assert @server.terminate(1)
78
- assert_equal 'Virtual server terminated', @server.statusmsg
77
+ stub_response "server/terminate"
79
78
 
80
- assert @server.terminate(1, true)
81
- assert_equal 'Virtual server terminated', @server.statusmsg
82
- end
79
+ assert @server.terminate(1)
80
+ assert @server.successful?
81
+
82
+ assert @server.terminate(1, true)
83
+ assert @server.successful?
83
84
  end
84
85
 
85
86
  def test_tun_enable
86
- VCR.use_cassette "server/tun_enable" do
87
- assert @server.tun_enable(1)
88
- end
87
+ stub_response 'server/tun-enable'
88
+
89
+ assert @server.tun_enable(1)
90
+ assert @server.successful?
89
91
  end
90
92
 
91
93
  def test_tun_disable
92
- VCR.use_cassette "server/tun_disable" do
93
- assert @server.tun_disable(1)
94
- end
94
+ stub_response 'server/tun-disable'
95
+
96
+ assert @server.tun_disable(1)
97
+ assert @server.successful?
95
98
  end
96
99
 
97
100
  def test_network_enable
98
- VCR.use_cassette "server/network_enable" do
99
- assert @server.network_enable(1)
100
- end
101
+ stub_response 'server/network-enable'
102
+
103
+ assert @server.network_enable(1)
104
+ assert @server.successful?
101
105
  end
102
106
 
103
107
  def test_network_disable
104
- VCR.use_cassette "server/network_disable" do
105
- assert @server.network_disable(1)
106
- end
108
+ stub_response 'server/network-disable'
109
+
110
+ assert @server.network_disable(1)
111
+ assert @server.successful?
107
112
  end
108
113
 
109
114
  def test_pae_enable
110
- VCR.use_cassette "server/pae_enable" do
111
- assert @server.pae_enable(1)
112
- end
115
+ stub_response 'server/pae-enable'
116
+
117
+ assert @server.pae_enable(1)
118
+ assert @server.successful?
113
119
  end
114
120
 
115
121
  def test_pae_disable
116
- VCR.use_cassette "server/pae_disable" do
117
- assert @server.pae_disable(1)
118
- end
122
+ stub_response 'server/pae-disable'
123
+
124
+ assert @server.pae_disable(1)
125
+ assert @server.successful?
119
126
  end
120
127
 
121
128
  def test_exists
122
- VCR.use_cassette "server/exists" do
123
- assert @server.exists?(1)
124
- end
125
- assert_equal 'Virtual server exists', @server.statusmsg
129
+ stub_response 'server/exists'
130
+
131
+ assert @server.exists?(1)
132
+ assert @server.successful?
126
133
  end
127
134
 
128
135
  def test_status
129
- VCR.use_cassette "server/status" do
130
- assert_equal 'online', @server.status(1)
131
- end
136
+ stub_response 'server/status'
137
+
138
+ assert_equal 'online', @server.status(1)
139
+ assert @server.successful?
132
140
  end
133
141
 
134
142
  def test_add_ip
135
- VCR.use_cassette "server/add_ip" do
136
- assert_equal '123.123.123.123', @server.add_ip(1)
137
- end
138
- assert_equal 'Ip address added', @server.statusmsg
143
+ stub_response 'server/add-ip'
144
+
145
+ assert_equal '123.123.123.123', @server.add_ip(1)
146
+ assert @server.successful?
139
147
  end
140
148
 
141
149
  def test_del_ip
142
- VCR.use_cassette "server/del_ip" do
143
- assert @server.del_ip(1, '123.123.123.123')
144
- end
150
+ stub_response 'server/del-ip'
151
+
152
+ assert @server.del_ip(1, '123.123.123.123')
153
+ assert @server.successful?
145
154
  end
146
155
 
147
156
  def test_change_plan
148
- VCR.use_cassette "server/change_plan" do
149
- assert @server.change_plan(1, 'newplan')
150
- end
151
- assert_equal 'Virtual server updated', @server.statusmsg
157
+ stub_response 'server/change-plan'
158
+
159
+ assert @server.change_plan(1, 'newplan')
160
+ assert @server.successful?
152
161
  end
153
162
 
154
163
  def test_change_owner
155
- VCR.use_cassette "server/change_owner" do
156
- assert @server.change_owner(1, 2)
157
- end
164
+ stub_response 'server/change-owner'
165
+
166
+ assert @server.change_owner(1, 2)
167
+ assert @server.successful?
158
168
  end
159
169
 
160
170
  def test_change_consolepass
161
- VCR.use_cassette "server/change_consolepass" do
162
- assert @server.change_consolepass(1, "thepassword")
171
+ pend do
172
+ stub_response 'server/change-consolepass'
173
+
174
+ assert @server.change_consolepass(1, 'thepassword')
163
175
  end
164
176
  end
165
177
 
166
178
  def test_change_vncpass
167
- VCR.use_cassette "server/change_vncpass" do
168
- assert @server.change_vncpass(1, "thepassword")
169
- end
179
+ stub_response 'server/change-vncpass'
180
+
181
+ assert @server.change_vncpass(1, "vncpassword")
182
+ assert @server.successful?
170
183
  end
171
184
 
172
185
  def test_change_rootpassword
173
- VCR.use_cassette "server/change_rootpassword" do
174
- assert @server.change_rootpassword(1, "thepassword")
175
- end
186
+ stub_response 'server/change-rootpassword'
187
+
188
+ assert @server.change_rootpassword(1, "rootpassword")
189
+ assert @server.successful?
176
190
  end
177
191
 
178
192
  def test_change_bootorder
179
- VCR.use_cassette "server/change_bootorder" do
180
- assert @server.change_bootorder(1, :c)
181
- end
193
+ stub_response 'server/change-bootorder'
194
+
195
+ assert @server.change_bootorder(1, :c)
196
+ assert @server.successful?
182
197
  end
183
198
 
184
199
  def test_change_hostname
185
- VCR.use_cassette "server/change_hostname" do
186
- assert @server.change_hostname(1, "thehostname")
187
- end
200
+ stub_response 'server/change-hostname'
201
+
202
+ assert @server.change_hostname(1, 'hostname')
203
+ assert @server.successful?
188
204
  end
189
205
 
190
206
  def test_info
191
- VCR.use_cassette "server/info" do
192
- assert @server.info(1, true)
193
- end
194
- VCR.use_cassette "server/info" do
195
- @server.info(1)
196
- end
197
- info = @server.returned_parameters
198
- assert_equal '1', info['vserverid']
199
- assert_equal '1', info['ctid-xid']
200
- assert_equal '1', info['clientid']
201
- assert_equal 'host.example.com', info['hostname']
202
- assert_equal '123.123.123.123', info['ipaddress']
203
- assert_equal 'vps1', info['template']
204
- assert_equal '123456', info['hdd']
205
- assert_equal '123456', info['memory']
206
- assert_equal 'swp', info['swap-burst']
207
- assert_equal 'xenhvm', info['type']
207
+ stub_response 'server/info'
208
+
209
+ assert @server.info(1, true).is_a? Hash
210
+ assert @server.successful?
211
+
212
+ assert @server.info(1).is_a? Hash
213
+ assert @server.successful?
208
214
  end
209
215
 
210
216
  def test_vnc
211
- VCR.use_cassette "server/vnc" do
212
- @server.vnc(1)
213
- end
214
- info = @server.returned_parameters
215
- assert_equal 'thetype', info['type']
216
- assert_equal 'thevncip', info['vncip']
217
- assert_equal 'thevncport', info['vncport']
218
- assert_equal 'thevncpassword', info['vncpassword']
217
+ stub_response 'server/vnc'
218
+
219
+ assert @server.vnc(1).is_a? Hash
220
+ assert @server.successful?
219
221
  end
220
222
 
221
223
  def test_console
222
- VCR.use_cassette "server/console" do
223
- @server.console(1)
224
- end
225
- info = @server.returned_parameters
226
- assert_equal 'thetype', info['type']
227
- assert_equal 'theconsoleip', info['consoleip']
228
- assert_equal 'theconsoleport', info['consoleport']
229
- assert_equal 'theconsolepassword', info['consolepassword']
230
- assert_equal 'theconsoleusername', info['consoleusername']
231
-
232
- # with the optional parameters
233
- VCR.use_cassette "server/console" do
234
- @server.console(1, access: "admin", time: 1)
235
- end
236
- # a check to see if it returned a expected parameter even with the optional parameter
237
- assert_equal 'thetype', @server.returned_parameters['type']
224
+ stub_response 'server/console'
225
+
226
+ assert @server.console(1).is_a? Hash
227
+ assert @server.successful?
228
+
229
+ assert @server.console(1, access: "admin", time: 1).is_a? Hash
230
+ assert @server.successful?
238
231
  end
239
232
 
240
233
  def test_info_all
241
- VCR.use_cassette "server/info_all" do
242
- @server.info_all(1)
243
- end
244
- info = @server.returned_parameters
245
- assert_equal "success", info["status"]
246
- assert_equal "123.123.123.123", info["mainipaddress"]
247
- assert_equal "tydeus", info["node"]
248
- assert_equal "openvz", info["type"]
249
- assert_equal "16106127360000,5370261749139,10735865610861,33", info["bandwidth"]
250
- assert_equal "1073741824,187097088,886644736,17", info["memory"]
251
- assert_equal "236223201280,103640707072,132582494208,44", info["hdd"]
252
- assert_equal "/graphs/9/214/214-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["trafficgraph"]
253
- assert_equal "/graphs/9/214/214-load-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["loadgraph"]
254
- assert_equal "/graphs/9/214/214-mem-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["memorygraph"]
234
+ stub_response 'server/info-all'
235
+
236
+ assert @server.info_all(1).is_a? Hash
237
+ assert @server.successful?
255
238
  end
256
239
 
257
240
  def test_mountiso
258
- VCR.use_cassette "server/mountiso" do
259
- assert @server.mountiso(1, "theiso")
260
- end
241
+ stub_response 'server/mountiso'
242
+
243
+ assert @server.mountiso(1, "theiso")
244
+ assert @server.successful?
261
245
  end
262
246
 
263
247
  def test_unmountiso
264
- VCR.use_cassette "server/unmountiso" do
265
- assert @server.unmountiso(1)
266
- end
248
+ stub_response 'server/unmountiso'
249
+
250
+ assert @server.unmountiso(1)
251
+ assert @server.successful?
267
252
  end
268
253
  end