Skip to content

Commit

Permalink
removed some env variables from default/mesos-* as preferred way is c…
Browse files Browse the repository at this point in the history
…onfiguration

via files in /etc/mesos-{master,slave} (as it was mentioned in #12)
  • Loading branch information
deric committed Jul 23, 2014
1 parent 32b456d commit 3994432
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 35 deletions.
16 changes: 14 additions & 2 deletions manifests/slave.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
# [*work_dir*] - directory for storing task's temporary files
# (default: /tmp/mesos)
# [*isolation*] - isolation mechanism - either 'process' or 'cgroups'
# newer versions of Mesos > 0.18 support isolation mechanism
# 'cgroups/cpu,cgroups/mem' or posix/cpu,posix/mem
#
#
# [*options*] any extra arguments that are not named here could be
# stored in a hash:
#
# options => { "key" => "value" }
#
# (as value you can pass either string, boolean or numeric value)
# which is serialized to disk and then passed to mesos-slave as:
#
# --key=value
Expand All @@ -37,7 +41,7 @@
$port = 5051,
$work_dir = '/tmp/mesos',
$checkpoint = false,
$isolation = 'process',
$isolation = '',
$conf_dir = '/etc/mesos-slave',
$conf_file = '/etc/default/mesos-slave',
$use_syslog = false,
Expand All @@ -59,6 +63,7 @@
validate_hash($options)
validate_hash($resources)
validate_hash($attributes)
validate_string($isolation)

file { $conf_dir:
ensure => directory,
Expand Down Expand Up @@ -96,6 +101,13 @@
}
)

# for backwards compatibility, prefered way is specification via $options
if !empty($isolation) {
$merged_options = merge($options, {'isolation' => $isolation})
}else {
$merged_options = $options
}

# work_dir can't be specified via options,
# we would get a duplicate declaration error
mesos::property {'slave_work_dir':
Expand All @@ -113,7 +125,7 @@
}

create_resources(mesos::property,
mesos_hash_parser($options),
mesos_hash_parser($merged_options),
{
dir => $conf_dir,
service => Service['mesos-slave'],
Expand Down
74 changes: 55 additions & 19 deletions spec/classes/slave_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@
end

it 'checkpoint should be false' do
should contain_file(
slave_file
).with_content(/^CHECKPOINT=false/)
should_not contain_file(
"#{conf}/?checkpoint"
).with({
'ensure' => 'present',
})
end

it 'should have workdir in /tmp/mesos' do
should contain_file(
slave_file
).with_content(/^WORKDIR="\/tmp\/mesos"/)
"#{conf}/work_dir"
).with_content(/^\/tmp\/mesos$/)
end

context 'one master node' do
Expand Down Expand Up @@ -99,18 +101,36 @@
}}

it { should contain_file(
slave_file
).with_content(/^WORKDIR="\/home\/mesos"/) }
"#{conf}/work_dir"
).with_content(/^\/home\/mesos$/) }
end

context 'changing checkpoint' do
context 'enabling checkpoint (enabled by default anyway)' do
let(:params){{
:checkpoint => true,
:options => {
'checkpoint' => true,
}
}}

it { should contain_file(
slave_file
).with_content(/CHECKPOINT=true/) }
"#{conf}/?checkpoint"
).with({
'ensure' => 'present',
}) }
end

context 'disabling checkpoint' do
let(:params){{
:options => {
'checkpoint' => false,
}
}}

it { should contain_file(
"#{conf}/?no-checkpoint"
).with({
'ensure' => 'present',
}) }
end

context 'setting environment variables' do
Expand All @@ -130,10 +150,24 @@
).with_content(/export MESOS_HOME="\/var\/lib\/mesos"/) }
end

it 'should have isolation eq to process' do
should contain_file(
slave_file
).with_content(/^ISOLATION="process"/)
it 'should not set isolation by default (value depends on mesos version)' do
should_not contain_file(
"#{conf}/isolation"
).with({
'ensure' => 'present',
})
end

context 'should set isolation to cgroups' do
let(:params){{
:isolation => 'cgroups/cpu,cgroups/mem',
}}

it { should contain_file(
"#{conf}/isolation"
).with({
'ensure' => 'present',
}).with_content(/^cgroups\/cpu,cgroups\/mem$/) }
end

it 'should not contain cgroups settings' do
Expand All @@ -144,7 +178,7 @@

context 'setting isolation mechanism' do
let(:params){{
:isolation => 'cgroups',
:isolation => 'cgroups/cpu,cgroups/mem',
:cgroups => {
'hierarchy' => '/sys/fs/cgroup',
'root' => 'mesos',
Expand All @@ -160,8 +194,10 @@
).with_content(/^\/sys\/fs\/cgroup$/)}

it { should contain_file(
slave_file
).with_content(/^ISOLATION="cgroups"/)}
"#{conf}/isolation"
).with({
'ensure' => 'present',
}).with_content(/^cgroups\/cpu,cgroups\/mem$/) }
end

context 'changing slave config file location' do
Expand Down Expand Up @@ -256,7 +292,7 @@
}}

it { should contain_file(
slave_file
"#{conf}/work_dir"
).with_content(/\/tmp\/mesos/) }

it { should contain_file(work_dir).with({
Expand Down
2 changes: 0 additions & 2 deletions templates/master.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ WHITELIST='<%= @whitelist %>'
# option list is available with /usr/sbin/mesos-master --help
# EX :
# export MESOS_log_dir=/var/log/mesos

#export MESOS_work_dir="<%= @work_dir %>"
12 changes: 0 additions & 12 deletions templates/slave.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ IP="<%= @listen_address %>"
# Port to listen on (default: 5051)
PORT=<%= @port %>

# Where to place framework work directories (default: /tmp/mesos)
WORKDIR="<%= @work_dir %>"

# Whether to checkpoint slave and frameworks information
# to disk. This enables a restarted slave to recover
# status updates and reconnect with (--recover=reconnect) or
# kill (--recover=kill) old executors (default: false)
CHECKPOINT=<%= @checkpoint %>

# Isolation mechanism, may be one of: process, cgroups (default: process)
ISOLATION="<%= @isolation %>"

<% @cgroups.sort.each do |key, val| -%>
CGROUPS_<%= key.upcase %>="<%= val %>"
<% end if @isolation == 'cgroups' -%>
Expand Down

0 comments on commit 3994432

Please sign in to comment.