ultravault 1.0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. data/.gitignore +15 -0
  2. data/Gemfile +2 -0
  3. data/README.md +88 -0
  4. data/Rakefile +17 -0
  5. data/lib/ultravault.rb +17 -0
  6. data/lib/ultravault/api_request.rb +26 -0
  7. data/lib/ultravault/client.rb +19 -0
  8. data/lib/ultravault/config.rb +55 -0
  9. data/lib/ultravault/data_objects/agent.rb +104 -0
  10. data/lib/ultravault/data_objects/disk_safe.rb +64 -0
  11. data/lib/ultravault/data_objects/recovery_point.rb +24 -0
  12. data/lib/ultravault/soap_service.rb +29 -0
  13. data/lib/ultravault/soap_service/agent_service.rb +62 -0
  14. data/lib/ultravault/soap_service/disk_safe_service.rb +18 -0
  15. data/lib/ultravault/soap_service/recovery_point_service.rb +21 -0
  16. data/test/all.rb +6 -0
  17. data/test/integration/client_code.rb +88 -0
  18. data/test/support/fixtures.rb +4 -0
  19. data/test/support/fixtures/agent_service.rb +56 -0
  20. data/test/support/fixtures/disk_safe.rb +35 -0
  21. data/test/support/fixtures/disk_safe_service.rb +60 -0
  22. data/test/support/fixtures/recovery_point_service.rb +26 -0
  23. data/test/test_helper.rb +35 -0
  24. data/test/unit/lib/ultravault/data_objects/test_agent.rb +133 -0
  25. data/test/unit/lib/ultravault/data_objects/test_disk_safe.rb +150 -0
  26. data/test/unit/lib/ultravault/data_objects/test_recovery_point.rb +59 -0
  27. data/test/unit/lib/ultravault/soap_service/test_agent_service.rb +139 -0
  28. data/test/unit/lib/ultravault/soap_service/test_disk_safe_service.rb +40 -0
  29. data/test/unit/lib/ultravault/soap_service/test_recovery_point_service.rb +39 -0
  30. data/test/unit/lib/ultravault/test_api_request.rb +36 -0
  31. data/test/unit/lib/ultravault/test_client.rb +47 -0
  32. data/test/unit/lib/ultravault/test_config.rb +37 -0
  33. data/test/unit/lib/ultravault/test_soap_service.rb +41 -0
  34. data/test/vcr_cassettes/agent_by_id.yml +41 -0
  35. data/test/vcr_cassettes/all_agents.yml +118 -0
  36. data/test/vcr_cassettes/create_mod_rm_agents.yml +158 -0
  37. data/ultravault.gemspec +25 -0
  38. metadata +212 -0
@@ -0,0 +1,133 @@
1
+ require_relative '../../../../test_helper'
2
+
3
+ module UltraVault
4
+ class AgentTest < Test::Unit::TestCase
5
+
6
+ context 'a new agent' do
7
+
8
+ setup do
9
+ @params = { :description=>"test-MSSQL",
10
+ :hostname=>"1.2.3.4",
11
+ :id=>"e9bd701b-dac1-4921-ab1c-467f35209e21",
12
+ :os_type=>"WINDOWS",
13
+ :port_number=>"1167"}
14
+ end
15
+
16
+ context 'attributes' do
17
+ setup do
18
+ @agent = Agent.new(@params)
19
+ end
20
+
21
+ should "match the input description" do
22
+ assert_equal @params[:description], @agent.description
23
+ end
24
+
25
+ should "match the input hostname" do
26
+ assert_equal @params[:hostname], @agent.hostname
27
+ end
28
+
29
+ should "match the input id" do
30
+ assert_equal @params[:id], @agent.id
31
+ end
32
+
33
+ should "match the input os_type" do
34
+ assert_equal @params[:os_type], @agent.os_type
35
+ end
36
+
37
+ should "match the input port_number" do
38
+ assert_equal @params[:port_number], @agent.port_number
39
+ end
40
+
41
+ should "respond to .disk_safes via an api call" do
42
+ DiskSafe.expects(
43
+ :find_all_by_agent_id).with(
44
+ @params[:id]).returns(stub)
45
+ @agent.disk_safes
46
+ end
47
+
48
+ end
49
+
50
+ context 'class methods' do
51
+ should "pass on the .find_by_id call to the agent service" do
52
+ AgentService.any_instance.expects(:find_agent_by_id).with('foo')
53
+ Agent.find_by_id('foo')
54
+ end
55
+
56
+ should "pass on the .all call to the agent service" do
57
+ AgentService.any_instance.expects(:all_agents)
58
+ Agent.all
59
+ end
60
+
61
+ should "pass on the .create call to the agent service" do
62
+ params = { :hostname => 'foobar', :port_number => 8080,
63
+ :description => 'foobar',
64
+ :os_type => 'linux'
65
+ }
66
+ AgentService.any_instance.expects(:create_agent).with(params)
67
+ Agent.expects(:check_params_strict).returns(true)
68
+ Agent.create(params)
69
+ end
70
+
71
+ should "pass on the .update call to the agent service" do
72
+ params = @params.merge({ :hostname => 'bazfoobar' })
73
+ AgentService.any_instance.expects(:update_agent).with(params)
74
+ Agent.expects(:check_params).returns(true)
75
+ agent = Agent.new(@params)
76
+ agent.update(params)
77
+ end
78
+
79
+ should "pass on the .destroy call to the agent service" do
80
+ id = "12345"
81
+ AgentService.any_instance.expects(:destroy_agent).with(id)
82
+ agent = Agent.new(@params.merge!(id: id))
83
+ agent.destroy
84
+ end
85
+ end
86
+
87
+ context "params checking" do
88
+
89
+ setup do
90
+ @complete_legal_params = {
91
+ :hostname => 'foo', :port_number => 40,
92
+ :description => "Bar", :os_type => "Baz"
93
+ }
94
+ @incomplete_legal_params = {
95
+ :port_number => 40,
96
+ :description => "Bar"
97
+ }
98
+ @incomplete_illegal_params = {
99
+ :rargh => 'foo', :port_number => 40,
100
+ :description => "Bar", :os_type => "Baz"
101
+ }
102
+ end
103
+
104
+ context '#check_params' do
105
+ should "return true if params are legal" do
106
+ assert_equal Agent.check_params(@complete_legal_params), true
107
+ end
108
+
109
+ should "raise ArgumentError if params are non-legal" do
110
+ assert_raise ArgumentError do
111
+ Agent.check_params(@incomplete_illegal_params)
112
+ end
113
+ end
114
+ end
115
+
116
+ context '#check_params_strict' do
117
+ should "return true if params are legal and all present" do
118
+ assert_equal Agent.check_params_strict(@complete_legal_params), true
119
+ end
120
+
121
+ should "raise ArgumentError if params are non-legal/all present" do
122
+ assert_raise ArgumentError do
123
+ Agent.check_params_strict(@incomplete_illegal_params)
124
+ end
125
+ assert_raise ArgumentError do
126
+ Agent.check_params_strict(@incomplete_legal_params)
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,150 @@
1
+ require_relative '../../../../test_helper'
2
+
3
+ module UltraVault
4
+ class DiskSafeTest < Test::Unit::TestCase
5
+ context 'A new disksafe' do
6
+
7
+ setup do
8
+ load_disk_safe_fixtures
9
+ end
10
+
11
+ context "attributes" do
12
+ setup do
13
+ @disk_safe = DiskSafe.new(@disk_safe_params)
14
+ end
15
+
16
+ should "match the agent id" do
17
+ assert_equal @disk_safe.agent_id, @disk_safe_params[:agent_id]
18
+ end
19
+
20
+ should "match the compression level" do
21
+ assert_equal @disk_safe.compression_level, @disk_safe_params[:compression_level]
22
+ end
23
+
24
+ should "match the compression type" do
25
+ assert_equal @disk_safe.compression_type, @disk_safe_params[:compression_type]
26
+ end
27
+
28
+ should "match the description" do
29
+ assert_equal @disk_safe.description, @disk_safe_params[:description]
30
+ end
31
+
32
+ should "match the device count as an integer" do
33
+ assert_equal @disk_safe.device_count, @disk_safe_params[:device_count].to_i
34
+ end
35
+
36
+ context "device_list" do
37
+ setup do
38
+ @device = @disk_safe.device_list.first
39
+ end
40
+
41
+ should "match the capacity at the right byte level" do
42
+ assert_equal @device.capacity, 64421359616
43
+ end
44
+
45
+ should "match the device content type" do
46
+ assert_equal @device.content_type,
47
+ @disk_safe_params[:device_list][:device_content_type]
48
+ end
49
+
50
+ should "match the device path" do
51
+ assert_equal @device.path,
52
+ @disk_safe_params[:device_list][:device_path]
53
+ end
54
+
55
+ should "match the enabled flag" do
56
+ assert_equal @device.enabled,
57
+ @disk_safe_params[:device_list][:enabled]
58
+ end
59
+
60
+ should "match the mount point" do
61
+ assert_equal @device.mount_point,
62
+ @disk_safe_params[:device_list][:mount_point]
63
+ end
64
+
65
+ should "match the mounted flag" do
66
+ assert_equal @device.mounted,
67
+ @disk_safe_params[:device_list][:mounted]
68
+ end
69
+ end
70
+
71
+ should "match the archiving enabled attribute" do
72
+ assert_equal @disk_safe.archiving_enabled, true
73
+ end
74
+
75
+ should "match the file excludes enabled attribute" do
76
+ assert_equal @disk_safe.file_excludes_enabled, true
77
+ end
78
+
79
+ should "match the quota type" do
80
+ assert_equal @disk_safe.quota_type, 'NONE'
81
+ end
82
+
83
+ should "match the control panels enabled attribute" do
84
+ assert_equal @disk_safe.controlpanels_enabled, true
85
+ end
86
+
87
+ should "match the archive point limit attribute" do
88
+ assert_equal @disk_safe.archive_point_limit, "-1"
89
+ end
90
+
91
+ should "match the recovery point limit attribute" do
92
+ assert_equal @disk_safe.recovery_point_limit, "-1"
93
+ end
94
+
95
+ should "match the soft quota value attribute" do
96
+ assert_equal @disk_safe.soft_quota_value, "-1.0"
97
+ end
98
+
99
+ should "match the replication frequency limit" do
100
+ assert_equal @disk_safe.replication_frequency_limit,
101
+ "NO_LIMIT"
102
+ end
103
+
104
+ should "match the hard quota value" do
105
+ assert_equal @disk_safe.hard_quota_value, "-1.0"
106
+ end
107
+
108
+ should "match the id" do
109
+ assert_equal @disk_safe.id, @disk_safe_params[:id]
110
+ end
111
+
112
+ should "match the open flag" do
113
+ assert_equal @disk_safe.open, @disk_safe_params[:open]
114
+ end
115
+
116
+ should "match the recovery point count as integer" do
117
+ assert_equal @disk_safe.recovery_point_count,
118
+ @disk_safe_params[:recovery_point_count].to_i
119
+ end
120
+
121
+ should "match the size at the right byte level" do
122
+ assert_equal @disk_safe.size, 20931331073
123
+ end
124
+
125
+ should "match the size of deltas at the right byte level" do
126
+ assert_equal @disk_safe.size_of_deltas, 18665326744
127
+ end
128
+
129
+ should "match the volume id" do
130
+ assert_equal @disk_safe.volume_id, @disk_safe_params[:volume_id]
131
+ end
132
+
133
+ should "define recovery points by api request" do
134
+ RecoveryPointService.any_instance.expects(
135
+ :find_recovery_points_by_disk_safe_id).with(
136
+ @disk_safe_params[:id]).returns(stub)
137
+ @disk_safe.recovery_points
138
+ end
139
+
140
+ end
141
+
142
+ context 'class methods' do
143
+ should "pass on the call to the disk safe service" do
144
+ DiskSafeService.any_instance.expects(:find_disksafes_by_agent_id).with('foo')
145
+ DiskSafe.find_all_by_agent_id('foo')
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../../../../test_helper'
2
+
3
+ module UltraVault
4
+ class RecoveryPointTest < Test::Unit::TestCase
5
+
6
+ context "creating a recovery point" do
7
+
8
+ setup do
9
+ @input = { agent_id: 'e9bd701b-dac1-4921-ab1c-467f35209e21',
10
+ created_on_timestamp_in_millis: 1330361712361,
11
+ disk_safe_id: '3067f030-9814-4314-ae03-75933ac29e37',
12
+ recovery_point_id: 1,
13
+ recovery_point_state: 'AVAILABLE'}
14
+ end
15
+
16
+ context 'attributes' do
17
+
18
+ setup do
19
+ @recovery_point = RecoveryPoint.new(@input)
20
+ end
21
+
22
+ should "match the input agent id" do
23
+ assert_equal @recovery_point.agent_id, @input[:agent_id]
24
+ end
25
+
26
+ should "give the created_at as a ruby date_time" do
27
+ assert_equal @recovery_point.created_at.year, 2012
28
+ assert_equal @recovery_point.created_at.month, 02
29
+ assert_equal @recovery_point.created_at.day, 27
30
+ assert_equal @recovery_point.created_at.hour, 16
31
+ assert_equal @recovery_point.created_at.min, 55
32
+ assert_equal @recovery_point.created_at.sec, 12
33
+ end
34
+
35
+ should "match the disk safe id" do
36
+ assert_equal @recovery_point.disk_safe_id, @input[:disk_safe_id]
37
+ end
38
+
39
+ should "match the recovery point ID" do
40
+ assert_equal @recovery_point.id, @input[:recovery_point_id]
41
+ end
42
+
43
+ should "match the recovery point state" do
44
+ assert_equal @recovery_point.state, @input[:recovery_point_state].downcase
45
+ end
46
+ end
47
+
48
+ context 'class methods' do
49
+ should "pass on the call to the disk safe service" do
50
+ RecoveryPointService.any_instance.expects(
51
+ :find_recovery_points_by_disk_safe_id).with('foo')
52
+ RecoveryPoint.find_all_by_disk_safe_id('foo')
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,139 @@
1
+ require_relative '../../../../test_helper'
2
+
3
+ module UltraVault
4
+ class AgentServiceTest < Test::Unit::TestCase
5
+
6
+ context 'a new agent service' do
7
+
8
+ setup do
9
+ load_agent_service_fixtures
10
+ end
11
+
12
+ context 'public methods' do
13
+
14
+ setup do
15
+ ApiRequest.expects(:new).returns(stub(endpoint: 'foo',
16
+ namespace: 'bar'))
17
+ @service = AgentService.new
18
+ @client = stub
19
+ @service.expects(:client).returns(@client)
20
+ @error = Savon::SOAP::Fault.new(stub(body: 'foo'))
21
+ end
22
+
23
+ context '#find_agent_by_id' do
24
+ should "return an agent object if it exists" do
25
+ @client.expects(:request).with(
26
+ :getAgentByID, id: 'foo').returns(mock(to_hash: @agent_by_id_wrapper))
27
+ Agent.expects(:new).returns(stub_everything)
28
+ agent = @service.find_agent_by_id('foo')
29
+ end
30
+
31
+ should "raise an error if it does not exist" do
32
+ @client.expects(:request).with(
33
+ :getAgentByID, id: 'bar').raises(@error)
34
+ assert_raise Savon::SOAP::Fault do
35
+ agent = @service.find_agent_by_id('bar')
36
+ end
37
+ end
38
+ end
39
+
40
+ context '#all_agents' do
41
+ should "return all agents available" do
42
+ @client.expects(:request).with(:getAgents).returns(
43
+ mock(to_hash: @all_agents_wrapper))
44
+ Agent.expects(:new).at_least_once.returns(stub_everything)
45
+ agents = @service.all_agents
46
+ end
47
+
48
+ should "raise an error if something goes wrong" do
49
+ @client.expects(:request).with(:getAgents).raises(@error)
50
+ assert_raise Savon::SOAP::Fault do
51
+ agent = @service.all_agents
52
+ end
53
+ end
54
+ end
55
+
56
+ context "#create_agent" do
57
+ setup do
58
+ @params = { :hostname => 'foobar', :portNumber => 8080,
59
+ :description => 'foobar', :databaseAddOnEnabled => true,
60
+ :osType => 'linux' }
61
+ end
62
+
63
+ should "return a new agent object" do
64
+ @client.expects(:request).with(:createAgentWithObject,
65
+ :agent => @params).returns(mock(to_hash: @agent_with_object_wrapper))
66
+ Agent.expects(:new).returns(stub_everything)
67
+ agent = @service.create_agent(@params)
68
+ end
69
+
70
+ should "raise an error if something goes wrong" do
71
+ @client.expects(:request).with(:createAgentWithObject, :agent => @params).raises(@error)
72
+ assert_raise Savon::SOAP::Fault do
73
+ agent = @service.create_agent(@params)
74
+ end
75
+ end
76
+ end
77
+
78
+ context "#update_agent" do
79
+ setup do
80
+ @params = { :hostname => 'foobarbazbar', :portNumber => 8080,
81
+ :description => 'foobar', :databaseAddOnEnabled => true,
82
+ :osType => 'linux' }
83
+ end
84
+
85
+ should "update an agent object" do
86
+ @client.expects(:request).with(:updateAgent,
87
+ :agent => @params).returns(
88
+ mock(to_hash: @update_agent_wrapper))
89
+ Agent.expects(:new).returns(stub_everything)
90
+ agent = @service.update_agent(@params)
91
+ end
92
+
93
+ should "raise an error if something goes wrong" do
94
+ @client.expects(:request).with(:updateAgent, :agent => @params
95
+ ).raises(@error)
96
+ assert_raise Savon::SOAP::Fault do
97
+ agent = @service.update_agent(@params)
98
+ end
99
+ end
100
+ end
101
+
102
+ context "#destroy_agent" do
103
+ setup do
104
+ @params = { id: "12345" }
105
+ end
106
+
107
+ should "destroy an agent object" do
108
+ @client.expects(:request).with(:deleteAgentById,
109
+ @params).returns(nil)
110
+ @service.destroy_agent(@params[:id])
111
+ end
112
+
113
+ should "raise an error if something goes wrong" do
114
+ @client.expects(:request).with(:updateAgent, :agent => @params
115
+ ).raises(@error)
116
+ assert_raise Savon::SOAP::Fault do
117
+ agent = @service.update_agent(@params)
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+
124
+ context "#map_agent_params" do
125
+ should "turn agent params ruby into agent params soap" do
126
+ @input = { :hostname => 'foobar', :port_number => 8080,
127
+ :description => 'foobar',
128
+ :os_type => 'linux'}
129
+ @output = { :hostname => 'foobar', :portNumber => 8080,
130
+ :description => 'foobar',
131
+ :osType => 'linux'}
132
+ assert_equal AgentService.new.send(:map_agent_params, @input),
133
+ @output
134
+ end
135
+ end
136
+ end
137
+
138
+ end
139
+ end