Skip to content

Commit

Permalink
[api] fix disabled target handling for channels for real
Browse files Browse the repository at this point in the history
and most important, fix the test suite which was supposed to verify this
  • Loading branch information
adrianschroeter committed Oct 28, 2015
1 parent 68600b4 commit a15373d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/api/api/api.txt
Expand Up @@ -420,7 +420,7 @@ Parameters:
status: enable or disable for set_flag command
comment: description for the history
# for modifychannels and addchannels command only:
mode: how to deal with disabled channels: skip_disabled, add_disabled, enable_all
mode: how to deal with disabled channels: add_disabled(default), skip_disabled, enable_all
# for copy command only:
oproject: origin project name (required)
resign: resign all binaries with new target project key
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/models/channel.rb
Expand Up @@ -156,7 +156,6 @@ def is_active?

def add_channel_repos_to_project(tpkg, mode = nil)
cp = self.package

if self.channel_targets.empty?
# not defined in channel, so take all from project
tpkg.project.branch_to_repositories_from(cp.project, cp, true)
Expand All @@ -165,14 +164,15 @@ def add_channel_repos_to_project(tpkg, mode = nil)

# defined in channel
self.channel_targets.each do |ct|
next if mode==:skip_disabled and ct.disabled
next if mode == :skip_disabled and ct.disabled
repo_name = ct.repository.extended_name
next unless mode==:enable_all or not ct.disabled
# add repositories
unless cp.project.repositories.find_by_name(repo_name)
tpkg.project.add_repository_with_targets(repo_name, ct.repository, [ct.repository])
end
# enable package
tpkg.enable_for_repository repo_name if mode==:enable_all or not ct.disabled
tpkg.enable_for_repository repo_name
end
end
end
4 changes: 3 additions & 1 deletion src/api/app/models/package.rb
Expand Up @@ -929,10 +929,12 @@ def add_channels(mode = :add_disabled)
end

def _add_channel(mode, channel_binary, message)
# add source container
return if mode == :skip_disabled and not channel_binary.channel_binary_list.channel.is_active?
cpkg = channel_binary.create_channel_package_into(self.project, message)
return unless cpkg
return if mode.nil? and not channel_binary.channel_binary_list.channel.is_active?
# add and enable repos
return if mode == :add_disabled and not channel_binary.channel_binary_list.channel.is_active?
cpkg.channels.first.add_channel_repos_to_project(cpkg, mode)
end
private :_add_channel
Expand Down
16 changes: 14 additions & 2 deletions src/api/test/functional/kgraft_maintenance_test.rb
Expand Up @@ -96,8 +96,11 @@ def test_kgraft_update_setup
put '/source/Channel/BaseDistro2/_meta', '<package project="Channel" name="BaseDistro2"><title/><description/></package>'
assert_response :success
# rubocop:disable Metrics/LineLength
post '/source/Channel/BaseDistro2?cmd=importchannel&target_project=BaseDistro2Channel&target_repository=channel_repo', '<?xml version="1.0" encoding="UTF-8"?>
post '/source/Channel/BaseDistro2?cmd=importchannel', '<?xml version="1.0" encoding="UTF-8"?>
<channel>
<target project="BaseDistro2Channel" repository="channel_repo">
<disabled/>
</target>
<binaries project="BaseDistro:Update" repository="BaseDistroUpdateProject_repo" arch="i586">
<binary name="package" package="pack2" project="BaseDistro2.0:LinkedUpdateProject" repository="BaseDistro2LinkedUpdateProject_repo" />
</binaries>
Expand All @@ -107,7 +110,9 @@ def test_kgraft_update_setup
assert_response :success
raw_put "/source/home:king:branches:BaseDistro2.0/BaseDistro2.Channel/_channel", "<?xml version='1.0' encoding='UTF-8'?>
<channel>
<target project='BaseDistro2Channel' repository='channel_repo'/>
<target project='BaseDistro2Channel' repository='channel_repo'>
<disabled/>
</target>
<binaries arch='i586' project='BaseDistro2.0:LinkedUpdateProject' repository='BaseDistro2LinkedUpdateProject_repo'>
<binary name='package' package='kgraft-GA' />
</binaries>
Expand Down Expand Up @@ -159,6 +164,13 @@ def test_kgraft_update_setup
:tag => "path", :attributes => { :project => kernelIncidentProject, :repository => "BaseDistro2.0_LinkedUpdateProject" }
assert_xml_tag :parent => { :tag => "repository", :attributes => { :name => "BaseDistro2.0" } },
:tag => "path", :attributes => { :project => "BaseDistro2.0", :repository => "BaseDistro2_repo" }
assert_no_xml_tag tag: "repository", attributes: { name: "BaseDistro2Channel" }

# add disabled target repo
post "/source/#{incidentProject}?cmd=modifychannels&mode=enable_all", nil
assert_response :success
get "/source/"+incidentProject+"/_meta"
assert_response :success
assert_xml_tag :parent => { :tag => "repository", :attributes => { :name => "BaseDistro2Channel" } },
:tag => "path", :attributes => { :project => "BaseDistro2Channel", :repository => "channel_repo" }
assert_xml_tag :parent => { :tag => "repository", :attributes => { :name => "BaseDistro2Channel" } },
Expand Down

0 comments on commit a15373d

Please sign in to comment.