Skip to content
Snippets Groups Projects
Commit 42203412 authored by Magnus Svensson's avatar Magnus Svensson
Browse files

Merge branch 'devel' into 'test'

Devel

See merge request pm-liuit/liu_pulpcore!117
parents 4e67efb8 13905c2c
No related branches found
No related tags found
No related merge requests found
Pipeline #165012 passed
# frozen_string_literal: true
require 'puppet/resource_api/simple_provider'
require 'puppet_x/liu_pulpcore/connection'
require 'puppet_x/liu_pulpcore/resource_cache'
# Implementation for the liu_pulpcore_deb_verbatim_publication type using Net::HTTP
class Puppet::Provider::LiuPulpcoreDebVerbatimPublication::LiuPulpcoreDebVerbatimPublication < Puppet::ResourceApi::SimpleProvider
include PuppetX::LiuPulpcore::Connection
include PuppetX::LiuPulpcore::ResourceCache
resource_type :liu_pulpcore_deb_verbatim_publication
def uncached_get(_context)
paginated(per_page: 1000) { request('/pulp/api/v3/publications/deb/verbatim/', 'get') }['results'].map do |pub|
next if pub['repository'].nil?
result = pub.transform_keys(&:to_sym).slice(*attribute_keys).compact
result[:ensure] = 'present'
result[:name] = find_cached(:liu_pulpcore_deb_repository, pub['repository'])[:name]
result[:pulp_href] = pub['pulp_href']
result
end
end
def create(_context, name, should)
payload = should.slice(*attribute_keys)
payload.delete :name
payload[:repository] = find_cached(:liu_pulpcore_deb_repository, name)[:pulp_href]
request('/pulp/api/v3/publications/deb/verbatim/', 'post', body: payload.compact)
cache << should.merge(name: name)
end
def update(_context, name, should)
pulp_href = should[:pulp_href]
pulp_href ||= find_cached(:liu_pulpcore_deb_publication, name)[:pulp_href]
request(pulp_href, 'delete')
payload = should.slice(*attribute_keys)
payload[:repository] = find_cached(:liu_pulpcore_deb_repository, name)[:pulp_href]
request('/pulp/api/v3/publications/deb/verbatim/', 'post', body: payload.compact)
cache.find { |pub| pub[:name] == name }&.merge!(should)
end
def delete(_context, name)
pulp_href = find_cached(:liu_pulpcore_deb_verbatim_publication, name)[:pulp_href]
request(pulp_href, 'delete')
# cache.delete_if { |pub| pub[:pulp_href] == pulp_href }
end
end
# frozen_string_literal: true
require 'puppet/resource_api'
Puppet::ResourceApi.register_type(
name: 'liu_pulpcore_deb_verbatim_publication',
docs: <<-EOS,
@summary Pulp DEB Verbatim Publication
EOS
features: [],
attributes: {
ensure: {
type: 'Enum[present, absent]',
default: 'present',
desc: 'Whether this resource should be present or absent on the target system.',
},
name: {
type: 'String',
behaviour: :namevar,
desc: 'Repository name.',
},
pulp_href: {
type: 'Optional[String]',
behaviour: :read_only,
desc: 'The internal pulp href for the object',
},
},
autorequire: {
liu_pulpcore_deb_repository: [
'$name',
],
},
)
{
"count": 3,
"next": null,
"previous": null,
"results": [
{
"pulp_href": "/pulp/api/v3/publications/deb/verbatim/0196cde8-5262-71a1-9ee9-f857da7d5f2d/",
"prn": "prn:deb.verbatimpublication:0196cde8-5262-71a1-9ee9-f857da7d5f2d",
"pulp_created": "2025-05-14T08:27:56.899878Z",
"pulp_last_updated": "2025-05-14T08:27:56.960171Z",
"repository_version": "/pulp/api/v3/repositories/deb/apt/018eadfc-4c94-72d6-8e16-bfa0bba968d1/versions/0/",
"repository": "/pulp/api/v3/repositories/deb/apt/018eadfc-4c94-72d6-8e16-bfa0bba968d1/"
}
]
}
...@@ -11,6 +11,7 @@ RSpec.describe 'LiU_pulpcore integration test' do ...@@ -11,6 +11,7 @@ RSpec.describe 'LiU_pulpcore integration test' do
let(:deb_remote) { Puppet::Type.type(:liu_pulpcore_deb_remote).new(name: 'testing', url: 'https://') } let(:deb_remote) { Puppet::Type.type(:liu_pulpcore_deb_remote).new(name: 'testing', url: 'https://') }
let(:deb_repository) { Puppet::Type.type(:liu_pulpcore_deb_repository).new(name: 'testing', remote: 'testing') } let(:deb_repository) { Puppet::Type.type(:liu_pulpcore_deb_repository).new(name: 'testing', remote: 'testing') }
let(:deb_publication) { Puppet::Type.type(:liu_pulpcore_deb_publication).new(name: 'testing') } let(:deb_publication) { Puppet::Type.type(:liu_pulpcore_deb_publication).new(name: 'testing') }
let(:deb_verbatim_publication) { Puppet::Type.type(:liu_pulpcore_deb_verbatim_publication).new(name: 'testing') }
let(:deb_distribution) { Puppet::Type.type(:liu_pulpcore_deb_distribution).new(name: 'testing', base_path: 'foo', repository: 'testing') } let(:deb_distribution) { Puppet::Type.type(:liu_pulpcore_deb_distribution).new(name: 'testing', base_path: 'foo', repository: 'testing') }
let(:python_remote) { Puppet::Type.type(:liu_pulpcore_python_remote).new(name: 'testing', url: 'https://') } let(:python_remote) { Puppet::Type.type(:liu_pulpcore_python_remote).new(name: 'testing', url: 'https://') }
let(:python_repository) { Puppet::Type.type(:liu_pulpcore_python_repository).new(name: 'testing', remote: 'testing') } let(:python_repository) { Puppet::Type.type(:liu_pulpcore_python_repository).new(name: 'testing', remote: 'testing') }
...@@ -28,7 +29,7 @@ RSpec.describe 'LiU_pulpcore integration test' do ...@@ -28,7 +29,7 @@ RSpec.describe 'LiU_pulpcore integration test' do
# Shuffle order to ensure autorequire does what it should # Shuffle order to ensure autorequire does what it should
[ [
rpm_remote, rpm_repository, rpm_publication, rpm_distribution, rpm_remote, rpm_repository, rpm_publication, rpm_distribution,
deb_remote, deb_repository, deb_publication, deb_distribution, deb_remote, deb_repository, deb_publication, deb_verbatim_publication, deb_distribution,
python_remote, python_repository, python_publication, python_distribution, python_remote, python_repository, python_publication, python_distribution,
role, group, user, role, group, user,
group_role, user_role group_role, user_role
...@@ -44,6 +45,7 @@ RSpec.describe 'LiU_pulpcore integration test' do ...@@ -44,6 +45,7 @@ RSpec.describe 'LiU_pulpcore integration test' do
# Add some role references # Add some role references
[user_role, group_role].each do |holder| [user_role, group_role].each do |holder|
holder[:object] << deb_publication holder[:object] << deb_publication
holder[:object] << deb_verbatim_publication
holder[:object] << rpm_publication holder[:object] << rpm_publication
holder[:object] << python_publication holder[:object] << python_publication
holder[:object] << deb_remote holder[:object] << deb_remote
...@@ -199,6 +201,19 @@ RSpec.describe 'LiU_pulpcore integration test' do ...@@ -199,6 +201,19 @@ RSpec.describe 'LiU_pulpcore integration test' do
}.to_json, }.to_json,
) )
debv_pub = stub_request(:post, 'http://pulpcore-api/pulp/api/v3/publications/deb/verbatim/')
.with(
body: {
repository: '/pulp/api/v3/repositories/deb/apt/def456/',
},
)
.to_return(
status: 202,
body: {
task: 'http://example.com',
}.to_json,
)
python_pub = stub_request(:post, 'http://pulpcore-api/pulp/api/v3/publications/python/pypi/') python_pub = stub_request(:post, 'http://pulpcore-api/pulp/api/v3/publications/python/pypi/')
.with( .with(
body: { body: {
...@@ -348,6 +363,7 @@ RSpec.describe 'LiU_pulpcore integration test' do ...@@ -348,6 +363,7 @@ RSpec.describe 'LiU_pulpcore integration test' do
assert_requested python_repo assert_requested python_repo
assert_requested rpm_pub assert_requested rpm_pub
assert_requested deb_pub assert_requested deb_pub
assert_requested debv_pub
assert_requested python_pub assert_requested python_pub
assert_requested rpm_dist assert_requested rpm_dist
assert_requested deb_dist assert_requested deb_dist
...@@ -365,6 +381,7 @@ RSpec.describe 'LiU_pulpcore integration test' do ...@@ -365,6 +381,7 @@ RSpec.describe 'LiU_pulpcore integration test' do
assert_requested :get, 'http://pulpcore-api/pulp/api/v3/distributions/python/pypi/?limit=100&offset=0', times: 1 assert_requested :get, 'http://pulpcore-api/pulp/api/v3/distributions/python/pypi/?limit=100&offset=0', times: 1
assert_requested :get, 'http://pulpcore-api/pulp/api/v3/publications/rpm/rpm/?limit=1000&offset=0', times: 1 assert_requested :get, 'http://pulpcore-api/pulp/api/v3/publications/rpm/rpm/?limit=1000&offset=0', times: 1
assert_requested :get, 'http://pulpcore-api/pulp/api/v3/publications/deb/apt/?limit=1000&offset=0', times: 1 assert_requested :get, 'http://pulpcore-api/pulp/api/v3/publications/deb/apt/?limit=1000&offset=0', times: 1
assert_requested :get, 'http://pulpcore-api/pulp/api/v3/publications/deb/verbatim/?limit=1000&offset=0', times: 1
assert_requested :get, 'http://pulpcore-api/pulp/api/v3/publications/python/pypi/?limit=1000&offset=0', times: 1 assert_requested :get, 'http://pulpcore-api/pulp/api/v3/publications/python/pypi/?limit=1000&offset=0', times: 1
assert_requested :get, 'http://pulpcore-api/pulp/api/v3/repositories/rpm/rpm/?limit=100&offset=0', times: 1 assert_requested :get, 'http://pulpcore-api/pulp/api/v3/repositories/rpm/rpm/?limit=100&offset=0', times: 1
assert_requested :get, 'http://pulpcore-api/pulp/api/v3/repositories/deb/apt/?limit=100&offset=0', times: 1 assert_requested :get, 'http://pulpcore-api/pulp/api/v3/repositories/deb/apt/?limit=100&offset=0', times: 1
......
...@@ -63,6 +63,11 @@ def allow_searching_full_cache ...@@ -63,6 +63,11 @@ def allow_searching_full_cache
status: 200, status: 200,
body: File.read('spec/fixtures/pulp_data/get_deb_publications.json'), body: File.read('spec/fixtures/pulp_data/get_deb_publications.json'),
) )
stub_request(:get, 'http://pulpcore-api/pulp/api/v3/publications/deb/verbatim/?limit=1000&offset=0')
.to_return(
status: 200,
body: File.read('spec/fixtures/pulp_data/get_deb_verbatim_publications.json'),
)
stub_request(:get, 'http://pulpcore-api/pulp/api/v3/publications/python/pypi/?limit=1000&offset=0') stub_request(:get, 'http://pulpcore-api/pulp/api/v3/publications/python/pypi/?limit=1000&offset=0')
.to_return( .to_return(
status: 200, status: 200,
......
# frozen_string_literal: true
require 'spec_helper'
ensure_module_defined('Puppet::Provider::LiuPulpcoreDebVerbatimPublication')
require 'puppet/provider/liu_pulpcore_deb_verbatim_publication/liu_pulpcore_deb_verbatim_publication'
RSpec.describe Puppet::Provider::LiuPulpcoreDebVerbatimPublication::LiuPulpcoreDebVerbatimPublication do
subject(:provider) { described_class.new }
let(:context) { instance_double('Puppet::ResourceApi::BaseContext', 'context') }
let(:test_data) do
{
pulp_href: '/pulp/api/v3/publications/deb/verbatim/0196cde8-5262-71a1-9ee9-f857da7d5f2d/',
ensure: 'present',
name: 'internal_jammy-x86_64',
}
end
before(:each) do
# Allows retrieving the publications
stub_request(:get, 'http://pulpcore-api/pulp/api/v3/publications/deb/verbatim/?limit=1000&offset=0')
.to_return(
status: 200,
body: File.read('spec/fixtures/pulp_data/get_deb_verbatim_publications.json'),
)
# Allow looking up repository names
stub_request(:get, 'http://pulpcore-api/pulp/api/v3/repositories/deb/apt/?limit=100&offset=0')
.to_return(
status: 200,
body: File.read('spec/fixtures/pulp_data/get_deb_repositories-trimmed.json'),
)
end
describe 'create(context, name, should)' do
it 'creates the resource' do
req = stub_request(:post, 'http://pulpcore-api/pulp/api/v3/publications/deb/verbatim/')
.with(
body: {
repository: '/pulp/api/v3/repositories/deb/apt/018eadfc-4c94-72d6-8e16-bfa0bba968d1/',
},
)
.to_return(
status: 200,
body: '{}',
)
provider.create(context, test_data[:name], test_data)
assert_requested req
end
end
describe '#get' do
it 'processes resources' do
data = provider.get(context)
expect(data.size).to eq 1
expect(data.first).to eq test_data
end
end
describe 'delete(context, name)' do
it 'deletes the resource' do
req = stub_request(:delete, 'http://pulpcore-api/pulp/api/v3/publications/deb/verbatim/0196cde8-5262-71a1-9ee9-f857da7d5f2d/')
.to_return(
status: 200,
body: '{}',
)
provider.delete(context, test_data[:name])
assert_requested req
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment