зеркало из
1
0
Форкнуть 0
azure-sdk-for-python/common/smoketest
Scott Beddall 42b1f3bc3a
bump to remove dependabot alert (#24991)
2022-06-27 12:47:01 -07:00
..
README.md Update links from master to main 2021-06-24 17:30:04 -07:00
cosmos_db.py move smoke tests 2019-11-07 10:31:45 -08:00
dependencies.py Smoke Tests use new workflow for package install (#11438) 2020-05-14 19:55:25 -07:00
event_hubs.py add support for dynamic resource allocation and sovereign cloud testing (#10469) 2020-04-02 14:20:46 -07:00
event_hubs_async.py add support for dynamic resource allocation and sovereign cloud testing (#10469) 2020-04-02 14:20:46 -07:00
key_vault_base.py Add Key Vault API versions to smoke tests (#13130) 2020-08-18 09:56:45 -07:00
key_vault_base_async.py Add Key Vault API versions to smoke tests (#13130) 2020-08-18 09:56:45 -07:00
key_vault_certificates.py Add Key Vault API versions to smoke tests (#13130) 2020-08-18 09:56:45 -07:00
key_vault_certificates_async.py Add Key Vault API versions to smoke tests (#13130) 2020-08-18 09:56:45 -07:00
key_vault_keys.py Add Key Vault API versions to smoke tests (#13130) 2020-08-18 09:56:45 -07:00
key_vault_keys_async.py Add Key Vault API versions to smoke tests (#13130) 2020-08-18 09:56:45 -07:00
key_vault_secrets.py Add Key Vault API versions to smoke tests (#13130) 2020-08-18 09:56:45 -07:00
key_vault_secrets_async.py Add Key Vault API versions to smoke tests (#13130) 2020-08-18 09:56:45 -07:00
program.py update smoke tests to latest version (#9350) 2020-01-31 12:39:48 -08:00
requirements-release.txt newest version of eventhub has no aio namespaces yet (#22954) 2022-02-08 10:03:16 -08:00
requirements.txt Run smoke tests against latest published versions in release pipeline (#15865) 2021-01-15 16:28:44 -05:00
requirements_async.txt bump to remove dependabot alert (#24991) 2022-06-27 12:47:01 -07:00
smoke-test.yml Use 1es hosted pools for smoke tests (#18272) 2021-04-23 17:46:43 -04:00
smoke_test.py temporarily disable cosmosdb smoke tests (#10779) 2020-04-10 14:56:32 -07:00
smoke_test_async.py add support for dynamic resource allocation and sovereign cloud testing (#10469) 2020-04-02 14:20:46 -07:00
storage_blob.py update smoke tests to latest version (#9350) 2020-01-31 12:39:48 -08:00
storage_blob_async.py update smoke tests to latest version (#9350) 2020-01-31 12:39:48 -08:00
test-resources.json temporarily disable cosmosdb smoke tests (#10779) 2020-04-10 14:56:32 -07:00

README.md

Azure Smoke Test for Python

This sample code is a smoke test to ensure that Azure Preview for Python work while loaded into the same process by performing 2 or more actions with them.

Libraries tested:

  • keyvault-secrets
  • identity
  • storage-blob
  • event-hubs
  • cosmos

Getting started

Setup Azure resources

For this sample, it is necessary to create/have the following resources in the Azure Portal:

  • App registration: Register a new app or use an existing one.
    • Under Certificates & secrets create a new client secret and store the value in a safe place.
  • Key Vaults: Create a new Key Vault resource or use an existing one.
    • Under Access policies, add the app registrated in the previous step.
  • Storage acounts: Create a container in a new or existing storage account. The container in this sample is named "mycontainer", if you want to use other name you can change the value in BlobStorage.ts file: const containerName = "mycontainer";
  • Event Hubs: Create an event hub inside a new or existing Event Hubs Namespace. The container in this sample is named "myeventhub", if you want to use other name you can change the value in EventHubsTest.ts file: let eventHubName = "myeventhub";
  • Azure Cosmos DB: Create a new account or use an existing one.

Azure credentials

The following environment variables are needed:

  • From App Registration, in the Overview section:

    • AZURE_TENANT_ID: The directory tentant ID.
    • AZURE_CLIENT_ID: The application ID.
    • AZURE_CLIENT_SECRET: The client secret stored previusly when creating the client secret.
  • From Key Vault, in the Overview section:

    • AZURE_PROJECT_URL: The DNS Name
  • From Event Hubs, in Shared access policies section:

    • EVENT_HUBS_CONNECTION_STRING: Connection string from a policy
  • From Storage Account, in the Access Keys section:

    • STORAGE_CONNECTION_STRING : A connection strings.
  • From Azure Cosmos DB, in the Keys section, select the Read-Write Keys tab:

    • COSMOS_ENDPOINT: URI.
    • COSMOS_KEY: Primary or secondary key.
# Bash code to create the environment variables
export AZURE_CLIENT_ID=""
export AZURE_CLIENT_SECRET=""
export AZURE_TENANT_ID=""
export EVENT_HUBS_CONNECTION_STRING=""
export AZURE_PROJECT_URL=""
export STORAGE_CONNECTION_STRING=""
export COSMOS_ENDPOINT=""
export COSMOS_KEY=""

Running the console app

Python version 2.7.16 and 3.7.4 were used to run this sample.

Install the libraries required using pip:

pip install -r requiriments.txt

In the \SmokeTest\ directory, run Program.py

python .\Program.py

Important: To run the async tests

In order to run the samples with the asynchronous clients, python 3.5 or greater is needed.

Install both requirements.txt and requirements_async.txt:

pip install -r requiriments.txt
pip install -r requiriments_async.txt

If a python version below 3.5 is being used, it is still possible to run the samples. When it gets to the async tests a message 'Async not supported' will be displayed.

Key concepts

Examples

All the classes in this sample has a Run() method as entry point, and do not depend on each other.

It is possible to run them individually:

from KeyVaultSecrets import KeyVault

KeyVault().Run()

They can be included in other projects by moving the class in it:

from KeyVaultSecrets import KeyVault

...

def  myTests():
    console.log("Smoke Test imported from other project")
    KeyVault().Run()

myTests()
otherFunction()
...

The classes can be used as base code and be changed to satisfied specific needs. For example, the method EventHub().SendAndReceiveEvents() can be change to only send events from an array given from a parameter:

def SendAndReceiveEvents(self, partitionID, events):
    producer = self.client.create_producer(partition_id=partitionID)
    producer.send(events)
    producer.close()

Note: The methods in the classes are not necessary independent on each other, and the order matters. For example, in order to run BlobStorage().DeleteBlob();, the method BlobStorage().UploadBLob(); must be run before, since in the other way it will fail because there is not going to be a blob to delete.

Troubleshooting

Authentication

Be sure to set the environment variables and credentials required before running the sample.

ImportError

ImportError: cannot import name 'AsyncPipelineClient' from 'azure.core'

The libraries in the requiriments_async.txt are not installed and the python version used has async capabilities. Install the libraries using pip.

Next steps

Check the Azure SDK for Python Repository for more samples inside the sdk folder.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.