Code Monkey home page Code Monkey logo

azure-python-devtools's Introduction

https://travis-ci.org/Azure/azure-python-devtools.svg?branch=master

Disclaimer: The package "azure-devtools" is no longer maintened nor used in any Microsoft projects anymore.

Development tools for Python-based Azure tools

This package contains tools to aid in developing Python-based Azure code.

This includes the following components:

scenario_tests

A testing framework to handle much of the busywork associated with testing code that interacts with Azure.

ci_tools

Some tooling to help developing CI tools. This includes some Git helpers, Github RestAPI wrapper and a Bot framework for Github issues.

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

azure-python-devtools's People

Contributors

adewaleo avatar juliehzl avatar lmazuel avatar microsoftopensource avatar msftgits avatar qwordy avatar tjprescott avatar troydai avatar valrus avatar williexu avatar yugangw-msft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-python-devtools's Issues

Subscription ID is not removed from request or some response bodies

Not, I think, for the same reason as #16, but it might make sense to fix both simultaneously.

This issue is actually two related problems with slightly different solutions:

  • The subscription ID isn't removed from the request body because process_request only replaces the uri field.
  • It's not removed from the response body because _replace_subscription_id's regex substitution is case sensitive: it searches for /subscriptions/([^/]+/ but sometimes it appears in the URI as /Subscriptions/....

src/azure_devtools/ci_tools/github_tools.py uses Python3-only syntax

Hi!

While updating the azure-python-devtools Debian package, I came across some Python3-only syntax in the ci_tools submodule (the keyword-only argument lone *).

I'll exclude that submodule from the Python2 Debian package, but I guess the packaging metadata should be updated, and/or the submodule excluded from setup.py on Python2.

Thanks!

create_random_name might not work well

As it stands, the two consumers of azure-devtools both override ReplayableTest.create_random_name, which is good because I think the default implementation might not work.

In particular, due to this line in azure_devtools.scenario_tests.utilities.create_random_name (which IntegrationTestBase.create_random_name calls):

random_bytes = os.urandom(int(math.ceil(float(padding_size) / 8) * 5))

the names it generates will be actually random and not consistent between test runs. (I haven't yet tested this but I can't see how it would be otherwise. This would also be a prime candidate for #5 as well.)

vcr: do not record the storage account keys

Sample recording content:

- request:
    body: null
    headers:
      Accept: [application/json]
      Accept-Encoding: ['gzip, deflate']
      CommandName: [functionapp create]
      Connection: [keep-alive]
      Content-Length: ['0']
      Content-Type: [application/json; charset=utf-8]
      User-Agent: [python/3.5.4 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29
          msrest_azure/0.4.29 azure-mgmt-storage/1.5.0 Azure-SDK-For-Python AZURECLI/2.0.33]
      accept-language: [en-US]
    method: POST
    uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Storage/storageAccounts/functionappplanstorage/listKeys?api-version=2017-10-01
  response:
    body: {string: '{"keys":[{"keyName":"key1","value":"...","permissions":"FULL"},{"keyName":"key2","value":"...","permissions":"FULL"}]}'}

SubscriptionRecordingProcessor still doesn't catch everything

The "SkuNotAvailable" response for VM creation has a body that looks like this:

    body: {string: '{"error": {"code": "SkuNotAvailable", "message": "The requested
        tier for resource ''/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/azure-sample-group-virtual-machines/providers/Microsoft.Compute/virtualMachines/VmName''
        is currently not available in location ''westus'' for subscription ''ACTUAL-SUBSCRIPTION-ID-SHOWN-HERE''.
        Please try another tier or deploy to a different location."}, "access_token":
        "fake_token"}'}

and where the string ACTUAL-SUBSCRIPTION-ID-SHOWN-HERE appears in that example, SubscriptionRecordingProcessor fails to remove it.

MSAL (AAD v2.0) requests are recorded

azure_devtools.scenario_tests.recording_processors.OAuthRequestResponsesFilter doesn't recognize MSAL requests due to the URL change in AAD v2.0.

class OAuthRequestResponsesFilter(RecordingProcessor):
"""Remove oauth authentication requests and responses from recording."""
def process_request(self, request):
# filter request like:
# GET https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/token
import re
if not re.match('https://login.microsoftonline.com/([^/]+)/oauth2/token', request.uri):
return request
return None

This results in all https://login.microsoftonline.com requests being recorded, including

  • Tenant discovery request: GET https://login.microsoftonline.com/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/v2.0/.well-known/openid-configuration
  • Get access token request: POST https://login.microsoftonline.com/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/oauth2/v2.0/token

Actually, all requests to https://login.microsoftonline.com should be ignored as it is related to authentication which is patched in playback mode.

VCR recording improvement

  1. Support serializing request/response payload with binary content. To reproduce, just try out the webapp log download test
  2. For large payload, suggest throw during the recording instead of injecting !!! The request body has been omitted from the recording because its.... You know, the test will still fail during the playback but becomes harder for me to figure out the cause since the test did pass during the recording

Releases will fail due to deprecated upload URL

This appears in the Jenkins output for the 0.5.0 release, which was not successfully pushed to PyPI:

Uploading distributions to https://pypi.python.org/pypi
Note: you are uploading to the old upload URL. It's recommended to use the new URL
"https://upload.pypi.org/legacy/" or to leave the URL unspecified and allow twine to choose.
Uploading azure_devtools-0.5.0-py2.py3-none-any.whl
HTTPError: 410 Client Error: Gone (This API has been deprecated and removed from legacy PyPI
in favor of using the APIs available in the new PyPI.org implementation of PyPI
(located at https://pypi.org/).
This is a 24h brownout of the API and access will be restored on June 30th. Please switch to PyPI.ORG
for uploads prior to July 3rd when this API will be removed for good. For more information about
migrating your use of this API to PyPI.org, please see
https://packaging.python.org/guides/migrating-to-pypi-org/#uploading.
For more information about the sunsetting of this API, please see
https://mail.python.org/pipermail/distutils-sig/2017-June/030766.html)
for url: https://pypi.python.org/pypi

azdev test failing with LROPoller Error

Running azdev test is failing on our private preview extension with the following error, please help resolve this

self = <azext_k8s_extension.tests.latest.test_k8s_extension_scenario.K8sExtensionScenarioTest testMethod=test_k8s_extension>

    def tearDown(self):
        os.environ = self.original_env
        # Autorest.Python 2.x
        assert not [t for t in threading.enumerate() if t.name.startswith("AzureOperationPoller")], \
            "You need to call 'result' or 'wait' on all AzureOperationPoller you have created"
        # Autorest.Python 3.x
>       assert not [t for t in threading.enumerate() if t.name.startswith("LROPoller")], \
            "You need to call 'result' or 'wait' on all LROPoller you have created"
E       AssertionError: You need to call 'result' or 'wait' on all LROPoller you have created

env\lib\site-packages\azure_devtools\scenario_tests\base.py:154: AssertionError
------------------------------------------------------------------------------------------------------------------ Captured stderr call ------------------------------------------------------------------------------------------------------------------- 
WARNING: Command group 'k8s-extension' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
Ignoring name, release-namespace and scope parameters since microsoft.azuremonitor.containers only supports cluster scope and single instance of this extension
--------------------------------------------------------------------- generated xml file: C:\Users\joinnis\.azdev\env_config\Users\joinnis\github\narayan-cli-pr\env\test_results.xml --------------------------------------------------------------------- 
================================================================================================================= short test summary info ================================================================================================================= 
FAILED src\k8s-extension\azext_k8s_extension\tests\latest\test_k8s_extension_scenario.py::K8sExtensionScenarioTest::test_k8s_extension - AssertionError: You need to call 'result' or 'wait' on all LROPoller you have created
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! xdist.dsession.Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================================================================================================== 1 failed in 11.24s ====================================================================================================================

DeprecationWarning

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/azure_devtools/scenario_tests/utilities.py:73: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()

verbose on Travis

Test preparer deletion order

I created 3 preparers: P1, P2 and P3. These depend on each other as such: P3 depends on P2 and P2 depends on P1. I've decorated the preparers on my test method in the order: P1, P2, P3. During resource creation, everything goes well. But during resource deletion, the order seems to be: P1, P2, P3 - whereas the order should be: P3, P2, P1.

Please look into this!

Fix versioning

The version number handling is a little sloppy. There's a __version__ in azure_devtools.scenario_tests.__init__ but not in azure_devtools.__init__, and the version number in setup.py is duplicated rather than imported as it probably should be. This makes releases a little messier than they should be.

Mapping to underlying VCR record modes is wrong

Currently ReplayableTest.__init__ passes self.config.record_mode through unchanged as record_mode to vcr.VCR(). But it's a boolean value, which is not an appropriate value for that argument. It should be a string. Somehow it seems to work ok regardless? But I think it only does so incidentally.

To match what I believe we expect (and what I claim is done in #19), we should pass record_mode like this:

record_mode='all' if self.config.record_mode else 'once'

Specifying Parameter Name Under 23 Characters Raises error on azdev linter

  • If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at Azure/azure-cli

Extension name (the extension in question)

k8sconfiguration

Description of issue (in as much detail as possible)

Parameter names must be under 23 characters according to the linter. When specifying a name in the options_list for an argument, my shortest parameter name --<parameter_name> is throwing an error in the linter because the linter includes the dashes in front of the parameter when taking the number of characters into account.

When no options_list is specified and the default argument name is used, the linter will not include these dashes in counting.

For instance, the parameter name --config-protected-file raises an error when it shouldn't


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.