candlepin/candlepin — pull request #83 by jbowes (2012-10-05 21:18:17+00:00)
Title: 800145: Update pools across all owners on product import

Previously, upon importing an export file, if a product was modified,
we would regenerate the certificates of all entitlements that referenced
that product. We would then run a refreshPools on the owner that
imported the export. the refreshPools would adjust that owner's pools to
reflect the new product attributes, but not any other owners.

That was the intention, anyways. In reality, the code to look for
changed products compared the new forms of the products to the products
from the db, but only after it had already updated the db. Thus, the
products were never found to have changed, and no certs were
regenerated.

This patch fixes that up by comparing the new forms of the products with
the form as it is in the db, before storing the new form. Further, it
corrects the code to check for changes, catching more instances when the
products are different.

To refresh the pools referencing the affected products, but also ensure
that a pool that references two products, or a pool that is owned by the
importing owner is not refreshed multiple times, introduce a new
Refresher object that takes care of gathering up the objects we want to
trigger a refresh on (products, owners), then executes the pool
refreshes and entitlement regens without repeating anything.

The existing code to trigger a refresh by product was being overly broad
on what pools it would refresh (triggering for all pools for an owner
that had a single pool that referenced the product, rather than just the
referencing pools). This patch also narrows the focus down to just the
affected pools, and introduces a spec test to verify that.