~fabricematrat/charmworld/redirect-charm

« back to all changes in this revision

Viewing changes to charmworld/migrations/versions/tests/test_migrations.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:
5
5
    CharmSource,
6
6
)
7
7
from charmworld.testing import (
 
8
    factory,
8
9
    MongoTestBase,
9
10
)
 
11
 
10
12
from charmworld.migrations import migrate
11
13
from charmworld.migrations.migrate import Versions
12
14
 
21
23
        self.use_context(patch.object(migrate, 'configure_logging'))
22
24
 
23
25
 
24
 
class TestMigration025(MigrationTestBase):
 
26
class TestExodus026(MigrationTestBase):
 
27
 
 
28
    version = 26
 
29
    exodus = '026_convert_comma_constraints.py'
25
30
 
26
31
    def setUp(self):
27
 
        super(TestMigration025, self).setUp()
 
32
        super(TestExodus026, self).setUp()
28
33
        self.use_index_client()
29
34
 
30
 
    # Test creation of charm indices, but only if they do not exist already.
31
 
    def test_calls_setup_mongo_indices(self):
 
35
    # Test converting service constraints to space-separated.
 
36
    def test_converts_constraints(self):
32
37
        source = CharmSource.from_request(self)
33
 
        index_name = 'owner_series_name_revision'
 
38
        source_db = source.collection.database
34
39
        exodus_update = self.versions.get_exodus(
35
 
            '025_charm_index_two.py')
36
 
        target = self.versions.get_pending_source(source, 25)
37
 
        index_info = target.collection.index_information()
38
 
        self.assertNotIn(index_name, index_info)
39
 
        exodus_update(source, target, 25)
40
 
        index_info = target.collection.index_information()
41
 
        self.assertIn(index_name, index_info)
 
40
            self.exodus)
 
41
        target = self.versions.get_pending_source(source, self.version)
 
42
        target_db = target.collection.database
 
43
        services = dict(
 
44
            svc1=dict(constraints='cpu-cores=4,mem=2G,arch=i686'),
 
45
            svc2=dict(constraints='cpu-cores=44 arch=i386 mem=9G'),
 
46
        )
 
47
        self.assertEqual(0, source_db.bundles.count())
 
48
        self.assertEqual(0, target_db.bundles.count())
 
49
        bundle, bundle_data = factory.make_bundle(
 
50
            source_db, services=services)
 
51
        self.assertEqual(1, source_db.bundles.count())
 
52
        self.assertEqual(1, target_db.bundles.count())
 
53
 
 
54
        # Run the exodus.
 
55
        exodus_update(source, target, self.version)
 
56
        # Ensure there is still just the one bundle.
 
57
        self.assertEqual(1, target_db.bundles.count())
 
58
        converted = target_db.bundles.find_one()
 
59
        services = converted['data']['services']
 
60
        # Constraints are now space-separated and sorted.
 
61
        self.assertEqual(services['svc1']['constraints'],
 
62
                         'arch=i686 cpu-cores=4 mem=2G')
 
63
        self.assertEqual(services['svc2']['constraints'],
 
64
                         'arch=i386 cpu-cores=44 mem=9G')
42
65
 
43
66
 
44
67
class TestExodusRestrictions(MigrationTestBase):