Skip to content

Instantly share code, notes, and snippets.

@mikekistler
Last active April 13, 2023 14:56
Show Gist options
  • Save mikekistler/dea3a09dce63c48623e299d04df38682 to your computer and use it in GitHub Desktop.
Save mikekistler/dea3a09dce63c48623e299d04df38682 to your computer and use it in GitHub Desktop.
Running Restler on the Azure Databricks service

Restler on Databricks (control plane)

This gist will describe how I ran Restler on the Azure Databricks control plane service and the results I obtained.

Clone and build Restler

git clone https://github.com/microsoft/restler-fuzzer.git
restler_bin=~/bin/restler
mkdir -p $restler_bin
# Need --python because it can’t find “python” — I use an alias that it did not understand.
python ./build-restler.py --dest_dir $restler_bin --python_path /opt/homebrew/bin/python3

Install test proxy

dotnet tool update azure.sdk.tools.testproxy --global --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json --version "1.0.0-dev*"

This will install to ~/.dotnet/tools. You need to add this to your path if not done previously.

Create the initial Restler config and dict files

We want to run RESTler on Azure Databricks, but like most control plane services the Azure Databricks REST API definition is not self-contained. We need to include operations for creating private connections so that the databricks operations for updating those connections can be exercised.

specs=$(find /Users/mikekistler/Projects/Azure/azure-rest-api-specs/specification/databricks/resource-manager/Microsoft.Databricks/preview/2022-04-01-preview -type f -depth 1)
dotnet $restler_bin/restler/Restler.dll generate_config --specs ${=specs}

Add values to restler_custom_payload of dict.json

vars='{
   "subscriptionId": ["my-subscription-id"],
   "resourceGroupName": ["my-resource-group"],
   "location": ["my-location"]
}'
jq ".restler_custom_payload = $vars" restlerConfig/dict.json > dict.json

Also set:

    "api-version": [
      "2022-04-01-preview"
    ]

Update engineSettings.json

Add the host and port for the test-proxy to the RESTler engine settings. This will send traffic to the recorder.

jq '.host = "localhost" | .target_port = 5000 | .no_ssl: true' restlerConfig/engine_settings.json > engine_settings.json

Update config.json

We need to update config.json CustomDictionaryFilePath to point to our modified dict.json and AnnotationFilePath to point to our annotations.json:

jq '.CustomDictionaryFilePath = "dict.json" | del(.AnnotationFilePath) | .DataFuzzing = false' restlerConfig/config.json > config.json

Compile with the base configuration

Compile using this base configuration. This is just to make sure there are no issues to this point.

dotnet $restler_bin/restler/Restler.dll compile config.json

Start the test proxy

In a separate terminal window/tab, start the test proxy with the location to save recordings.

test-proxy --storage-location c:\recordings

From your test session window, start a recording session with a request to the proxy. The response of this request will contain an "x-recording-id" header. Save the value in recording_id variable.

body='{ "x-recording-file": "databricks" }'
recording_id=$(curl -X POST -s -D - -d $body http://localhost:5000/Record/Start | grep 'x-recording-id' | awk '{print $2}' | sed 's/\r$//')

Update the Restler custom dictionary with test-proxy headers

header='{                                                 
  "x-recording-upstream-base-uri": ["https://management.azure.com"],
  "x-recording-id": ["'${recording_id}'"],
  "x-recording-mode": ["record"]
}'
jq ".restler_custom_payload_header = $header" dict.json > tmp.json && mv tmp.json dict.json 

And recompile to incorporate these changes.

dotnet $restler_bin/restler/Restler.dll compile config.json

Run the tests

Now you are ready to run the Test phase of Restler.

dotnet $restler_bin/restler/Restler.dll test --dictionary_file Compile/dict.json --grammar_file Compile/grammar.py --settings Compile/engine_settings.json --token_refresh_command "bash $PWD/getToken.sh" --token_refresh_interval 60

Stop the recording

Send the following request to the test proxy:

curl -X POST -D - -H  "x-recording-id: ${recording_id}" -H 'Content-Length: 0' http://localhost:5000/Record/Stop

Upload the Recording

Add assets.json for recording to azure-rest-api-specs

Update the recording

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment