Skip to content

Commit

Permalink
Fixes #34684 - install pulp-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Mar 28, 2022
1 parent 3dd9f37 commit 403950c
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 0 deletions.
71 changes: 71 additions & 0 deletions manifests/cli.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# = Pulpcore command line interface
#
# This class installs the Pulpcore command line interface (CLI).
#
# === Parameters:
#
# $pulpcore_url:: URL on which Pulpcore runs
#
# $username:: Username for authentication
#
# $password:: Password for authentication
#
# $cert:: Client certificate for authentication
#
# $key:: Client key for authentication
#
# === Advanced parameters:
#
# $api_root:: Absolute API base path on server (not including 'api/v3/')
#
# $verify_ssl:: Verify SSL connection
#
# $dry_run:: Trace commands without performing any unsafe HTTP calls
#
# $version:: pulp-cli package version, it's passed to ensure parameter of package resource
# can be set to specific version number, 'latest', 'present' etc.
#
class pulpcore::cli (
Optional[Stdlib::HTTPUrl] $pulpcore_url = $pulpcore::cli::params::pulpcore_url,
String $version = $pulpcore::cli::params::version,
Optional[String] $username = $pulpcore::cli::params::username,
Optional[String] $password = $pulpcore::cli::params::password,
Optional[String] $cert = $pulpcore::cli::params::cert,
Optional[String] $key = $pulpcore::cli::params::key,
Optional[String] $api_root = $pulpcore::cli::params::api_root,
Boolean $verify_ssl = $pulpcore::cli::params::verify_ssl,
Boolean $dry_run = $pulpcore::cli::params::dry_run,
) inherits pulpcore::cli::params {
# Workaround until https://github.com/theforeman/pulpcore-packaging/pull/425 is merged
if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '7' {
$_package_name = 'tfm-pulpcore-python3-pulp-cli'
} else {
$_package_name = 'python38-pulp-cli'
}

package { 'pulp-cli':
ensure => $version,
name => $_package_name,
}
-> file { '/etc/pulp/cli.toml':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => epp(
'pulpcore/cli-config.toml.epp',
{
base_url => $pulpcore_url,
username => $username,
password => $password,
cert => $cert,
key => $key,
api_root => $api_root,
verify_ssl => $verify_ssl,
dry_run => $dry_run,
}
),
}

Anchor <| title == 'pulpcore::repo' |> ~> Package <| tag == 'pulpcore::cli' |>
}
12 changes: 12 additions & 0 deletions manifests/cli/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Parameters for Pulpcore CLI class
class pulpcore::cli::params {
$pulpcore_url = undef
$version = 'installed'
$username = undef
$password = undef
$cert = undef
$key = undef
$api_root = undef
$verify_ssl = true
$dry_run = true
}
46 changes: 46 additions & 0 deletions spec/acceptance/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper_acceptance'

describe 'installation of cli only' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
include pulpcore::cli
PUPPET
end
end

describe command("pulp config validate --location /etc/pulp/cli.toml") do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match(/valid pulp-cli config/) }
end
end

describe 'installation of server with cli' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
include pulpcore
class { 'pulpcore::cli':
pulpcore_url => "https://#{host_inventory['fqdn']}/",
cert => "/etc/pulpcore-certs/client-cert.pem",
key => "/etc/pulpcore-certs/client-key.pem",
}
PUPPET
end
end

include_examples 'the default pulpcore application'

describe command("pulp config validate --location /etc/pulp/cli.toml") do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match(/valid pulp-cli config/) }
end

describe command("REQUESTS_CA_BUNDLE=/etc/pulpcore-certs/ca-cert.pem pulp status") do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match(/versions/) }
# currently this contains a warning:
# SubjectAltNameWarning: Certificate for centos8-64.example.com has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818.
# its(:stderr) { is_expected.to eq '' }
end
end
13 changes: 13 additions & 0 deletions spec/classes/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

describe 'pulpcore::cli' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
let(:pre_condition) { 'include pulpcore::cli' }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('pulp-cli') }
end
end
end
29 changes: 29 additions & 0 deletions templates/cli-config.toml.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%- |
Optional[Stdlib::HTTPUrl] $base_url,
Optional[String] $username,
Optional[String] $password,
Optional[String] $cert,
Optional[String] $key,
Optional[String] $api_root,
Boolean $verify_ssl,
Boolean $dry_run,
| -%>
[cli]
base_url = "<%= $base_url %>"
verify_ssl = <%= $verify_ssl %>
dry_run = <%= $dry_run %>
<% if $username { -%>
username = "<%= $username %>"
<% } -%>
<% if $password { -%>
password = "<%= $password %>"
<% } -%>
<% if $cert { -%>
cert = "<%= $cert %>"
<% } -%>
<% if $key { -%>
key = "<%= $key %>"
<% } -%>
<% if $api_root { -%>
api_root = "<%= $api_root %>"
<% } -%>

0 comments on commit 403950c

Please sign in to comment.