def test_burn_io_on_lnx(init, fetch, open): # arrange mocks client = MagicMock() init.return_value = client resource = __get_resource(os_type='Linux') resource_list = [resource] fetch.return_value = resource_list # run command mocks poller = MagicMock() client.virtual_machines.run_command.return_value = poller result = MagicMock(spec=RunCommandResult) poller.result.return_value = result result.value = [InstanceViewStatus()] # 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'", "Microsoft.Compute/virtualMachines", SECRETS, CONFIG) open.assert_called_with(AnyStringWith("burn_io.sh")) client.virtual_machines.run_command.assert_called_with( resource['resourceGroup'], resource['name'], { 'command_id': 'RunShellScript', 'script': ['script'], 'parameters': [{ 'name': 'duration', 'value': 60 }] })
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_invalid_resource(init, fetch, open): # arrange mocks client = MagicMock() init.return_value = client resource = __get_resource(os_type='Invalid') resource_list = [resource] fetch.return_value = resource_list # act with pytest.raises(Exception) as ex: burn_io("where name=='some_machine'", 60) assert str(ex.value) == 'Unknown OS Type: invalid'
def test_burn_io_timeout(init, fetch, open): # arrange mocks client = MagicMock() init.return_value = client resource = __get_resource(os_type='Linux') resource_list = [resource] fetch.return_value = resource_list # run command mocks poller = MagicMock() client.virtual_machines.run_command.return_value = poller poller.result.return_value = None # act & assert with pytest.raises(FailedActivity, match=r'burn_io operation did not ' r'finish on time'): burn_io("where name=='some_linux_machine'", 60)