# Path: teuthology/config.py
# def init_logging():
#     def __init__(self, yaml_path=None):
#     def load(self, conf=None):
#     def update(self, in_dict):
#     def from_dict(cls, in_dict):
#     def to_dict(self):
#     def from_str(cls, in_str):
#     def to_str(self):
#     def get(self, key, default=None):
#     def __str__(self):
#     def __repr__(self):
#     def __getitem__(self, name):
#     def __getattr__(self, name):
#     def __contains__(self, name):
#     def __setattr__(self, name, value):
#     def __delattr__(self, name):
#     def __len__(self):
#     def __iter__(self):
#     def __setitem__(self, name, value):
#     def __delitem__(self, name):
#     def __init__(self, yaml_path=None):
#     def get_ceph_cm_ansible_git_url(self):
#     def get_ceph_qa_suite_git_url(self):
#     def get_ceph_git_url(self):
#     def __init__(self, config_dict=None):
#     def _clean_config(self, config_dict):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __repr__(self):
#     def __str__(self):
# def set_config_attr(obj):
# def _get_config_path():
# class YamlConfig(collections.MutableMapping):
# class TeuthologyConfig(YamlConfig):
# class JobConfig(YamlConfig):
# class FakeNamespace(YamlConfig):
# 
# Path: teuthology/misc.py
# def decanonicalize_hostname(hostname):
#     lab_domain = ''
#     if config.lab_domain:
#         lab_domain='\.' + config.lab_domain.replace('.', '\.')
#     hostname_expr = hostname_expr_templ.format(lab_domain=lab_domain)
#     match = re.match(hostname_expr, hostname)
#     if match:
#         hostname = match.groupdict()['shortname']
#     return hostname
# 
# Path: teuthology/misc.py
# def deep_merge(a, b):
#     """
#     Deep Merge.  If a and b are both lists, all elements in b are
#     added into a.  If a and b are both dictionaries, elements in b are
#     recursively added to a.
#     :param a: object items will be merged into
#     :param b: object items will be merged from
#     """
#     if a is None:
#         return b
#     if b is None:
#         return a
#     if isinstance(a, list):
#         assert isinstance(b, list)
#         a.extend(b)
#         return a
#     if isinstance(a, dict):
#         assert isinstance(b, dict)
#         for (k, v) in b.items():
#             if k in a:
#                 a[k] = deep_merge(a[k], v)
#             else:
#                 a[k] = v
#         return a
#     return b
# 
# Path: teuthology/lock/query.py
# def get_status(name):
# def get_statuses(machines):
# def is_vm(name=None, status=None):
# def list_locks(keyed_by_name=False, **kwargs):
# def find_stale_locks(owner=None):
#     def might_be_stale(node_dict):
#     def node_job_is_active(node, cache):


import json
import logging
import os
import subprocess
import tempfile
import yaml
    import pwd
from teuthology.config import config
from teuthology.contextutil import safe_while
from teuthology.misc import decanonicalize_hostname
from teuthology.misc import deep_merge
from teuthology.lock import query
def downburst_executable():
    """
    First check for downburst in the user's path.
    Then check in ~/src, ~ubuntu/src, and ~teuthology/src.
    Return '' if no executable downburst is found.
    """
    if config.downburst:
        if isinstance(config.downburst, dict):
            if 'path' in config.downburst:
                return config.downburst['path']
        else:
            return config.downburst
    path = os.environ.get('PATH', None)
    if path:
        for p in os.environ.get('PATH', '').split(os.pathsep):
            pth = os.path.join(p, 'downburst')
            if os.access(pth, os.X_OK):
                return pth
    little_old_me = pwd.getpwuid(os.getuid()).pw_name
    for user in [little_old_me, 'ubuntu', 'teuthology']:
        pth = os.path.expanduser(
            "~%s/src/downburst/virtualenv/bin/downburst" % user)
        if os.access(pth, os.X_OK):
            return pth
    return ''


def downburst_environment():
    env = dict()
    discover_url = os.environ.get('DOWNBURST_DISCOVER_URL')

# Path: teuthology/config.py
# def init_logging():
#     def __init__(self, yaml_path=None):
#     def load(self, conf=None):
#     def update(self, in_dict):
#     def from_dict(cls, in_dict):
#     def to_dict(self):
#     def from_str(cls, in_str):
#     def to_str(self):
#     def get(self, key, default=None):
#     def __str__(self):
#     def __repr__(self):
#     def __getitem__(self, name):
#     def __getattr__(self, name):
#     def __contains__(self, name):
#     def __setattr__(self, name, value):
#     def __delattr__(self, name):
#     def __len__(self):
#     def __iter__(self):
#     def __setitem__(self, name, value):
#     def __delitem__(self, name):
#     def __init__(self, yaml_path=None):
#     def get_ceph_cm_ansible_git_url(self):
#     def get_ceph_qa_suite_git_url(self):
#     def get_ceph_git_url(self):
#     def __init__(self, config_dict=None):
#     def _clean_config(self, config_dict):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __repr__(self):
#     def __str__(self):
# def set_config_attr(obj):
# def _get_config_path():
# class YamlConfig(collections.MutableMapping):
# class TeuthologyConfig(YamlConfig):
# class JobConfig(YamlConfig):
# class FakeNamespace(YamlConfig):
# 
# Path: teuthology/misc.py
# def decanonicalize_hostname(hostname):
#     lab_domain = ''
#     if config.lab_domain:
#         lab_domain='\.' + config.lab_domain.replace('.', '\.')
#     hostname_expr = hostname_expr_templ.format(lab_domain=lab_domain)
#     match = re.match(hostname_expr, hostname)
#     if match:
#         hostname = match.groupdict()['shortname']
#     return hostname
# 
# Path: teuthology/misc.py
# def deep_merge(a, b):
#     """
#     Deep Merge.  If a and b are both lists, all elements in b are
#     added into a.  If a and b are both dictionaries, elements in b are
#     recursively added to a.
#     :param a: object items will be merged into
#     :param b: object items will be merged from
#     """
#     if a is None:
#         return b
#     if b is None:
#         return a
#     if isinstance(a, list):
#         assert isinstance(b, list)
#         a.extend(b)
#         return a
#     if isinstance(a, dict):
#         assert isinstance(b, dict)
#         for (k, v) in b.items():
#             if k in a:
#                 a[k] = deep_merge(a[k], v)
#             else:
#                 a[k] = v
#         return a
#     return b
# 
# Path: teuthology/lock/query.py
# def get_status(name):
# def get_statuses(machines):
# def is_vm(name=None, status=None):
# def list_locks(keyed_by_name=False, **kwargs):
# def find_stale_locks(owner=None):
#     def might_be_stale(node_dict):
#     def node_job_is_active(node, cache):


# Path: teuthology/provision/downburst.py
import json
import logging
import os
import subprocess
import tempfile
import yaml
    import pwd
from teuthology.config import config
from teuthology.contextutil import safe_while
from teuthology.misc import decanonicalize_hostname
from teuthology.misc import deep_merge
from teuthology.lock import query

def downburst_executable():
    """
    First check for downburst in the user's path.
    Then check in ~/src, ~ubuntu/src, and ~teuthology/src.
    Return '' if no executable downburst is found.
    """
    if config.downburst:
        if isinstance(config.downburst, dict):
            if 'path' in config.downburst:
                return config.downburst['path']
        else:
            return config.downburst
    path = os.environ.get('PATH', None)
    if path:
        for p in os.environ.get('PATH', '').split(os.pathsep):
            pth = os.path.join(p, 'downburst')
            if os.access(pth, os.X_OK):
                return pth
    little_old_me = pwd.getpwuid(os.getuid()).pw_name
    for user in [little_old_me, 'ubuntu', 'teuthology']:
        pth = os.path.expanduser(
            "~%s/src/downburst/virtualenv/bin/downburst" % user)
        if os.access(pth, os.X_OK):
            return pth
    return ''


def downburst_environment():
    env = dict()
    discover_url = os.environ.get('DOWNBURST_DISCOVER_URL')

    if config.downburst and not discover_url: