Skip to content

Commit

Permalink
[api] add tracking of released updateinfo IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Jul 17, 2014
1 parent b876429 commit 2b46ae2
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/api/app/helpers/maintenance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,21 @@ def copy_binaries(filterSourceRepository, sourcePackage, targetPackageName, targ
sourcePackage.project.repositories.each do |sourceRepo|
next if filterSourceRepository and filterSourceRepository != sourceRepo
sourceRepo.release_targets.each do |releasetarget|
#FIXME2.5: filter given release and/or target repos here
#FIXME: filter given release and/or target repos here
sourceRepo.architectures.each do |arch|
if releasetarget.target_repository.project == targetProject
# get updateinfo id in case the source package comes from a maintenance project
uID = get_updateinfo_id(sourcePackage, releasetarget.target_repository)
copy_single_binary(arch, releasetarget, sourcePackage, sourceRepo, targetPackageName, uID, setrelease)
updateIDs << uID
if uID
updateIDs << uID
# add uID to database
pkg = targetProject.packages.where(name: targetPackageName).first
Updateinfo.create(repository: releasetarget.target_repository,
package: pkg,
identifier: uID,
created_at: Time.now)
end
end
end
# remove maintenance release trigger in source
Expand Down
9 changes: 8 additions & 1 deletion src/api/app/models/binary_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ def render_xml
self.used_in_products.each do |product|
p.product( :project => product.package.project.name, :name => product.name )
end
end
end if self.used_in_products.length > 0
b.updates do |u|
self.release_package.updateinfos.each do |update|
u.updateinfo( update.identifier,
:project => update.package.project.name,
:package => update.package.name )
end
end if self.release_package and self.release_package.updateinfos.length > 0
end
builder.to_xml :save_with => Nokogiri::XML::Node::SaveOptions::NO_DECLARATION |
Nokogiri::XML::Node::SaveOptions::FORMAT
Expand Down
1 change: 1 addition & 0 deletions src/api/app/models/maintenance_incident.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def initUpdateinfoId(template = "%Y-%C", patch_name = nil)
def getUpdateinfoId( id_template, patch_name=nil )
# this is not used anymore, but we need to keep it for released incidents base on old (OBS 2.5) code
return self.updateinfo_id if self.updateinfo_id

# initialize on first run
initUpdateinfoId(id_template, patch_name) unless self.released_at

Expand Down
2 changes: 2 additions & 0 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class ReadSourceAccessError < APIException

has_many :comments, :dependent => :destroy, inverse_of: :package, class_name: 'CommentPackage'

has_many :updateinfos, dependent: :delete_all

before_destroy :delete_cache_lines
before_destroy :remove_linked_packages

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/patchinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def is_repository_matching?(repo, rt)
return true
end

# check if we caa find the releasetarget (xmlhash) in the project
# check if we can find the releasetarget (xmlhash) in the project
def check_releasetarget!(rt)
@project.repositories.each do |r|
r.release_targets.each do |prt|
Expand Down
1 change: 1 addition & 0 deletions src/api/app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Repository < ActiveRecord::Base
has_many :binary_releases, :dependent => :destroy
has_many :product_update_repositories, dependent: :delete_all
has_many :product_medium, dependent: :delete_all
has_many :updateinfos, dependent: :delete_all
has_many :repository_architectures, -> { order("position") }, :dependent => :destroy, inverse_of: :repository
has_many :architectures, -> { order("position") }, :through => :repository_architectures

Expand Down
20 changes: 20 additions & 0 deletions src/api/db/migrate/20140717101042_add_updateinfo_tracking.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class AddUpdateinfoTracking < ActiveRecord::Migration
def up
create_table :updateinfos do |t|
t.references :repository, null: false
t.references :package, null: false
t.datetime :created_at, null: false
t.string :identifier, null: false
end

add_index :updateinfos, :identifier
add_index :updateinfos, [:repository_id, :package_id]
execute("alter table updateinfos add FOREIGN KEY (repository_id) references repositories(id)")
execute("alter table updateinfos add FOREIGN KEY (package_id) references packages(id)")
end

def down
drop_table :updateinfos
end

end
16 changes: 15 additions & 1 deletion src/api/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ CREATE TABLE `binary_releases` (
KEY `exact_search_index` (`binary_name`,`binary_epoch`,`binary_version`,`binary_release`,`binary_arch`),
KEY `release_package_id` (`release_package_id`),
CONSTRAINT `binary_releases_ibfk_1` FOREIGN KEY (`repository_id`) REFERENCES `repositories` (`id`),
CONSTRAINT `binary_releases_ibfk_2` FOREIGN KEY (`release_package_id`) REFERENCES `packages` (`id`)
CONSTRAINT `binary_releases_ibfk_2` FOREIGN KEY (`release_package_id`) REFERENCES `packages` (`id`),
CONSTRAINT `binary_releases_ibfk_3` FOREIGN KEY (`repository_id`) REFERENCES `repositories` (`id`),
CONSTRAINT `binary_releases_ibfk_4` FOREIGN KEY (`release_package_id`) REFERENCES `packages` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `blacklist_tags` (
Expand Down Expand Up @@ -982,6 +984,16 @@ CREATE TABLE `updateinfo_counter` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `updateinfos` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`repository_id` int(11) NOT NULL,
`package_id` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `index_updateinfos_on_repository_id_and_package_id` (`repository_id`,`package_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `user_registrations` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL DEFAULT '0',
Expand Down Expand Up @@ -1507,6 +1519,8 @@ INSERT INTO schema_migrations (version) VALUES ('20140709071042');

INSERT INTO schema_migrations (version) VALUES ('20140714112346');

INSERT INTO schema_migrations (version) VALUES ('20140717101042');

INSERT INTO schema_migrations (version) VALUES ('20160714112346');

INSERT INTO schema_migrations (version) VALUES ('21');
Expand Down
4 changes: 2 additions & 2 deletions src/api/test/fixtures/binary_releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ BaseDistro3_BaseDistro3_repo:
repository_id: 93
operation: 'added'
# build_container_id:
# release_container_id: BaseDistro3_pack2
release_package: BaseDistro3_pack2
binary_name: package
# binary_epoch:
binary_version: 1.0
Expand All @@ -21,7 +21,7 @@ BaseDistro3_BaseDistro3_repo_droped:
operation: 'removed'
obsolete_time: 2013-09-31 15:50:30.000000000 Z
# build_container_id:
# release_container_id: BaseDistro3_pack2
# release_package: BaseDistro3_pack2
binary_name: dropped
# binary_epoch:
binary_version: 1.0
Expand Down
2 changes: 1 addition & 1 deletion src/api/test/fixtures/repositories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ repositories_92:
id: 92
name: BaseDistro2_repo
project: BaseDistro2.0
repositories_93:
BaseDistro3_repo:
id: 93
name: BaseDistro3_repo
project: BaseDistro3
Expand Down
15 changes: 15 additions & 0 deletions src/api/test/unit/binary_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ def teardown
Timecop.return
end

def test_render_fixture
r = Repository.find_by_project_and_repo_name("BaseDistro3",
"BaseDistro3_repo")
br = BinaryRelease.where(repository: r).first
xml = br.render_xml
assert_xml_tag xml, :tag => 'binary',
:attributes => { :project => "BaseDistro3", :repository => "BaseDistro3_repo",
:name => "package", :version => "1.0", :release => "1", :arch => "i586" }
assert_xml_tag xml, :tag => 'maintainer', :content => 'Iggy'
assert_xml_tag xml, :tag => 'operation', :content => 'added'
assert_xml_tag xml, :tag => 'supportstatus', :content => 'l3'
assert_xml_tag xml, :tag => 'updateinfo', :content => 'updateinfo_identifier',
:attributes => { :package => "pack2" }
end

def test_create_and_find_entries
p = Project.find_by_name("BaseDistro")
r = p.repositories.build(:name => "Dummy")
Expand Down
1 change: 1 addition & 0 deletions src/api/test/unit/code_quality_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def setup
BlackList = {
'ApplicationController#extract_ldap_user' => 123.29,
'AttributeController#attribute_definition' => 87.7,
'BinaryRelease#render_xml' => 84.54,
'BinaryRelease::update_binary_releases_via_json' => 114.78,
'BranchPackage#find_packages_to_branch' => 239.64,
'BranchPackage#create_branch_packages' => 210.91,
Expand Down

0 comments on commit 2b46ae2

Please sign in to comment.