def test_burn_io(mocked_command_run, mocked_command_prepare, fetch):
    # arrange mocks
    mocked_command_prepare.return_value = 'RunShellScript', 'burn_io.sh'

    machine = machine_provider.provide_machine()
    machines = [machine]
    fetch.return_value = machines

    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_via_service_principal()

    # act
    burn_io(filter="where name=='some_linux_machine'",
            duration=60,
            configuration=config,
            secrets=secrets)

    # assert
    fetch.assert_called_with("where name=='some_linux_machine'", RES_TYPE_VM,
                             secrets, config)
    mocked_command_prepare.assert_called_with(machine, 'burn_io')
    mocked_command_run.assert_called_with(
        machine['resourceGroup'], machine, 120, {
            'command_id': 'RunShellScript',
            'script': ['burn_io.sh'],
            'parameters': [{
                'name': 'duration',
                'value': 60
            }]
        }, secrets, config)
def test_burn_io(mocked_command_run, mocked_command_prepare, fetch_instances,
                 fetch_vmss):
    # arrange mocks
    mocked_command_prepare.return_value = 'RunShellScript', 'burn_io.sh'

    scale_set = vmss_provider.provide_scale_set()
    scale_sets = [scale_set]
    instance = vmss_provider.provide_instance()
    instances = [instance]
    fetch_vmss.return_value = scale_sets
    fetch_instances.return_value = instances

    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_via_service_principal()

    # act
    burn_io(filter="where name=='some_random_instance'",
            duration=60,
            configuration=config,
            secrets=secrets)

    # assert
    fetch_vmss.assert_called_with("where name=='some_random_instance'", config,
                                  secrets)
    fetch_instances.assert_called_with(scale_set, None, config, secrets)
    mocked_command_run.assert_called_with(
        scale_set['resourceGroup'], instance, 120, {
            'command_id': 'RunShellScript',
            'script': ['burn_io.sh'],
            'parameters': [{
                'name': 'duration',
                'value': 60
            }]
        }, secrets, config)
def test_fill_disk(mocked_command_run, mocked_command_prepare,
                   mocked_command_prepare_path, fetch_instances, fetch_vmss):
    # arrange mocks
    mocked_command_prepare.return_value = 'RunShellScript', 'fill_disk.sh'
    mocked_command_prepare_path.return_value = '/root/burn/hard'

    scale_set = vmss_provider.provide_scale_set()
    scale_sets = [scale_set]
    instance = vmss_provider.provide_instance()
    instances = [instance]
    fetch_vmss.return_value = scale_sets
    fetch_instances.return_value = instances

    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_via_service_principal()

    # act
    fill_disk(filter="where name=='some_random_instance'",
              duration=60,
              timeout=60,
              size=1000,
              path='/root/burn/hard',
              configuration=config,
              secrets=secrets)

    # assert
    fetch_vmss.assert_called_with("where name=='some_random_instance'", config,
                                  secrets)
    fetch_instances.assert_called_with(scale_set, None, config, secrets)
    mocked_command_run.assert_called_with(
        scale_set['resourceGroup'], instance, 120, {
            'command_id':
            'RunShellScript',
            'script': ['fill_disk.sh'],
            'parameters': [{
                'name': "duration",
                'value': 60
            }, {
                'name': "size",
                'value': 1000
            }, {
                'name': "path",
                'value': '/root/burn/hard'
            }]
        }, secrets, config)
def test_network_latency(mocked_command_run, mocked_command_prepare,
                         fetch_instances, fetch_vmss):
    # arrange mocks
    mocked_command_prepare.return_value = 'RunShellScript', 'network_latency.sh'

    scale_set = vmss_provider.provide_scale_set()
    scale_sets = [scale_set]
    instance = vmss_provider.provide_instance()
    instances = [instance]
    fetch_vmss.return_value = scale_sets
    fetch_instances.return_value = instances

    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_via_service_principal()

    # act
    network_latency(filter="where name=='some_random_instance'",
                    duration=60,
                    timeout=60,
                    delay=200,
                    jitter=50,
                    configuration=config,
                    secrets=secrets)

    # assert
    fetch_vmss.assert_called_with("where name=='some_random_instance'", config,
                                  secrets)
    fetch_instances.assert_called_with(scale_set, None, config, secrets)
    mocked_command_prepare.assert_called_with(instance, 'network_latency')
    mocked_command_run.assert_called_with(
        scale_set['resourceGroup'], instance, 120, {
            'command_id':
            'RunShellScript',
            'script': ['network_latency.sh'],
            'parameters': [{
                'name': "duration",
                'value': 60
            }, {
                'name': "delay",
                'value': 200
            }, {
                'name': "jitter",
                'value': 50
            }]
        }, secrets, config)
def test_fill_disk(mocked_command_run, mocked_command_prepare_path,
                   mocked_command_prepare, fetch):
    # arrange mocks
    mocked_command_prepare.return_value = 'RunShellScript', 'fill_disk.sh'
    mocked_command_prepare_path.return_value = '/root/burn/hard'

    machine = machine_provider.provide_machine()
    machines = [machine]
    fetch.return_value = machines

    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_via_service_principal()

    # act
    fill_disk(filter="where name=='some_linux_machine'",
              duration=60,
              timeout=60,
              size=1000,
              path='/root/burn/hard',
              configuration=config,
              secrets=secrets)

    # assert
    fetch.assert_called_with("where name=='some_linux_machine'", RES_TYPE_VM,
                             secrets, config)
    mocked_command_prepare.assert_called_with(machine, 'fill_disk')
    mocked_command_run.assert_called_with(
        machine['resourceGroup'], machine, 120, {
            'command_id':
            'RunShellScript',
            'script': ['fill_disk.sh'],
            'parameters': [{
                'name': "duration",
                'value': 60
            }, {
                'name': "size",
                'value': 1000
            }, {
                'name': "path",
                'value': '/root/burn/hard'
            }]
        }, secrets, config)
def test_network_latency(mocked_command_run, mocked_command_prepare, fetch):
    # arrange mocks
    mocked_command_prepare.return_value = 'RunShellScript', 'network_latency.sh'

    machine = machine_provider.provide_machine()
    machines = [machine]
    fetch.return_value = machines

    config = config_provider.provide_default_config()
    secrets = secrets_provider.provide_secrets_via_service_principal()

    # act
    network_latency(filter="where name=='some_linux_machine'",
                    duration=60,
                    delay=200,
                    jitter=50,
                    timeout=60,
                    configuration=config,
                    secrets=secrets)

    # assert
    fetch.assert_called_with("where name=='some_linux_machine'", RES_TYPE_VM,
                             secrets, config)
    mocked_command_prepare.assert_called_with(machine, 'network_latency')
    mocked_command_run.assert_called_with(
        machine['resourceGroup'], machine, 120, {
            'command_id':
            'RunShellScript',
            'script': ['network_latency.sh'],
            'parameters': [{
                'name': "duration",
                'value': 60
            }, {
                'name': "delay",
                'value': 200
            }, {
                'name': "jitter",
                'value': 50
            }]
        }, secrets, config)