Skip to content

Commit 9ad0a7f

Browse files
committed
Attempt to eliminate hardcoded paths for yas3fs and python
Thank you @djtaylor pcfens#5 Closes !5
1 parent 9a86749 commit 9ad0a7f

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

manifests/package.pp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@
6161
$_exec_command = ". ${venv_path}/bin/activate && ${python_version} /var/tmp/yas3fs/setup.py install --prefix=${venv_path}"
6262
$_exec_creates = "${venv_path}/bin/yas3fs"
6363
}else{
64-
$_exec_command = "/usr/bin/${python_version} /var/tmp/yas3fs/setup.py install"
64+
$_exec_command = "/usr/bin/env ${python_version} /var/tmp/yas3fs/setup.py install"
65+
# Users which install does not create /usr/bin/yasfs consider making a symlink to
66+
# Wherever it got installed so puppet will not attempt to reinstall every run
67+
# I can really only test on a Redhat machine and relay on rspec to test everything else
68+
# - Ron (mojibake-umd) -
6569
$_exec_creates = '/usr/bin/yas3fs'
66-
6770
}
6871

6972
exec { 'install yas3fs':

spec/classes/yas3fs_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040
it {
4141
is_expected.to contain_exec('install yas3fs').with(
42-
'command' => '/usr/bin/python3 /var/tmp/yas3fs/setup.py install',
42+
'command' => '/usr/bin/env python3 /var/tmp/yas3fs/setup.py install',
4343
'creates' => '/usr/bin/yas3fs',
4444
'cwd' => '/var/tmp/yas3fs',
4545
'require' => 'Vcsrepo[/var/tmp/yas3fs]',
@@ -89,6 +89,7 @@
8989
'venv_path' => '/opt/yas3fs/venv'
9090
}
9191
end
92+
9293
it {
9394
is_expected.to contain_exec('install yas3fs').with(
9495
'command' => '. /opt/yas3fs/venv/bin/activate && python3 /var/tmp/yas3fs/setup.py install --prefix=/opt/yas3fs/venv',

spec/defines/mount_spec.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
'ensure' => 'present',
3131
'path' => '/etc/init/s3fs-test-mount.conf',
3232
'notify' => 'Service[s3fs-test-mount]',
33-
'content' => /exec \/usr\/local\/bin\/yas3fs -f \"\$S3_URL\" \"\$LOCAL_PATH\"/
33+
'content' => %r{exec /usr/bin/env yas3fs -f \"\$S3_URL\" \"\$LOCAL_PATH\"},
3434
)
3535
}
3636

@@ -63,7 +63,7 @@
6363
'ensure' => 'present',
6464
'path' => '/etc/init/s3fs-test-mount.conf',
6565
'notify' => 'Service[s3fs-test-mount]',
66-
'content' => /exec \/opt\/yas3fs\/venv\/bin\/yas3fs -f \"\$S3_URL\" \"\$LOCAL_PATH\"/
66+
'content' => %r{exec /opt/yas3fs/venv/bin/yas3fs -f \"\$S3_URL\" \"\$LOCAL_PATH\"},
6767
)
6868
}
6969

@@ -103,7 +103,7 @@
103103
'ensure' => 'present',
104104
'path' => '/etc/systemd/system/s3fs-test-mount.service',
105105
'notify' => 'Service[s3fs-test-mount]',
106-
'content' => /ExecStart=\/usr\/bin\/yas3fs -f s3:\/\/test-bucket \/media\/test-mount/
106+
'content' => %r{ExecStart=/usr/bin/env yas3fs -f s3://test-bucket /media/test-mount},
107107
)
108108
}
109109

@@ -133,10 +133,9 @@
133133

134134
it {
135135
is_expected.to contain_file('yas3fs-test-mount').with(
136-
'content' => /\/opt\/yas3fs\/venv\/yas3fs -f s3:\/\/test-bucket \/media\/test-mount/
136+
'content' => %r{/opt/yas3fs/venv/bin/yas3fs -f s3://test-bucket /media/test-mount},
137137
)
138138
}
139-
140139
end
141140

142141
context 'with sysvinit' do
@@ -159,7 +158,7 @@
159158
'ensure' => 'present',
160159
'path' => '/etc/init.d/s3fs-test-mount',
161160
'notify' => 'Service[s3fs-test-mount]',
162-
'content' => /PATH=\/usr\/local\/bin:\$PATH/
161+
'content' => %r{PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:\$PATH},
163162
)
164163
}
165164

@@ -188,7 +187,7 @@
188187

189188
it {
190189
is_expected.to contain_file('yas3fs-test-mount').with(
191-
'content' => /PATH=\/opt\/yas3fs\/venv:\/usr\/local\/bin:\$PATH/
190+
'content' => %r{PATH=/opt/yas3fs/venv/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:\$PATH},
192191
)
193192
}
194193
end

templates/systemd.erb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ Environment=AWS_ACCESS_KEY_ID=<%= @aws_access_key_id %> AWS_SECRET_ACCESS_KEY=<%
1313
<% @options.each do |v| -%>
1414
<% cmd_args = "#{cmd_args} --#{v}" -%>
1515
<% end -%>
16-
# TODO: systemd requires a fully qualified path... but Puppet doesn't give us a
17-
# good way to query what the path to a particular binary is :-/ This may need
18-
# some further work, PRs welcome
16+
# Thank @djtaylor https://github.com/pcfens/puppet-yas3fs/pull/5
17+
# /usr/bin/env yas3fs
1918
<% if @venv_path -%>
2019
WorkingDirectory=<%= @venv_path %>
21-
Environment=PATH=<%= @venv_path %>/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/puppetlabs/bin
22-
ExecStart=<%= @venv_path %>/yas3fs -f <%= cmd_args %> <%= @s3_url %> <%= @local_path %>
20+
Environment=PATH=<%= @venv_path %>/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
21+
ExecStart=<%= @venv_path %>/bin/yas3fs -f <%= cmd_args %> <%= @s3_url %> <%= @local_path %>
2322
<% else %>
24-
ExecStart=/usr/bin/yas3fs -f <%= cmd_args %> <%= @s3_url %> <%= @local_path %>
23+
Environment=PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
24+
ExecStart=/usr/bin/env yas3fs -f <%= cmd_args %> <%= @s3_url %> <%= @local_path %>
2525
<% end %>
26-
ExecStop=/bin/umount <%= @local_path %>
26+
ExecStop=/usr/bin/env umount <%= @local_path %>
2727
RestartSec=5
2828
Restart=on-failure
2929
OOMScoreAdjust=-1000

templates/sysvinit.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
### END INIT INFO
1515

1616
<% if @venv_path -%>
17-
PATH=<%= @venv_path %>:/usr/local/bin:$PATH
17+
PATH=<%= @venv_path %>/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
1818
<% else %>
19-
PATH=/usr/local/bin:$PATH
19+
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
2020
<% end %>
2121

2222
export S3_URL="<%= @s3_url %>"

templates/upstart.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ script
2525
<% if @venv_path -%>
2626
<%= "exec #{@venv_path}/bin/yas3fs -f #{cmd_args} \"$S3_URL\" \"$LOCAL_PATH\"" %>
2727
<% else %>
28-
<%= "exec /usr/local/bin/yas3fs -f #{cmd_args} \"$S3_URL\" \"$LOCAL_PATH\"" %>
28+
<%= "exec /usr/bin/env yas3fs -f #{cmd_args} \"$S3_URL\" \"$LOCAL_PATH\"" %>
2929
<% end %>
3030
end script
3131

0 commit comments

Comments
 (0)