From 034a68b5acd79bda5b73edd3b99518f998c73836 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 29 Aug 2024 15:06:15 +0100 Subject: [PATCH] pre-commit: Bump mypy There are quite a few issues to resolve here but the vast majority are down to signature differences. Change-Id: Ifdcfb4c772e7485ed36c6cce69852a23f31679c2 Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 2 +- .../accelerator/v2/accelerator_request.py | 6 ++- openstack/accelerator/v2/device_profile.py | 16 ++++++-- openstack/baremetal/v1/node.py | 2 + openstack/block_storage/v3/group.py | 2 +- openstack/block_storage/v3/service.py | 5 ++- openstack/block_storage/v3/volume.py | 4 +- openstack/clustering/v1/_async_resource.py | 2 +- openstack/common/quota_set.py | 30 ++++++++++++--- openstack/common/tag.py | 2 +- openstack/compute/v2/limits.py | 12 +++--- openstack/compute/v2/server.py | 5 +++ openstack/compute/v2/service.py | 8 +--- openstack/database/v1/user.py | 8 +++- openstack/dns/v2/zone_export.py | 2 +- openstack/dns/v2/zone_import.py | 2 +- openstack/identity/v3/limit.py | 8 +++- openstack/identity/v3/registered_limit.py | 8 +++- openstack/image/v2/cache.py | 4 +- openstack/image/v2/image.py | 3 ++ openstack/key_manager/v1/secret.py | 1 + openstack/load_balancer/v2/amphora.py | 20 ++++++---- openstack/load_balancer/v2/load_balancer.py | 8 ++-- openstack/load_balancer/v2/quota.py | 8 +++- openstack/message/v2/claim.py | 29 +++++++++++--- openstack/message/v2/message.py | 5 ++- openstack/message/v2/queue.py | 7 +++- openstack/message/v2/subscription.py | 7 +++- openstack/network/v2/_base.py | 1 + openstack/network/v2/quota.py | 8 +++- openstack/object_store/v1/_base.py | 13 +++++-- openstack/object_store/v1/_proxy.py | 2 + openstack/object_store/v1/container.py | 2 +- openstack/object_store/v1/info.py | 5 ++- openstack/object_store/v1/obj.py | 14 ++++--- openstack/orchestration/v1/software_config.py | 4 +- .../orchestration/v1/software_deployment.py | 8 ++-- openstack/orchestration/v1/stack.py | 6 ++- openstack/orchestration/v1/stack_files.py | 4 +- .../v2/share_access_rule.py | 3 +- .../v2/share_network_subnet.py | 10 ++++- .../tests/unit/block_storage/v2/test_proxy.py | 37 +++++++++++++----- .../tests/unit/block_storage/v3/test_proxy.py | 37 +++++++++++++----- openstack/tests/unit/compute/v2/test_proxy.py | 38 +++++++++++++------ .../tests/unit/orchestration/v1/test_stack.py | 4 +- openstack/workflow/v2/cron_trigger.py | 10 ++++- openstack/workflow/v2/execution.py | 8 +++- openstack/workflow/v2/workflow.py | 8 +++- 48 files changed, 317 insertions(+), 121 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 581e10a54..4f4516377 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,7 +37,7 @@ repos: - flake8-import-order~=0.18.2 exclude: '^(doc|releasenotes|tools)/.*$' - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.1 + rev: v1.11.2 hooks: - id: mypy additional_dependencies: diff --git a/openstack/accelerator/v2/accelerator_request.py b/openstack/accelerator/v2/accelerator_request.py index 71f6b099b..cf1c6f372 100644 --- a/openstack/accelerator/v2/accelerator_request.py +++ b/openstack/accelerator/v2/accelerator_request.py @@ -64,6 +64,8 @@ class AcceleratorRequest(resource.Resource): has_body=True, retry_on_conflict=None, base_path=None, + *, + microversion=None, ): # This overrides the default behavior of patch because # the PATCH method consumes a dict rather than a list. spec: @@ -104,7 +106,7 @@ class AcceleratorRequest(resource.Resource): attrs = attrs[self.resources_key][0] return super()._consume_attrs(mapping, attrs) - def create(self, session, base_path=None): + def create(self, session, prepend_key=False, *args, **kwargs): # This overrides the default behavior of resource creation because # cyborg doesn't accept resource_key in its request. - return super().create(session, prepend_key=False, base_path=base_path) + return super().create(session, prepend_key, *args, **kwargs) diff --git a/openstack/accelerator/v2/device_profile.py b/openstack/accelerator/v2/device_profile.py index 67d289564..dfa8a85ec 100644 --- a/openstack/accelerator/v2/device_profile.py +++ b/openstack/accelerator/v2/device_profile.py @@ -38,11 +38,19 @@ class DeviceProfile(resource.Resource): # TODO(s_shogo): This implementation only treat [ DeviceProfile ], and # cannot treat multiple DeviceProfiles in list. - def _prepare_request_body(self, patch, prepend_key): - body = super()._prepare_request_body(patch, prepend_key) + def _prepare_request_body( + self, + patch, + prepend_key, + *, + resource_request_key=None, + ): + body = super()._prepare_request_body( + patch, prepend_key, resource_request_key=resource_request_key + ) return [body] - def create(self, session, base_path=None): + def create(self, session, prepend_key=False, *args, **kwargs): # This overrides the default behavior of resource creation because # cyborg doesn't accept resource_key in its request. - return super().create(session, prepend_key=False, base_path=base_path) + return super().create(session, prepend_key, *args, **kwargs) diff --git a/openstack/baremetal/v1/node.py b/openstack/baremetal/v1/node.py index 47c0b48b6..8605e9e91 100644 --- a/openstack/baremetal/v1/node.py +++ b/openstack/baremetal/v1/node.py @@ -1465,6 +1465,8 @@ class Node(_common.Resource): has_body=True, retry_on_conflict=None, base_path=None, + *, + microversion=None, reset_interfaces=None, ): if reset_interfaces is not None: diff --git a/openstack/block_storage/v3/group.py b/openstack/block_storage/v3/group.py index 82af284ae..13c9871c9 100644 --- a/openstack/block_storage/v3/group.py +++ b/openstack/block_storage/v3/group.py @@ -60,7 +60,7 @@ class Group(resource.Resource): exceptions.raise_from_response(response) return response - def delete(self, session, *, delete_volumes=False): + def delete(self, session, *args, delete_volumes=False, **kwargs): """Delete a group.""" body = {'delete': {'delete-volumes': delete_volumes}} self._action(session, body) diff --git a/openstack/block_storage/v3/service.py b/openstack/block_storage/v3/service.py index 1454fc8f1..438e1f717 100644 --- a/openstack/block_storage/v3/service.py +++ b/openstack/block_storage/v3/service.py @@ -90,11 +90,12 @@ class Service(resource.Resource): f"No {cls.__name__} found for {name_or_id}" ) - def commit(self, session, prepend_key=False, **kwargs): + def commit(self, session, prepend_key=False, *args, **kwargs): # we need to set prepend_key to false return super().commit( session, - prepend_key=prepend_key, + prepend_key, + *args, **kwargs, ) diff --git a/openstack/block_storage/v3/volume.py b/openstack/block_storage/v3/volume.py index eb927ec40..e566f5ac7 100644 --- a/openstack/block_storage/v3/volume.py +++ b/openstack/block_storage/v3/volume.py @@ -359,7 +359,9 @@ class Volume(resource.Resource, metadata.MetadataMixin): self._action(session, body) - def _prepare_request_body(self, patch, prepend_key): + def _prepare_request_body( + self, patch, prepend_key, *, resource_request_key=None + ): body = self._body.dirty # Scheduler hints is external to the standard volume request # so pass it separately and not under the volume JSON object. diff --git a/openstack/clustering/v1/_async_resource.py b/openstack/clustering/v1/_async_resource.py index f37bb629b..01d59af9e 100644 --- a/openstack/clustering/v1/_async_resource.py +++ b/openstack/clustering/v1/_async_resource.py @@ -16,7 +16,7 @@ from openstack import resource class AsyncResource(resource.Resource): - def delete(self, session, error_message=None): + def delete(self, session, error_message=None, **kwargs): """Delete the remote resource based on this instance. :param session: The session to use for making this request. diff --git a/openstack/common/quota_set.py b/openstack/common/quota_set.py index a7bd86b5c..35d70fa1d 100644 --- a/openstack/common/quota_set.py +++ b/openstack/common/quota_set.py @@ -55,17 +55,31 @@ class QuotaSet(resource.Resource): requires_id=False, base_path=None, error_message=None, + skip_cache=False, + *, + resource_response_key=None, + microversion=None, **params, ): return super().fetch( session, - requires_id=False, - base_path=base_path, - error_message=error_message, + requires_id, + base_path, + error_message, + skip_cache, + resource_response_key=resource_response_key, + microversion=microversion, **params, ) - def _translate_response(self, response, has_body=None, error_message=None): + def _translate_response( + self, + response, + has_body=None, + error_message=None, + *, + resource_response_key=None, + ): """Given a KSA response, inflate this instance with its data DELETE operations don't return a body, so only try to work @@ -127,7 +141,13 @@ class QuotaSet(resource.Resource): self._update_location() dict.update(self, self.to_dict()) - def _prepare_request_body(self, patch, prepend_key): + def _prepare_request_body( + self, + patch, + prepend_key, + *, + resource_request_key=None, + ): body = self._body.dirty # Ensure we never try to send meta props reservation and usage body.pop('reservation', None) diff --git a/openstack/common/tag.py b/openstack/common/tag.py index 0a2d16ec3..09e2323ba 100644 --- a/openstack/common/tag.py +++ b/openstack/common/tag.py @@ -52,7 +52,7 @@ class TagMixin: self._body.attributes.update({'tags': json['tags']}) return self - def set_tags(self, session, tags=[]): + def set_tags(self, session, tags): """Sets/Replaces all tags on the resource. :param session: The session to use for making this request. diff --git a/openstack/compute/v2/limits.py b/openstack/compute/v2/limits.py index 86946bf3a..ef223e06d 100644 --- a/openstack/compute/v2/limits.py +++ b/openstack/compute/v2/limits.py @@ -121,8 +121,8 @@ class Limits(resource.Resource): self, session, requires_id=False, - error_message=None, base_path=None, + error_message=None, skip_cache=False, **params, ): @@ -137,10 +137,10 @@ class Limits(resource.Resource): # TODO(mordred) We shouldn't have to subclass just to declare # requires_id = False. return super().fetch( - session=session, - requires_id=requires_id, - error_message=error_message, - base_path=base_path, - skip_cache=skip_cache, + session, + requires_id, + error_message, + base_path, + skip_cache, **params, ) diff --git a/openstack/compute/v2/server.py b/openstack/compute/v2/server.py index 132ed81b1..2099e554f 100644 --- a/openstack/compute/v2/server.py +++ b/openstack/compute/v2/server.py @@ -280,13 +280,18 @@ class Server(resource.Resource, metadata.MetadataMixin, tag.TagMixin): self, requires_id=True, prepend_key=True, + patch=False, base_path=None, + params=None, **kwargs, ): request = super()._prepare_request( requires_id=requires_id, prepend_key=prepend_key, + patch=patch, base_path=base_path, + params=params, + **kwargs, ) server_body = request.body[self.resource_key] diff --git a/openstack/compute/v2/service.py b/openstack/compute/v2/service.py index ba371122f..0623fa0a7 100644 --- a/openstack/compute/v2/service.py +++ b/openstack/compute/v2/service.py @@ -87,13 +87,9 @@ class Service(resource.Resource): f"No {cls.__name__} found for {name_or_id}" ) - def commit(self, session, prepend_key=False, **kwargs): + def commit(self, session, prepend_key=False, *args, **kwargs): # we need to set prepend_key to false - return super().commit( - session, - prepend_key=prepend_key, - **kwargs, - ) + return super().commit(session, prepend_key, *args, **kwargs) def _action(self, session, action, body, microversion=None): if not microversion: diff --git a/openstack/database/v1/user.py b/openstack/database/v1/user.py index 3e7d9a688..d1c29cd68 100644 --- a/openstack/database/v1/user.py +++ b/openstack/database/v1/user.py @@ -35,7 +35,13 @@ class User(resource.Resource): password = resource.Body('password') def _prepare_request( - self, requires_id=True, prepend_key=True, base_path=None, **kwargs + self, + requires_id=True, + prepend_key=True, + patch=False, + base_path=None, + *args, + **kwargs, ): """Prepare a request for the database service's create call diff --git a/openstack/dns/v2/zone_export.py b/openstack/dns/v2/zone_export.py index 18cb4b1ac..34e0012e2 100644 --- a/openstack/dns/v2/zone_export.py +++ b/openstack/dns/v2/zone_export.py @@ -51,7 +51,7 @@ class ZoneExport(_base.Resource): #: ID for the zone that was created by this export zone_id = resource.Body('zone_id') - def create(self, session, prepend_key=True, base_path=None): + def create(self, session, prepend_key=True, base_path=None, **kwargs): """Create a remote resource based on this instance. :param session: The session to use for making this request. diff --git a/openstack/dns/v2/zone_import.py b/openstack/dns/v2/zone_import.py index 1ed3153bc..8f875f7b1 100644 --- a/openstack/dns/v2/zone_import.py +++ b/openstack/dns/v2/zone_import.py @@ -51,7 +51,7 @@ class ZoneImport(_base.Resource): #: ID for the zone that was created by this import zone_id = resource.Body('zone_id') - def create(self, session, prepend_key=True, base_path=None): + def create(self, session, prepend_key=True, base_path=None, **kwargs): """Create a remote resource based on this instance. :param session: The session to use for making this request. diff --git a/openstack/identity/v3/limit.py b/openstack/identity/v3/limit.py index 7918024a7..54190932b 100644 --- a/openstack/identity/v3/limit.py +++ b/openstack/identity/v3/limit.py @@ -47,7 +47,13 @@ class Limit(resource.Resource): #: ID of project. *Type: string* project_id = resource.Body('project_id') - def _prepare_request_body(self, patch, prepend_key): + def _prepare_request_body( + self, + patch, + prepend_key, + *, + resource_request_key=None, + ): body = self._body.dirty if prepend_key and self.resource_key is not None: if patch: diff --git a/openstack/identity/v3/registered_limit.py b/openstack/identity/v3/registered_limit.py index 7e8b67d66..6cdf07a20 100644 --- a/openstack/identity/v3/registered_limit.py +++ b/openstack/identity/v3/registered_limit.py @@ -45,7 +45,13 @@ class RegisteredLimit(resource.Resource): #: The default limit value. *Type: int* default_limit = resource.Body('default_limit') - def _prepare_request_body(self, patch, prepend_key): + def _prepare_request_body( + self, + patch, + prepend_key, + *, + resource_request_key=None, + ): body = self._body.dirty if prepend_key and self.resource_key is not None: if patch: diff --git a/openstack/image/v2/cache.py b/openstack/image/v2/cache.py index 1b240afd3..f181cf59b 100644 --- a/openstack/image/v2/cache.py +++ b/openstack/image/v2/cache.py @@ -54,7 +54,9 @@ class Cache(resource.Resource): exceptions.raise_from_response(response) return response - def clear(self, session, target='both'): + # FIXME(stephenfin): This needs to be renamed as it conflicts with + # dict.clear + def clear(self, session, target='both'): # type: ignore[override] """Clears the cache. :param session: The session to use for making this request :param target: Specify which target you want to clear diff --git a/openstack/image/v2/image.py b/openstack/image/v2/image.py index d84eaef01..28e7c19b0 100644 --- a/openstack/image/v2/image.py +++ b/openstack/image/v2/image.py @@ -383,6 +383,7 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin): prepend_key=False, patch=False, base_path=None, + params=None, **kwargs, ): request = super()._prepare_request( @@ -390,6 +391,8 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin): prepend_key=prepend_key, patch=patch, base_path=base_path, + params=params, + **kwargs, ) if patch: headers = { diff --git a/openstack/key_manager/v1/secret.py b/openstack/key_manager/v1/secret.py index aba4bca9f..ed092693a 100644 --- a/openstack/key_manager/v1/secret.py +++ b/openstack/key_manager/v1/secret.py @@ -91,6 +91,7 @@ class Secret(resource.Resource): base_path=None, error_message=None, skip_cache=False, + **kwargs, ): request = self._prepare_request( requires_id=requires_id, base_path=base_path diff --git a/openstack/load_balancer/v2/amphora.py b/openstack/load_balancer/v2/amphora.py index b33a4a603..31f22db25 100644 --- a/openstack/load_balancer/v2/amphora.py +++ b/openstack/load_balancer/v2/amphora.py @@ -111,10 +111,12 @@ class AmphoraConfig(resource.Resource): #: The ID of the amphora. amphora_id = resource.URI('amphora_id') - # The default _update code path also has no - # way to pass has_body into this function, so overriding the method here. - def commit(self, session, base_path=None): - return super().commit(session, base_path=base_path, has_body=False) + # The default _update code path also has no way to pass has_body into this + # function, so overriding the method here. + def commit( + self, session, prepend_key=True, has_body=False, *args, **kwargs + ): + return super().commit(session, prepend_key, has_body, *args, *kwargs) class AmphoraFailover(resource.Resource): @@ -134,7 +136,9 @@ class AmphoraFailover(resource.Resource): #: The ID of the amphora. amphora_id = resource.URI('amphora_id') - # The default _update code path also has no - # way to pass has_body into this function, so overriding the method here. - def commit(self, session, base_path=None): - return super().commit(session, base_path=base_path, has_body=False) + # The default _update code path also has no way to pass has_body into this + # function, so overriding the method here. + def commit( + self, session, prepend_key=True, has_body=False, *args, **kwargs + ): + return super().commit(session, prepend_key, has_body, *args, *kwargs) diff --git a/openstack/load_balancer/v2/load_balancer.py b/openstack/load_balancer/v2/load_balancer.py index a23708f17..d435c2a70 100644 --- a/openstack/load_balancer/v2/load_balancer.py +++ b/openstack/load_balancer/v2/load_balancer.py @@ -83,7 +83,7 @@ class LoadBalancer(resource.Resource, tag.TagMixin): #: Additional VIPs additional_vips = resource.Body('additional_vips', type=list) - def delete(self, session, error_message=None): + def delete(self, session, error_message=None, **kwargs): request = self._prepare_request() params = {} if ( @@ -145,5 +145,7 @@ class LoadBalancerFailover(resource.Resource): # The default _update code path also has no # way to pass has_body into this function, so overriding the method here. - def commit(self, session, base_path=None): - return super().commit(session, base_path=base_path, has_body=False) + def commit( + self, session, prepend_key=True, has_body=False, *args, **kwargs + ): + return super().commit(session, prepend_key, has_body, *args, **kwargs) diff --git a/openstack/load_balancer/v2/quota.py b/openstack/load_balancer/v2/quota.py index ddab05746..2151418a4 100644 --- a/openstack/load_balancer/v2/quota.py +++ b/openstack/load_balancer/v2/quota.py @@ -42,7 +42,13 @@ class Quota(resource.Resource): project_id = resource.Body('project_id', alternate_id=True) def _prepare_request( - self, requires_id=True, base_path=None, prepend_key=False, **kwargs + self, + requires_id=True, + prepend_key=False, + patch=False, + base_path=None, + *args, + **kwargs, ): _request = super()._prepare_request( requires_id, prepend_key, base_path=base_path diff --git a/openstack/message/v2/claim.py b/openstack/message/v2/claim.py index d4fb9bb30..2aedf57ef 100644 --- a/openstack/message/v2/claim.py +++ b/openstack/message/v2/claim.py @@ -55,13 +55,25 @@ class Claim(resource.Resource): #: authentication is not enabled in Zaqar service. project_id = resource.Header("X-PROJECT-ID") - def _translate_response(self, response, has_body=True): - super()._translate_response(response, has_body=has_body) + def _translate_response( + self, + response, + has_body=None, + error_message=None, + *, + resource_response_key=None, + ): + super()._translate_response( + response, + has_body, + error_message, + resource_response_key=resource_response_key, + ) if has_body and self.location: # Extract claim ID from location self.id = self.location.split("claims/")[1] - def create(self, session, prepend_key=False, base_path=None): + def create(self, session, prepend_key=False, base_path=None, **kwargs): request = self._prepare_request( requires_id=False, prepend_key=prepend_key, base_path=base_path ) @@ -89,6 +101,7 @@ class Claim(resource.Resource): base_path=None, error_message=None, skip_cache=False, + **kwargs, ): request = self._prepare_request( requires_id=requires_id, base_path=base_path @@ -107,7 +120,13 @@ class Claim(resource.Resource): return self def commit( - self, session, prepend_key=False, has_body=False, base_path=None + self, + session, + prepend_key=True, + has_body=True, + retry_on_conflict=None, + base_path=None, + **kwargs, ): request = self._prepare_request( prepend_key=prepend_key, base_path=base_path @@ -122,7 +141,7 @@ class Claim(resource.Resource): return self - def delete(self, session): + def delete(self, session, *args, **kwargs): request = self._prepare_request() headers = { "Client-ID": self.client_id or str(uuid.uuid4()), diff --git a/openstack/message/v2/message.py b/openstack/message/v2/message.py index da36c58b0..0b73b0605 100644 --- a/openstack/message/v2/message.py +++ b/openstack/message/v2/message.py @@ -123,6 +123,7 @@ class Message(resource.Resource): base_path=None, error_message=None, skip_cache=False, + **kwargs, ): request = self._prepare_request( requires_id=requires_id, base_path=base_path @@ -140,7 +141,9 @@ class Message(resource.Resource): return self - def delete(self, session): + def delete( + self, session, error_message=None, *, microversion=None, **kwargs + ): request = self._prepare_request() headers = { "Client-ID": self.client_id or str(uuid.uuid4()), diff --git a/openstack/message/v2/queue.py b/openstack/message/v2/queue.py index a256dee57..42b0b00c5 100644 --- a/openstack/message/v2/queue.py +++ b/openstack/message/v2/queue.py @@ -50,7 +50,7 @@ class Queue(resource.Resource): #: in case keystone auth is not enabled in Zaqar service. project_id = resource.Header("X-PROJECT-ID") - def create(self, session, prepend_key=True, base_path=None): + def create(self, session, prepend_key=False, base_path=None, **kwargs): request = self._prepare_request( requires_id=True, prepend_key=prepend_key, base_path=None ) @@ -117,6 +117,7 @@ class Queue(resource.Resource): base_path=None, error_message=None, skip_cache=False, + **kwargs, ): request = self._prepare_request( requires_id=requires_id, base_path=base_path @@ -133,7 +134,9 @@ class Queue(resource.Resource): return self - def delete(self, session): + def delete( + self, session, error_message=None, *, microversion=None, **kwargs + ): request = self._prepare_request() headers = { "Client-ID": self.client_id or str(uuid.uuid4()), diff --git a/openstack/message/v2/subscription.py b/openstack/message/v2/subscription.py index d8d36e753..884c1ea83 100644 --- a/openstack/message/v2/subscription.py +++ b/openstack/message/v2/subscription.py @@ -58,7 +58,7 @@ class Subscription(resource.Resource): #: authentication is not enabled in Zaqar service. project_id = resource.Header("X-PROJECT-ID") - def create(self, session, prepend_key=True, base_path=None): + def create(self, session, prepend_key=False, base_path=None, **kwargs): request = self._prepare_request( requires_id=False, prepend_key=prepend_key, base_path=base_path ) @@ -125,6 +125,7 @@ class Subscription(resource.Resource): base_path=None, error_message=None, skip_cache=False, + **kwargs, ): request = self._prepare_request( requires_id=requires_id, base_path=base_path @@ -142,7 +143,9 @@ class Subscription(resource.Resource): return self - def delete(self, session): + def delete( + self, session, error_message=None, *, microversion=None, **kwargs + ): request = self._prepare_request() headers = { "Client-ID": self.client_id or str(uuid.uuid4()), diff --git a/openstack/network/v2/_base.py b/openstack/network/v2/_base.py index 9ca01747e..e55b900ec 100644 --- a/openstack/network/v2/_base.py +++ b/openstack/network/v2/_base.py @@ -25,6 +25,7 @@ class NetworkResource(resource.Resource): patch=False, base_path=None, params=None, + *, if_revision=None, **kwargs, ): diff --git a/openstack/network/v2/quota.py b/openstack/network/v2/quota.py index 8c5bc7eb8..e4a4c55cb 100644 --- a/openstack/network/v2/quota.py +++ b/openstack/network/v2/quota.py @@ -61,7 +61,13 @@ class Quota(resource.Resource): security_groups = resource.Body('security_group', type=int) def _prepare_request( - self, requires_id=True, prepend_key=False, base_path=None, **kwargs + self, + requires_id=True, + prepend_key=False, + patch=False, + base_path=None, + *args, + **kwargs, ): _request = super()._prepare_request(requires_id, prepend_key) if self.resource_key in _request.body: diff --git a/openstack/object_store/v1/_base.py b/openstack/object_store/v1/_base.py index 0f910d0cf..b7e19f612 100644 --- a/openstack/object_store/v1/_base.py +++ b/openstack/object_store/v1/_base.py @@ -40,8 +40,8 @@ class BaseResource(resource.Resource): else: self.metadata[k] = v - def _prepare_request(self, **kwargs): - request = super()._prepare_request(**kwargs) + def _prepare_request(self, *args, **kwargs): + request = super()._prepare_request(*args, **kwargs) request.headers.update(self._calculate_headers(self.metadata)) return request @@ -91,7 +91,14 @@ class BaseResource(resource.Resource): key = header[len(self._custom_metadata_prefix) :].lower() self.metadata[key] = headers[header] - def _translate_response(self, response, has_body=None, error_message=None): + def _translate_response( + self, + response, + has_body=None, + error_message=None, + *, + resource_response_key=None, + ): # Save headers of the last operation for potential use (get_object of # cloud layer). # This must happen before invoking parent _translate_response, cause it diff --git a/openstack/object_store/v1/_proxy.py b/openstack/object_store/v1/_proxy.py index 8b661ff28..9bb6de618 100644 --- a/openstack/object_store/v1/_proxy.py +++ b/openstack/object_store/v1/_proxy.py @@ -12,6 +12,7 @@ from calendar import timegm import collections +import functools from hashlib import sha1 import hmac import json @@ -56,6 +57,7 @@ class Proxy(proxy.Proxy): log = _log.setup_logging('openstack') + @functools.lru_cache(maxsize=256) def _extract_name(self, url, service_type=None, project_id=None): url_path = parse.urlparse(url).path.strip() # Remove / from the beginning to keep the list indexes of interesting diff --git a/openstack/object_store/v1/container.py b/openstack/object_store/v1/container.py index 5c225e2e0..e709f3034 100644 --- a/openstack/object_store/v1/container.py +++ b/openstack/object_store/v1/container.py @@ -123,7 +123,7 @@ class Container(_base.BaseResource): kwargs.setdefault('name', name) return cls(_synchronized=False, **kwargs) - def create(self, session, prepend_key=True, base_path=None): + def create(self, session, prepend_key=True, base_path=None, **kwargs): """Create a remote resource based on this instance. :param session: The session to use for making this request. diff --git a/openstack/object_store/v1/info.py b/openstack/object_store/v1/info.py index e71e25480..572c1bb66 100644 --- a/openstack/object_store/v1/info.py +++ b/openstack/object_store/v1/info.py @@ -12,7 +12,7 @@ # under the License. import re -import urllib +import urllib.parse from openstack import exceptions from openstack import resource @@ -58,8 +58,9 @@ class Info(resource.Resource): session, requires_id=False, base_path=None, - skip_cache=False, error_message=None, + skip_cache=False, + **kwargs, ): """Get a remote resource based on this instance. diff --git a/openstack/object_store/v1/obj.py b/openstack/object_store/v1/obj.py index af95f2ca3..3b036e55a 100644 --- a/openstack/object_store/v1/obj.py +++ b/openstack/object_store/v1/obj.py @@ -213,7 +213,7 @@ class Object(_base.BaseResource): # The Object Store treats the metadata for its resources inconsistently so # Object.set_metadata must override the BaseResource.set_metadata to # account for it. - def set_metadata(self, session, metadata): + def set_metadata(self, session, metadata, refresh=True): # Filter out items with empty values so the create metadata behaviour # is the same as account and container filtered_metadata = { @@ -321,7 +321,7 @@ class Object(_base.BaseResource): ) return response.iter_content(chunk_size, decode_unicode=False) - def create(self, session, base_path=None, **params): + def create(self, session, prepend_key=True, base_path=None, **kwargs): request = self._prepare_request(base_path=base_path) response = session.put( @@ -330,11 +330,11 @@ class Object(_base.BaseResource): self._translate_response(response, has_body=False) return self - def _raw_delete(self, session, microversion=None): + def _raw_delete(self, session, microversion=None, **kwargs): if not self.allow_delete: - raise exceptions.MethodNotSupported(self, "delete") + raise exceptions.MethodNotSupported(self, 'delete') - request = self._prepare_request() + request = self._prepare_request(**kwargs) session = self._get_session(session) if microversion is None: microversion = self._get_microversion(session, action='delete') @@ -349,5 +349,7 @@ class Object(_base.BaseResource): headers['multipart-manifest'] = 'delete' return session.delete( - request.url, headers=headers, microversion=microversion + request.url, + headers=headers, + microversion=microversion, ) diff --git a/openstack/orchestration/v1/software_config.py b/openstack/orchestration/v1/software_config.py index cbd053fba..f0b67b3cd 100644 --- a/openstack/orchestration/v1/software_config.py +++ b/openstack/orchestration/v1/software_config.py @@ -45,7 +45,7 @@ class SoftwareConfig(resource.Resource): #: produces. outputs = resource.Body('outputs') - def create(self, session, base_path=None): + def create(self, session, prepend_key=False, *args, **kwargs): # This overrides the default behavior of resource creation because # heat doesn't accept resource_key in its request. - return super().create(session, prepend_key=False, base_path=base_path) + return super().create(session, prepend_key, *args, **kwargs) diff --git a/openstack/orchestration/v1/software_deployment.py b/openstack/orchestration/v1/software_deployment.py index 12178fc06..24d6952d2 100644 --- a/openstack/orchestration/v1/software_deployment.py +++ b/openstack/orchestration/v1/software_deployment.py @@ -49,12 +49,12 @@ class SoftwareDeployment(resource.Resource): #: The date and time when the software deployment resource was created. updated_at = resource.Body('updated_time') - def create(self, session, base_path=None): + def create(self, session, prepend_key=False, *args, **kwargs): # This overrides the default behavior of resource creation because # heat doesn't accept resource_key in its request. - return super().create(session, prepend_key=False, base_path=base_path) + return super().create(session, prepend_key, *args, **kwargs) - def commit(self, session, base_path=None): + def commit(self, session, prepend_key=False, *args, **kwargs): # This overrides the default behavior of resource creation because # heat doesn't accept resource_key in its request. - return super().commit(session, prepend_key=False, base_path=base_path) + return super().commit(session, prepend_key, *args, **kwargs) diff --git a/openstack/orchestration/v1/stack.py b/openstack/orchestration/v1/stack.py index 62a816f72..5247a7f60 100644 --- a/openstack/orchestration/v1/stack.py +++ b/openstack/orchestration/v1/stack.py @@ -112,10 +112,10 @@ class Stack(resource.Resource): #: The ID of the user project created for this stack. user_project_id = resource.Body('stack_user_project_id') - def create(self, session, base_path=None): + def create(self, session, prepend_key=False, *args, **kwargs): # This overrides the default behavior of resource creation because # heat doesn't accept resource_key in its request. - return super().create(session, prepend_key=False, base_path=base_path) + return super().create(session, prepend_key, *args, **kwargs) def commit( self, @@ -219,7 +219,9 @@ class Stack(resource.Resource): base_path=None, error_message=None, skip_cache=False, + *, resolve_outputs=True, + **params, ): if not self.allow_fetch: raise exceptions.MethodNotSupported(self, "fetch") diff --git a/openstack/orchestration/v1/stack_files.py b/openstack/orchestration/v1/stack_files.py index 0b72c6b68..e38907c12 100644 --- a/openstack/orchestration/v1/stack_files.py +++ b/openstack/orchestration/v1/stack_files.py @@ -33,7 +33,9 @@ class StackFiles(resource.Resource): # Backwards compat stack_id = id # type: ignore - def fetch(self, session, base_path=None): + def fetch( + self, session, requires_id=False, base_path=None, *args, **kwargs + ): # The stack files response contains a map of filenames and file # contents. request = self._prepare_request(requires_id=False, base_path=base_path) diff --git a/openstack/shared_file_system/v2/share_access_rule.py b/openstack/shared_file_system/v2/share_access_rule.py index 930f35dc1..792cc8100 100644 --- a/openstack/shared_file_system/v2/share_access_rule.py +++ b/openstack/shared_file_system/v2/share_access_rule.py @@ -73,9 +73,10 @@ class ShareAccessRule(resource.Resource): url, json=body, headers=headers, microversion=microversion ) - def create(self, session, **kwargs): + def create(self, session, *args, **kwargs): return super().create( session, + *args, resource_request_key='allow_access', resource_response_key='access', **kwargs, diff --git a/openstack/shared_file_system/v2/share_network_subnet.py b/openstack/shared_file_system/v2/share_network_subnet.py index 5d248b183..06e843a77 100644 --- a/openstack/shared_file_system/v2/share_network_subnet.py +++ b/openstack/shared_file_system/v2/share_network_subnet.py @@ -55,7 +55,13 @@ class ShareNetworkSubnet(resource.Resource): #: Date and time the share network subnet was last updated at. updated_at = resource.Body("updated_at", type=str) - def create(self, session, **kwargs): + def create( + self, + session, + *args, + resource_request_key='share-network-subnet', + **kwargs, + ): return super().create( - session, resource_request_key='share-network-subnet', **kwargs + session, resource_request_key=resource_request_key, *args, **kwargs ) diff --git a/openstack/tests/unit/block_storage/v2/test_proxy.py b/openstack/tests/unit/block_storage/v2/test_proxy.py index 50cf48eb7..2831d06a5 100644 --- a/openstack/tests/unit/block_storage/v2/test_proxy.py +++ b/openstack/tests/unit/block_storage/v2/test_proxy.py @@ -498,10 +498,16 @@ class TestQuotaSet(TestVolumeProxy): 'openstack.resource.Resource.fetch', self.proxy.get_quota_set, method_args=['prj'], - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + None, + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, + 'microversion': None, + 'resource_response_key': None, 'usage': False, }, method_result=quota_set.QuotaSet(), @@ -514,10 +520,16 @@ class TestQuotaSet(TestVolumeProxy): self.proxy.get_quota_set, method_args=['prj'], method_kwargs={'usage': True, 'user_id': 'uid'}, - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + None, + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, + 'microversion': None, + 'resource_response_key': None, 'usage': True, 'user_id': 'uid', }, @@ -528,11 +540,16 @@ class TestQuotaSet(TestVolumeProxy): 'openstack.resource.Resource.fetch', self.proxy.get_quota_set_defaults, method_args=['prj'], - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + '/os-quota-sets/defaults', + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, - 'base_path': '/os-quota-sets/defaults', + 'microversion': None, + 'resource_response_key': None, }, ) diff --git a/openstack/tests/unit/block_storage/v3/test_proxy.py b/openstack/tests/unit/block_storage/v3/test_proxy.py index c8b82f76f..27a9ee0e5 100644 --- a/openstack/tests/unit/block_storage/v3/test_proxy.py +++ b/openstack/tests/unit/block_storage/v3/test_proxy.py @@ -971,10 +971,16 @@ class TestQuotaSet(TestVolumeProxy): 'openstack.resource.Resource.fetch', self.proxy.get_quota_set, method_args=['prj'], - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + None, + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, + 'microversion': None, + 'resource_response_key': None, 'usage': False, }, method_result=quota_set.QuotaSet(), @@ -987,10 +993,16 @@ class TestQuotaSet(TestVolumeProxy): self.proxy.get_quota_set, method_args=['prj'], method_kwargs={'usage': True, 'user_id': 'uid'}, - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + None, + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, + 'microversion': None, + 'resource_response_key': None, 'usage': True, 'user_id': 'uid', }, @@ -1001,11 +1013,16 @@ class TestQuotaSet(TestVolumeProxy): 'openstack.resource.Resource.fetch', self.proxy.get_quota_set_defaults, method_args=['prj'], - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + '/os-quota-sets/defaults', + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, - 'base_path': '/os-quota-sets/defaults', + 'microversion': None, + 'resource_response_key': None, }, ) diff --git a/openstack/tests/unit/compute/v2/test_proxy.py b/openstack/tests/unit/compute/v2/test_proxy.py index 996ccb88b..05ac01a2f 100644 --- a/openstack/tests/unit/compute/v2/test_proxy.py +++ b/openstack/tests/unit/compute/v2/test_proxy.py @@ -1654,10 +1654,16 @@ class TestQuotaSet(TestComputeProxy): 'openstack.resource.Resource.fetch', self.proxy.get_quota_set, method_args=['prj'], - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + None, + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, + 'microversion': None, + 'resource_response_key': None, }, method_result=quota_set.QuotaSet(), expected_result=quota_set.QuotaSet(), @@ -1669,12 +1675,17 @@ class TestQuotaSet(TestComputeProxy): self.proxy.get_quota_set, method_args=['prj'], method_kwargs={'usage': True, 'user_id': 'uid'}, - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + '/os-quota-sets/%(project_id)s/detail', + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, + 'microversion': None, + 'resource_response_key': None, 'user_id': 'uid', - 'base_path': '/os-quota-sets/%(project_id)s/detail', }, ) @@ -1683,11 +1694,16 @@ class TestQuotaSet(TestComputeProxy): 'openstack.resource.Resource.fetch', self.proxy.get_quota_set_defaults, method_args=['prj'], - expected_args=[self.proxy], + expected_args=[ + self.proxy, + False, + '/os-quota-sets/%(project_id)s/defaults', + None, + False, + ], expected_kwargs={ - 'error_message': None, - 'requires_id': False, - 'base_path': '/os-quota-sets/%(project_id)s/defaults', + 'microversion': None, + 'resource_response_key': None, }, ) diff --git a/openstack/tests/unit/orchestration/v1/test_stack.py b/openstack/tests/unit/orchestration/v1/test_stack.py index e9614ec08..9019887dc 100644 --- a/openstack/tests/unit/orchestration/v1/test_stack.py +++ b/openstack/tests/unit/orchestration/v1/test_stack.py @@ -183,9 +183,7 @@ class TestStack(base.TestCase): res = sot.create(sess) - mock_create.assert_called_once_with( - sess, prepend_key=False, base_path=None - ) + mock_create.assert_called_once_with(sess, False) self.assertEqual(mock_create.return_value, res) def test_check(self): diff --git a/openstack/workflow/v2/cron_trigger.py b/openstack/workflow/v2/cron_trigger.py index 15a338159..139672d2c 100644 --- a/openstack/workflow/v2/cron_trigger.py +++ b/openstack/workflow/v2/cron_trigger.py @@ -71,5 +71,11 @@ class CronTrigger(resource.Resource): #: The time at which the cron trigger was created updated_at = resource.Body("updated_at") - def create(self, session, base_path=None): - return super().create(session, prepend_key=False, base_path=base_path) + def create( + self, + session, + prepend_key=False, + *args, + **kwargs, + ): + return super().create(session, prepend_key, *args, **kwargs) diff --git a/openstack/workflow/v2/execution.py b/openstack/workflow/v2/execution.py index 0f9633c76..2eb2730e8 100644 --- a/openstack/workflow/v2/execution.py +++ b/openstack/workflow/v2/execution.py @@ -58,7 +58,13 @@ class Execution(resource.Resource): #: The time at which the Execution was updated updated_at = resource.Body("updated_at") - def create(self, session, prepend_key=True, base_path=None): + def create( + self, + session, + prepend_key=True, + base_path=None, + **kwargs, + ): request = self._prepare_request( requires_id=False, prepend_key=prepend_key, base_path=base_path ) diff --git a/openstack/workflow/v2/workflow.py b/openstack/workflow/v2/workflow.py index 47e1afe9d..fc21f0322 100644 --- a/openstack/workflow/v2/workflow.py +++ b/openstack/workflow/v2/workflow.py @@ -64,7 +64,13 @@ class Workflow(resource.Resource): request.headers.update(headers) return dict(url=uri, json=None, headers=request.headers, **kwargs) - def create(self, session, prepend_key=True, base_path=None): + def create( + self, + session, + prepend_key=True, + base_path=None, + **kwargs, + ): kwargs = self._request_kwargs( prepend_key=prepend_key, base_path=base_path )