~juju-gui-bot/charmworld/trunk

« back to all changes in this revision

Viewing changes to charmworld/models.py

  • Committer: Tarmac
  • Author(s): Matthew Scott
  • Date: 2014-03-07 16:13:24 UTC
  • mfrom: (487.3.4 charm-urls)
  • Revision ID: tarmac-20140307161324-8quz1tbpjxvq5all
Normalize charm URLs in bundles

This branch normalizes the charm URLs in bundles for the GUI, which is expecting at least a <schema>:<series>/<name> style URL.  Current proof allows bundles with charms specified only by name, so long as they're in the charmstore already.

Caveats:
* Currently only works on ingest
* May require a GUI branch as well to add -HEAD if no version number (a smart move anyway) depending on API support.


QA:
* Run
* Enqueue and ingest at least mysql and mediawiki
* bin/enqueue --prefix=~bac/charms/bundles
* bin/ingest-queued --prefix=~bac/charms/bundles --limit=100
* Get bac's bundle wiki:wiki - the charms should all have a charm: attribute, and the attributes should all be URLs as specified above.

https://codereview.appspot.com/71070051/

R=benji, rharding.

Approved by Benji York, Juju Gui Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1795
1795
 
1796
1796
 
1797
1797
def make_bundle_doc(data, owner, basket_id, bundle_name, first_change,
1798
 
                    last_change, changes, branch_spec, promulgated=False):
 
1798
                    last_change, changes, branch_spec,
 
1799
                    promulgated=False, services_info=None):
1799
1800
    basket_name, basket_revision = basket_id.split('/')
1800
1801
    _id = Bundle.construct_id(owner, basket_name, bundle_name, basket_revision)
 
1802
    if services_info is not None:
 
1803
        # Ensure that the charm URLs for the services included are fully
 
1804
        # resolved excluding only the revision.
 
1805
        for name, info in data['services'].iteritems():
 
1806
            # Note that this will drop the revision number from the provided
 
1807
            # service URL in the case that they do not match.  This will not
 
1808
            # affect bundles created with fully specified charm URLs.
 
1809
            if 'charm' not in info or \
 
1810
                    info['charm'] != services_info[name]['store_url']:
 
1811
                info['charm'] = re.sub('-\d+$', '',
 
1812
                                       services_info[name]['store_url'])
1801
1813
    return {
1802
1814
        '_id': _id,
1803
1815
        'name': bundle_name,
1814
1826
 
1815
1827
 
1816
1828
def store_bundles(collection, deployer_config, owner, basket_id, first_change,
1817
 
                  last_change, changes, branch_spec, index_client=None,
1818
 
                  promulgated=False):
 
1829
                  last_change, changes, branch_spec, services_info,
 
1830
                  index_client=None, promulgated=False):
1819
1831
    """Store a basket of bundles into MongoDB and/or ElasticSearch.
1820
1832
 
1821
1833
    :param: collection: A db bundles collection.  If None the bundles are not
1841
1853
        data = get_flattened_deployment(deployer_config, bundle_name)
1842
1854
        index_data[bundle_name] = make_bundle_doc(
1843
1855
            data, owner, basket_id, bundle_name, first_change, last_change,
1844
 
            changes, branch_spec, promulgated)
 
1856
            changes, branch_spec, promulgated, services_info)
1845
1857
        if collection is not None:
1846
1858
            collection.save(index_data[bundle_name])
1847
1859