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

Generate resources for Central tests #498

Merged
merged 14 commits into from
Mar 11, 2022
Merged

Generate resources for Central tests #498

merged 14 commits into from
Mar 11, 2022

Conversation

vilit1
Copy link
Contributor

@vilit1 vilit1 commented Mar 7, 2022

Automate resource generation for central tests. If the resource values are provided in the configuration file, they will be used. Otherwise, new resources will be created to run the tests. Within a given testing resource group,

  • a storage account will be created to be used for all the central tests
  • a separate central app will be created for each test and retrieving all possible central app values
  • the resources will be deleted once the tests are done.

Specifically, these configuration variables can be safely removed:

  • azext_iot_central_app_id
  • azext_iot_central_primarykey
  • azext_iot_central_scope_id
  • azext_iot_central_token
  • azext_iot_central_dns_suffix
  • azext_iot_central_storage_cstring
  • azext_iot_central_storage_container

Generated variables

If the central app id is not provided, the resource group to create the central app must be provided with:

  • azext_iot_testrg

If a central app is provided, the resource group value will be retrieved in case it is needed for storage account creation.
Then, the following variables will be populated:

  • azext_iot_central_app_id during central app creation
  • azext_iot_central_scope_id by creating a throwaway device (in get_app_scope_id)
  • azext_iot_central_storage_cstring and azext_iot_central_storage_container during storage account creation.

Limitations and non-generated variables

Note that with the current commands, two parameters will still be needed to run all tests:

  • azext_iot_central_primarykey
  • azext_iot_central_app_id

If one of these parameters is not provided, then this test will be skipped:

  • test_device_connect

If only azext_iot_central_primarykey is provided, then the primary key value will be nulled out because the newly created central app would not have the same primary key as the one that is defined in the configuration file.

For internal testing, these parameters will only be populated (and used) if present in the pytest.ini configuration file:

  • azext_iot_central_dns_suffix
  • azext_iot_central_token

Other fixes

Delete device templates

Changed the _delete_device_template code to invoke the correct command each time. There was an issue in which the list command defined after was invoked instead of the delete command.

sys.excepthook error

In addition, fixing sys.excepthook error by specifying which loop is to be closed.

The issue is here: #475


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.

Thank you for contributing to the IoT extension!

This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

Intent for Production

  • It is expected that pull requests made to default or core branches such as dev or main are of production grade. Corollary to this, any merged contributions to these branches may be deployed in a public release at any given time. By checking this box, you agree and commit to the expected production quality of code.

Basic expectations

  • If introducing new functionality or modified behavior, are they backed by unit and/or integration tests?
  • In the same context as above are command names and their parameter definitions accurate? Do help docs have sufficient content?
  • Have all the relevant unit and integration tests pass? i.e. pytest <project root> -vv. Please provide evidence in the form of a screenshot showing a succesful run of tests locally OR a link to a test pipeline that has been run against the change-set.
  • Have linter checks passed using the .pylintrc and .flake8 rules? Look at the CI scripts for example usage.
  • Have extraneous print or debug statements, commented out code-blocks or code-statements (if any) been removed from the surface area of changes?
    - [x] Have you made an entry in HISTORY.rst which concisely explains your user-facing feature or change?

Azure IoT CLI maintainers reserve the right to enforce any of the outlined expectations.

A PR is considered ready for review when all basic expectations have been met (or do not apply).

@vilit1 vilit1 requested a review from digimaun as a code owner March 7, 2022 22:21
@vilit1
Copy link
Contributor Author

vilit1 commented Mar 7, 2022

Test run with app id and primary key defined (only storage account generated for test suite):
image

Durations:
image

Test run with no variables (central application generated for each test and storage account generated for test suite):
image

Durations:
image

Copy link
Contributor

@yang-hai-feng yang-hai-feng left a comment

Choose a reason for hiding this comment

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

Looks good to me, put some comments on creating new app flow, btw have you run the integration tests successfully with auto created apps?

azext_iot/tests/central/__init__.py Show resolved Hide resolved
Copy link
Contributor

@lucadruda lucadruda left a comment

Choose a reason for hiding this comment

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

Looks good to me

digimaun
digimaun previously approved these changes Mar 9, 2022
@digimaun digimaun dismissed their stale review March 10, 2022 20:06

We discussed some changes offline.

@vilit1
Copy link
Contributor Author

vilit1 commented Mar 10, 2022

I removed the functionality in the integration tests that would run the tests twice (once with a token and once without). This meant that tests took twice as long.

Instead, the integration tests will rely on the configuration to determine if they are going to be run with a token or not; if there is a token defined then the integration tests will use that token and if there is no token, the integration tests will run without a token.

In a future pr, I will add unit tests to ensure that the tokens are generated properly. Specifically the unit tests will cover the functions in the central utility.

@vilit1
Copy link
Contributor Author

vilit1 commented Mar 11, 2022

@digimaun digimaun merged commit 3ded5b7 into Azure:dev Mar 11, 2022
@vilit1 vilit1 deleted the central_jit branch February 10, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants