Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #26047 - Add check for puppet in cvv export. #632

Merged
merged 1 commit into from Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 1 addition & 26 deletions lib/hammer_cli_katello/content_view_version.rb
Expand Up @@ -301,6 +301,7 @@ def execute
export_json_options[:repositories] = []
else
repositories = fetch_cvv_repositories(cvv)
puppet_check(cvv)
check_repo_type(repositories)
check_repo_download_policy(repositories)

Expand Down Expand Up @@ -349,32 +350,6 @@ def create_tar(cv, cvv, repositories, json)
FileUtils.rm_rf(export_prefix)
end
end

def check_repo_type(repositories)
repositories.select do |repo|
if repo['content_type'] != 'yum'
raise _("The Repository '#{repo['name']}' is a non-yum repository."\
" Only Yum is supported at this time."\
" Please remove the repository from the Content View,"\
" republish and try the export again.")
end
end
end

def check_repo_download_policy(repositories)
chris1984 marked this conversation as resolved.
Show resolved Hide resolved
non_immediate = repositories.select do |repo|
show(:repositories, 'id' => repo['library_instance_id'])['download_policy'] != 'immediate'
end
return true if non_immediate.empty?

non_immediate_names = repositories.collect { |repo| repo['name'] }
msg = <<~MSG
All exported repositories must be set to an immediate download policy and re-synced.
The following repositories need action:
#{non_immediate_names.join(', ')}
MSG
raise _(msg)
end
end

class ImportCommand < HammerCLIForeman::Command
Expand Down
36 changes: 36 additions & 0 deletions lib/hammer_cli_katello/cv_import_export_helper.rb
@@ -1,3 +1,4 @@
# rubocop:disable Metrics/ModuleLength
module HammerCLIKatello
module CVImportExportHelper
PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
Expand All @@ -22,6 +23,41 @@ def find_local_component_id(component_from_export)
found_composite_version.first['id']
end

def puppet_check(cvv)
unless cvv['puppet_modules'].empty?
raise _("The Content View '#{cvv['content_view']['label']}'"\
" contains Puppet modules, this is not supported at this time."\
" Please remove the modules, publish a new version"\
" and try the export again.")
end
end

def check_repo_type(repositories)
repositories.select do |repo|
if repo['content_type'] != 'yum'
raise _("The Repository '#{repo['name']}' is a non-yum repository."\
" Only Yum is supported at this time."\
" Please remove the repository from the Content View,"\
" republish and try the export again.")
end
end
end

def check_repo_download_policy(repositories)
non_immediate = repositories.select do |repo|
show(:repositories, 'id' => repo['library_instance_id'])['download_policy'] != 'immediate'
end
unless non_immediate.empty?
non_immediate_names = repositories.collect { |repo| repo['name'] }
msg = <<~MSG
All exported repositories must be set to an immediate download policy and re-synced.
The following repositories need action:
#{non_immediate_names.join(', ')}
MSG
raise _(msg)
end
end

def import_checks(cv, import_cv, major, minor)
version = "#{major}.#{minor}".to_f

Expand Down
51 changes: 48 additions & 3 deletions test/functional/content_view/version/export_test.rb
Expand Up @@ -20,7 +20,9 @@
'major' => 1,
'minor' => 0,
'content_view' => {'name' => 'cv'},
'content_view_id' => 4321
'content_view_id' => 4321,
'puppet_modules' => []

)

ex = api_expects(:content_views, :show)
Expand Down Expand Up @@ -108,7 +110,8 @@
'major' => 1,
'minor' => 0,
'content_view' => {'name' => 'cv'},
'content_view_id' => 4321
'content_view_id' => 4321,
'puppet_modules' => []
)

ex = api_expects(:content_views, :show)
Expand Down Expand Up @@ -139,6 +142,47 @@
assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
end

it "fails export if cvv contains puppet module" do
params = [
'--id=5',
'--export-dir=/tmp/exports'
]

ex = api_expects(:content_view_versions, :show)
ex.returns(
'id' => '5',
'repositories' => [{'id' => '2'}],
'major' => 1,
'minor' => 0,
'content_view' => {'name' => 'cv'},
'content_view_id' => 4321,
'puppet_modules' => [{'id' => '1'}]
)

ex = api_expects(:content_views, :show)
ex.returns(
'id' => '4321',
'composite' => false,
'puppet_modules' => [{'id' => '1'}]
)

ex = api_expects(:repositories, :show).with_params('id' => '2')
ex.returns(
'id' => '2',
'label' => 'Test_Repo',
'content_type' => 'yum',
'backend_identifier' => 'Default_Organization-Library-Test_Repo',
'relative_path' => 'Default_Organization/Library/Test_Repo',
'library_instance_id' => '1'
)

File.expects(:exist?).with('/usr/share/foreman').returns(true)
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)

result = run_cmd(@cmd + params)
assert_equal(result.exit_code, 70)
end

it "fails export if any repository is set to on_demand" do
params = [
'--id=5',
Expand All @@ -152,7 +196,8 @@
'major' => 1,
'minor' => 0,
'content_view' => {'name' => 'cv'},
'content_view_id' => 4321
'content_view_id' => 4321,
'puppet_modules' => []
)

ex = api_expects(:content_views, :show)
Expand Down