# Buggy code
def get_configured_provider(vm_=None):
    """
    Return the contextual provider of None if no configured
    one can be found.
    """
    if vm_ is None:
        vm_ = {}
    dalias, driver = __active_provider_name__.split(":")
    data = None
    tgt = "unknown"
    img_provider = __opts__.get("list_images", "")
    arg_providers = __opts__.get("names", [])
    matched = False
    # --list-images level
    if img_provider:
        tgt = "provider: {0}".format(img_provider)
        if dalias == img_provider:
            data = get_provider(img_provider)
            matched = True
    # providers are set in configuration
    if not data and "profile" not in __opts__ and arg_providers:
        for name in arg_providers:
            tgt = "provider: {0}".format(name)
            if dalias == name:
                data = get_provider(name)
            if data:
                matched = True
                break
    # -p is providen, get the uplinked provider
    elif "profile" in __opts__:
        curprof = __opts__["profile"]
        profs = __opts__["profiles"]
        tgt = "profile: {0}".format(curprof)
        if curprof in profs and profs[curprof]["provider"] == __active_provider_name__:
            prov, cdriver = profs[curprof]["provider"].split(":")
            tgt += " provider: {0}".format(prov)
            data = get_provider(prov)
            matched = True
    # fallback if we have only __active_provider_name__
    if (__opts__.get("destroy", False) and not data) or (
        not matched and __active_provider_name__
    ):
        data = __opts__.get("providers", {}).get(dalias, {}).get(driver, {})
    # in all cases, verify that the linked saltmaster is alive.
    if data:
        try:
            ret = _salt("test.ping", salt_target=data["target"])
            if not ret:
                raise Exception("error")
            return data
        except Exception:
            raise SaltCloudSystemExit(
                "Configured provider {0} minion: {1} is unreachable".format(
                    __active_provider_name__, data["target"]
                )
            )
    return False


# Traceback (salt.exceptions.SaltCloudSystemExit)
# salt-cloud -m map_lxc_test
[INFO    ] salt-cloud starting
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
[INFO    ] Runner completed: 20150513153526561971
[INFO    ] Runner completed: 20150513153527922468
[INFO    ] Runner completed: 20150513153528777523
[INFO    ] Runner completed: 20150513153529730576
[INFO    ] Runner completed: 20150513153530693758
[INFO    ] Runner completed: 20150513153531631134
[INFO    ] Runner completed: 20150513153532586328
[INFO    ] Runner completed: 20150513153533544745
[INFO    ] Runner completed: 20150513153534447523
[INFO    ] Runner completed: 20150513153535369341
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
SaltCloudSystemExit: Configured provider ursa-lxc:lxc minion: ursa is unreachable
Traceback (most recent call last):
File "/usr/bin/salt-cloud", line 10, in <module>
salt_cloud()
File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 316, in salt_cloud
client.run()
File "/usr/lib/python2.7/dist-packages/salt/cloud/cli.py", line 86, in run
mapper = salt.cloud.Map(self.config)
File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1557, in __init__
Cloud.__init__(self, opts)
File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 478, in __init__
self.__filter_non_working_providers()
File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1536, in __filter_non_working_providers
if self.clouds[fun]() is False:
File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/lxc.py", line 501, in get_configured_provider
__active_provider_name__, data['target']))
SaltCloudSystemExit: Configured provider ursa-lxc:lxc minion: ursa is unreachable
Traceback (most recent call last):
File "/usr/bin/salt-cloud", line 10, in <module>
salt_cloud()
File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 316, in salt_cloud
client.run()
File "/usr/lib/python2.7/dist-packages/salt/cloud/cli.py", line 86, in run
mapper = salt.cloud.Map(self.config)
File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1557, in __init__
Cloud.__init__(self, opts)
File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 478, in __init__
self.__filter_non_working_providers()
File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1536, in __filter_non_working_providers
if self.clouds[fun]() is False:
File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/lxc.py", line 501, in get_configured_provider
__active_provider_name__, data['target']))
salt.exceptions.SaltCloudSystemExit: Configured provider ursa-lxc:lxc minion: ursa is unreachable
# salt-run --versions-report
Salt: 2015.5.0
Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
Jinja2: 2.7.2
M2Crypto: 0.21.1
msgpack-python: 0.3.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.10
ioflo: Not Installed
PyZMQ: 14.0.1
RAET: Not Installed
ZMQ: 4.0.4
Mako: 0.9.1
Debian source package: 2015.5.0+ds-1trusty1

# Fixed code
def get_configured_provider(vm_=None):
    """
    Return the contextual provider of None if no configured
    one can be found.
    """
    if vm_ is None:
        vm_ = {}
    dalias, driver = __active_provider_name__.split(":")
    data = None
    tgt = "unknown"
    img_provider = __opts__.get("list_images", "")
    arg_providers = __opts__.get("names", [])
    matched = False
    # --list-images level
    if img_provider:
        tgt = "provider: {0}".format(img_provider)
        if dalias == img_provider:
            data = get_provider(img_provider)
            matched = True
    # providers are set in configuration
    if not data and "profile" not in __opts__ and arg_providers:
        for name in arg_providers:
            tgt = "provider: {0}".format(name)
            if dalias == name:
                data = get_provider(name)
            if data:
                matched = True
                break
    # -p is providen, get the uplinked provider
    elif "profile" in __opts__:
        curprof = __opts__["profile"]
        profs = __opts__["profiles"]
        tgt = "profile: {0}".format(curprof)
        if curprof in profs and profs[curprof]["provider"] == __active_provider_name__:
            prov, cdriver = profs[curprof]["provider"].split(":")
            tgt += " provider: {0}".format(prov)
            data = get_provider(prov)
            matched = True
    # fallback if we have only __active_provider_name__
    if (__opts__.get("destroy", False) and not data) or (
        not matched and __active_provider_name__
    ):
        data = __opts__.get("providers", {}).get(dalias, {}).get(driver, {})
    # in all cases, verify that the linked saltmaster is alive.
    if data:
        ret = _salt("test.ping", salt_target=data["target"])
        if not ret:
            raise SaltCloudSystemExit(
                "Configured provider {0} minion: {1} is unreachable".format(
                    __active_provider_name__, data["target"]
                )
            )
        return data
    return False