~ubuntu-branches/ubuntu/vivid/juju/vivid

« back to all changes in this revision

Viewing changes to juju/unit/lifecycle.py

  • Committer: Package Import Robot
  • Author(s): Martin Packman, Clint Byrum, Mark Mims, Martin Packman
  • Date: 2013-04-10 13:57:21 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20130410135721-s87t2g5pxe4yxk85
Tags: 0.7-0ubuntu1
[ Clint Byrum ]
* d/p/fix-tests-do-not-use-etc-lsb-release: Dropped, patch applied upstream.
* d/p/maas-tag-conversion.patch: Dropped, patch applied upstream.
* d/juju.docs: Remove examples as they have been dropped upstream.

[ Mark Mims ]
* Add postinst and prerm scripts using update-alternatives to install into
  a versioned location, enabling co-installability with the go juju port.

[ Martin Packman ]
* New upstream release. (lp: #1167921)
* d/p/workaround-lxc-python-env.patch: Workaround regression with local
  provider failing with SyntaxError on running lxc scripts when user has
  Python 3 specific environment variables set. (lp: #1130809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
360
360
        finally:
361
361
            self._run_lock.release()
362
362
 
 
363
    def _sort_relations(self, rel_ids, rels, invert=False):
 
364
        """ Sort a set of relations.
 
365
 
 
366
        We process peer relations first when adding, and last when
 
367
        removing, else deferring to creation order.
 
368
        """
 
369
        rel_ids = list(rel_ids)
 
370
 
 
371
        def _sort(x, y):
 
372
            xr, yr = rels[x].relation_role, rels[y].relation_role
 
373
            if xr == yr:
 
374
                return cmp(x, y)
 
375
            elif xr == "peer":
 
376
                return -1
 
377
            elif yr == "peer":
 
378
                return 1
 
379
            return cmp(x, y)
 
380
 
 
381
        rel_ids.sort(_sort)
 
382
 
 
383
        if invert:
 
384
            return list(reversed(rel_ids))
 
385
        return rel_ids
 
386
 
363
387
    @inlineCallbacks
364
388
    def _process_service_changes(self, old_relations, new_relations):
365
389
        """Add and remove unit lifecycles per the service relations Determine.
374
398
                (service_relation.internal_relation_id, service_relation)
375
399
                for service_relation in old_relations)
376
400
 
377
 
        added = set(new_relations.keys()) - set(self._relations.keys())
378
 
        removed = set(self._relations.keys()) - set(new_relations.keys())
 
401
        added = self._sort_relations(
 
402
            set(new_relations.keys()) - set(self._relations.keys()),
 
403
            new_relations)
 
404
 
 
405
        removed = self._sort_relations(
 
406
            set(self._relations.keys()) - set(new_relations.keys()),
 
407
            self._relations,
 
408
            invert=True)
 
409
 
379
410
        # Could this service be a principal container?
380
411
        is_principal = not (yield self._service.is_subordinate())
381
412
 
404
435
                yield workflow.transition_state("departed")
405
436
            self._store_relations()
406
437
 
407
 
        # Process new relations.
 
438
        # Process new relations
408
439
        for relation_id in added:
409
440
            service_relation = new_relations[relation_id]
410
441
            yield self._add_relation(service_relation)
411
 
            if (is_principal and service_relation.relation_scope == "container"):
412
 
                self._add_subordinate_unit(service_relation)
 
442
            if (is_principal
 
443
                    and service_relation.relation_scope == "container"):
 
444
                yield self._add_subordinate_unit(service_relation)
413
445
            yield self._store_relations()
414
446
 
415
447
    @inlineCallbacks