~fabricematrat/charmworld/redirect-charm

« back to all changes in this revision

Viewing changes to charmworld/tests/test_models.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:
36
36
    CharmFileSet,
37
37
    CharmSource,
38
38
    construct_charm_id,
 
39
    convert_bundle_constraints,
39
40
    DatedMetric,
40
41
    DatedMetricSource,
41
42
    FeaturedSource,
2321
2322
        self.assertEqual(expected, filelist)
2322
2323
 
2323
2324
 
2324
 
class TestMassageBundlesYaml(TestCase):
 
2325
class TestConvertingConstraints(TestCase):
 
2326
 
 
2327
    comma_constraints = 'mem=2G,cpu-cores=4,arch=i386'
 
2328
    yaml_template = dedent("""\
 
2329
        wiki:
 
2330
          series: precise
 
2331
          promulgated: True
 
2332
          services:
 
2333
            wiki:
 
2334
              charm: mediawiki
 
2335
              branch: lp:charms/precise/mediawiki
 
2336
              constraints: {}
 
2337
              num_units: 2
 
2338
            db:
 
2339
              charm: mysql
 
2340
              branch: lp:charms/precise/mysql
 
2341
              options:
 
2342
                tuning-level: fast
 
2343
    """)
 
2344
 
 
2345
    def test_convert_bundle_constraints(self):
 
2346
        """The contraints within bundle_data are converted."""
 
2347
        data = yaml.load(self.yaml_template.format(self.comma_constraints))
 
2348
        # Convert in place.
 
2349
        convert_bundle_constraints(data['wiki'])
 
2350
        expected = ' '.join(sorted(
 
2351
            self.comma_constraints.split(',')))
 
2352
        self.assertEqual(
 
2353
            expected,
 
2354
            data['wiki']['services']['wiki']['constraints'])
2325
2355
 
2326
2356
    def test_massage_bundle_file(self):
2327
2357
        """Constraints with comma-separators are converted."""
2328
 
        comma_constraints = 'mem=2G,cpu-cores=4,arch=i386'
2329
 
        yaml_template = dedent("""\
2330
 
            wiki:
2331
 
              series: precise
2332
 
              promulgated: True
2333
 
              services:
2334
 
                wiki:
2335
 
                  charm: mediawiki
2336
 
                  branch: lp:charms/precise/mediawiki
2337
 
                  constraints: {}
2338
 
                  num_units: 2
2339
 
                db:
2340
 
                  charm: mysql
2341
 
                  branch: lp:charms/precise/mysql
2342
 
                  options:
2343
 
                    tuning-level: fast
2344
 
        """)
2345
2358
        massaged = make_constraints_space_separated(
2346
 
            yaml_template.format(comma_constraints))
 
2359
            self.yaml_template.format(self.comma_constraints))
2347
2360
        expected = yaml.dump(
2348
 
            yaml.load(yaml_template.format('arch=i386 cpu-cores=4 mem=2G')),
 
2361
            yaml.load(self.yaml_template.format(
 
2362
                'arch=i386 cpu-cores=4 mem=2G')),
2349
2363
            default_flow_style=False)
2350
2364
        self.assertEqual(expected, massaged)
2351
2365
 
2359
2373
            'name': 'wikipedia',
2360
2374
            'series': 'precise',
2361
2375
            'owner': 'charmers',
2362
 
            'promulgated': True
 
2376
            'promulgated': True,
2363
2377
        }
2364
2378
        charm_args['revision'] = 1
2365
2379
        charm_args['store_revision'] = 1