~fabricematrat/charmworld/redirect-charm

« back to all changes in this revision

Viewing changes to charmworld/migrations/versions/026_convert_comma_constraints.py

  • Committer: Tarmac
  • Author(s): Brad Crittenden
  • Date: 2014-04-21 15:59:48 UTC
  • mfrom: (501.2.4 comma-migration-2)
  • Revision ID: tarmac-20140421155948-ot1x6l5gu321ul4v
Exodus to remove comma-sep constraints.

Comma-separated constraints in bundles are deprecated.  Currently newly
processed bundles are converted to space-separated on ingestion but there are
a number of old bundles in the db that need fixing.

As this is an exodus, and only one can be present at a time, the 025 exodus is
deleted.

https://codereview.appspot.com/89770044/

R=jcsackett.

Approved by Juju Gui Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# convert-comma-constraints
 
2
import logging
 
3
from charmworld.migrations.migrate import setup_mongo_indices
 
4
from charmworld.models import (
 
5
    convert_bundle_constraints,
 
6
    store_bundles,
 
7
)
 
8
 
 
9
 
 
10
def exodus_update(source, target, current_version):
 
11
    """Complete this function with work for an exodus.
 
12
 
 
13
    source is the original CharmSource.
 
14
    target is the CharmSource to be used after the exodus.
 
15
    current_version is the version of this exodus.
 
16
    """
 
17
    source_db = source.collection.database
 
18
    target_db = target.collection.database
 
19
 
 
20
    log = logging.getLogger('charm.exodus026')
 
21
    log.warning('Starting')
 
22
    charms = target.collection
 
23
    setup_mongo_indices(charms)
 
24
    log.warning('Indices built')
 
25
 
 
26
    log.warning('Converting bundles')
 
27
    bundles = source_db.bundles.find()
 
28
    for bundle_data in bundles:
 
29
        convert_bundle_constraints(bundle_data['data'])
 
30
        basket_id = '{}/{}'.format(
 
31
            bundle_data['basket_name'],
 
32
            bundle_data['basket_revision'])
 
33
        deployer_config = {bundle_data['name']: bundle_data['data']}
 
34
        store_bundles(
 
35
            target_db.bundles,
 
36
            deployer_config,
 
37
            bundle_data['owner'],
 
38
            basket_id,
 
39
            bundle_data['first_change'],
 
40
            bundle_data['last_change'],
 
41
            bundle_data['changes'],
 
42
            bundle_data['branch_spec'],
 
43
            None,
 
44
            target.index_client,
 
45
            bundle_data['promulgated'])
 
46
 
 
47
    log.warning('Copying charms')
 
48
    for charm in source_db.charms.find():
 
49
        target.save(charm)
 
50
    log.warning('Finished')