Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api][backend] freeze package sources on release #1275

Merged
merged 1 commit into from
Oct 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/api/api/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ POST /source

Parameters:

linkrev: linked revision, optional (for linkrev=base)
attribute: attribute used for package search, default is OBS:Maintained
update_project_attribute: attribute name used to find out possible existing update projects of a package
request: branch by request, branch all packages in actions of request for superseding it
Expand Down Expand Up @@ -797,14 +798,14 @@ Parameters:
keeplink: keep link on source commit, optional
repairlink: repair link on source commit, optional
dontupdatesource: Do not update origin package, optional (copy only)
noservice: do not run source services
comment: comment for history, optional
meta: switch to meta files
arch: architecture when using flag modifing command
repository: repository when using flag modifing command
view: may be "xml" for structured answered (for diff commands)
withissues: set to get issues parsed from changelogs (for diff commands)
onlyissues: used to limit to issues (for diff commands)
noservice: do not run source services
setrelease: define a specific release tag when used with "release" command. Setting it to "-" strips
the release string.

Expand Down
3 changes: 2 additions & 1 deletion src/api/app/helpers/branch_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ def create_branch_packages(tprj)
opackage = p[:package].name if p[:package].is_a? Package
oproject = p[:link_target_project]
oproject = p[:link_target_project].name if p[:link_target_project].is_a? Project

# branch sources in backend
tpkg.branch_from(oproject, opackage, p[:rev], params[:missingok])
tpkg.branch_from(oproject, opackage, p[:rev], params[:missingok], nil, params[:linkrev])
if response
# multiple package transfers, just tell the target project
response = { targetproject: tpkg.project.name }
Expand Down
5 changes: 3 additions & 2 deletions src/api/app/helpers/maintenance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ def release_package_copy_sources(action, sourcePackage, targetPackageName, targe
withacceptinfo: "1"
}
cp_params[:requestid] = action.bs_request.id if action
cp_params[:freezelink] = 1 if sourcePackage.is_link? # no permission check here on purpose
cp_path = "/source/#{CGI.escape(targetProject.name)}/#{CGI.escape(targetPackageName)}"
cp_path << Suse::Backend.build_query_from_hash(cp_params, [:cmd, :user, :oproject,
:opackage, :comment, :requestid,
:expand, :withvrev, :noservice,
:withacceptinfo])
result = Suse::Backend.post cp_path, nil
:freezelink, :withacceptinfo])
result = Suse::Backend.post(cp_path, nil)
result = Xmlhash.parse(result.body)
action.set_acceptinfo(result["acceptinfo"]) if action
end
Expand Down
3 changes: 2 additions & 1 deletion src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -968,14 +968,15 @@ def valid_name
errors.add(:name, 'is illegal') unless Package.valid_name?(self.name)
end

def branch_from(origin_project, origin_package, rev = nil, missingok = nil, comment = nil)
def branch_from(origin_project, origin_package, rev = nil, missingok = nil, comment = nil, linkrev = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a good point to replace some of the parameters by an options hash:)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed.

myparam = { cmd: "branch",
noservice: "1",
oproject: origin_project,
opackage: origin_package,
user: User.current.login
}
myparam[:orev] = rev if rev and not rev.empty?
myparam[:olinkrev] = linkrev if linkrev and not linkrev.empty?
myparam[:missingok] = '1' if missingok
myparam[:comment] = comment if comment
path = self.source_path + Suse::Backend.build_query_from_hash(myparam, [:cmd, :oproject, :opackage, :user, :comment, :orev, :missingok])
Expand Down
42 changes: 34 additions & 8 deletions src/api/test/functional/kgraft_maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ def test_kgraft_update_setup

# add channel
put '/source/BaseDistro2Channel/_meta', '<project name="BaseDistro2Channel"><title/><description/>
<build><disable/></build>
<publish><enable/></publish>
<repository name="channel_repo">
<arch>i586</arch>
<arch>x86_64</arch>
</repository>
</project>'
<build><disable/></build>
<publish><enable/></publish>
<repository name="channel_repo">
<arch>i586</arch>
<arch>x86_64</arch>
</repository>
</project>'
assert_response :success
put '/source/BaseDistro2Channel/_config', "Repotype: rpm-md-legacy\nType: spec"
assert_response :success
# channel def
put '/source/Channel/_meta', '<project name="Channel"><title/><description/>
</project>'
</project>'
assert_response :success
put '/source/Channel/BaseDistro2/_meta', '<package project="Channel" name="BaseDistro2"><title/><description/></package>'
assert_response :success
Expand Down Expand Up @@ -274,6 +274,16 @@ def test_kgraft_update_setup
post "/request/#{reqid}?cmd=diff"
assert_response :success

# link is still unfrozen
get "/source/#{incidentProject}/kgraft-GA.BaseDistro2.0/_link"
assert_response :success
node = ActiveXML::Node.new(@response.body)
assert_not node.has_attribute?(:rev)
get "/source/#{incidentProject}/kgraft-incident-0.My_Maintenance_0/_link"
assert_response :success
node = ActiveXML::Node.new(@response.body)
assert_not node.has_attribute?(:rev)

#### release packages
post "/request/#{reqid}?cmd=changestate&newstate=accepted&comment=releasing"
assert_response :success
Expand All @@ -288,6 +298,22 @@ def test_kgraft_update_setup
get '/source/BaseDistro2Channel/patchinfo.1'
assert_response :success

# links are frozen now
get "/source/#{incidentProject}/kgraft-GA.BaseDistro2.0/_link"
assert_response :success
node = ActiveXML::Node.new(@response.body)
assert node.has_attribute?(:rev)
get "/source/#{incidentProject}/kgraft-incident-0.My_Maintenance_0/_link"
assert_response :success
node = ActiveXML::Node.new(@response.body)
assert node.has_attribute?(:rev)

# old one still branchable even though conflicting change has been released?
post '/source', :cmd => 'branch', :package => 'pack2', :add_repositories => 1
assert_response :success
delete "/source/home:king:branches:OBS_Maintained:pack2"
assert_response :success

# cleanup
delete '/source/BaseDistro2.0:LinkedUpdateProject/kgraft-GA.1'
assert_response :success
Expand Down
2 changes: 1 addition & 1 deletion src/api/test/unit/code_quality_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def setup
'AttributeController#attribute_definition' => 87.7,
'BinaryRelease::update_binary_releases_via_json' => 128.58,
'BranchPackage#find_packages_to_branch' => 238.17,
'BranchPackage#create_branch_packages' => 214.0,
'BranchPackage#create_branch_packages' => 223.88,
'BranchPackage#check_for_update_project' => 105.96,
'BranchPackage#determine_details_about_package_to_branch' => 91.39,
'BranchPackage#lookup_incident_pkg' => 83.09,
Expand Down
28 changes: 19 additions & 9 deletions src/backend/bs_srcserver
Original file line number Diff line number Diff line change
Expand Up @@ -5973,16 +5973,17 @@ sub sourcecopy {

my $autosimplifylink;
my $autosimplifylink_lrev;
my $olink;

if ($files->{'_link'} && !$cgi->{'dontupdatesource'} && !$cgi->{'rev'}) {
# fix me: do this in a more generic way
my $ol = repreadxml($orev, '_link', $files->{'_link'}, $BSXML::link, 1);
if ($ol) {
$olink = repreadxml($orev, '_link', $files->{'_link'}, $BSXML::link, 1);
if ($olink) {
my $lprojid = $oprojid;
my $lpackid = $opackid;
my $lrev = $ol->{'rev'};
$lprojid = $ol->{'project'} if exists $ol->{'project'};
$lpackid = $ol->{'package'} if exists $ol->{'package'};
my $lrev = $olink->{'rev'};
$lprojid = $olink->{'project'} if exists $olink->{'project'};
$lpackid = $olink->{'package'} if exists $olink->{'package'};
if ($lprojid eq $projid && $lpackid eq $packid) {
# copy destination is target of link
# we're integrating this link
Expand All @@ -5991,12 +5992,12 @@ sub sourcecopy {
my $lfiles = $cgi->{'noservice'} && !$cgi->{'expand'} ? lsrev_service({ %$lrev }) : lsrev($lrev);
if ($lfiles->{'_link'} && !$cgi->{'expand'}) {
# link to a link, join
$files = integratelink($lfiles, $lprojid, $lpackid, $lrev, $files, $oprojid, $opackid, $ol, $orev);
$files = integratelink($lfiles, $lprojid, $lpackid, $lrev, $files, $oprojid, $opackid, $olink, $orev);
} else {
# auto expand
$cgi->{'expand'} = 1;
}
$autosimplifylink = $ol;
$autosimplifylink = $olink;
}
}
}
Expand Down Expand Up @@ -6039,7 +6040,16 @@ sub sourcecopy {
notify_repservers('package', $oprojid, $opackid);
}

if ($autosimplifylink && !defined($autosimplifylink->{'rev'})) {
if ($cgi->{'freezelink'}) {
die("400 freezelink: origin provides no link") unless $olink;
die("400 freezelink: link points to a revision already") if $olink->{'rev'};
die("400 freezelink: link has no baserev") unless $olink->{'baserev'};
$olink->{'rev'} = $olink->{'baserev'};
mkdir_p($uploaddir);
writexml("$uploaddir/$$", undef, $olink, $BSXML::link);
$files->{'_link'} = addfile($oprojid, $opackid, "$uploaddir/$$", '_link');
addrev({ %$cgi, 'user' => 'buildservice-autocommit', 'comment' => 'freeze link'}, $oprojid, $opackid, $files);
} elsif ($autosimplifylink && !defined($autosimplifylink->{'rev'})) {
$orev->{'srcmd5'} = $orev_srcmd5; # back to unexpanded

# make sure that vrev doesn't decrease when copying to the
Expand Down Expand Up @@ -8436,7 +8446,7 @@ my $dispatches = [
'POST:/source/$project/$package cmd=servicediff rev? unified:bool? file:filename* filelimit:num? tarlimit:num? view:? withissues:bool? onlyissues:bool?' => \&servicediff,
'POST:/source/$project/$package cmd=commit rev? user:? comment:? keeplink:bool? repairlink:bool? linkrev? setrev:bool? requestid:num? noservice:bool?' => \&sourcecommit,
'POST:/source/$project/$package cmd=commitfilelist rev? user:? comment:? keeplink:bool? repairlink:bool? linkrev? setrev:bool? requestid:num? time:num? version:? vrev:? noservice:bool? servicemark:?' => \&sourcecommitfilelist,
'POST:/source/$project/$package cmd=copy rev? user:? comment:? orev:rev? oproject:project? opackage:package? expand:bool? keeplink:bool? repairlink:bool? linkrev? setrev:linkrev? olinkrev:linkrev? requestid:num? dontupdatesource:bool? noservice:bool? withvrev:bool? withacceptinfo:bool? makeoriginolder:bool?' => \&sourcecopy,
'POST:/source/$project/$package cmd=copy rev? user:? comment:? orev:rev? oproject:project? opackage:package? expand:bool? keeplink:bool? repairlink:bool? linkrev? setrev:linkrev? olinkrev:linkrev? requestid:num? dontupdatesource:bool? noservice:bool? withvrev:bool? withacceptinfo:bool? makeoriginolder:bool? freezelink:bool?' => \&sourcecopy,
'POST:/source/$project/$package cmd=collectbuildenv user:? comment:? orev:rev? oproject:project? opackage:package?' => \&sourcecollectbuildenv,
'POST:/source/$project/$package cmd=branch rev? user:? comment:? orev:rev? oproject:project? opackage:package? olinkrev:linkrev? requestid:num? force:bool? keepcontent:bool? missingok:bool? noservice:bool? withacceptinfo:bool?' => \&sourcebranch,
'POST:/source/$project/$package cmd=linktobranch rev? user:? comment:? linkrev?' => \&linktobranch,
Expand Down