# Buggy code
def create_av_set(
    cmd,
    availability_set_name,
    resource_group_name,
    platform_fault_domain_count=2,
    platform_update_domain_count=None,
    location=None,
    no_wait=False,
    unmanaged=False,
    tags=None,
    validate=False,
):
    from azure.cli.core.util import random_string
    from azure.cli.command_modules.vm._template_builder import (
        ArmTemplateBuilder,
        build_av_set_resource,
    )

    tags = tags or {}

    # Build up the ARM template
    master_template = ArmTemplateBuilder()

    av_set_resource = build_av_set_resource(
        cmd,
        availability_set_name,
        location,
        tags,
        platform_update_domain_count,
        platform_fault_domain_count,
        unmanaged,
    )
    master_template.add_resource(av_set_resource)

    template = master_template.build()

    # deploy ARM template
    deployment_name = "av_set_deploy_" + random_string(32)
    client = get_mgmt_service_client(
        cmd.cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES
    ).deployments
    DeploymentProperties = cmd.get_models(
        "DeploymentProperties", resource_type=ResourceType.MGMT_RESOURCE_RESOURCES
    )

    properties = DeploymentProperties(
        template=template, parameters={}, mode="incremental"
    )
    if validate:
        return client.validate(resource_group_name, deployment_name, properties)

    if no_wait:
        return client.create_or_update(
            resource_group_name, deployment_name, properties, raw=no_wait
        )

    LongRunningOperation(cmd.cli_ctx)(
        client.create_or_update(
            resource_group_name, deployment_name, properties, raw=no_wait
        )
    )
    compute_client = _compute_client_factory(cmd.cli_ctx)
    return compute_client.availability_sets.get(
        resource_group_name, availability_set_name
    )


# Traceback (FileNotFoundError)
(env) C:\Users\trpresco\Documents\github\azure-cli>run_tests --module network --parallel
The run_tests command is going to be replaced by 'azdev test' command.

Traceback (most recent call last):
File "C:\Users\trpresco\Documents\github\azure-cli\env\Scripts\run_tests-script.py", line 11, in <module>
load_entry_point('azure-cli-dev-tools', 'console_scripts', 'run_tests')()
File "c:\users\trpresco\documents\github\azure-cli\tools\automation\tests\__init__.py", line 79, in legacy_entry_point
args.func(args)
File "c:\users\trpresco\documents\github\azure-cli\tools\automation\tests\__init__.py", line 20, in execute
current_profile = check_output(shlex.split('az cloud show --query profile -otsv')).decode('utf-8').strip()
File "C:\Users\trpresco\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\trpresco\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\trpresco\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\trpresco\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

# Fixed code
def create_av_set(
    cmd,
    availability_set_name,
    resource_group_name,
    platform_fault_domain_count=2,
    platform_update_domain_count=None,
    location=None,
    no_wait=False,
    unmanaged=False,
    tags=None,
    validate=False,
):
    from azure.cli.core.util import random_string
    from azure.cli.core.commands.arm import ArmTemplateBuilder
    from azure.cli.command_modules.vm._template_builder import build_av_set_resource

    tags = tags or {}

    # Build up the ARM template
    master_template = ArmTemplateBuilder()

    av_set_resource = build_av_set_resource(
        cmd,
        availability_set_name,
        location,
        tags,
        platform_update_domain_count,
        platform_fault_domain_count,
        unmanaged,
    )
    master_template.add_resource(av_set_resource)

    template = master_template.build()

    # deploy ARM template
    deployment_name = "av_set_deploy_" + random_string(32)
    client = get_mgmt_service_client(
        cmd.cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES
    ).deployments
    DeploymentProperties = cmd.get_models(
        "DeploymentProperties", resource_type=ResourceType.MGMT_RESOURCE_RESOURCES
    )

    properties = DeploymentProperties(
        template=template, parameters={}, mode="incremental"
    )
    if validate:
        return client.validate(resource_group_name, deployment_name, properties)

    if no_wait:
        return client.create_or_update(
            resource_group_name, deployment_name, properties, raw=no_wait
        )

    LongRunningOperation(cmd.cli_ctx)(
        client.create_or_update(
            resource_group_name, deployment_name, properties, raw=no_wait
        )
    )
    compute_client = _compute_client_factory(cmd.cli_ctx)
    return compute_client.availability_sets.get(
        resource_group_name, availability_set_name
    )