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

Add aosm extension #6426

Merged
merged 297 commits into from
Oct 24, 2023
Merged

Add aosm extension #6426

merged 297 commits into from
Oct 24, 2023

Conversation

sunnycarter
Copy link
Contributor

@sunnycarter sunnycarter commented Jun 20, 2023


Summary

Work item https://msazure.visualstudio.com/One/_workitems/edit/17617678 on AZ CLI team for the CLI Engagement Onboard.
az aosm commands for Azure Operator Service Manager.

GA Launch Date: 2023-09-30

This is our first Az CLI release and we intend to release the CLI with version <1.0.0.

This is the first time that our team has gone through the APEX process so please can you lay out the next steps after this review so that we can make sure we understand correctly?

Our swagger definition:

We have had an initial meeting with Damien Caro where we explained that standard CRUD operations on many of the HybridNetwork resources are not very beneficial to the user, as it is more likely that they will want to do a suite of complex operations involving multiple linked resource types. As such, have written a customization for the Azure CLI, as an extension az aosm which will help them do this. This does NOT include every CRUD operation you can do over the API, Peter Whiting from AOSM team has been in discussions with the Jeremy Li in the CLI team about this.

I am asking AZ CLI team to make a second review of this extension. We want to submit the PR finally 15th September 2023.

Kind Regards and thanks in advance,

Sunny Carter

More detail

The readme outlines the commands, let me expand a little more on the design.

The basic overview of the function is explained here: azure-cli-extensions/README.md . To add more detail to that, our customization would:

  • Output one or more bicep templates which would create the most complex resources in our API

  • Allow the user to review those templates

  • When the user chooses to publish, create some of the simpler HybridNetwork resources using the generated Python SDK. These being:

    • Publisher
    • Network Function Definition Group
    • Artifact Stores (these can be backed by an ACR or by a storage account)
    • Network Service Design Group
    • Site
  • Then deploy the bicep templates for the more complex HybridNetwork resources

    • Upload binary artifacts to the artifact stores using either Blob storage Python API for Azure storage account, or ORAS python implementation for ACR

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

Related command

General Guidelines

  • [todo ] Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
    Yes
  • [ todo] Have you run python scripts/ci/test_index.py -q locally?
    Yes. output is
Ran 9 tests in 0.019s

OK (skipped=2)

Tests:
See src/aosm/development.md
We have Unit Tests and Integration tests. The integration tests seem to be failing with an intermittent issue where the the test is looking for a request that exist in the recording of a test multiple times while it was only run once in the live test

This issue is intermittent but can be fixed by running a test live or allowing playback repeats in the cassette. We did not have enough time to test those solutions in our branch.

I have spoken to Zelin Wang from the Azure CLI team about this and he confirmed that this was an issue that they have seen before too. Here are his recommendations:

_

Found a similar issues in our repo:
Azure/azure-cli#19804

And the fix pr:
https://github.com/Azure/azure-cli/pull/19848/files (change to live only)
Another similar PR that fix the same issue: Azure/azure-cli#27016
Root cause: Azure/azure-cli#27016 (comment)


both MainThread and LROPoller are consuming the same URL https://cli-test-kv-ct-sd-000002.vault.azure.net/certificates/cert1/pending?api-version=REDACTED and waiting for a response with "status":"completed"

If MainThread runs faster, get_certificate_operation in LROPoller thread will not have enough recording entries to consume and fail, but the error won't surface because the result of the poller is not checked.
If LROPoller thread runs faster, get_certificate_operation in MainThread thread will not have enough recording entries to consume and fail. An error will be thrown.

_

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

Jordan and others added 30 commits May 15, 2023 12:14
* Add temporary build workflow for AOSM extension

* Add Releaser to maintain a release with the latest build in a consistent place
Add empty init files to inner modules so setuptools recognises them
Use latest RG model to remove unnecessary dependency on version
Use latest Deployment model to remove unnecessary dependency on version
Update readme with install/bug reporting instructions
Add CNF NFD generation to build command
jddarby and others added 7 commits October 13, 2023 15:50
* Regen Python SDK from 2023-09-01 API 
  - also uses latest AutoRest client
  - fix for HybridNetworkManagementClient init signature (swap order of subscription_id and credential parameters)

* Update CLI extension code to use new SDK

* added SAMI to publisher pre deploy

* Update bicep templates to use 2023-09-01

* Update NF templates

* Update metaschema

* Add Allow-Publisher to required feature flags

* Use secure objects for deployment parameters
.flake8 Outdated
Comment on lines 5 to 17
E501, # line too long, it is covered by pylint
E722, # bare except, bad practice, to be removed in the future
F401, # imported but unused, too many violations, to be removed in the future
F811, # redefinition of unused, to be removed in the future
C901 # code flow is too complex, too many violations, to be removed in the future
W503 # line break before binary operator effect on readability is subjective
W504 # line break after binary operator effect on readability is subjective
# line too long, it is covered by pylint
E501,
# bare except, bad practice, to be removed in the future
E722,
# imported but unused, too many violations, to be removed in the future
F401,
# redefinition of unused, to be removed in the future
F811,
# code flow is too complex, too many violations, to be removed in the future
C901,
# line break before binary operator effect on readability is subjective
W503,
# line break after binary operator effect on readability is subjective
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to modify this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

The linter complained about the existing format (inline comments and missing commas), so it was modified to keep the linter happy. But you're right, this isn't our file to worry about, so I've reverted it to how it was.

network_function_definition_version_name=self.config.version,
)
LongRunningOperation(self.cli_ctx, "Deleting NFDV...")(poller)
print("Deleted NFDV.")
Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, the design of the vast majority of CLI delete commands defaults to successful deletion if no information is output. Therefore, it is recommended to keep the design style consistent with other CLI commands.

Copy link
Contributor

@Cyclam Cyclam Oct 23, 2023

Choose a reason for hiding this comment

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

I've moved the message to logger.info(), so won't be output by default. Thanks for the advice.

Comment on lines +151 to +155
message = (
f"Delete NSDV {self.config.nsd_version} from group"
f" {self.config.nsd_name} and publisher {self.config.publisher_name}"
)
logger.debug(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why print and record debug logs simultaneously?

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to rethink how we output to console. These changes are too widespread to make before GA release, so I've opened work item https://dev.azure.com/msazuredev/AzureForOperators/_workitems/edit/992775 to track.

network_service_design_version_name=self.config.nsd_version,
)
LongRunningOperation(self.cli_ctx, "Deleting NSDV...")(poller)
print("Deleted NSDV.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I've moved the message to logger.info(), so won't be output by default. Thanks for the advice.

Comment on lines +199 to +200
logger.debug(message)
print(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to rethink how we output to console. These changes are too widespread to make before GA release, so I've opened work item https://dev.azure.com/msazuredev/AzureForOperators/_workitems/edit/992775 to track.

Comment on lines +224 to +225
logger.debug(message)
print(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. There are many similar places below, so I won't repeat the comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to rethink how we output to console. These changes are too widespread to make before GA release, so I've opened work item https://dev.azure.com/msazuredev/AzureForOperators/_workitems/edit/992775 to track.

)
)
LongRunningOperation(self.cli_ctx, "Deleting NSD...")(poller)
print("Deleted NSD")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. There are many similar places below, so I won't repeat the comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've moved all similar messages to logger.info(), so won't be output by default. Thanks for the advice.

"License :: OSI Approved :: MIT License",
]

DEPENDENCIES = ["oras~=0.1.19", "azure-storage-blob>=12.15.0", "jinja2>=3.1.2"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity, can the dependency azure-storage-blob be included by the dependency azure-multiapi-storage and azure-storage-common in the azure-cli-core? code link

Copy link
Contributor

Choose a reason for hiding this comment

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

azure-storage-blob depends on azure-storage-common (not vice versa).

https://pypi.org/project/azure-multiapi-storage/ suggests azure-multiapi-storage might cover azure-storage-blob, but I don't know how to use it, and would rather not make an important dependency change at this late stage. I've raised work item https://dev.azure.com/msazuredev/AzureForOperators/_workitems/edit/992831 to track.

@zhoxing-ms
Copy link
Contributor

Due to the super huge size of this PR, and CLI team only reviews the code specification and is not responsible for reviewing the business logic, please have at least one engineer from your team review and sign off this PR

@Cyclam
Copy link
Contributor

Cyclam commented Oct 23, 2023

Due to the super huge size of this PR, and CLI team only reviews the code specification and is not responsible for reviewing the business logic, please have at least one engineer from your team review and sign off this PR

Thanks for your review.

The business logic has been developed over the last few months, with every merge into our development branch reviewed by at least one member of the team.

Several of us have also done a general high level review before this PR, and we can sign off the business logic as fully reviewed.

* moved blob url to vhd config only; untested

* stopped error in post innit before validate

* changed ordering of inputs so that blob and filepath are next to each other; helptext for filepath different for each option

* Markups from sunny

* appease mypy

---------

Co-authored-by: Jordan <[email protected]>
Co-authored-by: Sunny Carter <[email protected]>
@yanzhudd yanzhudd merged commit 638f562 into Azure:main Oct 24, 2023
14 checks passed
@azclibot
Copy link
Collaborator

[Release] Update index.json for extension [ aosm ] : https://dev.azure.com/azclitools/internal/_build/results?buildId=99338&view=results

class VNFConfiguration(NFConfiguration):
blob_artifact_store_name: str = ""
image_name_parameter: str = ""
arm_template: Union[Dict[str, str], ArtifactConfig] = ArtifactConfig()
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this line is not compatible with 3.11.

Change field default mutability check, allowing only defaults which are hashable instead of any object which is not an instance of dict, list or set. (Contributed by Eric V. Smith in bpo-44674.) --What’s New In Python 3.11 — Python 3.12.0 documentation

This error is raised when run az self-test --debug:

  File "/opt/az/azcliextensions/aosm/azext_aosm/_configuration.py", line 267, in <module>
    @dataclass
     ^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/dataclasses.py", line 1230, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/dataclasses.py", line 1220, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'azext_aosm._configuration.ArtifactConfig'> for field arm_template is not allowed: use default_factory

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we expected to support Python 3.11? I can't run azdev setup against 3.11, and the pipelines for our PR didn't test at Python 3.11, as far as I can see.

I have a potential fix, but because of the above problems, testing and ensuring there aren't other occurrences of this problem (I expect there will be), is not possible.

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.