#470: Pass extra variables for building of product build lists.

This commit is contained in:
Vokhmin Alexey V 2015-04-20 23:29:43 +03:00
parent 12c98b9a08
commit b46d44395d
4 changed files with 85 additions and 20 deletions

View File

@ -34,27 +34,10 @@ module ProductBuildLists::AbfWorkerable
end end
def abf_worker_args def abf_worker_args
file_name = "#{project.name}-#{commit_hash}"
opts = default_url_options
opts.merge!({user: user.authentication_token, password: ''}) if user.present?
srcpath = url_helpers.archive_url(
project.name_with_owner,
file_name,
'tar.gz',
opts
)
cmd_params = "BUILD_ID=#{id} "
if product.platform.hidden?
token = product.platform.tokens.by_active.where(description: CACHED_CHROOT_TOKEN_DESCRIPTION).first
cmd_params << "TOKEN=#{token.authentication_token} " if token
end
cmd_params << params.to_s
{ {
id: id, id: id,
srcpath: srcpath, srcpath: abf_worker_srcpath,
params: cmd_params, params: abf_worker_params,
time_living: time_living, time_living: time_living,
main_script: main_script, main_script: main_script,
platform: { platform: {
@ -66,4 +49,36 @@ module ProductBuildLists::AbfWorkerable
} }
end end
# Private: Get URL to project archive.
#
# Returns the String.
def abf_worker_srcpath
file_name = "#{project.name}-#{commit_hash}"
opts = default_url_options
opts.merge!({user: user.authentication_token, password: ''}) if user.present?
url_helpers.archive_url(
project.name_with_owner,
file_name,
'tar.gz',
opts
)
end
# Private: Get params for ABF worker task.
#
# Returns the String with space separated params.
def abf_worker_params
p = {
'BUILD_ID' => id,
'PROJECT' => project.name_with_owner,
'PROJECT_VERSION' => project_version,
'COMMIT_HASH' => commit_hash,
}
if product.platform.hidden?
token = product.platform.tokens.by_active.where(description: CACHED_CHROOT_TOKEN_DESCRIPTION).first
p.merge!('TOKEN' => token.authentication_token) if token
end
p.map{ |k, v| "#{k}=#{v}" } * ' ' + ' ' + params.to_s
end
end end

View File

@ -69,3 +69,17 @@ en:
status: Select a status status: Select a status
product_name: Enter the name of product here. product_name: Enter the name of product here.
product_id: Enter the ID of product build list here. product_id: Enter the ID of product build list here.
params: "ARCH=x86_64"
hints:
product_build_list:
params_html: >
Enter above a params which will be used for running of <i>Main script</i>.
<br/>
By default passes next params:
<ul class='help-block'>
<li><i>BUILD_ID</i> - The build ID.</li>
<li><i>PROJECT</i> - The project name (e.g. abf/rosa-build).</li>
<li><i>PROJECT_VERSION</i> - The version of project.</li>
<li><i>COMMIT_HASH</i> - The commit hash.</li>
<li><i>TOKEN</i> - The token for access to hidden platform.</li>
</ul>

View File

@ -69,3 +69,17 @@ ru:
status: Выберите статус status: Выберите статус
product_name: Введите название продукта здесь. product_name: Введите название продукта здесь.
product_id: Введите Id сборочного листа продукта здесь. product_id: Введите Id сборочного листа продукта здесь.
params: "ARCH=x86_64"
hints:
product_build_list:
params_html: >
Введите выше параметры, с которыми будет запускаться <i>Основной скрипт</i>.
<br/>
По умолчанию передаются следующие параметры:
<ul class='help-block'>
<li><i>BUILD_ID</i> - ID сборки.</li>
<li><i>PROJECT</i> - Название проекта (например abf/rosa-build).</li>
<li><i>PROJECT_VERSION</i> - Версия проекта.</li>
<li><i>COMMIT_HASH</i> - Хэш коммита.</li>
<li><i>TOKEN</i> - Токен для доступа к закрытой платформе.</li>
</ul>

View File

@ -3,6 +3,8 @@ require 'spec_helper'
describe ProductBuildList do describe ProductBuildList do
before { stub_symlink_methods } before { stub_symlink_methods }
let(:pbl) { FactoryGirl.build(:product_build_list) }
context 'ensures that validations and associations exist' do context 'ensures that validations and associations exist' do
before do before do
arch = double(:arch, id: 123, name: 'x86_64') arch = double(:arch, id: 123, name: 'x86_64')
@ -35,4 +37,24 @@ describe ProductBuildList do
it { is_expected.to allow_mass_assignment_of(:status) } it { is_expected.to allow_mass_assignment_of(:status) }
it { is_expected.to allow_mass_assignment_of(:base_url) } it { is_expected.to allow_mass_assignment_of(:base_url) }
end end
describe '#abf_worker_srcpath' do
it 'returns URL to project archive' do
expect(pbl.send :abf_worker_srcpath).to be_present
end
end
describe '#abf_worker_params' do
let(:pbl) { FactoryGirl.build(:product_build_list, id: 1234, params: 'ARCH=x86') }
it 'returns String with params' do
expect(pbl.send :abf_worker_params).to eq "BUILD_ID=#{pbl.id} PROJECT=#{pbl.project.name_with_owner} PROJECT_VERSION=#{pbl.project_version} COMMIT_HASH=#{pbl.commit_hash} ARCH=x86"
end
end
describe '#abf_worker_args' do
it 'returns Hash with args' do
expect(pbl.send :abf_worker_args).to be_present
end
end
end end