~bloodearnest/juju-deployer/annotate-branches

« back to all changes in this revision

Viewing changes to deployer/utils.py

  • Committer: Simon Davy
  • Date: 2015-03-30 15:16:10 UTC
  • mfrom: (126.1.18 juju-deployer)
  • Revision ID: bloodearnest@gmail.com-20150330151610-ft7lwajcbnnroa39
merge upstream and fix review comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
242
242
def _check_call(params, log, *args, **kw):
243
243
    max_retry = kw.get('max_retry', None)
244
244
    cur = kw.get('cur_try', 1)
 
245
    shell = kw.get('shell', False)
245
246
    try:
246
247
        cwd = abspath(".")
247
248
        if 'cwd' in kw:
250
251
        if 'stderr' in kw:
251
252
            stderr = kw['stderr']
252
253
        output = subprocess.check_output(
253
 
            params, cwd=cwd, stderr=stderr, env=os.environ)
 
254
            params, cwd=cwd, stderr=stderr, env=os.environ, shell=shell)
254
255
    except subprocess.CalledProcessError, e:
255
256
        if 'ignoreerr' in kw:
256
257
            return
372
373
        if not 'default' in conf:
373
374
            raise ValueError("No Environment specified")
374
375
        return conf['default']
 
376
 
 
377
def x_in_y(x, y):
 
378
    """Check to see if the second argument is named in the first
 
379
    argument's unit placement spec.
 
380
    
 
381
    Both arguments provided are services with unit placement directives.
 
382
    If the first service appears in the second service's unit placement,
 
383
    either colocated on a default unit, colocated with a specific unit,
 
384
    or containerized alongside that service, then True is returned, False
 
385
    otherwise.
 
386
    """
 
387
    for placement in y.unit_placement:
 
388
        if ':' in placement:
 
389
            _, placement = placement.split(':')
 
390
        if '/' in placement:
 
391
            placement, _ = placement.split('/')
 
392
        if x.name == placement:
 
393
            return True
 
394
    return False