From 96eee90ccd79af1f81bc1fd578ee61619733e46f Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Mon, 4 May 2015 16:55:22 -0600 Subject: [PATCH] Proxy update identity changes Change-Id: I5d50b079059f7cd39404ec491e1da238fe7fc8ac --- openstack/identity/v2/_proxy.py | 48 ++++-- openstack/identity/v3/_proxy.py | 144 ++++++++++++++---- .../tests/unit/identity/v2/test_proxy.py | 27 +++- .../tests/unit/identity/v3/test_proxy.py | 84 +++++++--- 4 files changed, 243 insertions(+), 60 deletions(-) diff --git a/openstack/identity/v2/_proxy.py b/openstack/identity/v2/_proxy.py index 5c096cc6..1bd738b6 100644 --- a/openstack/identity/v2/_proxy.py +++ b/openstack/identity/v2/_proxy.py @@ -30,7 +30,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the role does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent role. :returns: ``None`` """ @@ -45,8 +45,18 @@ class Proxy(proxy.BaseProxy): def list_roles(self): return role.Role.list(self.session) - def update_role(self, **data): - return role.Role(data).update(self.session) + def update_role(self, value, **attrs): + """Update a role + + :param value: Either the id of a role or a + :class:`~openstack.compute.v2.role.Role` instance. + :attrs kwargs: The attributes to update on the role represented + by ``value``. + + :returns: The updated role + :rtype: :class:`~openstack.compute.v2.role.Role` + """ + return self._update(role.Role, value, **attrs) def create_tenant(self, **data): return tenant.Tenant(data).create(self.session) @@ -60,7 +70,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the tenant does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent tenant. :returns: ``None`` """ @@ -75,8 +85,18 @@ class Proxy(proxy.BaseProxy): def list_tenants(self): return tenant.Tenant.list(self.session) - def update_tenant(self, **data): - return tenant.Tenant(data).update(self.session) + def update_tenant(self, value, **attrs): + """Update a tenant + + :param value: Either the id of a tenant or a + :class:`~openstack.compute.v2.tenant.Tenant` instance. + :attrs kwargs: The attributes to update on the tenant represented + by ``value``. + + :returns: The updated tenant + :rtype: :class:`~openstack.compute.v2.tenant.Tenant` + """ + return self._update(tenant.Tenant, value, **attrs) def create_user(self, **data): return user.User(data).create(self.session) @@ -90,7 +110,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the user does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent user. :returns: ``None`` """ @@ -105,5 +125,15 @@ class Proxy(proxy.BaseProxy): def list_users(self): return user.User.list(self.session) - def update_user(self, **data): - return user.User(data).update(self.session) + def update_user(self, value, **attrs): + """Update a user + + :param value: Either the id of a user or a + :class:`~openstack.compute.v2.user.User` instance. + :attrs kwargs: The attributes to update on the user represented + by ``value``. + + :returns: The updated user + :rtype: :class:`~openstack.compute.v2.user.User` + """ + return self._update(user.User, value, **attrs) diff --git a/openstack/identity/v3/_proxy.py b/openstack/identity/v3/_proxy.py index d62495ab..db7ebe52 100644 --- a/openstack/identity/v3/_proxy.py +++ b/openstack/identity/v3/_proxy.py @@ -36,7 +36,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the credential does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent credential. :returns: ``None`` """ @@ -51,8 +51,19 @@ class Proxy(proxy.BaseProxy): def list_credentials(self): return credential.Credential.list(self.session) - def update_credential(self, **data): - return credential.Credential(data).update(self.session) + def update_credential(self, value, **attrs): + """Update a credential + + :param value: Either the id of a credential or a + :class:`~openstack.compute.v2.credential.Credential` + instance. + :attrs kwargs: The attributes to update on the credential represented + by ``value``. + + :returns: The updated credential + :rtype: :class:`~openstack.compute.v2.credential.Credential` + """ + return self._update(credential.Credential, value, **attrs) def create_domain(self, **data): return domain.Domain(data).create(self.session) @@ -66,7 +77,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the domain does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent domain. :returns: ``None`` """ @@ -81,8 +92,18 @@ class Proxy(proxy.BaseProxy): def list_domains(self): return domain.Domain.list(self.session) - def update_domain(self, **data): - return domain.Domain(data).update(self.session) + def update_domain(self, value, **attrs): + """Update a domain + + :param value: Either the id of a domain or a + :class:`~openstack.compute.v2.domain.Domain` instance. + :attrs kwargs: The attributes to update on the domain represented + by ``value``. + + :returns: The updated domain + :rtype: :class:`~openstack.compute.v2.domain.Domain` + """ + return self._update(domain.Domain, value, **attrs) def create_endpoint(self, **data): return endpoint.Endpoint(data).create(self.session) @@ -96,7 +117,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the endpoint does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent endpoint. :returns: ``None`` """ @@ -111,8 +132,19 @@ class Proxy(proxy.BaseProxy): def list_endpoints(self): return endpoint.Endpoint.list(self.session) - def update_endpoint(self, **data): - return endpoint.Endpoint(data).update(self.session) + def update_endpoint(self, value, **attrs): + """Update a endpoint + + :param value: Either the id of a endpoint or a + :class:`~openstack.compute.v2.endpoint.Endpoint` + instance. + :attrs kwargs: The attributes to update on the endpoint represented + by ``value``. + + :returns: The updated endpoint + :rtype: :class:`~openstack.compute.v2.endpoint.Endpoint` + """ + return self._update(endpoint.Endpoint, value, **attrs) def create_group(self, **data): return group.Group(data).create(self.session) @@ -126,7 +158,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the group does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent group. :returns: ``None`` """ @@ -141,8 +173,18 @@ class Proxy(proxy.BaseProxy): def list_groups(self): return group.Group.list(self.session) - def update_group(self, **data): - return group.Group(data).update(self.session) + def update_group(self, value, **attrs): + """Update a group + + :param value: Either the id of a group or a + :class:`~openstack.compute.v2.group.Group` instance. + :attrs kwargs: The attributes to update on the group represented + by ``value``. + + :returns: The updated group + :rtype: :class:`~openstack.compute.v2.group.Group` + """ + return self._update(group.Group, value, **attrs) def create_policy(self, **data): return policy.Policy(data).create(self.session) @@ -156,7 +198,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the policy does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent policy. :returns: ``None`` """ @@ -171,8 +213,18 @@ class Proxy(proxy.BaseProxy): def list_policys(self): return policy.Policy.list(self.session) - def update_policy(self, **data): - return policy.Policy(data).update(self.session) + def update_policy(self, value, **attrs): + """Update a policy + + :param value: Either the id of a policy or a + :class:`~openstack.compute.v2.policy.Policy` instance. + :attrs kwargs: The attributes to update on the policy represented + by ``value``. + + :returns: The updated policy + :rtype: :class:`~openstack.compute.v2.policy.Policy` + """ + return self._update(policy.Policy, value, **attrs) def create_project(self, **data): return project.Project(data).create(self.session) @@ -186,7 +238,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the project does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent project. :returns: ``None`` """ @@ -201,8 +253,18 @@ class Proxy(proxy.BaseProxy): def list_projects(self): return project.Project.list(self.session) - def update_project(self, **data): - return project.Project(data).update(self.session) + def update_project(self, value, **attrs): + """Update a project + + :param value: Either the id of a project or a + :class:`~openstack.compute.v2.project.Project` instance. + :attrs kwargs: The attributes to update on the project represented + by ``value``. + + :returns: The updated project + :rtype: :class:`~openstack.compute.v2.project.Project` + """ + return self._update(project.Project, value, **attrs) def create_service(self, **data): return service.Service(data).create(self.session) @@ -216,7 +278,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the service does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent service. :returns: ``None`` """ @@ -231,8 +293,18 @@ class Proxy(proxy.BaseProxy): def list_services(self): return service.Service.list(self.session) - def update_service(self, **data): - return service.Service(data).update(self.session) + def update_service(self, value, **attrs): + """Update a service + + :param value: Either the id of a service or a + :class:`~openstack.compute.v2.service.Service` instance. + :attrs kwargs: The attributes to update on the service represented + by ``value``. + + :returns: The updated service + :rtype: :class:`~openstack.compute.v2.service.Service` + """ + return self._update(service.Service, value, **attrs) def create_user(self, **data): return user.User(data).create(self.session) @@ -246,7 +318,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the user does not exist. When set to ``True``, no exception will be set when - attempting to delete a nonexistent server. + attempting to delete a nonexistent user. :returns: ``None`` """ @@ -261,8 +333,18 @@ class Proxy(proxy.BaseProxy): def list_users(self): return user.User.list(self.session) - def update_user(self, **data): - return user.User(data).update(self.session) + def update_user(self, value, **attrs): + """Update a user + + :param value: Either the id of a user or a + :class:`~openstack.compute.v2.user.User` instance. + :attrs kwargs: The attributes to update on the user represented + by ``value``. + + :returns: The updated user + :rtype: :class:`~openstack.compute.v2.user.User` + """ + return self._update(user.User, value, **attrs) def create_trust(self, **data): return trust.Trust(data).create(self.session) @@ -279,5 +361,15 @@ class Proxy(proxy.BaseProxy): def list_trusts(self): return trust.Trust.list(self.session) - def update_trust(self, **data): - return trust.Trust(data).update(self.session) + def update_trust(self, value, **attrs): + """Update a trust + + :param value: Either the id of a trust or a + :class:`~openstack.compute.v2.trust.Trust` instance. + :attrs kwargs: The attributes to update on the trust represented + by ``value``. + + :returns: The updated trust + :rtype: :class:`~openstack.compute.v2.trust.Trust` + """ + return self._update(trust.Trust, value, **attrs) diff --git a/openstack/tests/unit/identity/v2/test_proxy.py b/openstack/tests/unit/identity/v2/test_proxy.py index 2c23d7fb..ab5abad3 100644 --- a/openstack/tests/unit/identity/v2/test_proxy.py +++ b/openstack/tests/unit/identity/v2/test_proxy.py @@ -45,8 +45,13 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_roles) def test_role_update(self): - self.verify_update('openstack.identity.v2.role.Role.update', - self.proxy.update_role) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_role, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[role.Role, "resource_or_id"], + expected_kwargs=kwargs) def test_tenant_create(self): self.verify_create('openstack.identity.v2.tenant.Tenant.create', @@ -71,8 +76,13 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_tenants) def test_tenant_update(self): - self.verify_update('openstack.identity.v2.tenant.Tenant.update', - self.proxy.update_tenant) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_tenant, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[tenant.Tenant, "resource_or_id"], + expected_kwargs=kwargs) def test_user_create(self): self.verify_create('openstack.identity.v2.user.User.create', @@ -97,5 +107,10 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_users) def test_user_update(self): - self.verify_update('openstack.identity.v2.user.User.update', - self.proxy.update_user) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_user, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[user.User, "resource_or_id"], + expected_kwargs=kwargs) diff --git a/openstack/tests/unit/identity/v3/test_proxy.py b/openstack/tests/unit/identity/v3/test_proxy.py index 42a1816b..9458748b 100644 --- a/openstack/tests/unit/identity/v3/test_proxy.py +++ b/openstack/tests/unit/identity/v3/test_proxy.py @@ -54,9 +54,14 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_credentials) def test_credential_update(self): - self.verify_update( - 'openstack.identity.v3.credential.Credential.update', - self.proxy.update_credential) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_credential, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[credential.Credential, + "resource_or_id"], + expected_kwargs=kwargs) def test_domain_create(self): self.verify_create('openstack.identity.v3.domain.Domain.create', @@ -81,8 +86,13 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_domains) def test_domain_update(self): - self.verify_update('openstack.identity.v3.domain.Domain.update', - self.proxy.update_domain) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_domain, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[domain.Domain, "resource_or_id"], + expected_kwargs=kwargs) def test_endpoint_create(self): self.verify_create('openstack.identity.v3.endpoint.Endpoint.create', @@ -109,8 +119,14 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_endpoints) def test_endpoint_update(self): - self.verify_update('openstack.identity.v3.endpoint.Endpoint.update', - self.proxy.update_endpoint) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_endpoint, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[endpoint.Endpoint, + "resource_or_id"], + expected_kwargs=kwargs) def test_group_create(self): self.verify_create('openstack.identity.v3.group.Group.create', @@ -135,8 +151,13 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_groups) def test_group_update(self): - self.verify_update('openstack.identity.v3.group.Group.update', - self.proxy.update_group) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_group, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[group.Group, "resource_or_id"], + expected_kwargs=kwargs) def test_policy_create(self): self.verify_create('openstack.identity.v3.policy.Policy.create', @@ -161,8 +182,13 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_policys) def test_policy_update(self): - self.verify_update('openstack.identity.v3.policy.Policy.update', - self.proxy.update_policy) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_policy, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[policy.Policy, "resource_or_id"], + expected_kwargs=kwargs) def test_project_create(self): self.verify_create('openstack.identity.v3.project.Project.create', @@ -187,8 +213,13 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_projects) def test_project_update(self): - self.verify_update('openstack.identity.v3.project.Project.update', - self.proxy.update_project) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_project, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[project.Project, "resource_or_id"], + expected_kwargs=kwargs) def test_service_create(self): self.verify_create('openstack.identity.v3.service.Service.create', @@ -213,8 +244,13 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_services) def test_service_update(self): - self.verify_update('openstack.identity.v3.service.Service.update', - self.proxy.update_service) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_service, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[service.Service, "resource_or_id"], + expected_kwargs=kwargs) def test_user_create(self): self.verify_create('openstack.identity.v3.user.User.create', @@ -239,8 +275,13 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_users) def test_user_update(self): - self.verify_update('openstack.identity.v3.user.User.update', - self.proxy.update_user) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_user, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[user.User, "resource_or_id"], + expected_kwargs=kwargs) def test_trust_create(self): self.verify_create('openstack.identity.v3.trust.Trust.create', @@ -265,5 +306,10 @@ class TestIdentityProxy(test_proxy_base.TestProxyBase): self.proxy.list_trusts) def test_trust_update(self): - self.verify_update('openstack.identity.v3.trust.Trust.update', - self.proxy.update_trust) + kwargs = {"x": 1, "y": 2, "z": 3} + self.verify_update2('openstack.proxy.BaseProxy._update', + self.proxy.update_trust, + method_args=["resource_or_id"], + method_kwargs=kwargs, + expected_args=[trust.Trust, "resource_or_id"], + expected_kwargs=kwargs)