Switch put_update to patch_update

As PUT updates are the great majority, and PATCH is only used in a
handful of places, swap out this name and the behavior so that PUT is
the default. Identity v3 and one resource in Image v2 use PATCH for
their updates, so they enable it.

Change-Id: I3f7ed19f050a0c6477f1b91112ff2dc4e1fc2528
Closes-Bug: 1427479
This commit is contained in:
Brian Curtin
2015-06-10 13:18:28 -05:00
parent 139c27fbd1
commit dbcc1934ed
32 changed files with 26 additions and 37 deletions

View File

@@ -31,8 +31,6 @@ class Server(resource.Resource):
allow_delete = True
allow_list = True
put_update = True
# Properties
access_ipv4 = resource.prop('accessIPv4')
access_ipv6 = resource.prop('accessIPv6')

View File

@@ -26,6 +26,7 @@ class Credential(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
blob = resource.prop('blob')

View File

@@ -26,6 +26,7 @@ class Domain(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
description = resource.prop('description')

View File

@@ -26,6 +26,7 @@ class Endpoint(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
enabled = resource.prop('enabled', type=bool)

View File

@@ -26,6 +26,7 @@ class Group(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
description = resource.prop('description')

View File

@@ -26,6 +26,7 @@ class Policy(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
blob = resource.prop('blob')

View File

@@ -26,6 +26,7 @@ class Project(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
description = resource.prop('description')

View File

@@ -26,6 +26,7 @@ class Service(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
description = resource.prop('description')

View File

@@ -26,6 +26,7 @@ class User(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
default_project_id = resource.prop('default_project_id')

View File

@@ -25,6 +25,7 @@ class Image(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
patch_update = True
# Properties
checksum = resource.prop('checksum')

View File

@@ -28,7 +28,6 @@ class FloatingIP(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The fixed IP address associated with the floating IP. If you

View File

@@ -26,7 +26,6 @@ class HealthMonitor(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The administrative state of the health monitor, which is up

View File

@@ -26,7 +26,6 @@ class Listener(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The administrative state of the listener, which is up

View File

@@ -26,7 +26,6 @@ class LoadBalancer(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The administrative state of the load_balancer, which is up

View File

@@ -26,7 +26,6 @@ class MeteringLabel(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: Description of the label.

View File

@@ -26,7 +26,6 @@ class MeteringLabelRule(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: ingress or egress: The direction in which metering rule is

View File

@@ -26,7 +26,6 @@ class Network(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The administrative state of the network, which is up ``True`` or

View File

@@ -26,7 +26,6 @@ class Pool(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The administrative state of the pool, which is up ``True`` or down

View File

@@ -26,7 +26,6 @@ class PoolMember(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
# TODO(briancurtin): I can't find where this is documented.

View File

@@ -26,7 +26,6 @@ class Port(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The administrative state of the port, which is up ``True`` or

View File

@@ -27,7 +27,6 @@ class Router(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The administrative state of the router, which is up ``True``

View File

@@ -27,7 +27,6 @@ class SecurityGroup(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The security group description.

View File

@@ -26,7 +26,6 @@ class SecurityGroupRule(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: ``ingress`` or ``egress``: The direction in which the security group

View File

@@ -26,7 +26,6 @@ class Subnet(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The start and end addresses for the allocation pools.

View File

@@ -26,7 +26,6 @@ class VPNService(resource.Resource):
allow_update = True
allow_delete = True
allow_list = True
put_update = True
# Properties
#: The administrative state of the vpnservice, which is up ``True`` or

View File

@@ -234,7 +234,7 @@ class Resource(collections.MutableMapping):
#: Allow head operation for this resource.
allow_head = False
put_update = False
patch_update = False
def __init__(self, attrs=None, loaded=False):
"""Construct a Resource to interact with a service's REST API.
@@ -742,10 +742,10 @@ class Resource(collections.MutableMapping):
args = {'json': body}
if headers:
args[HEADERS] = headers
if cls.put_update:
resp = session.put(url, service=cls.service, **args).body
else:
if cls.patch_update:
resp = session.patch(url, service=cls.service, **args).body
else:
resp = session.put(url, service=cls.service, **args).body
if cls.resource_key:
resp = resp[cls.resource_key]

View File

@@ -59,7 +59,6 @@ class TestServer(testtools.TestCase):
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
self.assertTrue(sot.put_update)
def test_make_it(self):
sot = server.Server(EXAMPLE)

View File

@@ -40,7 +40,6 @@ class TestVPNService(testtools.TestCase):
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
self.assertTrue(sot.put_update)
def test_make_it(self):
sot = vpn_service.VPNService(EXAMPLE)

View File

@@ -192,12 +192,12 @@ class TestConnectionObjectMethods(base.TestCase):
test = TestResource.existing(**self.args)
test['name'] = 'newname'
self.body = {'testable': {'name': 'newname'}}
self.conn.session.patch = mock.MagicMock()
self.conn.session.patch.and_return = self.response
self.conn.session.put = mock.MagicMock()
self.conn.session.put.and_return = self.response
self.assertEqual(test, self.conn.update(test))
url = 'testables/fie'
self.conn.session.patch.assert_called_with(url, json=self.body,
service=test.service)
self.conn.session.put.assert_called_with(url, json=self.body,
service=test.service)
def test_obj_delete(self):
test = TestResource.existing(**self.args)

View File

@@ -245,7 +245,7 @@ class HeaderTests(base.TestCase):
response.body = {'id': 1}
sess = mock.MagicMock()
sess.post = mock.MagicMock(return_value=response)
sess.patch = mock.MagicMock(return_value=response)
sess.put = mock.MagicMock(return_value=response)
sot.create(sess)
headers = {'guitar': 'johnny', 'bass': 'deedee'}
@@ -258,10 +258,10 @@ class HeaderTests(base.TestCase):
sot.letsgo = "cj"
headers = {'guitar': 'johnny', 'bass': 'cj'}
sot.update(sess)
sess.patch.assert_called_with('ramones/1',
service=HeaderTests.Test.service,
headers=headers,
json={})
sess.put.assert_called_with('ramones/1',
service=HeaderTests.Test.service,
headers=headers,
json={})
class ResourceTests(base.TestTransportBase):
@@ -472,7 +472,7 @@ class ResourceTests(base.TestTransportBase):
attrs, json_body):
class FakeResource2(FakeResource):
put_update = False
patch_update = True
resource_key = key
service = "my_service"
@@ -650,7 +650,7 @@ class ResourceTests(base.TestTransportBase):
def test_patch_update(self):
class FakeResourcePatch(FakeResource):
put_update = False
patch_update = True
resp = mock.Mock(body=fake_body)
self.session.patch = mock.Mock(return_value=resp)
@@ -681,7 +681,8 @@ class ResourceTests(base.TestTransportBase):
def test_put_update(self):
class FakeResourcePut(FakeResource):
put_update = True
# This is False by default, but explicit for this test.
patch_update = False
resp = mock.Mock(body=fake_body)
self.session.put = mock.Mock(return_value=resp)

View File

@@ -25,7 +25,6 @@ class Snapshot(resource.Resource):
allow_create = True
allow_delete = True
allow_update = True
put_update = True
# Properties
#: A UUID representing this snapshot.

View File

@@ -25,7 +25,6 @@ class Volume(resource.Resource):
allow_create = True
allow_delete = True
allow_update = True
put_update = True
# Properties
#: A UUID representing this volume.