Skip to content

Commit

Permalink
Merge branch 'master' into fix_ca_install_for_rh8
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaltom authored Aug 23, 2019
2 parents d1276cf + c3f08fa commit 2acb3f0
Show file tree
Hide file tree
Showing 15 changed files with 474 additions and 182 deletions.
13 changes: 4 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-07-04 10:28:23 +0200 using RuboCop version 0.53.0.
# on 2019-08-13 14:02:20 +0200 using RuboCop version 0.53.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -11,7 +11,7 @@ FactoryGirl/DynamicAttributeDefinedStatically:
Exclude:
- 'spec/factories/subscriptions.rb'

# Offense count: 125
# Offense count: 126
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
Expand All @@ -29,7 +29,7 @@ Lint/MissingCopEnableDirective:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 167
Max: 165

# Offense count: 1
# Configuration parameters: CountComments.
Expand All @@ -48,7 +48,7 @@ RSpec/ExampleLength:
Exclude:
- 'spec/features/**/*'
- 'spec/lib/rmt/cli/import_spec.rb'
- 'spec/lib/rmt/cli/main_spec.rb'
- 'spec/lib/rmt/cli/mirror_spec.rb'
- 'spec/lib/rmt/rpm/repomd_xml_parser_spec.rb'

# Offense count: 60
Expand Down Expand Up @@ -153,11 +153,6 @@ Rails/LexicallyScopedActionFilter:
Exclude:
- 'app/controllers/api/connect/v3/systems/products_controller.rb'

# Offense count: 1
Style/DateTime:
Exclude:
- 'spec/lib/rmt/cli/main_spec.rb'

# Offense count: 6
# Cop supports --auto-correct.
Style/ExpandPathArguments:
Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_model_serializers (0.10.9)
actionpack (>= 4.1, < 6)
activemodel (>= 4.1, < 6)
active_model_serializers (0.10.10)
actionpack (>= 4.1, < 6.1)
activemodel (>= 4.1, < 6.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activemodel (5.1.6.2)
Expand Down Expand Up @@ -150,12 +150,12 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashdiff (0.4.0)
hashdiff (1.0.0)
hpricot (0.8.6)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
json (2.2.0)
jsonapi-renderer (0.2.0)
jsonapi-renderer (0.2.2)
jwt (2.2.1)
kramdown (2.1.0)
kramdown-parser-gfm (1.1.0)
Expand All @@ -180,7 +180,7 @@ GEM
nap (1.1.0)
nenv (0.3.0)
no_proxy_fix (0.1.2)
nokogiri (1.10.3)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
notiffany (0.1.1)
nenv (~> 0.1)
Expand All @@ -195,7 +195,7 @@ GEM
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.1.0)
public_suffix (3.1.1)
puma (3.10.0)
rack (2.0.7)
rack-test (1.1.0)
Expand Down Expand Up @@ -274,7 +274,7 @@ GEM
rubocop-rspec (= 1.19)
sexp_processor (4.12.0)
shellany (0.0.1)
shoulda-matchers (4.1.1)
shoulda-matchers (4.1.2)
activesupport (>= 4.2.0)
simplecov (0.16.1)
docile (~> 1.1)
Expand Down Expand Up @@ -306,7 +306,7 @@ GEM
activesupport (>= 3)
railties (>= 3)
yard (~> 0.9.20)
webmock (3.6.0)
webmock (3.6.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down
17 changes: 17 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,21 @@ def create_service!

service
end

def self.get_by_target!(target)
product_id = Integer(target, 10) rescue nil

products = []
if product_id
product = find(product_id)
products << product unless product.nil?
else
identifier, version, arch = target.split('/')
conditions = { identifier: identifier, version: version }
conditions[:arch] = arch if arch
products = where(conditions).to_a
end

products
end
end
8 changes: 7 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug

log_level = Settings&.log_level&.rails&.to_s&.upcase
config.log_level = if RMT::Logger::LABEL_TO_SEVERITY_MAPPING[log_level]
log_level
else
:debug
end

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
Expand Down
2 changes: 1 addition & 1 deletion lib/rmt.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module RMT
VERSION ||= '2.3.5'.freeze
VERSION ||= '2.4.0'.freeze

DEFAULT_USER = '_rmt'.freeze
DEFAULT_GROUP = 'nginx'.freeze
Expand Down
35 changes: 1 addition & 34 deletions lib/rmt/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,7 @@ def sync
subcommand 'repos', RMT::CLI::Repos

desc 'mirror', _('Mirror repositories')
def mirror
RMT::Lockfile.lock do
logger = RMT::Logger.new(STDOUT)
mirror = RMT::Mirror.new(logger: logger)

begin
mirror.mirror_suma_product_tree(repository_url: 'https://scc.suse.com/suma/')
rescue RMT::Mirror::Exception => e
logger.warn(e.message)
end

raise RMT::CLI::Error.new(_('There are no repositories marked for mirroring.')) if Repository.where(mirroring_enabled: true).empty?

mirrored_repo_ids = []
until Repository.where(mirroring_enabled: true).where.not(id: mirrored_repo_ids).blank?
repo = Repository.where(mirroring_enabled: true).where.not(id: mirrored_repo_ids).first

begin
mirror.mirror(
repository_url: repo.external_url,
local_path: Repository.make_local_path(repo.external_url),
auth_token: repo.auth_token,
repo_name: repo.name
)

repo.refresh_timestamp!
rescue RMT::Mirror::Exception => e
logger.warn e.to_s
ensure
mirrored_repo_ids << repo.id
end
end
end
end
subcommand 'mirror', RMT::CLI::Mirror

desc 'import', _('Import commands for Offline Sync')
subcommand 'import', RMT::CLI::Import
Expand Down
103 changes: 103 additions & 0 deletions lib/rmt/cli/mirror.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
class RMT::CLI::Mirror < RMT::CLI::Base
desc 'all', _('Mirror all enabled repositories')
def all
RMT::Lockfile.lock do
logger = RMT::Logger.new(STDOUT)
mirror = RMT::Mirror.new(logger: logger, mirror_src: RMT::Config.mirror_src_files?)

begin
mirror.mirror_suma_product_tree(repository_url: 'https://scc.suse.com/suma/')
rescue RMT::Mirror::Exception => e
logger.warn(e.message)
end

raise RMT::CLI::Error.new(_('There are no repositories marked for mirroring.')) if Repository.where(mirroring_enabled: true).empty?

mirrored_repo_ids = []
until Repository.where(mirroring_enabled: true).where.not(id: mirrored_repo_ids).blank?
repo = Repository.where(mirroring_enabled: true).where.not(id: mirrored_repo_ids).first

begin
mirror_repo!(mirror, repo)
rescue RMT::Mirror::Exception => e
logger.warn e.to_s
ensure
mirrored_repo_ids << repo.id
end
end
end
end

default_task :all

desc 'repository IDS', _('Mirror enabled repositories with given repository IDs')
def repository(*ids)
RMT::Lockfile.lock do
logger = RMT::Logger.new(STDOUT)
mirror = RMT::Mirror.new(logger: logger, mirror_src: RMT::Config.mirror_src_files?)

ids = clean_target_input(ids)
raise RMT::CLI::Error.new(_('No repository IDs supplied')) if ids.empty?

repos = []
ids.each do |id|
repo = Repository.find_by!(scc_id: id)
raise RMT::CLI::Error.new(_('Mirroring of repository with ID %{repo_id} is not enabled') % { repo_id: id }) unless repo.mirroring_enabled
repos << repo
rescue ActiveRecord::RecordNotFound
raise RMT::CLI::Error.new(_('Repository with ID %{repo_id} not found') % { repo_id: id })
end

repos.each do |repo|
mirror_repo!(mirror, repo)
rescue RMT::Mirror::Exception => e
logger.warn e.to_s
end
end
end

desc 'product IDS', _('Mirror enabled repositories for a product with given product IDs')
def product(*targets)
RMT::Lockfile.lock do
logger = RMT::Logger.new(STDOUT)
mirror = RMT::Mirror.new(logger: logger, mirror_src: RMT::Config.mirror_src_files?)

targets = clean_target_input(targets)
raise RMT::CLI::Error.new(_('No product IDs supplied')) if targets.empty?

repos = []
targets.each do |target|
products = Product.get_by_target!(target)
raise RMT::CLI::Error.new(_('Product for target %{target} not found') % { target: target }) if products.empty?
products.each do |product|
product_repos = product.repositories.where(mirroring_enabled: true)
raise RMT::CLI::Error.new(_('Product %{target} has no repositories enabled') % { target: target }) if product_repos.empty?
repos += product_repos.to_a
end
rescue ActiveRecord::RecordNotFound
raise RMT::CLI::Error.new(_('Product with ID %{target} not found') % { target: target })
end

repos.each do |repo|
mirror_repo!(mirror, repo)
rescue RMT::Mirror::Exception => e
logger.warn e.to_s
end
end
end

protected

def mirror_repo!(mirror, repo)
mirror.mirror(
repository_url: repo.external_url,
local_path: Repository.make_local_path(repo.external_url),
auth_token: repo.auth_token,
repo_name: repo.name
)

repo.refresh_timestamp!
end


end
17 changes: 2 additions & 15 deletions lib/rmt/cli/products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,9 @@ def change_product(target, set_enabled, all_modules)
private

def find_products(target)
product_id = Integer(target, 10) rescue nil

products = []
if product_id
product = Product.find(product_id)
products << product unless product.nil?
else
identifier, version, arch = target.split('/')
conditions = { identifier: identifier, version: version }
conditions[:arch] = arch if arch
products = Product.where(conditions).to_a
end

products
Product.get_by_target!(target)
rescue ActiveRecord::RecordNotFound
raise ProductNotFoundException.new(_('Product by ID %{id} not found.') % { id: product_id })
raise ProductNotFoundException.new(_('Product by ID %{id} not found.') % { id: target })
end

def repository_service
Expand Down
4 changes: 4 additions & 0 deletions lib/rmt/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ def self.deduplication_by_hardlink?
Settings.try(:mirroring).try(:dedup_method).to_s.to_sym != :copy
end

def self.mirror_src_files?
ActiveModel::Type::Boolean.new.cast(Settings.try(:mirroring).try(:mirror_src))
end

end
19 changes: 19 additions & 0 deletions package/obs/rmt-server.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
-------------------------------------------------------------------
Tue Aug 20 11:12:58 UTC 2019 - Ivan Kapelyukhin <[email protected]>

- Version 2.4.0
- Allow to mirror individual products/repositories (bsc#1138863)

-------------------------------------------------------------------
Fri Aug 16 11:07:26 UTC 2019 - [email protected]

- Version 2.3.7
- RMT now uses mirror_src to determine whether or not to download
source packages. (bsc#1145688)

-------------------------------------------------------------------
Thu Aug 8 10:50:26 UTC 2019 - Ivan Kapelyukhin <[email protected]>

- Version 2.3.6
- Make Rails log level configurable; set default log level to INFO

-------------------------------------------------------------------
Wed Aug 7 12:43:02 UTC 2019 - Thomas Schmidt <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion package/obs/rmt-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
%define ruby_version %{rb_default_ruby_suffix}

Name: rmt-server
Version: 2.3.5
Version: 2.4.0
Release: 0
Summary: Repository mirroring tool and registration proxy for SCC
License: GPL-2.0-or-later
Expand Down
3 changes: 3 additions & 0 deletions package/obs/rmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ http_client:
proxy_auth:
proxy_user:
proxy_password:

log_level:
rails: info
Loading

0 comments on commit 2acb3f0

Please sign in to comment.