Merge "Fix unsafe interpolations in exec"

This commit is contained in:
Zuul 2024-04-16 08:10:22 +00:00 committed by Gerrit Code Review
commit 4efaf7b895
2 changed files with 32 additions and 15 deletions

View File

@ -593,7 +593,7 @@ class tempest(
}
exec { 'install-tox':
command => "${tempest::params::pip_command} install -U tox",
command => [$tempest::params::pip_command, 'install', '-U', 'tox'],
unless => 'which tox',
path => ['/bin','/usr/bin','/usr/local/bin'],
}
@ -612,20 +612,24 @@ class tempest(
if $setup_venv {
# virtualenv will be installed along with tox
exec { 'setup-venv':
command => join(["virtualenv -p python3 ${tempest_clone_path}/.venv",
"${tempest_clone_path}/.venv/bin/${tempest::params::pip_command} install -U -r requirements.txt"],
' && '),
cwd => $tempest_clone_path,
exec { 'create-venv':
command => ['virtualenv', '-p', 'python3', "${tempest_clone_path}/.venv"],
creates => "${tempest_clone_path}/.venv",
path => ['/bin','/usr/bin','/usr/local/bin'],
path => ['/bin', '/usr/bin', '/usr/local/bin'],
require => [
Exec['install-tox'],
Package[$tempest::params::dev_packages],
],
}
exec { 'install-tempest':
command => ["${tempest_clone_path}/.venv/bin/${tempest::params::pip_command}", 'install', '-U', '-r', 'requirements.txt'],
cwd => $tempest_clone_path,
refreshonly => true,
subscribe => Exec['create-venv'],
}
if $git_clone {
Vcsrepo<||> -> Exec['setup-venv']
Vcsrepo<||> -> Exec['create-venv']
}
}
@ -642,7 +646,7 @@ class tempest(
# It will generate etc/tempest.conf, logs and tempest_lock folder
# in tempest workspace
exec {'tempest-workspace':
command => "tempest init ${tempest_workspace}",
command => ['tempest', 'init', $tempest_workspace],
path => ['/bin', '/usr/bin'],
refreshonly => true,
require => Package['tempest'],

View File

@ -183,7 +183,7 @@ describe 'tempest' do
end
is_expected.to contain_exec('install-tox').with(
:command => "#{platform_params[:pip_command]} install -U tox",
:command => [platform_params[:pip_command], 'install', '-U', 'tox'],
:unless => 'which tox',
:path => ['/bin', '/usr/bin', '/usr/local/bin'],
)
@ -387,13 +387,26 @@ describe 'tempest' do
end
it 'sets up virtualenv for tempest' do
is_expected.to contain_exec('setup-venv').with(
:command => "virtualenv -p python3 /var/lib/tempest/.venv && /var/lib/tempest/.venv/bin/#{platform_params[:pip_command]} install -U -r requirements.txt",
:cwd => '/var/lib/tempest',
is_expected.to contain_exec('create-venv').with(
:command => ['virtualenv', '-p', 'python3', '/var/lib/tempest/.venv'],
:creates => '/var/lib/tempest/.venv',
:path => ['/bin', '/usr/bin', '/usr/local/bin']
)
end
it 'installs tempest into the virtualenv' do
is_expected.to contain_exec('install-tempest').with(
:command => [
'virtualenv', '-p', 'python3', '/var/lib/tempest/.venv'
],
:command => [
"/var/lib/tempest/.venv/bin/#{platform_params[:pip_command]}", 'install',
'-U', '-r', 'requirements.txt'
],
:cwd => '/var/lib/tempest',
:refreshonly => true,
)
end
end
end
@ -429,7 +442,7 @@ describe 'tempest' do
end
it 'creates tempest workspace' do
is_expected.to contain_exec('tempest-workspace').with(
:command => 'tempest init /var/lib/tempest',
:command => ['tempest', 'init', '/var/lib/tempest'],
:path => ['/bin', '/usr/bin'],
:refreshonly => true,
:require => 'Package[tempest]'
@ -449,7 +462,7 @@ describe 'tempest' do
it 'supports customizes tempest workspace' do
is_expected.to contain_exec('tempest-workspace').with(
:command => 'tempest init /tmp/tempest',
:command => ['tempest', 'init', '/tmp/tempest'],
)
end
end