diff --git a/openstack/resource.py b/openstack/resource.py index b4a1ed4d..de235464 100644 --- a/openstack/resource.py +++ b/openstack/resource.py @@ -248,15 +248,11 @@ class Resource(collections.MutableMapping): :param bool loaded: ``True`` if this Resource exists on the server, ``False`` if it does not. """ - if attrs is None: - attrs = {} - - self._dirty = set() if loaded else set(attrs.keys()) + self._attrs = {} if attrs is None else attrs.copy() + self._dirty = set() if loaded else set(self._attrs.keys()) + self.update_attrs(self._attrs) self._loaded = loaded - self._attrs = attrs - self.update_attrs(attrs) - def __repr__(self): return "%s.%s(attrs=%s, loaded=%s)" % (self.__module__, self.__class__.__name__, diff --git a/openstack/telemetry/v2/sample.py b/openstack/telemetry/v2/sample.py index 8a3159c0..ae6a5031 100644 --- a/openstack/telemetry/v2/sample.py +++ b/openstack/telemetry/v2/sample.py @@ -58,7 +58,9 @@ class Sample(resource.Resource): def create(self, session): url = self._get_url(self) # telemetry expects a list of samples - resp = session.post(url, service=self.service, json=[self._attrs]) + attrs = self._attrs.copy() + attrs.pop('meter', None) + resp = session.post(url, service=self.service, json=[attrs]) self.update_attrs(**resp.body.pop()) self._reset_dirty() return self diff --git a/openstack/tests/unit/cluster/v1/test_cluster.py b/openstack/tests/unit/cluster/v1/test_cluster.py index 594850dc..14e5c543 100644 --- a/openstack/tests/unit/cluster/v1/test_cluster.py +++ b/openstack/tests/unit/cluster/v1/test_cluster.py @@ -78,7 +78,7 @@ class TestCluster(testtools.TestCase): def test_instantiate(self): sot = cluster.Cluster(FAKE) - self.assertEqual(FAKE['id'], sot.id) + self.assertIsNone(sot.id) self.assertEqual(FAKE['name'], sot.name) self.assertEqual(FAKE['profile_id'], sot.profile_id) diff --git a/openstack/tests/unit/orchestration/v1/test_stack.py b/openstack/tests/unit/orchestration/v1/test_stack.py index 33e98841..76f51e6b 100644 --- a/openstack/tests/unit/orchestration/v1/test_stack.py +++ b/openstack/tests/unit/orchestration/v1/test_stack.py @@ -93,9 +93,9 @@ class TestStack(testtools.TestCase): sot.create(sess) url = '/stacks' - body = FAKE.copy() - body.pop('id') - body.pop('name') + body = sot._attrs.copy() + body.pop('id', None) + body.pop('name', None) sess.post.assert_called_with(url, service=sot.service, json=body) self.assertEqual(FAKE_ID, sot.id) self.assertEqual(FAKE_NAME, sot.name) diff --git a/openstack/tests/unit/telemetry/v2/test_sample.py b/openstack/tests/unit/telemetry/v2/test_sample.py index a72ecd0b..e1191074 100644 --- a/openstack/tests/unit/telemetry/v2/test_sample.py +++ b/openstack/tests/unit/telemetry/v2/test_sample.py @@ -135,5 +135,5 @@ class TestSample(testtools.TestCase): new_sample.create(sess) url = '/meters/temperature' sess.post.assert_called_with(url, service=new_sample.service, - json=[SAMPLE]) + json=[data]) self.assertIsNone(new_sample.id)