def get_product_ids(subscribedchannels): """ For the subscribed base and child channels look up product ids """ global CERT_DIR if CERT_DIR is None: CERT_DIR = CertificateDirectory(CERT_DIR_PATH) mapping_file = os.path.join( os.path.join(constants.CHANNEL_PRODUCT_ID_MAPPING_DIR, utils.get_release()), constants.CHANNEL_PRODUCT_ID_MAPPING_FILE) channel_mappings = utils.read_mapping_file(mapping_file) product_ids = [] for channel in subscribedchannels.split(';'): origin_channel = channel if origin_channel in channel_mappings: cert = channel_mappings[origin_channel] product_ids.append(cert.split('-')[-1].split('.')[0]) _LOG.debug("mapped subscribed channels %s to installed products %s" % (subscribedchannels, product_ids)) # reformat to how candlepin expects the product id list installed_products = [] for p in product_ids: product_cert = CERT_DIR.findByProduct(str(p)) installed_products.append({"productId": product_cert.products[0].id, "productName": product_cert.products[0].name}) return installed_products
def test_get_release(self): self.unmock(utils, 'get_release') utils.open = Mock() utils.open.return_value.readlines.return_value = \ 'Red Hat Enterprise Linux Server release 6.4 (Santiago)' release = utils.get_release() self.assertEquals('RHEL-6', release)