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
data/test/test_base.rb DELETED
@@ -1,115 +0,0 @@
1
- require 'helper'
2
-
3
- class TestBase < Test::Unit::TestCase
4
-
5
- def setup
6
- FakeWeb.allow_net_connect = false
7
- FakeWeb.clean_registry
8
- setup_solusvm
9
- @base = Solusvm::Base.new
10
- end
11
-
12
- def test_valid_server_types
13
- assert_equal 3, Solusvm::Base::VALID_SERVER_TYPES.size
14
- assert_equal ['openvz', 'xen', 'xen hvm'].sort, Solusvm::Base::VALID_SERVER_TYPES.sort
15
- end
16
-
17
- def test_parse_response
18
- FakeWeb.register_uri(:get, "#{base_uri}&action=test&vserverid=1", :body => load_response('server_create_success'))
19
- assert_nil @base.returned_parameters
20
- @base.perform_request(:action => 'test', :vserverid => 1)
21
- params = @base.returned_parameters
22
-
23
- assert_equal 10, params.size
24
- assert_equal '123.123.123.123', params['mainipaddress']
25
- assert_equal 'console-123', params['consoleuser']
26
- assert_equal '100', params['vserverid']
27
- assert_equal 'Virtual server created', params['statusmsg']
28
- assert_equal 'vm101|101', params['virtid']
29
- assert_equal '123456', params['consolepassword']
30
- assert_equal '122.122.122.122,111.111.111.111', params['extraipaddress']
31
- assert_equal 'server.hostname.com', params['hostname']
32
- assert_equal '123456', params['rootpassword']
33
- assert_equal 'success', params['status']
34
- end
35
-
36
- def test_successful
37
- FakeWeb.register_uri(:get, "#{base_uri}&action=testsuccess&vserverid=1", :body => load_response('server_create_success'))
38
- FakeWeb.register_uri(:get, "#{base_uri}&action=testfail&vserverid=1", :body => load_response('error'))
39
-
40
- @base.perform_request(:action => 'testsuccess', :vserverid => 1)
41
- assert @base.successful?
42
-
43
- assert ! @base.perform_request(:action => 'testfail', :vserverid => 1)
44
- assert_equal "error message", @base.statusmsg
45
- end
46
-
47
- def test_api_login
48
- assert_equal api_login, @base.api_login
49
- end
50
-
51
- def test_statusmsg
52
- FakeWeb.register_uri(:get, "#{base_uri}&action=testsuccess&vserverid=1", :body => load_response('server_create_success'))
53
- @base.perform_request(:action => 'testsuccess', :vserverid => 1)
54
- assert_equal 'Virtual server created', @base.statusmsg
55
- end
56
-
57
- def test_validate_server_type
58
- Solusvm::Base::VALID_SERVER_TYPES.each do |type|
59
- assert_nothing_raised do
60
- @base.validate_server_type!(type)
61
- end
62
- end
63
-
64
- begin
65
- @base.validate_server_type!('bob')
66
- flunk "Shouldn't get here"
67
- rescue Solusvm::SolusvmError => e
68
- assert_equal 'Invalid Virtual Server type: bob', e.message
69
- end
70
- end
71
-
72
- def test_unautorized_ip
73
- FakeWeb.register_uri(:get, "#{base_uri}&action=unauthorized", :body => load_response('base_unauthorized_ip'))
74
- message = ""
75
- begin
76
- @base.perform_request(:action => 'unauthorized')
77
- rescue Exception => e
78
- message = e
79
- end
80
- assert_equal "This IP is not authorized to use the API", message.to_s
81
- end
82
-
83
- def test_invalid_key_or_id
84
- FakeWeb.register_uri(:get, "#{base_uri}&action=badkey", :body => load_response('base_bad_key'))
85
- message = ""
86
- begin
87
- @base.perform_request(:action => 'badkey')
88
- rescue Exception => e
89
- message = e
90
- end
91
- assert_equal "Invalid ID or key", message.to_s
92
- end
93
-
94
- def test_node_does_not_exist
95
- FakeWeb.register_uri(:get, "#{base_uri}&action=nodeexist", :body => load_response('base_node_does_not_exist'))
96
- message = ""
97
- begin
98
- @base.perform_request(:action => 'nodeexist')
99
- rescue Exception => e
100
- message = e
101
- end
102
- assert_equal "Node does not exist", message.to_s
103
- end
104
-
105
- def test_invalid_http_status
106
- FakeWeb.register_uri(:get, "#{base_uri}&action=httperror", :body => "", :status => ["404", "Not Found"])
107
- message = ""
108
- begin
109
- @base.perform_request(:action => 'httperror')
110
- rescue Solusvm::SolusvmError => e
111
- message = e
112
- end
113
- assert_equal "Bad HTTP Status: 404", message.to_s
114
- end
115
- end
data/test/test_client.rb DELETED
@@ -1,98 +0,0 @@
1
- require 'helper'
2
-
3
- class TestClient < Test::Unit::TestCase
4
-
5
- def setup
6
- setup_solusvm
7
- FakeWeb.allow_net_connect = false
8
- FakeWeb.clean_registry
9
- @client = Solusvm::Client.new
10
- end
11
-
12
- def test_create
13
- options = {:username => 'vps123', :password=> '123456', :email=> 'email@address.com', :firstname => 'phill', :lastname => 'smith'}
14
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-create&#{options.to_query}", :body => load_response('client_create_success'))
15
-
16
- params = @client.create(options)
17
- assert params
18
- assert_equal options[:username], params['username']
19
- assert_equal options[:firstname], params['firstname']
20
- assert_equal options[:lastname], params['lastname']
21
- assert_equal options[:password], params['password']
22
- assert_equal options[:email], params['email']
23
- assert_equal 'Successfully added client', params['statusmsg']
24
- assert_equal 'success', params['status']
25
- end
26
-
27
- def test_create_fail
28
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-create", :body => load_response('client_create_error'))
29
- assert ! @client.create
30
- assert_equal 'Empty username field', @client.statusmsg
31
- end
32
-
33
- def test_exists
34
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-checkexists&username=vps123", :body => load_response('client_exists_success'))
35
- assert @client.exists?("vps123")
36
- assert_equal 'Client exists', @client.statusmsg
37
- end
38
-
39
- def test_change_password
40
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-updatepassword&username=vps123&password=123456", :body => load_response('client_change_password_success'))
41
- assert @client.change_password("vps123","123456")
42
- end
43
-
44
- def test_change_password_fail
45
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-updatepassword&username=vps13&password=thecake", :body => load_response('client_change_password_error'))
46
- assert !@client.change_password("vps13","thecake")
47
- end
48
-
49
- def test_authenticate
50
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-authenticate&username=u&password=p", :body => load_response('client_authenticate_success'))
51
- assert @client.authenticate('u', 'p')
52
- end
53
-
54
- def test_authenticate_fail
55
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-authenticate&username=u&password=notp", :body => load_response('client_authenticate_error'))
56
- assert ! @client.authenticate('u', 'notp')
57
- assert_equal 'invalid username or password', @client.statusmsg
58
- end
59
-
60
- def test_delete
61
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-delete&username=vps123", :body => load_response('client_delete_success'))
62
- assert @client.delete("vps123")
63
- end
64
-
65
- def test_delete_fail
66
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-delete&username=vps123", :body => load_response('error'))
67
- assert !@client.delete("vps123")
68
- end
69
-
70
- def test_list
71
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-list", :body => load_response('client_list_success'))
72
-
73
- clients = @client.list
74
- assert_equal 1, clients.size
75
-
76
- client = clients.first
77
- assert_equal "1", client["id"]
78
- assert_equal "vps123", client["username"]
79
- assert_equal "vps123@email.com", client["email"]
80
- assert_equal "phill", client["firstname"]
81
- assert_equal "smith", client["lastname"]
82
- assert_equal "VPS Co", client["company"]
83
- assert_equal "Client", client["level"]
84
- assert_equal "Active", client["status"]
85
- assert_equal "2009-01-01", client["created"]
86
- assert_equal "2010-04-23", client["lastlogin"]
87
- end
88
-
89
- def test_list_empty
90
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-list", :body => load_response('client_list_success_empty'))
91
- assert @client.list.empty?
92
- end
93
-
94
- def test_list_fail
95
- FakeWeb.register_uri(:get, "#{base_uri}&action=client-list", :body => load_response('error'))
96
- assert_nil @client.list
97
- end
98
- end
data/test/test_general.rb DELETED
@@ -1,70 +0,0 @@
1
- require 'helper'
2
-
3
- class TestGeneral < Test::Unit::TestCase
4
- def setup
5
- FakeWeb.allow_net_connect = false
6
- FakeWeb.clean_registry
7
- setup_solusvm
8
- @general = Solusvm::General.new
9
- end
10
-
11
- def test_templates
12
- FakeWeb.register_uri(:get, "#{base_uri}&action=listtemplates&type=xen", :body => load_response('general_templates_success'))
13
- assert_equal %w(template1 template2 template3), @general.templates('xen')
14
- end
15
-
16
- def test_templates_empty
17
- FakeWeb.register_uri(:get, "#{base_uri}&action=listtemplates&type=xen", :body => load_response('error'))
18
- assert !@general.templates('xen')
19
- end
20
-
21
- def test_templates_with_invalid_type
22
- FakeWeb.register_uri(:get, "#{base_uri}&action=listtemplates&type=whatever", :body => load_response('error'))
23
- begin
24
- @general.templates('whatever')
25
- flunk "Shouldn't get here"
26
- rescue Solusvm::SolusvmError => e
27
- assert e.message.match /Invalid Virtual Server type/
28
- end
29
- end
30
-
31
- def test_plans
32
- FakeWeb.register_uri(:get, "#{base_uri}&action=listplans&type=xen", :body => load_response('general_plans_success'))
33
- assert_equal %w(plan1 plan2 plan3 plan4), @general.plans('xen')
34
- end
35
-
36
- def test_plans_empty
37
- FakeWeb.register_uri(:get, "#{base_uri}&action=listplans&type=xen", :body => load_response('error'))
38
- assert !@general.plans('xen')
39
- end
40
-
41
- def test_plans_with_invalid_type
42
- FakeWeb.register_uri(:get, "#{base_uri}&action=listplans&type=whatever", :body => load_response('error'))
43
- begin
44
- @general.plans('whatever')
45
- flunk "Shouldn't get here"
46
- rescue Solusvm::SolusvmError => e
47
- assert e.message.match /Invalid Virtual Server type/
48
- end
49
- end
50
-
51
- def test_isos
52
- FakeWeb.register_uri(:get, "#{base_uri}&action=listiso&type=xen", :body => load_response('general_isos_success'))
53
- assert_equal %w(iso1 iso2 iso3), @general.isos('xen')
54
- end
55
-
56
- def test_isos_empty
57
- FakeWeb.register_uri(:get, "#{base_uri}&action=listiso&type=xen", :body => load_response('error'))
58
- assert !@general.isos('xen')
59
- end
60
-
61
- def test_isos_with_invalid_type
62
- FakeWeb.register_uri(:get, "#{base_uri}&action=listiso&type=whatever", :body => load_response('error'))
63
- begin
64
- @general.isos('whatever')
65
- flunk "Shouldn't get here"
66
- rescue Solusvm::SolusvmError => e
67
- assert e.message.match /Invalid Virtual Server type/
68
- end
69
- end
70
- end
data/test/test_node.rb DELETED
@@ -1,112 +0,0 @@
1
- require 'helper'
2
-
3
- class TestNode < Test::Unit::TestCase
4
- def setup
5
- FakeWeb.allow_net_connect = false
6
- FakeWeb.clean_registry
7
- setup_solusvm
8
- @nodes = Solusvm::Node.new
9
- end
10
-
11
- def test_list
12
- FakeWeb.register_uri(:get, "#{base_uri}&action=listnodes&type=xen", :body => load_response('nodes_list_success'))
13
- assert_equal %w(node1 node2 node3 node4), @nodes.list('xen')
14
- end
15
-
16
- def test_list_empty
17
- FakeWeb.register_uri(:get, "#{base_uri}&action=listnodes&type=xen", :body => load_response('error'))
18
- assert !@nodes.list('xen')
19
- end
20
-
21
- def test_nodes_with_invalid_type
22
- FakeWeb.register_uri(:get, "#{base_uri}&action=listnodes&type=whatever", :body => load_response('error'))
23
- begin
24
- @nodes.list('whatever')
25
- flunk "Shouldn't get here"
26
- rescue Solusvm::SolusvmError => e
27
- assert e.message.match /Invalid Virtual Server type/
28
- end
29
- end
30
-
31
- def test_statistics
32
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-statistics&nodeid=1", :body => load_response('node_statistics_success'))
33
- node_statistics = @nodes.statistics(1)
34
-
35
- assert_equal '1000', node_statistics['freedisk']
36
- assert_equal '22', node_statistics['sshport']
37
- assert_equal 'city', node_statistics['city']
38
- assert_equal 'name', node_statistics['name']
39
- assert_equal '0', node_statistics['freeips']
40
- assert_equal 'country', node_statistics['country']
41
- assert_equal 'x86_64', node_statistics['arch']
42
- assert_equal '1', node_statistics['id']
43
- assert_equal '10', node_statistics['freememory']
44
- assert_equal '2', node_statistics['virtualservers']
45
- assert_equal '127.0.0.1', node_statistics['ip']
46
- assert_equal 'hostname.com', node_statistics['hostname']
47
- assert_equal 'success', node_statistics['status']
48
- end
49
-
50
- def test_list_all_ips_available
51
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-iplist&nodeid=1", :body => load_response('node_list_all_ips_available'))
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
-
55
- def test_list_all_ips_not_available
56
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-iplist&nodeid=1", :body => load_response('node_list_all_ips_not_available'))
57
- assert @nodes.available_ips(1).empty?
58
- end
59
-
60
- def test_ids
61
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-idlist&type=xen", :body => load_response('nodes_ids_success'))
62
- assert_equal %w(nodeid1 nodeid2 nodeid3 nodeid4), @nodes.ids('xen')
63
- end
64
-
65
- def test_nodes_ids_error
66
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-idlist&type=whatever", :body => load_response('error'))
67
- begin
68
- @nodes.ids('whatever')
69
- flunk "Shouldn't get here"
70
- rescue Solusvm::SolusvmError => e
71
- assert e.message.match /Invalid Virtual Server type/
72
- end
73
- end
74
-
75
- def test_virtualservers
76
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-virtualservers&nodeid=1", :body => load_response('node_virtualservers_success'))
77
-
78
- servers = @nodes.virtualservers(1)
79
- assert_equal 1, servers.size
80
-
81
- server = servers.first
82
- assert_equal "theid", server["vserverid"]
83
- assert_equal "thexid", server["ctid-xid"]
84
- assert_equal "theclientid", server["clientid"]
85
- assert_equal "theip", server["ipaddress"]
86
- assert_equal "thehostname", server["hostname"]
87
- assert_equal "thetemplate", server["template"]
88
- assert_equal "thediskspace", server["hdd"]
89
- assert_equal "thememory", server["memory"]
90
- assert_equal "theswap", server["swap-burst"]
91
- assert_equal "thetype", server["type"]
92
- assert_equal "themac", server["mac"]
93
- end
94
-
95
- def test_virtualservers_empty
96
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-virtualservers&nodeid=1", :body => load_response('node_virtualservers_success_empty'))
97
- assert @nodes.virtualservers(1).empty?
98
- end
99
-
100
- def test_virtualservers_fail
101
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-virtualservers&nodeid=1", :body => load_response('error'))
102
- assert_nil @nodes.virtualservers(1)
103
- end
104
-
105
- def test_xenresources
106
- FakeWeb.register_uri(:get, "#{base_uri}&action=node-xenresources&nodeid=1", :body => load_response('node_xenresources_success'))
107
- node_resources = @nodes.xenresources(1)
108
-
109
- assert_equal 'thefreememory', node_resources['freememory']
110
- assert_equal 'thefreehdd', node_resources['freehdd']
111
- end
112
- end
@@ -1,80 +0,0 @@
1
- require 'helper'
2
-
3
- class TestReseller < Test::Unit::TestCase
4
-
5
- def setup
6
- setup_solusvm
7
- FakeWeb.allow_net_connect = false
8
- FakeWeb.clean_registry
9
- @reseller = Solusvm::Reseller.new
10
- end
11
-
12
- def test_create
13
- options = {:username => 'reseller123', :password=> '123456', :email=> 'reseller3@email.com', :firstname => 'Phill', :lastname => 'Smith'}
14
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-create&#{options.to_query}", :body => load_response('reseller_create_success'))
15
-
16
- params = @reseller.create(options)
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']
24
- end
25
-
26
- def test_create_fail
27
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-create", :body => load_response('error'))
28
- assert ! @reseller.create
29
- assert_equal 'error message', @reseller.statusmsg
30
- end
31
-
32
- def test_change_resources
33
- options = {:maxvps => 10}
34
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-modifyresources&username=vps123&#{options.to_query}", :body => load_response('reseller_change_resources_success'))
35
-
36
- params = @reseller.change_resources("vps123", options)
37
-
38
- assert params
39
- assert "10", params['maxvps']
40
- end
41
-
42
- def test_change_resources_fail
43
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-modifyresources&username=vps13", :body => load_response('error'))
44
- assert !@reseller.change_resources("vps13")
45
- end
46
-
47
- def test_info
48
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-info&username=vps123", :body => load_response('reseller_info_success'))
49
-
50
- params = @reseller.info("vps123")
51
-
52
- assert params
53
- assert_equal "reseller123", params['username']
54
- assert_equal "Phill", params['firstname']
55
- assert_equal "Smith", params['lastname']
56
- assert_equal "123456", params['password']
57
- assert_equal "reseller3@email.com", params['email']
58
- end
59
-
60
- def test_info_fail
61
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-info&username=vps13", :body => load_response('error'))
62
- assert !@reseller.info("vps13")
63
- end
64
-
65
- def test_list
66
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-list", :body => load_response('reseller_list_success'))
67
- assert_equal %w(username1 username2 username3), @reseller.list
68
- end
69
-
70
- def test_list_empty
71
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-list", :body => load_response('error'))
72
- assert !@reseller.list
73
- end
74
-
75
- def test_delete
76
- FakeWeb.register_uri(:get, "#{base_uri}&action=reseller-delete&username=vps123", :body => load_response('reseller_delete_success'))
77
- assert @reseller.delete("vps123")
78
- end
79
-
80
- end