contained_mr 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/contained_mr.gemspec +2 -2
- data/lib/contained_mr/mock/runner.rb +33 -0
- data/test/test_mock_runner.rb +60 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a671efb4fb8421ddf841a9eeabb64b5612bf930
|
4
|
+
data.tar.gz: 304aff98010a52db78225a845406f0cb19bd0651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d558c08cce053336b116dda4a270c8d391de24d1b1d7ddecaf4c7761b0cb5ac227dbc7952f268c9b6a1448fd935290510d6e34ff061e09d203b2758fb0b14f0f
|
7
|
+
data.tar.gz: 388ef7ed32cf7506b732cabe66b8f38b869014f89d2b6916e6fc955133c953d6811cbce86daba9fc037746af68063c3fa96738ff6c8dd5eb5fcd9993fd37e8fd
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/contained_mr.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: contained_mr 0.3.
|
5
|
+
# stub: contained_mr 0.3.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "contained_mr"
|
9
|
-
s.version = "0.3.
|
9
|
+
s.version = "0.3.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -83,4 +83,37 @@ class ContainedMr::Mock::Runner
|
|
83
83
|
end
|
84
84
|
nil
|
85
85
|
end
|
86
|
+
|
87
|
+
# Convenience method for looking up the RAM limit in the container options.
|
88
|
+
#
|
89
|
+
# @return {Number} the container's RAM limit, in megabytes
|
90
|
+
def _ram_limit
|
91
|
+
return nil unless host_config = @_container_options['HostConfig']
|
92
|
+
return nil unless memory = host_config['Memory']
|
93
|
+
memory / (1024 * 1024).to_f
|
94
|
+
end
|
95
|
+
|
96
|
+
# Convenience method for looking up the swap limit in the container options.
|
97
|
+
#
|
98
|
+
# @return {Number} the container's swap limit, in megabytes
|
99
|
+
def _swap_limit
|
100
|
+
return nil unless host_config = @_container_options['HostConfig']
|
101
|
+
return nil unless memory = host_config['Memory']
|
102
|
+
return nil unless memory_swap = host_config['MemorySwap']
|
103
|
+
|
104
|
+
return 0 if memory_swap == -1
|
105
|
+
(memory_swap - memory) / (1024 * 1024).to_f
|
106
|
+
end
|
107
|
+
|
108
|
+
# Convenience method for looking up CPU allocation in the container options.
|
109
|
+
#
|
110
|
+
# @return {Number} the number of CPU cores allocated to the container; this
|
111
|
+
# can be a fraction
|
112
|
+
def _vcpus
|
113
|
+
return nil unless host_config = @_container_options['HostConfig']
|
114
|
+
return nil unless period = host_config['CpuPeriod']
|
115
|
+
return nil unless shares = host_config['CpuShares']
|
116
|
+
|
117
|
+
shares / period.to_f
|
118
|
+
end
|
86
119
|
end
|
data/test/test_mock_runner.rb
CHANGED
@@ -102,4 +102,64 @@ class TestMockRunner < MiniTest::Test
|
|
102
102
|
assert_equal nil, runner._ulimit('cpu')
|
103
103
|
assert_equal nil, runner._ulimit('rss')
|
104
104
|
end
|
105
|
+
|
106
|
+
def test_memory_cpu_limits
|
107
|
+
assert_equal 256.5, @runner._ram_limit
|
108
|
+
assert_equal 64, @runner._swap_limit
|
109
|
+
assert_equal 1.5, @runner._vcpus
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_memory_cpu_limits_without_host_config
|
113
|
+
@container_options.delete 'HostConfig'
|
114
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
115
|
+
'/usr/mrd/map-output'
|
116
|
+
assert_equal nil, runner._ram_limit
|
117
|
+
assert_equal nil, runner._swap_limit
|
118
|
+
assert_equal nil, runner._vcpus
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_memory_cpu_limits_without_host_config_memory
|
122
|
+
@container_options['HostConfig'].delete 'Memory'
|
123
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
124
|
+
'/usr/mrd/map-output'
|
125
|
+
assert_equal nil, runner._ram_limit
|
126
|
+
assert_equal nil, runner._swap_limit
|
127
|
+
assert_equal 1.5, runner._vcpus
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_memory_cpu_limits_without_host_config_memory_swap
|
131
|
+
@container_options['HostConfig'].delete 'MemorySwap'
|
132
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
133
|
+
'/usr/mrd/map-output'
|
134
|
+
assert_equal 256.5, runner._ram_limit
|
135
|
+
assert_equal nil, runner._swap_limit
|
136
|
+
assert_equal 1.5, runner._vcpus
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_memory_cpu_limits_without_host_config_cpu_shares
|
140
|
+
@container_options['HostConfig'].delete 'CpuShares'
|
141
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
142
|
+
'/usr/mrd/map-output'
|
143
|
+
assert_equal 256.5, runner._ram_limit
|
144
|
+
assert_equal 64, runner._swap_limit
|
145
|
+
assert_equal nil, runner._vcpus
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_memory_cpu_limits_without_host_config_cpu_period
|
149
|
+
@container_options['HostConfig'].delete 'CpuPeriod'
|
150
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
151
|
+
'/usr/mrd/map-output'
|
152
|
+
assert_equal 256.5, runner._ram_limit
|
153
|
+
assert_equal 64, runner._swap_limit
|
154
|
+
assert_equal nil, runner._vcpus
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_memory_limits_without_swap
|
158
|
+
@container_options['HostConfig']['MemorySwap'] = -1
|
159
|
+
runner = ContainedMr::Mock::Runner.new @container_options, 2.5,
|
160
|
+
'/usr/mrd/map-output'
|
161
|
+
assert_equal 256.5, runner._ram_limit
|
162
|
+
assert_equal 0, runner._swap_limit
|
163
|
+
assert_equal 1.5, runner._vcpus
|
164
|
+
end
|
105
165
|
end
|