Skip to content

Commit

Permalink
[api] support different modes on creating channels
Browse files Browse the repository at this point in the history
also allow to enable the channels later
  • Loading branch information
adrianschroeter committed Jul 10, 2015
1 parent 49a062d commit c9f3f22
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/api/api/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ POST /source/<project>
createmaintenanceincident: create a single mainatenance incident project as sub project
createpatchinfo: create a new patchinfo package collecting all mentioned issues in sources
addchannels: add channel packages and repositories for matching packages in project
modifychannels: modify existing channels by specified mode
set_flag: change a defined flag, requires at least flag and status parameters
remove_flag: remove a defined flag, requires at least flag and status parameters
unlock: unlock a locked project
Expand All @@ -416,6 +417,8 @@ Parameters:
flag: modify this flag (build/publish/..) for set_flag command
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
# for copy command only:
oproject: origin project name (required)
resign: resign all binaries with new target project key
Expand Down Expand Up @@ -768,6 +771,7 @@ POST /source/<project>/<package>
release: release sources and binaries according to release target specification
branch: branch a package into another one
linktobranch: convert a plain source link into a full branch
enablechannel: adds repositories and enable this channel package
updatepatchinfo: update _patchinfo file, esp. the issues list
remove_flag: remove a specific flag from meta (flag must be defined, optionally arch and repository)
set_flag: remove a specific flag from meta (flag must be defined, optionally arch and repository)
Expand Down
36 changes: 32 additions & 4 deletions src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def project_command
# init and validation
#--------------------
valid_commands=%w(undelete showlinked remove_flag set_flag createpatchinfo createkey extendkey copy
createmaintenanceincident unlock release addchannels move)
createmaintenanceincident unlock release addchannels modifychannels move)
if params[:cmd]
raise IllegalRequest.new 'invalid_command' unless valid_commands.include?(params[:cmd])
command = params[:cmd]
Expand Down Expand Up @@ -362,8 +362,9 @@ def package_command

# valid post commands
valid_commands=%w(diff branch servicediff linkdiff showlinked copy remove_flag set_flag rebuild undelete
wipe runservice commit commitfilelist createSpecFileTemplate deleteuploadrev linktobranch
updatepatchinfo getprojectservices unlock release importchannel collectbuildenv instantiate)
wipe runservice commit commitfilelist createSpecFileTemplate deleteuploadrev
linktobranch updatepatchinfo getprojectservices unlock release importchannel
collectbuildenv instantiate enablechannel)

@command = params[:cmd]
raise IllegalRequest.new 'invalid_command' unless valid_commands.include?(@command)
Expand Down Expand Up @@ -1015,9 +1016,27 @@ def project_command_unlock
# add channel packages and extend repository list
# POST /source/<project>?cmd=addchannels
def project_command_addchannels
mode=nil
mode=:add_disabled if params[:mode] == "add_disabled"
mode=:skip_disabled if params[:mode] == "skip_disabled"
mode=:enable_all if params[:mode] == "enable_all"

@project.packages.each do |pkg|
pkg.add_channels
pkg.add_channels(mode)
end

render_ok
end

# add repositories and/or enable them for all existing channel instances
# POST /source/<project>?cmd=modifychannels
def project_command_modifychannels
mode=nil
mode=:add_disabled if params[:mode] == "add_disabled"
mode=:enable_all if params[:mode] == "enable_all"

@project.packages.each do |pkg|
pkg.modify_channel(mode)
end

render_ok
Expand Down Expand Up @@ -1277,6 +1296,15 @@ def package_command_unlock
render_ok
end

# add repositories and/or enable them for a specified channel
# POST /source/<project>/<package>?cmd=enablechannel
def package_command_enablechannel
@package.modify_channel(:enable_all)
@package.store({user: User.current.login})

render_ok
end

# Collect all project source services for a package
# POST /source/<project>/<package>?cmd=getprojectservices
def package_command_getprojectservices
Expand Down
9 changes: 8 additions & 1 deletion src/api/app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def branch_channel_package_into_project(project)
tpkg
end

def is_active?
# no targets defined, the project has some
return true if self.channel_targets.size == 0

self.channel_targets.where(disabled: false).size > 0
end

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

Expand All @@ -165,7 +172,7 @@ def add_channel_repos_to_project(tpkg, mode=nil)
tpkg.project.add_repository_with_targets(repo_name, ct.repository, [ct.repository])
end
# enable package
tpkg.enable_for_repository repo_name unless ct.disabled or mode==:enable_all
tpkg.enable_for_repository repo_name if mode==:enable_all or not ct.disabled
end
end
end
9 changes: 9 additions & 0 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,13 @@ def is_local_link?
return li['project'] == self.project.name
end

def modify_channel(mode=nil)
raise InvalidParameterError unless [:add_disabled, :enable_all].include? mode
channel = self.channels.first
return unless channel
channel.add_channel_repos_to_project(self, mode)
end

def add_channels(mode=nil)
raise InvalidParameterError unless [nil, :add_disabled, :skip_disabled, :enable_all].include? mode

Expand All @@ -812,6 +819,7 @@ def add_channels(mode=nil)

# main package
ChannelBinary.find_by_project_and_package(project_name, opkg.name).each do |cb|
next if mode == :skip_disabled and not cb.channel_binary_list.channel.is_active?
cpkg = cb.create_channel_package_into(self.project)
next unless cpkg
cpkg.channels.first.add_channel_repos_to_project(cpkg, mode)
Expand All @@ -828,6 +836,7 @@ def add_channels(mode=nil)
# strip incident suffix in update release projects
name.gsub!(/\.[^\.]*$/,'') if opkg.project.is_maintenance_release?
ChannelBinary.find_by_project_and_package(project_name, name).each do |cb|
next if mode == :skip_disabled and not cb.channel_binary_list.channel.is_active?
cpkg = cb.create_channel_package_into(self.project)
next unless cpkg
cpkg.channels.first.add_channel_repos_to_project(cpkg, mode)
Expand Down
23 changes: 21 additions & 2 deletions src/api/test/functional/channel_maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,16 @@ def test_large_channel_test
post "/source/#{incidentProject}?cmd=addchannels", nil
assert_response 403
prepare_request_with_user 'maintenance_coord', 'power'
post "/source/#{incidentProject}?cmd=addchannels", nil
post "/source/#{incidentProject}?cmd=addchannels&mode=skip_disabled", nil
assert_response :success
get "/source/#{incidentProject}/BaseDistro2.0.Channel/_meta"
assert_response 404 # skipped because it just has a disabled target
get "/source/#{incidentProject}/BaseDistro3.Channel/_meta"
assert_response :success

post "/source/#{incidentProject}?cmd=addchannels", nil
post "/source/#{incidentProject}?cmd=addchannels&mode=add_disabled", nil
assert_response :success # now it appeared
get "/source/#{incidentProject}/BaseDistro2.0.Channel/_meta"
assert_response :success
get "/source/#{incidentProject}/BaseDistro3.Channel/_meta"
assert_response :success
Expand Down Expand Up @@ -444,11 +450,24 @@ def test_large_channel_test
assert_response :success
end
prepare_request_with_user 'maintenance_coord', 'power'
get "/source/#{incidentProject}/BaseDistro2.0.Channel/_meta"
old_meta = @response.body
assert_response :success
assert_no_xml_tag :tag => 'enable', :attributes => {repository: "BaseDistro2.0_LinkedUpdateProject"}
post "/source/#{incidentProject}/BaseDistro2.0.Channel?cmd=set_flag&product=simple&flag=build&status=enable"
assert_response :success
get "/source/#{incidentProject}/BaseDistro2.0.Channel/_meta"
assert_response :success
assert_xml_tag :tag => 'enable', :attributes => {repository: "BaseDistro2.0_LinkedUpdateProject"}
# revert and enable via enablechannel
put "/source/#{incidentProject}/BaseDistro2.0.Channel/_meta", old_meta
assert_response :success
post "/source/#{incidentProject}/BaseDistro2.0.Channel?cmd=enablechannel"
assert_response :success
get "/source/#{incidentProject}/BaseDistro2.0.Channel/_meta"
assert_response :success
assert_xml_tag :tag => 'enable', :attributes => {repository: "BaseDistro2.0_LinkedUpdateProject"}

# check repository search by product
get "/search/repository/id?match=targetproduct/@name='simple'"
assert_response :success
Expand Down

0 comments on commit c9f3f22

Please sign in to comment.