Skip to content

Commit

Permalink
Add specs for mirroring log messages; finalize refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ikapelyukhin committed Jun 13, 2018
1 parent 8b0662a commit df08595
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 84 deletions.
46 changes: 13 additions & 33 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-03-22 12:18:52 +0100 using RuboCop version 0.53.0.
# on 2018-06-13 14:58:43 +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,44 +11,38 @@ FactoryGirl/DynamicAttributeDefinedStatically:
Exclude:
- 'spec/factories/subscriptions.rb'

# Offense count: 150
# Offense count: 116
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
Layout/EmptyLinesAroundClassBody:
Enabled: false

# Offense count: 11
# Offense count: 4
# Configuration parameters: MaximumRangeSize.
Lint/MissingCopEnableDirective:
Exclude:
- 'db/migrate/20170619104044_create_products_and_repositories.rb'
- 'lib/rmt/mirror.rb'
- 'spec/lib/rmt/cli/export_spec.rb'
- 'spec/lib/rmt/cli/main_spec.rb'
- 'spec/lib/rmt/cli/products_spec.rb'
- 'spec/lib/rmt/cli/repos_spec.rb'
- 'spec/lib/rmt/mirror_spec.rb'
- 'spec/models/migration_engine_spec.rb'
- 'spec/requests/api/connect/v4/subscriptions/products_controller_spec.rb'
- 'spec/support/messy_stdout_guard.rb'

# Offense count: 1
# Offense count: 3
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/features/**/*'
- 'spec/lib/rmt/cli/import_spec.rb'
- 'spec/lib/rmt/rpm/repomd_xml_parser_spec.rb'

# Offense count: 43
# Offense count: 41
RSpec/ExpectInHook:
Exclude:
- 'spec/lib/rmt/cli/export_spec.rb'
- 'spec/lib/rmt/cli/import_spec.rb'
- 'spec/lib/rmt/cli/main_spec.rb'
- 'spec/lib/rmt/cli/products_spec.rb'
- 'spec/lib/rmt/cli/repos_custom_spec.rb'
- 'spec/lib/rmt/cli/repos_spec.rb'
- 'spec/lib/rmt/mirror_spec.rb'
- 'spec/lib/rmt/scc_spec.rb'

# Offense count: 1
Expand All @@ -58,7 +52,7 @@ RSpec/HookArgument:
Exclude:
- 'spec/support/messy_stdout_guard.rb'

# Offense count: 20
# Offense count: 22
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
Expand All @@ -69,34 +63,30 @@ RSpec/IteratedExpectation:
Exclude:
- 'spec/requests/api/connect/v3/systems/activations_controller_spec.rb'

# Offense count: 12
# Offense count: 13
RSpec/LetBeforeExamples:
Exclude:
- 'spec/lib/rmt/cli/export_spec.rb'
- 'spec/lib/rmt/cli/import_spec.rb'
- 'spec/models/activation_spec.rb'

# Offense count: 41
# Offense count: 66
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 30
# Offense count: 55
RSpec/MultipleExpectations:
Max: 4
Max: 6

# Offense count: 28
# Offense count: 8
# Configuration parameters: Max.
RSpec/NestedGroups:
Exclude:
- 'spec/lib/rmt/downloader_spec.rb'
- 'spec/requests/api/connect/v3/subscriptions/systems_controller_spec.rb'
- 'spec/requests/api/connect/v3/systems/activations_controller_spec.rb'
- 'spec/requests/api/connect/v3/systems/products_controller_spec.rb'
- 'spec/requests/api/connect/v3/systems/systems_controller_spec.rb'
- 'spec/requests/api/connect/v4/systems/products_controller_spec.rb'
- 'spec/requests/services_controller_spec.rb'

# Offense count: 5
# Configuration parameters: Strict, EnforcedStyle.
Expand All @@ -115,16 +105,6 @@ RSpec/ReturnFromStub:
- 'spec/lib/rmt/mirror_spec.rb'
- 'spec/lib/rmt/scc_spec.rb'

# Offense count: 7
# Configuration parameters: Include.
# Include: db/migrate/*.rb
Rails/CreateTableWithTimestamps:
Exclude:
- 'db/migrate/20170619104044_create_products_and_repositories.rb'
- 'db/migrate/20170822151044_create_subscription_product_classes.rb'
- 'db/migrate/20170824112223_create_product_predecessors.rb'
- 'db/migrate/20171211143013_add_downloaded_files.rb'

# Offense count: 6
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Expand Down
2 changes: 1 addition & 1 deletion lib/rmt/cli/export.rb
Expand Up @@ -28,7 +28,7 @@ def repos(path)
needs_path(path)

logger = RMT::Logger.new(STDOUT)
mirror = RMT::Mirror.new(mirroring_base_dir: path, logger: logger, disable_hardlinks: true)
mirror = RMT::Mirror.new(mirroring_base_dir: path, logger: logger, airgap_mode: true)

repos_file = File.join(path, 'repos.json')
raise RMT::CLI::Error.new("#{repos_file} does not exist.") unless File.exist?(repos_file)
Expand Down
2 changes: 1 addition & 1 deletion lib/rmt/cli/import.rb
Expand Up @@ -14,7 +14,7 @@ def repos(path)
needs_path(path)

logger = RMT::Logger.new(STDOUT)
mirror = RMT::Mirror.new(logger: logger, disable_hardlinks: true)
mirror = RMT::Mirror.new(logger: logger, airgap_mode: true)

repos_file = File.join(path, 'repos.json')
raise RMT::CLI::Error.new("#{repos_file} does not exist.") unless File.exist?(repos_file)
Expand Down
3 changes: 2 additions & 1 deletion lib/rmt/cli/main.rb
Expand Up @@ -32,7 +32,8 @@ def mirror
mirror.mirror(
repository_url: repo.external_url,
local_path: Repository.make_local_path(repo.external_url),
auth_token: repo.auth_token
auth_token: repo.auth_token,
repo_name: repo.name
)

repo.refresh_timestamp!
Expand Down
32 changes: 17 additions & 15 deletions lib/rmt/mirror.rb
Expand Up @@ -6,35 +6,32 @@ class RMT::Mirror
class RMT::Mirror::Exception < RuntimeError
end

def initialize(mirroring_base_dir: RMT::DEFAULT_MIRROR_DIR, logger:, mirror_src: false, disable_hardlinks: false)
def initialize(mirroring_base_dir: RMT::DEFAULT_MIRROR_DIR, logger:, mirror_src: false, airgap_mode: false)
@mirroring_base_dir = mirroring_base_dir
@mirror_src = mirror_src
@logger = logger
@force_dedup_by_copy = disable_hardlinks
@force_dedup_by_copy = airgap_mode

@downloader = RMT::Downloader.new(
repository_url: @repository_url,
destination_dir: @repository_dir,
logger: @logger,
save_for_dedup: !disable_hardlinks # don't save files for deduplication when in offline mode
save_for_dedup: !airgap_mode # don't save files for deduplication when in offline mode
)
end

def mirror(repository_url:, local_path:, auth_token: nil, repo_name: nil)
@logger.info "Mirroring repository #{repo_name || repository_url} to #{local_path}"

@primary_files = []
@deltainfo_files = []

@repository_dir = File.join(@mirroring_base_dir, local_path)
@repository_url = repository_url

@logger.info "Mirroring repository #{repo_name || repository_url} to #{@repository_dir}"

create_directories
mirror_license
# downloading license doesn't require an auth token
@downloader.auth_token = auth_token
mirror_metadata
mirror_data
primary_files, deltainfo_files = mirror_metadata
mirror_data(primary_files, deltainfo_files)

replace_directory(@temp_licenses_dir, File.join(@repository_dir, '../product.license/')) if Dir.exist?(@temp_licenses_dir)
replace_directory(File.join(@temp_metadata_dir, 'repodata'), File.join(@repository_dir, 'repodata'))
Expand Down Expand Up @@ -78,6 +75,9 @@ def mirror_metadata
end

begin
primary_files = []
deltainfo_files = []

repomd_parser = RMT::Rpm::RepomdXmlParser.new(local_filename)
repomd_parser.parse

Expand All @@ -87,9 +87,11 @@ def mirror_metadata
checksum_type: reference.checksum_type,
checksum_value: reference.checksum
)
@primary_files << reference.location if (reference.type == :primary)
@deltainfo_files << reference.location if (reference.type == :deltainfo)
primary_files << reference.location if (reference.type == :primary)
deltainfo_files << reference.location if (reference.type == :deltainfo)
end

return primary_files, deltainfo_files
rescue RuntimeError => e
raise RMT::Mirror::Exception.new("Error while mirroring metadata files: #{e}")
rescue Interrupt => e
Expand Down Expand Up @@ -121,12 +123,12 @@ def mirror_license
end
end

def mirror_data
def mirror_data(primary_files, deltainfo_files)
@downloader.repository_url = @repository_url
@downloader.destination_dir = @repository_dir
@downloader.cache_dir = nil

@deltainfo_files.each do |filename|
deltainfo_files.each do |filename|
parser = RMT::Rpm::DeltainfoXmlParser.new(
File.join(@temp_metadata_dir, filename),
@mirror_src
Expand All @@ -136,7 +138,7 @@ def mirror_data
@downloader.download_multi(to_download) unless to_download.empty?
end

@primary_files.each do |filename|
primary_files.each do |filename|
parser = RMT::Rpm::PrimaryXmlParser.new(
File.join(@temp_metadata_dir, filename),
@mirror_src
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/rmt/cli/export_spec.rb
Expand Up @@ -61,7 +61,7 @@
expect(RMT::Mirror).to receive(:new).with(
mirroring_base_dir: path,
logger: instance_of(RMT::Logger),
disable_hardlinks: true
airgap_mode: true
).once.and_return(mirror_double)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/rmt/cli/import_spec.rb
Expand Up @@ -75,7 +75,7 @@

expect(RMT::Mirror).to receive(:new).with(
logger: instance_of(RMT::Logger),
disable_hardlinks: true
airgap_mode: true
).and_return(mirror_double)

expect(mirror_double).to receive(:mirror).with(
Expand Down Expand Up @@ -110,7 +110,7 @@

expect(RMT::Mirror).to receive(:new).with(
logger: instance_of(RMT::Logger),
disable_hardlinks: true
airgap_mode: true
).and_return(mirror_double)

expect(mirror_double).to receive(:mirror).with(
Expand Down
3 changes: 0 additions & 3 deletions spec/lib/rmt/cli/smt_importer_spec.rb
Expand Up @@ -219,9 +219,6 @@
OUTPUT
end
end


# rubocop:disable RSpec/MultipleExpectations
describe '#run' do
context 'without --no-system flag' do
it 'runs all steps including importing the systems' do
Expand Down
33 changes: 6 additions & 27 deletions spec/lib/rmt/mirror_spec.rb
Expand Up @@ -59,6 +59,10 @@
end

before do
expect(logger).to receive(:info).with(/Mirroring repository/).once
expect(logger).to receive(:info).with('No product license found').once
expect(logger).to receive(:info).with('Repository metadata signatures are missing').once
expect(logger).to receive(:info).with(/↓/).at_least(1).times
rmt_mirror.mirror(mirror_params)
end

Expand Down Expand Up @@ -91,6 +95,8 @@
end

before do
expect(logger).to receive(:info).with(/Mirroring repository/).once
expect(logger).to receive(:info).with(/↓/).at_least(1).times
rmt_mirror.mirror(mirror_params)
end

Expand Down Expand Up @@ -395,32 +401,5 @@
expect(rpm_entries.length).to eq(4)
end
end

context 'when repo_name parameter is not specified' do
let(:rmt_mirror) do
described_class.new(
mirroring_base_dir: mirroring_dir,
logger: logger
)
end

let(:mirror_params) do
{
repository_url: 'http://localhost/dummy_product/product/',
local_path: '/dummy_product/product/',
auth_token: 'repo_auth_token'
}
end

it 'logs with the URL' do
pending 'TBD'
end
end

context 'when repo_name parameter is specified' do
it 'logs with the repo_name' do
pending 'TBD'
end
end
end
end

0 comments on commit df08595

Please sign in to comment.