Skip to content

Commit

Permalink
[api] take local linked packages into account in add_channels command
Browse files Browse the repository at this point in the history
Also OBS:Maintained attribute is used as default filter for channels
  • Loading branch information
adrianschroeter committed Nov 18, 2014
1 parent 313b6d7 commit d7578a1
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 36 deletions.
4 changes: 0 additions & 4 deletions src/api/app/models/attrib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ def container
end
end

#def project
# return project if self.project_id
# return package.project if self.package_id
#end
def project
if package
return package.project
Expand Down
12 changes: 3 additions & 9 deletions src/api/app/models/channel_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ def self.find_by_project_and_package(project, package)
return ChannelBinary.find_by_sql(['SELECT channel_binaries.* FROM channel_binaries LEFT JOIN channel_binary_lists ON channel_binary_lists.id = channel_binaries.channel_binary_list_id WHERE (channel_binary_lists.project_id = ? and package = ?)', project.id, package])
end

def create_channel_package(pkg, maintenanceProject)
def create_channel_package_into(project)
channel = self.channel_binary_list.channel

# does it exist already? then just skip it
return if Package.exists_by_project_and_name(pkg.project.name, channel.name)

# do we need to take care about a maintained list from upper project?
if maintenanceProject and MaintainedProject.where(maintenance_project: maintenanceProject, project: channel.package.project).count < 1
# not a maintained project here
return
end
return if Package.exists_by_project_and_name(project.name, channel.name)

# create a channel package beside my package
channel.branch_channel_package_into_project(pkg.project)
channel.branch_channel_package_into_project(project)
end

end
57 changes: 41 additions & 16 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -722,27 +722,52 @@ def channels
super
end

def origin_container
# no link, so I am origin
return self unless self.dir_hash

# link target package name is more important, since local name could be
# extended. for example in maintenance incident projects.
li = self.dir_hash['linkinfo']
return self unless li

# from external project, so it is my origin
pkg = Package.get_by_project_and_name(li['project'], li['package'])
return pkg if li['project'] != self.project.name

# broke or remote link, aborting
return nil if pkg.nil?

# local link, go one step deeper
return pkg.origin_container
end

def add_channels
project_name = self.project.name
package_name = self.name
dir = self.dir_hash
if dir
# link target package name is more important, since local name could be
# extended. for example in maintenance incident projects.
li = dir['linkinfo']
if li
project_name = li['project']
package_name = li['package']
end
end
opkg = self.origin_container
# remote or broken link?
return if opkg.nil?

project_name = opkg.project.name

# Update projects are usually used in _channels
if prj = Project.find_by_name(project_name) and a = prj.find_attribute('OBS', 'UpdateProject') and a.values[0]
project_name = a.values[0].value
prj = Project.find_by_name(project_name)
end
parent = nil
ChannelBinary.find_by_project_and_package(project_name, package_name).each do |cb|
parent ||= self.project.find_parent
cb.create_channel_package(self, parent)

at = AttribType.find_by_namespace_and_name("OBS", "Maintained")

# main package
ChannelBinary.find_by_project_and_package(project_name, opkg.name).each do |cb|
next if at and cb.channel_binary_list.channel.package.project.attribs.where(attrib_type: at).count < 1
cb.create_channel_package_into(self.project)
end
# and all possible existing local links
opkg.find_project_local_linking_packages.each do |p|
ChannelBinary.find_by_project_and_package(project_name, p.name).each do |cb|
next if at and cb.channel_binary_list.channel.package.project.attribs.where(attrib_type: at).count < 1
cb.create_channel_package_into(self.project)
end
end
self.project.store
end
Expand Down
1 change: 1 addition & 0 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ def set_project_type(project_type_name)
end

def add_repository_with_targets(repoName, source_repo, add_target_repos = [])
return if self.repositories.where(name: repoName).exists?
trepo = self.repositories.create :name => repoName
source_repo.repository_architectures.each do |ra|
trepo.repository_architectures.create :architecture => ra.architecture, :position => ra.position
Expand Down
36 changes: 29 additions & 7 deletions src/api/test/functional/maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,22 +458,49 @@ def test_mbranch_and_maintenance_per_package_request
put '/source/Channel/_meta', '<project name="Channel"><title/><description/>
</project>'
assert_response :success
raw_post '/source/Channel/_attribute', "<attributes><attribute namespace='OBS' name='Maintained'></attribute></attributes>"
assert_response :success

# create channel package
put '/source/Channel/BaseDistro2/_meta', '<package project="Channel" name="BaseDistro2"><title/><description/></package>'
assert_response :success
post '/source/Channel/BaseDistro2?cmd=importchannel&target_project=BaseDistro3Channel&target_repository=channel_repo', '<?xml version="1.0" encoding="UTF-8"?>
<channel>
<binaries project="BaseDistro2.0:LinkedUpdateProject" repository="BaseDistro2LinkedUpdateProject_repo" arch="i586">
<binary name="package" package="pack2.linked" project="BaseDistro2.0:LinkedUpdateProject" />
</binaries>
</channel>'
assert_response :success
put '/source/Channel/BaseDistro3/_meta', '<package project="Channel" name="BaseDistro3"><title/><description/></package>'
assert_response :success
post '/source/Channel/BaseDistro3?cmd=importchannel&target_project=BaseDistro3Channel&target_repository=channel_repo', '<?xml version="1.0" encoding="UTF-8"?>
<channel>
<binaries project="BaseDistro3" repository="BaseDistro3_repo" arch="i586">
<binary name="package" package="pack2.linked" project="BaseDistro2.0" />
<binary name="does_not_exist" />
</binaries>
</channel>'
assert_response :success
get '/source/Channel/BaseDistro3/_channel'
get '/source/Channel/BaseDistro2/_channel'
assert_response :success
# it found the update project
assert_xml_tag :tag => 'binary', :attributes => { project: 'BaseDistro2.0:LinkedUpdateProject', package: 'pack2.linked' }
# target repo parameter worked
assert_xml_tag :tag => 'target', :attributes => { project: 'BaseDistro3Channel', repository: 'channel_repo' }
# create channel packages and repos
login_adrian
post "/source/#{incidentProject}?cmd=addchannels", nil
assert_response 403
prepare_request_with_user 'maintenance_coord', 'power'
post "/source/#{incidentProject}?cmd=addchannels", nil
assert_response :success
get "/source/#{incidentProject}/BaseDistro2.Channel/_meta"
assert_response :success
#cleanup channel 2
login_king
delete "/source/#{incidentProject}/BaseDistro2.Channel"
assert_response :success
delete '/source/Channel/BaseDistro2'
assert_response :success

put '/source/Channel/BaseDistro3/_channel', '<?xml version="1.0" encoding="UTF-8"?>
<channel>
Expand All @@ -496,11 +523,6 @@ def test_mbranch_and_maintenance_per_package_request
prepare_request_with_user 'maintenance_coord', 'power'
post "/source/#{incidentProject}?cmd=addchannels", nil
assert_response :success
get "/source/#{incidentProject}/BaseDistro3.Channel/_meta"
assert_response 404 # not a maintained project
# make Channel project a maintained project and try again.
mprj = Project.find_by_name('My:Maintenance')
MaintainedProject.create(project: Project.find_by_name('Channel'), maintenance_project: mprj)

post "/source/#{incidentProject}?cmd=addchannels", nil
assert_response :success
Expand Down

0 comments on commit d7578a1

Please sign in to comment.