Skip to content

[EngSys] updating the delete methods - #18304

Merged
Laurent Mazuel (lmazuel) merged 3 commits into
Azure:mainfrom
seankane-msft:es-update-preparer
Jul 6, 2021
Merged

[EngSys] updating the delete methods#18304
Laurent Mazuel (lmazuel) merged 3 commits into
Azure:mainfrom
seankane-msft:es-update-preparer

Conversation

@seankane-msft

Copy link
Copy Markdown
Contributor


def remove_resource(self, name, **kwargs):
if self.is_live and self._need_creation:
name = u"rgpy-" + name

@weshaggard Wes Haggard (weshaggard) Apr 26, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh this must have broken ever since you added the prefix. I was under an incorrect assumption when I responded to issue I thought they were hardcoding something in the test code.

It might be worth putting this name logic in a common function that can be shared between create and delete.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think adding this hardcode tricky logic in both create_resource and remove_resource is a good way. Maybe you can consider adding prefix for the name before you pass name parameter into create_resource and remove_resource.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also the log shows the wrong name (the name without prefix), actually we create resource with prefix.

                logging.info(
                    "Attempting to create a Resource Group with name {} and parameters {}".format(name, parameters)
                )
                # Prefixing all RGs created here with 'rgpy-' for tracing purposes
                name = u"rgpy-" + name
                if len(name) > 90:
                    name = name[:90]
                self.resource = self.client.resource_groups.create_or_update(name, parameters)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think adding this hardcode tricky logic in both create_resource and remove_resource is a good way. Maybe you can consider adding prefix for the name before you pass name parameter into create_resource and remove_resource.

Yu Chen (@jsntcy) I don't understand what you mean by this, can you elaborate or provide a code snippet?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure we would want to update all the callers of create/remove resources to have them pass in the name with the prefix but I do think it is a good idea to factor the name updates into a common function that we call at the beginning of both create and remove resources.

Also from a quick look it seems as though there is already a name_prefix value in this class which serves a slight different but similar purpose. We might want to reconcile the concepts and perhaps have a rgname_prefix or something along those lines.

@jsntcy Yu Chen (jsntcy) Apr 28, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, agree with Wes Haggard (@weshaggard), since both create_resource and remove_resource are in class ResourceGroupPreparer, you can define a variable in class which can be shared among all functions in class ResourceGroupPreparer.

Not sure if we can reuse self.name_prefix which already exists in class ResourceGroupPreparer.
https://github.com/Azure/azure-sdk-for-python/blob/master/tools/azure-sdk-tools/devtools_testutils/resource_testcase.py#L62

BTW, could you tell more about "add this prefix for tracking purpose"? Sean Kane (@seankane-msft)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yu Chen (@jsntcy) a few weeks ago our Subscription ID hit the maximum number of resource groups allowed, and we had no information on hundreds of RGs. Wes and I added the prefix so we could easily determine where at least some of the generated RGs were coming from.

@jsntcy Yu Chen (jsntcy) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please take a look at the comments.

Comment thread tools/azure-sdk-tools/devtools_testutils/resource_testcase.py Outdated
@ghost

Copy link
Copy Markdown

Hello Sean Kane (@seankane-msft)!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@seankane-msft

Copy link
Copy Markdown
Contributor Author

/check-enforcer override

@lmazuel
Laurent Mazuel (lmazuel) merged commit f1126cc into Azure:main Jul 6, 2021
@seankane-msft
Sean Kane (seankane-msft) deleted the es-update-preparer branch July 6, 2021 17:16
openapi-sdkautomation Bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this pull request Mar 17, 2022
openapi-sdkautomation Bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this pull request Mar 17, 2022
openapi-sdkautomation Bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this pull request Mar 17, 2022
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.

Hardcoding prefixname in create_resource causes ResoruceNotFound when deleting resource group

4 participants