warden-protocol 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +6 -0
- data/README.md +13 -0
- data/Rakefile +40 -0
- data/lib/warden/protocol.rb +4 -0
- data/lib/warden/protocol/base.rb +168 -0
- data/lib/warden/protocol/buffer.rb +69 -0
- data/lib/warden/protocol/build.sh +13 -0
- data/lib/warden/protocol/message.rb +50 -0
- data/lib/warden/protocol/pb.rb +497 -0
- data/lib/warden/protocol/pb/copy_in.proto +35 -0
- data/lib/warden/protocol/pb/copy_out.proto +39 -0
- data/lib/warden/protocol/pb/create.proto +65 -0
- data/lib/warden/protocol/pb/destroy.proto +33 -0
- data/lib/warden/protocol/pb/echo.proto +26 -0
- data/lib/warden/protocol/pb/error.proto +19 -0
- data/lib/warden/protocol/pb/info.proto +95 -0
- data/lib/warden/protocol/pb/limit_bandwidth.proto +30 -0
- data/lib/warden/protocol/pb/limit_disk.proto +70 -0
- data/lib/warden/protocol/pb/limit_memory.proto +34 -0
- data/lib/warden/protocol/pb/link.proto +40 -0
- data/lib/warden/protocol/pb/list.proto +25 -0
- data/lib/warden/protocol/pb/message.proto +36 -0
- data/lib/warden/protocol/pb/net_in.proto +39 -0
- data/lib/warden/protocol/pb/net_out.proto +35 -0
- data/lib/warden/protocol/pb/ping.proto +24 -0
- data/lib/warden/protocol/pb/resource_limits.proto +30 -0
- data/lib/warden/protocol/pb/run.proto +29 -0
- data/lib/warden/protocol/pb/spawn.proto +37 -0
- data/lib/warden/protocol/pb/stop.proto +40 -0
- data/lib/warden/protocol/pb/stream.proto +41 -0
- data/lib/warden/protocol/version.rb +7 -0
- data/spec/base_spec.rb +150 -0
- data/spec/buffer_spec.rb +65 -0
- data/spec/copy_in_spec.rb +51 -0
- data/spec/copy_out_spec.rb +56 -0
- data/spec/create_spec.rb +70 -0
- data/spec/destroy_spec.rb +36 -0
- data/spec/echo_spec.rb +42 -0
- data/spec/error_spec.rb +33 -0
- data/spec/info_spec.rb +122 -0
- data/spec/limit_bandwidth_spec.rb +57 -0
- data/spec/limit_disk_spec.rb +103 -0
- data/spec/limit_memory_spec.rb +47 -0
- data/spec/link_spec.rb +67 -0
- data/spec/list_spec.rb +41 -0
- data/spec/net_in_spec.rb +57 -0
- data/spec/net_out_spec.rb +47 -0
- data/spec/ping_spec.rb +32 -0
- data/spec/resource_limits_spec.rb +84 -0
- data/spec/run_spec.rb +79 -0
- data/spec/spawn_spec.rb +55 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/stop_spec.rb +46 -0
- data/spec/stream_spec.rb +65 -0
- data/spec/support/examples/wrappable_reply.rb +26 -0
- data/spec/support/examples/wrappable_request.rb +26 -0
- data/spec/support/helper.rb +122 -0
- data/spec/support/matchers.rb +22 -0
- data/warden-protocol.gemspec +21 -0
- metadata +166 -0
data/spec/buffer_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "warden/protocol/buffer"
|
5
|
+
|
6
|
+
describe Warden::Protocol::Buffer do
|
7
|
+
let(:request) { Warden::Protocol::EchoRequest.new(:message => "request") }
|
8
|
+
let(:response) { Warden::Protocol::EchoResponse.new(:message => "response") }
|
9
|
+
|
10
|
+
it "should support iterating over requests" do
|
11
|
+
subject << Warden::Protocol::Buffer.request_to_wire(request)
|
12
|
+
subject.each_request do |request|
|
13
|
+
request.class.should == Warden::Protocol::EchoRequest
|
14
|
+
request.message.should == "request"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should support iterating over responses" do
|
19
|
+
subject << Warden::Protocol::Buffer.response_to_wire(response)
|
20
|
+
subject.each_response do |response|
|
21
|
+
response.class.should == Warden::Protocol::EchoResponse
|
22
|
+
response.message.should == "response"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "fuzzing" do
|
27
|
+
it "should not break request iteration" do
|
28
|
+
data = Warden::Protocol::Buffer.request_to_wire(request)
|
29
|
+
|
30
|
+
loop do
|
31
|
+
chunk = data.slice!(0)
|
32
|
+
subject << chunk
|
33
|
+
break if data.empty?
|
34
|
+
|
35
|
+
subject.each_request do
|
36
|
+
fail
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
subject.each_request do |request|
|
41
|
+
request.class.should == Warden::Protocol::EchoRequest
|
42
|
+
request.message.should == "request"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not break response iteration" do
|
47
|
+
data = Warden::Protocol::Buffer.response_to_wire(response)
|
48
|
+
|
49
|
+
loop do
|
50
|
+
chunk = data.slice!(0)
|
51
|
+
subject << chunk
|
52
|
+
break if data.empty?
|
53
|
+
|
54
|
+
subject.each_response do
|
55
|
+
fail
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
subject.each_response do |response|
|
60
|
+
response.class.should == Warden::Protocol::EchoResponse
|
61
|
+
response.message.should == "response"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Warden::Protocol::CopyInRequest do
|
6
|
+
subject(:request) do
|
7
|
+
described_class.new(
|
8
|
+
:handle => "handle",
|
9
|
+
:src_path => "/src",
|
10
|
+
:dst_path => "/dst",
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like "wrappable request"
|
15
|
+
|
16
|
+
its("class.type_camelized") { should == "CopyIn" }
|
17
|
+
its("class.type_underscored") { should == "copy_in" }
|
18
|
+
|
19
|
+
field :handle do
|
20
|
+
it_should_be_required
|
21
|
+
it_should_be_typed_as_string
|
22
|
+
end
|
23
|
+
|
24
|
+
field :src_path do
|
25
|
+
it_should_be_required
|
26
|
+
it_should_be_typed_as_string
|
27
|
+
end
|
28
|
+
|
29
|
+
field :dst_path do
|
30
|
+
it_should_be_required
|
31
|
+
it_should_be_typed_as_string
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should respond to #create_response" do
|
35
|
+
request.create_response.should be_a(Warden::Protocol::CopyInResponse)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe Warden::Protocol::CopyInResponse do
|
40
|
+
subject(:response) do
|
41
|
+
described_class.new
|
42
|
+
end
|
43
|
+
|
44
|
+
it_should_behave_like "wrappable response"
|
45
|
+
|
46
|
+
its("class.type_camelized") { should == "CopyIn" }
|
47
|
+
its("class.type_underscored") { should == "copy_in" }
|
48
|
+
|
49
|
+
it { should be_ok }
|
50
|
+
it { should_not be_error }
|
51
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Warden::Protocol::CopyOutRequest do
|
6
|
+
subject(:request) do
|
7
|
+
described_class.new(
|
8
|
+
:handle => "handle",
|
9
|
+
:src_path => "/src",
|
10
|
+
:dst_path => "/dst",
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like "wrappable request"
|
15
|
+
|
16
|
+
its("class.type_camelized") { should == "CopyOut" }
|
17
|
+
its("class.type_underscored") { should == "copy_out" }
|
18
|
+
|
19
|
+
field :handle do
|
20
|
+
it_should_be_required
|
21
|
+
it_should_be_typed_as_string
|
22
|
+
end
|
23
|
+
|
24
|
+
field :src_path do
|
25
|
+
it_should_be_required
|
26
|
+
it_should_be_typed_as_string
|
27
|
+
end
|
28
|
+
|
29
|
+
field :dst_path do
|
30
|
+
it_should_be_required
|
31
|
+
it_should_be_typed_as_string
|
32
|
+
end
|
33
|
+
|
34
|
+
field :owner do
|
35
|
+
it_should_be_optional
|
36
|
+
it_should_be_typed_as_string
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should respond to #create_response" do
|
40
|
+
request.create_response.should be_a(Warden::Protocol::CopyOutResponse)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Warden::Protocol::CopyOutResponse do
|
45
|
+
subject(:response) do
|
46
|
+
described_class.new
|
47
|
+
end
|
48
|
+
|
49
|
+
it_should_behave_like "wrappable response"
|
50
|
+
|
51
|
+
its("class.type_camelized") { should == "CopyOut" }
|
52
|
+
its("class.type_underscored") { should == "copy_out" }
|
53
|
+
|
54
|
+
it { should be_ok }
|
55
|
+
it { should_not be_error }
|
56
|
+
end
|
data/spec/create_spec.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Warden::Protocol::CreateRequest do
|
6
|
+
subject(:request) do
|
7
|
+
described_class.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it_should_behave_like "wrappable request"
|
11
|
+
|
12
|
+
its("class.type_camelized") { should == "Create" }
|
13
|
+
its("class.type_underscored") { should == "create" }
|
14
|
+
|
15
|
+
field :bind_mounts do
|
16
|
+
it_should_be_optional
|
17
|
+
|
18
|
+
it "should be populated with BindMount objects" do
|
19
|
+
m = Warden::Protocol::CreateRequest::BindMount.new
|
20
|
+
m.src_path = "/src"
|
21
|
+
m.dst_path = "/dst"
|
22
|
+
m.mode = Warden::Protocol::CreateRequest::BindMount::Mode::RO
|
23
|
+
|
24
|
+
subject.bind_mounts = [m]
|
25
|
+
subject.should be_valid
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
field :grace_time do
|
30
|
+
it_should_be_optional
|
31
|
+
it_should_be_typed_as_uint
|
32
|
+
end
|
33
|
+
|
34
|
+
field :handle do
|
35
|
+
it_should_be_optional
|
36
|
+
it_should_be_typed_as_string
|
37
|
+
end
|
38
|
+
|
39
|
+
field :network do
|
40
|
+
it_should_be_optional
|
41
|
+
it_should_be_typed_as_string
|
42
|
+
end
|
43
|
+
|
44
|
+
field :rootfs do
|
45
|
+
it_should_be_optional
|
46
|
+
it_should_be_typed_as_string
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should respond to #create_response" do
|
50
|
+
request.create_response.should be_a(Warden::Protocol::CreateResponse)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe Warden::Protocol::CreateResponse do
|
55
|
+
subject(:response) do
|
56
|
+
described_class.new(:handle => "handle")
|
57
|
+
end
|
58
|
+
|
59
|
+
it_should_behave_like "wrappable response"
|
60
|
+
|
61
|
+
its("class.type_camelized") { should == "Create" }
|
62
|
+
its("class.type_underscored") { should == "create" }
|
63
|
+
|
64
|
+
it { should be_ok }
|
65
|
+
it { should_not be_error }
|
66
|
+
|
67
|
+
field :handle do
|
68
|
+
it_should_be_required
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Warden::Protocol::DestroyRequest do
|
6
|
+
subject(:request) do
|
7
|
+
described_class.new(:handle => "handle")
|
8
|
+
end
|
9
|
+
|
10
|
+
it_should_behave_like "wrappable request"
|
11
|
+
|
12
|
+
its("class.type_camelized") { should == "Destroy" }
|
13
|
+
its("class.type_underscored") { should == "destroy" }
|
14
|
+
|
15
|
+
field :handle do
|
16
|
+
it_should_be_required
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should respond to #create_response" do
|
20
|
+
request.create_response.should be_a(Warden::Protocol::DestroyResponse)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Warden::Protocol::DestroyResponse do
|
25
|
+
subject(:response) do
|
26
|
+
described_class.new
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like "wrappable response"
|
30
|
+
|
31
|
+
its("class.type_camelized") { should == "Destroy" }
|
32
|
+
its("class.type_underscored") { should == "destroy" }
|
33
|
+
|
34
|
+
it { should be_ok }
|
35
|
+
it { should_not be_error }
|
36
|
+
end
|
data/spec/echo_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Warden::Protocol::EchoRequest do
|
6
|
+
subject(:request) do
|
7
|
+
described_class.new(:message => "here's a snowman: ☃")
|
8
|
+
end
|
9
|
+
|
10
|
+
it_should_behave_like "wrappable request"
|
11
|
+
|
12
|
+
its("class.type_camelized") { should == "Echo" }
|
13
|
+
its("class.type_underscored") { should == "echo" }
|
14
|
+
|
15
|
+
field :message do
|
16
|
+
it_should_be_required
|
17
|
+
it_should_be_typed_as_string
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should respond to #create_response" do
|
21
|
+
request.create_response.should be_a(Warden::Protocol::EchoResponse)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Warden::Protocol::EchoResponse do
|
26
|
+
subject(:response) do
|
27
|
+
described_class.new(:message => "here's a snowman: ☃")
|
28
|
+
end
|
29
|
+
|
30
|
+
it_should_behave_like "wrappable response"
|
31
|
+
|
32
|
+
its("class.type_camelized") { should == "Echo" }
|
33
|
+
its("class.type_underscored") { should == "echo" }
|
34
|
+
|
35
|
+
it { should be_ok }
|
36
|
+
it { should_not be_error }
|
37
|
+
|
38
|
+
field :message do
|
39
|
+
it_should_be_required
|
40
|
+
it_should_be_typed_as_string
|
41
|
+
end
|
42
|
+
end
|
data/spec/error_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Warden::Protocol::ErrorResponse do
|
6
|
+
subject(:response) do
|
7
|
+
described_class.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it_should_behave_like "wrappable response"
|
11
|
+
|
12
|
+
it { should_not be_ok }
|
13
|
+
it { should be_error }
|
14
|
+
|
15
|
+
field :message do
|
16
|
+
it_should_be_optional
|
17
|
+
it_should_be_typed_as_string
|
18
|
+
end
|
19
|
+
|
20
|
+
field :data do
|
21
|
+
it_should_be_optional
|
22
|
+
it_should_be_typed_as_string
|
23
|
+
end
|
24
|
+
|
25
|
+
field :backtrace do
|
26
|
+
it_should_be_optional
|
27
|
+
|
28
|
+
it "should allow one or more entries" do
|
29
|
+
subject.backtrace = ["a", "b"]
|
30
|
+
subject.should be_valid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/info_spec.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Warden::Protocol::InfoRequest do
|
6
|
+
subject(:request) do
|
7
|
+
described_class.new(:handle => "handle")
|
8
|
+
end
|
9
|
+
|
10
|
+
it_should_behave_like "wrappable request"
|
11
|
+
|
12
|
+
its("class.type_camelized") { should == "Info" }
|
13
|
+
its("class.type_underscored") { should == "info" }
|
14
|
+
|
15
|
+
field :handle do
|
16
|
+
it_should_be_required
|
17
|
+
it_should_be_typed_as_string
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should respond to #create_response" do
|
21
|
+
request.create_response.should be_a(Warden::Protocol::InfoResponse)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Warden::Protocol::InfoResponse::CpuStat do
|
26
|
+
field :usage do
|
27
|
+
it_should_be_optional
|
28
|
+
it_should_be_typed_as_uint64
|
29
|
+
end
|
30
|
+
|
31
|
+
field :user do
|
32
|
+
it_should_be_optional
|
33
|
+
it_should_be_typed_as_uint64
|
34
|
+
end
|
35
|
+
|
36
|
+
field :system do
|
37
|
+
it_should_be_optional
|
38
|
+
it_should_be_typed_as_uint64
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe Warden::Protocol::InfoResponse::DiskStat do
|
43
|
+
field :bytes_used do
|
44
|
+
it_should_be_optional
|
45
|
+
it_should_be_typed_as_uint64
|
46
|
+
end
|
47
|
+
|
48
|
+
field :inodes_used do
|
49
|
+
it_should_be_optional
|
50
|
+
it_should_be_typed_as_uint64
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe Warden::Protocol::InfoResponse do
|
55
|
+
subject(:response) do
|
56
|
+
described_class.new
|
57
|
+
end
|
58
|
+
|
59
|
+
it_should_behave_like "wrappable response"
|
60
|
+
|
61
|
+
its("class.type_camelized") { should == "Info" }
|
62
|
+
its("class.type_underscored") { should == "info" }
|
63
|
+
|
64
|
+
it { should be_ok }
|
65
|
+
it { should_not be_error }
|
66
|
+
|
67
|
+
field :state do
|
68
|
+
it_should_be_optional
|
69
|
+
it_should_be_typed_as_string
|
70
|
+
end
|
71
|
+
|
72
|
+
field :events do
|
73
|
+
it_should_be_optional
|
74
|
+
|
75
|
+
it "should allow one or more events" do
|
76
|
+
subject.events = ["a", "b"]
|
77
|
+
subject.should be_valid
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
field :host_ip do
|
82
|
+
it_should_be_optional
|
83
|
+
it_should_be_typed_as_string
|
84
|
+
end
|
85
|
+
|
86
|
+
field :container_ip do
|
87
|
+
it_should_be_optional
|
88
|
+
it_should_be_typed_as_string
|
89
|
+
end
|
90
|
+
|
91
|
+
field :container_path do
|
92
|
+
it_should_be_optional
|
93
|
+
it_should_be_typed_as_string
|
94
|
+
end
|
95
|
+
|
96
|
+
field :cpu_stat do
|
97
|
+
it_should_be_optional
|
98
|
+
|
99
|
+
it "should allow instances of CpuStat" do
|
100
|
+
subject.cpu_stat = Warden::Protocol::InfoResponse::CpuStat.new
|
101
|
+
subject.should be_valid
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
field :disk_stat do
|
106
|
+
it_should_be_optional
|
107
|
+
|
108
|
+
it "should allow instances of DiskStat" do
|
109
|
+
subject.disk_stat = Warden::Protocol::InfoResponse::DiskStat.new
|
110
|
+
subject.should be_valid
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
field :job_ids do
|
115
|
+
it_should_be_optional
|
116
|
+
|
117
|
+
it "should allow one or more job ids" do
|
118
|
+
subject.job_ids = [1, 2]
|
119
|
+
subject.should be_valid
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|