Revision bdebc611
Added by Michael Stead about 10 years ago
app/models/katello/glue/provider.rb | ||
---|---|---|
# that one that subscriptions are assigned to. Between marketing and
|
||
# engineering products is M:N relation (see MarketingEngineeringProduct
|
||
# model)
|
||
#
|
||
# When a subscription is defined as a virtual data center subscription,
|
||
# its pools will have a seperate 'derived' marketing product and a seperate set
|
||
# of 'derived' engineering products. These products become the marketing and
|
||
# engineering products for the sub pool once a host binds to the original pool.
|
||
# We need to make sure to include these 'derived' products when creating our mapping.
|
||
def marketing_to_engineering_product_ids_mapping
|
||
mapping = {}
|
||
pools = Resources::Candlepin::Owner.pools self.organization.label
|
||
... | ... | |
eng_product_ids = pool[:providedProducts].map { |provided| provided[:productId] }
|
||
mapping[pool[:productId]].concat(eng_product_ids)
|
||
end
|
||
# Check to see if there are any 'derived' products defined.
|
||
if pool[:derivedProductId]
|
||
mapping[pool[:derivedProductId]] ||= []
|
||
if pool[:derivedProvidedProducts]
|
||
eng_product_ids = pool[:derivedProvidedProducts].map { |provided| provided[:productId] }
|
||
mapping[pool[:derivedProductId]].concat(eng_product_ids)
|
||
end
|
||
end
|
||
end
|
||
mapping
|
||
end
|
spec/helpers/product_test_data.rb | ||
---|---|---|
"created" => "2011-07-11T20=>26=>26.510+0000"
|
||
})
|
||
|
||
DERIVED_PROVIDED_PRODUCT = HashWithIndifferentAccess.new({
|
||
"created" => "2013-12-30T16:11:26.000+0000",
|
||
"id" => "8a85f987430cc341014344462dc06c38",
|
||
"productId" => "180",
|
||
"productName" => "Red Hat Beta",
|
||
"updated" => "2013-12-30T16:11:26.000+0000"
|
||
})
|
||
|
||
# PRODUCT_WITHOUT_CONTENT_ID = HashWithIndifferentAccess.new({
|
||
# :name => ProductTestData::PRODUCT_NAME,
|
||
# :id => ProductTestData::PRODUCT_ID,
|
spec/models/provider_spec.rb | ||
---|---|---|
end
|
||
|
||
end
|
||
|
||
describe "there were derived products and derived provided products included in the manifest" do
|
||
let(:pools) {
|
||
ProductTestData::POOLS.merge(
|
||
"derivedProductId" => "200",
|
||
"derivedProvidedProducts" => [ProductTestData::DERIVED_PROVIDED_PRODUCT.merge("productId" => "700")]
|
||
)
|
||
}
|
||
|
||
# product specified on the pool
|
||
let(:pool_product) {ProductTestData::PRODUCT_WITH_CONTENT.merge("id" => "rhel6-server")}
|
||
# derived product specified on the pool
|
||
let(:derived_product) {ProductTestData::PRODUCT_WITH_CONTENT.merge("id" => "200")}
|
||
# derived provided product specified on the pool
|
||
let(:derived_provided_product) {ProductTestData::PRODUCT_WITH_CONTENT.merge("id" => "700")}
|
||
|
||
before do
|
||
Glue::Candlepin::Product.stubs(:import_from_cp => [], :import_marketing_from_cp => true)
|
||
Resources::Candlepin::Product.stubs(:destroy).returns(true)
|
||
@provider.stubs(:index_subscriptions).returns([])
|
||
|
||
Resources::Candlepin::Owner.stubs(:pools).returns([pools])
|
||
Resources::Candlepin::Product.stubs(:get).with("rhel6-server").returns([pool_product])
|
||
Resources::Candlepin::Product.stubs(:get).with("200").returns([derived_product])
|
||
Resources::Candlepin::Product.stubs(:get).with("700").returns([derived_provided_product])
|
||
|
||
Resources::Candlepin::Product.stubs(:create).returns({:id => "200"})
|
||
@existing_derived_product = Product.create!({
|
||
:label=>"dp",
|
||
:name=> derived_product["name"],
|
||
:productContent => [],
|
||
:provider => @provider
|
||
})
|
||
|
||
Resources::Candlepin::Product.stubs(:create).returns({:id => "700"})
|
||
@existing_derived_provided_product = Product.create!({
|
||
:label=>"dpp",
|
||
:name=> derived_provided_product["name"],
|
||
:productContent => [],
|
||
:provider => @provider
|
||
})
|
||
|
||
end
|
||
|
||
it 'derived marketing and engineering products should not be removed' do
|
||
@provider.import_products_from_cp
|
||
Product.find_by_cp_id(@existing_derived_product.cp_id).wont_be_nil
|
||
Product.find_by_cp_id(@existing_derived_provided_product.cp_id).wont_be_nil
|
||
end
|
||
|
||
end
|
||
end
|
||
|
||
describe "marketing to product id mapping" do
|
||
let(:pools) {
|
||
ProductTestData::POOLS.merge(
|
||
"derivedProductId" => "200",
|
||
"derivedProvidedProducts" => [ProductTestData::DERIVED_PROVIDED_PRODUCT.merge("productId" => "700")]
|
||
)
|
||
}
|
||
|
||
before do
|
||
Resources::Candlepin::Owner.stubs(:pools).returns([pools])
|
||
end
|
||
|
||
it "should be generated correctly" do
|
||
mapping = @provider.send(:marketing_to_engineering_product_ids_mapping)
|
||
# keys should include product and derived product ids.
|
||
mapping.assert_valid_keys('rhel6-server', '200')
|
||
|
||
# Ensure provided product is mapped to product
|
||
mapping['rhel6-server'].must_equal(['20'])
|
||
|
||
# Ensure derived provided product is mapped to derived product
|
||
mapping['200'].must_equal(['700'])
|
||
end
|
||
end
|
||
|
||
end
|
||
|
||
describe "products refresh(katello)" do
|
Also available in: Unified diff
1057652: No longer delete derived products on import
Must include all derived marketing/engineering products
when determining the marketing/engineering product
mapping during manifest import, else katello thinks
that they should be deleted after an import.
Derived products are used to create a sub pool once
the subscription is attached. We can not delete them.