Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TextAnalytics to enable live testing in sovereign clouds for multiple services #22461

Merged
merged 1 commit into from
Jan 18, 2022

Conversation

v-xuto
Copy link
Member

@v-xuto v-xuto commented Jan 12, 2022

These changes enable textanalytics to run live tests against Public, UsGov and China.

  1. As suggested in the issue [Text Analytics]"Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.us), or have expired." in USGOV and China #21448,
    So update text_analytics = TextAnalyticsClient(textanalytics_test_endpoint, token) in test_auth.py(async)
    to:
    text_analytics_endpoint_suffix = os.environ.get("TEXTANALYTICS_ENDPOINT_SUFFIX",".cognitiveservices.azure.com")
    credential_scopes = ["https://{}/.default".format(text_analytics_endpoint_suffix[1:])]
    text_analytics = TextAnalyticsClient(textanalytics_test_endpoint, token, credential_scopes=credential_scopes)
    
  2. As suggested in the issue [Text Analytics] "Invalid URL '$(js-textanalytics-test-service-endpoint)/text/analytics/v3.2-preview.2/analyze': No schema supplied" in Public, USGOV and China clouds #22281,
    move MatrixReplace: - TestSamples=.*/true to the PublicCloud config in test.yaml, and skip these tests related to env textanalytics_custom_text_endpoint in usgov and china clouds.

Besides, in order to solve the error:KeyError: 'TEXTANALYTICS_CUSTOM_TEXT_ENDPOINT' in most tests,
add code TextAnalyticsCustomPreparer in files test_analyze.py(async) and update TextAnalyticsPreparer in testcase.py.

Pipeline results:
https://dev.azure.com/azure-sdk/internal/_build/results?buildId=1289623&view=results

@benbp, @kristapratico, @jameszliao-msft, @lmazuel, @meeraharidasa , @mayurid, @abhahn for notification.

@check-enforcer
Copy link

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run python - [service] - ci

@v-xuto v-xuto marked this pull request as ready for review January 12, 2022 07:51
@@ -47,6 +47,17 @@
# pre-apply the client_cls positional argument so it needn't be explicitly passed below
TextAnalyticsClientPreparer = functools.partial(_TextAnalyticsClientPreparer, TextAnalyticsClient)

TextAnalyticsCustomPreparer = functools.partial(
TextAnalyticsPreparer,
textanalytics_custom_text_endpoint="https://fakeendpoint.cognitiveservices.azure.com",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these variables moved from the testcase to the test files?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, they needed to be separated since these env vars don't exist in the UsGov/China cloud.

Copy link
Member Author

@v-xuto v-xuto Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kristapratico @iscai-msft If I don't remove these variables, I'll get an error when rerun textanalytics weekly pipeline. Error message: azure_devtools.scenario_tests.preparers:preparers.py:82 Preparer failure when creating resource PowerShellPreparer for test <test_auth.TestAuth object at 0x111e26190>: 'TEXTANALYTICS_CUSTOM_TEXT_ENDPOINT'
For more details please check here.

For example test_auth.py::TestAuth::test_active_directory_auth, I have debugged this test locally. When the code is executed to devtools_testutils/powershell_preparer.py , it will get the corresponding values of these variables ( in TextAnalyticsPreparer) from the environment variables one by one, if not, an exception will be thrown. Because the values of these variables are not passed in UsGov/China cloud, the test will fail before the testcase actually runs.

So I moved variables from the testcase to the test files. Or do you have better suggestions?

Copy link
Member

@kristapratico kristapratico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all your work on this @v-xuto!

@v-xuto
Copy link
Member Author

v-xuto commented Jan 14, 2022

@benbp Please review this PR when you are free. Thanks.

@benbp
Copy link
Member

benbp commented Jan 18, 2022

Thank you @v-xuto!

@benbp benbp merged commit e2b5852 into Azure:main Jan 18, 2022
iscai-msft added a commit to iscai-msft/azure-sdk-for-python that referenced this pull request Jan 18, 2022
…into add_back_error_message

* 'main' of https://github.com/Azure/azure-sdk-for-python:
  switch error str tests to in (Azure#22016)
  drop py27 support (Azure#22531)
  Update TextAnalytics to enable live testing in sovereign clouds for multiple services (Azure#22461)
  fix: body is too long when create github release (Azure#22522)
  [AutoRelease] t2-labservices-2022-01-10-05622 (Azure#22401)
  [ACR] Change to support python3.6 or above only (Azure#22325)
  Sync eng/common directory with azure-sdk-tools for PR 2554 (Azure#22515)
  [purview catalog] regen with guids rest name fix (Azure#22495)
  Migrate EG tests to test proxy (Azure#21772)
  [Test Proxy] Normalize paths in test IDs (Azure#22508)
  Add packages to $PackageExclusions which do not build properly in Docs CI (Azure#22493)
  Update Manifest Publishing (Azure#22476)
  Issue Azure#9324 by DaisyCisneros (Azure#21824)
rakshith91 pushed a commit to rakshith91/azure-sdk-for-python that referenced this pull request Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants