Skip to content

Commit 1025c0b

Browse files
authored
[Key Vault] Add perf tests for certificates, keys, and secrets (#17073)
1 parent c90a60d commit 1025c0b

File tree

9 files changed

+294
-0
lines changed

9 files changed

+294
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# azure-keyvault-certificates Performance Tests
2+
3+
In order to run the performance tests, the `azure-devtools` package must be installed. This is done as part of the
4+
`dev_requirements` install. Start by creating a new virtual environment for your perf tests. This will need to be a
5+
Python 3 environment, preferably >=3.7.
6+
7+
### Setup for test resources
8+
9+
The following environment variables will need to be set for the tests to access the live resources:
10+
11+
```
12+
AZURE_TENANT_ID=<tenant ID of testing service principal>
13+
AZURE_CLIENT_ID=<client ID of testing service principal>
14+
AZURE_CLIENT_SECRET=<client secret of testing service principal>
15+
AZURE_KEYVAULT_URL=<URL of the testing key vault>
16+
```
17+
18+
### Setup for perf test runs
19+
20+
```cmd
21+
(env) ~/azure-keyvault-certificates> pip install -r dev_requirements.txt
22+
(env) ~/azure-keyvault-certificates> pip install -e .
23+
```
24+
25+
## Test commands
26+
27+
Once `azure-devtools` is installed, you will have access to the `perfstress` command line tool, which will scan the
28+
current module for runnable perf tests. Only a specific test can be run at a time (i.e. there is no "run all" feature).
29+
30+
```cmd
31+
(env) ~/azure-keyvault-certificates> cd tests/perfstress_tests/
32+
(env) ~/azure-keyvault-certificates/tests> perfstress
33+
```
34+
Using the `perfstress` command alone will list the available perf tests found.
35+
36+
### Common perf command line options
37+
These options are available for all perf tests:
38+
- `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10.
39+
- `--iterations=1` Number of test iterations to run. Default is 1.
40+
- `--parallel=1` Number of tests to run in parallel. Default is 1.
41+
- `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5.
42+
- `--sync` Whether to run the tests in sync or async. Default is False (async).
43+
- `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted).
44+
45+
## Example command
46+
```cmd
47+
(env) ~/azure-keyvault-certificates/tests> perfstress GetCertificateTest
48+
```

sdk/keyvault/azure-keyvault-certificates/tests/perfstress_tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
6+
from azure_devtools.perfstress_tests import PerfStressTest
7+
from azure.identity import EnvironmentCredential
8+
from azure.identity.aio import EnvironmentCredential as AsyncEnvironmentCredential
9+
from azure.keyvault.certificates import CertificateClient, CertificatePolicy
10+
from azure.keyvault.certificates.aio import CertificateClient as AsyncCertificateClient
11+
12+
13+
class GetCertificateTest(PerfStressTest):
14+
15+
def __init__(self, arguments):
16+
super().__init__(arguments)
17+
18+
# Auth configuration
19+
self.credential = EnvironmentCredential()
20+
self.async_credential = AsyncEnvironmentCredential()
21+
22+
# Create clients
23+
vault_url = self.get_from_env("AZURE_KEYVAULT_URL")
24+
self.client = CertificateClient(vault_url, self.credential)
25+
self.async_client = AsyncCertificateClient(vault_url, self.async_credential)
26+
27+
async def global_setup(self):
28+
"""The global setup is run only once."""
29+
await super().global_setup()
30+
await self.async_client.create_certificate("livekvtestperfcert", CertificatePolicy.get_default())
31+
32+
async def global_cleanup(self):
33+
"""The global cleanup is run only once."""
34+
await self.async_client.delete_certificate("livekvtestperfcert")
35+
await self.async_client.purge_deleted_certificate("livekvtestperfcert")
36+
await super().global_cleanup()
37+
38+
async def close(self):
39+
"""This is run after cleanup."""
40+
await self.async_client.close()
41+
await self.async_credential.close()
42+
await super().close()
43+
44+
def run_sync(self):
45+
"""The synchronous perf test."""
46+
self.client.get_certificate("livekvtestperfcert")
47+
48+
async def run_async(self):
49+
"""The asynchronous perf test."""
50+
await self.async_client.get_certificate("livekvtestperfcert")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# azure-keyvault-keys Performance Tests
2+
3+
In order to run the performance tests, the `azure-devtools` package must be installed. This is done as part of the
4+
`dev_requirements` install. Start by creating a new virtual environment for your perf tests. This will need to be a
5+
Python 3 environment, preferably >=3.7.
6+
7+
### Setup for test resources
8+
9+
The following environment variables will need to be set for the tests to access the live resources:
10+
11+
```
12+
AZURE_TENANT_ID=<tenant ID of testing service principal>
13+
AZURE_CLIENT_ID=<client ID of testing service principal>
14+
AZURE_CLIENT_SECRET=<client secret of testing service principal>
15+
AZURE_KEYVAULT_URL=<URL of the testing key vault>
16+
```
17+
18+
### Setup for perf test runs
19+
20+
```cmd
21+
(env) ~/azure-keyvault-keys> pip install -r dev_requirements.txt
22+
(env) ~/azure-keyvault-keys> pip install -e .
23+
```
24+
25+
## Test commands
26+
27+
Once `azure-devtools` is installed, you will have access to the `perfstress` command line tool, which will scan the
28+
current module for runnable perf tests. Only a specific test can be run at a time (i.e. there is no "run all" feature).
29+
30+
```cmd
31+
(env) ~/azure-keyvault-keys> cd tests/perfstress_tests/
32+
(env) ~/azure-keyvault-keys/tests> perfstress
33+
```
34+
Using the `perfstress` command alone will list the available perf tests found.
35+
36+
### Common perf command line options
37+
These options are available for all perf tests:
38+
- `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10.
39+
- `--iterations=1` Number of test iterations to run. Default is 1.
40+
- `--parallel=1` Number of tests to run in parallel. Default is 1.
41+
- `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5.
42+
- `--sync` Whether to run the tests in sync or async. Default is False (async).
43+
- `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted).
44+
45+
## Example command
46+
```cmd
47+
(env) ~/azure-keyvault-keys/tests> perfstress GetKeyTest
48+
```

sdk/keyvault/azure-keyvault-keys/tests/perfstress_tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
6+
from azure_devtools.perfstress_tests import PerfStressTest
7+
from azure.identity import EnvironmentCredential
8+
from azure.identity.aio import EnvironmentCredential as AsyncEnvironmentCredential
9+
from azure.keyvault.keys import KeyClient
10+
from azure.keyvault.keys.aio import KeyClient as AsyncKeyClient
11+
12+
13+
class GetKeyTest(PerfStressTest):
14+
15+
def __init__(self, arguments):
16+
super().__init__(arguments)
17+
18+
# Auth configuration
19+
self.credential = EnvironmentCredential()
20+
self.async_credential = AsyncEnvironmentCredential()
21+
22+
# Create clients
23+
vault_url = self.get_from_env("AZURE_KEYVAULT_URL")
24+
self.client = KeyClient(vault_url, self.credential)
25+
self.async_client = AsyncKeyClient(vault_url, self.async_credential)
26+
27+
async def global_setup(self):
28+
"""The global setup is run only once."""
29+
await super().global_setup()
30+
await self.async_client.create_rsa_key("livekvtestperfkey")
31+
32+
async def global_cleanup(self):
33+
"""The global cleanup is run only once."""
34+
await self.async_client.delete_key("livekvtestperfkey")
35+
await self.async_client.purge_deleted_key("livekvtestperfkey")
36+
await super().global_cleanup()
37+
38+
async def close(self):
39+
"""This is run after cleanup."""
40+
await self.async_client.close()
41+
await self.async_credential.close()
42+
await super().close()
43+
44+
def run_sync(self):
45+
"""The synchronous perf test."""
46+
self.client.get_key("livekvtestperfkey")
47+
48+
async def run_async(self):
49+
"""The asynchronous perf test."""
50+
await self.async_client.get_key("livekvtestperfkey")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# azure-keyvault-secrets Performance Tests
2+
3+
In order to run the performance tests, the `azure-devtools` package must be installed. This is done as part of the
4+
`dev_requirements` install. Start by creating a new virtual environment for your perf tests. This will need to be a
5+
Python 3 environment, preferably >=3.7.
6+
7+
### Setup for test resources
8+
9+
The following environment variables will need to be set for the tests to access the live resources:
10+
11+
```
12+
AZURE_TENANT_ID=<tenant ID of testing service principal>
13+
AZURE_CLIENT_ID=<client ID of testing service principal>
14+
AZURE_CLIENT_SECRET=<client secret of testing service principal>
15+
AZURE_KEYVAULT_URL=<URL of the testing key vault>
16+
```
17+
18+
### Setup for perf test runs
19+
20+
```cmd
21+
(env) ~/azure-keyvault-secrets> pip install -r dev_requirements.txt
22+
(env) ~/azure-keyvault-secrets> pip install -e .
23+
```
24+
25+
## Test commands
26+
27+
Once `azure-devtools` is installed, you will have access to the `perfstress` command line tool, which will scan the
28+
current module for runnable perf tests. Only a specific test can be run at a time (i.e. there is no "run all" feature).
29+
30+
```cmd
31+
(env) ~/azure-keyvault-secrets> cd tests/perfstress_tests/
32+
(env) ~/azure-keyvault-secrets/tests> perfstress
33+
```
34+
Using the `perfstress` command alone will list the available perf tests found.
35+
36+
### Common perf command line options
37+
These options are available for all perf tests:
38+
- `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10.
39+
- `--iterations=1` Number of test iterations to run. Default is 1.
40+
- `--parallel=1` Number of tests to run in parallel. Default is 1.
41+
- `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5.
42+
- `--sync` Whether to run the tests in sync or async. Default is False (async).
43+
- `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted).
44+
45+
## Example command
46+
```cmd
47+
(env) ~/azure-keyvault-secrets/tests> perfstress GetSecretTest
48+
```

sdk/keyvault/azure-keyvault-secrets/tests/perfstress_tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
6+
from azure_devtools.perfstress_tests import PerfStressTest
7+
from azure.identity import EnvironmentCredential
8+
from azure.identity.aio import EnvironmentCredential as AsyncEnvironmentCredential
9+
from azure.keyvault.secrets import SecretClient
10+
from azure.keyvault.secrets.aio import SecretClient as AsyncSecretClient
11+
12+
13+
class GetSecretTest(PerfStressTest):
14+
15+
def __init__(self, arguments):
16+
super().__init__(arguments)
17+
18+
# Auth configuration
19+
self.credential = EnvironmentCredential()
20+
self.async_credential = AsyncEnvironmentCredential()
21+
22+
# Create clients
23+
vault_url = self.get_from_env("AZURE_KEYVAULT_URL")
24+
self.client = SecretClient(vault_url, self.credential)
25+
self.async_client = AsyncSecretClient(vault_url, self.async_credential)
26+
27+
async def global_setup(self):
28+
"""The global setup is run only once."""
29+
await super().global_setup()
30+
await self.async_client.set_secret("livekvtestperfsecret", "secret-value")
31+
32+
async def global_cleanup(self):
33+
"""The global cleanup is run only once."""
34+
await self.async_client.delete_secret("livekvtestperfsecret")
35+
await self.async_client.purge_deleted_secret("livekvtestperfsecret")
36+
await super().global_cleanup()
37+
38+
async def close(self):
39+
"""This is run after cleanup."""
40+
await self.async_client.close()
41+
await self.async_credential.close()
42+
await super().close()
43+
44+
def run_sync(self):
45+
"""The synchronous perf test."""
46+
self.client.get_secret("livekvtestperfsecret")
47+
48+
async def run_async(self):
49+
"""The asynchronous perf test."""
50+
await self.async_client.get_secret("livekvtestperfsecret")

0 commit comments

Comments
 (0)