Update attributes uses hard coded id
This is the last one of these I hope, but I just noticed that update attributes is using a hard coded id instead of id_attribute. Telemetry sample was doing some very messed up things around this bug which is tracked in the bug #1488271. Change-Id: I3a4725c7cc4ace0b83b3ad19e687b5c544c4a5f6
This commit is contained in:
parent
5d723e1d26
commit
d7e5dabcb3
|
@ -451,14 +451,15 @@ class Resource(collections.MutableMapping):
|
|||
|
||||
# ensure setters are called for type coercion
|
||||
for key, value in itertools.chain(dict(*args).items(), kwargs.items()):
|
||||
if key != "id": # id property is read only
|
||||
if key != self.id_attribute: # id property is read only
|
||||
|
||||
# Don't allow None values to override a key unless we've
|
||||
# explicitly specified they can. Proxy methods have default
|
||||
# None arguments that we don't want to override any values
|
||||
# that may have been passed in on Resource instances.
|
||||
if not all([ignore_none, value is None]):
|
||||
setattr(self, key, value)
|
||||
if key != "id":
|
||||
setattr(self, key, value)
|
||||
self[key] = value
|
||||
|
||||
def get_headers(self):
|
||||
|
|
|
@ -34,8 +34,6 @@ class Sample(resource.Resource):
|
|||
recorded_at = resource.prop('recorded_at')
|
||||
#: The Resource this sample was taken for
|
||||
resource_id = resource.prop('resource_id')
|
||||
#: The unique identifier for the sample
|
||||
sample_id = resource.prop('id', alias='message_id')
|
||||
#: The source that identifies where the sample comes from
|
||||
source = resource.prop('source')
|
||||
#: When the sample has been generated
|
||||
|
|
|
@ -20,7 +20,6 @@ FAKE = {
|
|||
'cluster_name': 'test_cluster',
|
||||
'data': {'purpose': 'unknown'},
|
||||
'enabled': True,
|
||||
'id': 'c378e474-d091-43a3-b083-e19719291358',
|
||||
'policy_id': 'ac5415bd-f522-4160-8be0-f8853e4bc332',
|
||||
'policy_name': 'dp01',
|
||||
'policy_type': 'senlin.poicy.deletion-1.0',
|
||||
|
|
|
@ -16,7 +16,7 @@ import testtools
|
|||
from openstack.telemetry.v2 import sample
|
||||
|
||||
SAMPLE = {
|
||||
'id': None,
|
||||
'sample_id': '0',
|
||||
'metadata': {'1': 'one'},
|
||||
'counter_name': '2',
|
||||
'project_id': '3',
|
||||
|
@ -35,7 +35,7 @@ OLD_SAMPLE = {
|
|||
'counter_type': '2',
|
||||
'counter_unit': '3',
|
||||
'counter_volume': '4',
|
||||
'message_id': None,
|
||||
'message_id': '0',
|
||||
'project_id': '5',
|
||||
'recorded_at': '6',
|
||||
'resource_id': '7',
|
||||
|
@ -62,13 +62,12 @@ class TestSample(testtools.TestCase):
|
|||
|
||||
def test_make_new(self):
|
||||
sot = sample.Sample(SAMPLE)
|
||||
self.assertIsNone(sot.id)
|
||||
self.assertEqual(SAMPLE['sample_id'], sot.id)
|
||||
self.assertEqual(SAMPLE['metadata'], sot.metadata)
|
||||
self.assertEqual(SAMPLE['counter_name'], sot.counter_name)
|
||||
self.assertEqual(SAMPLE['project_id'], sot.project_id)
|
||||
self.assertEqual(SAMPLE['recorded_at'], sot.recorded_at)
|
||||
self.assertEqual(SAMPLE['resource_id'], sot.resource_id)
|
||||
self.assertIsNone(sot.sample_id)
|
||||
self.assertEqual(SAMPLE['source'], sot.source)
|
||||
self.assertEqual(SAMPLE['timestamp'], sot.generated_at)
|
||||
self.assertEqual(SAMPLE['type'], sot.type)
|
||||
|
@ -79,7 +78,6 @@ class TestSample(testtools.TestCase):
|
|||
def test_make_old(self):
|
||||
sot = sample.Sample(OLD_SAMPLE)
|
||||
self.assertIsNone(sot.id)
|
||||
self.assertIsNone(sot.sample_id),
|
||||
self.assertEqual(OLD_SAMPLE['counter_name'], sot.counter_name)
|
||||
self.assertEqual(OLD_SAMPLE['counter_type'], sot.type)
|
||||
self.assertEqual(OLD_SAMPLE['counter_unit'], sot.unit)
|
||||
|
@ -101,8 +99,7 @@ class TestSample(testtools.TestCase):
|
|||
|
||||
found = sample.Sample.list(sess, path_args=path_args)
|
||||
first = next(found)
|
||||
self.assertIsNone(first.id)
|
||||
self.assertIsNone(first.sample_id)
|
||||
self.assertEqual(SAMPLE['sample_id'], first.id)
|
||||
self.assertEqual(SAMPLE['metadata'], first.metadata)
|
||||
self.assertEqual(SAMPLE['counter_name'], first.counter_name)
|
||||
self.assertEqual(SAMPLE['project_id'], first.project_id)
|
||||
|
@ -123,7 +120,7 @@ class TestSample(testtools.TestCase):
|
|||
resp.json = mock.Mock(return_value=[SAMPLE])
|
||||
sess.post = mock.Mock(return_value=resp)
|
||||
|
||||
data = {'id': None,
|
||||
data = {'sample_id': None,
|
||||
'counter_name': 'temperature',
|
||||
'project_id': 'project',
|
||||
'resource_id': 'resource',
|
||||
|
|
Loading…
Reference in New Issue