diff options
author | Angus Salkeld <asalkeld@mirantis.com> | 2014-10-27 10:23:33 +1000 |
---|---|---|
committer | Crag Wolfe <cwolfe@redhat.com> | 2015-11-12 04:06:47 +0000 |
commit | c5555a449dfa569df81ca699203ec83a22b1141d (patch) | |
tree | d9bc4a4d67b7d98c013ed41ebd10e4a22ef871e8 | |
parent | 788b2e3a7e68cd1190baebbb99e3149c864ee3b8 (diff) | |
download | heat-c5555a449dfa569df81ca699203ec83a22b1141d.tar.gz |
Validate nova server's metadata
This prevents "foo" getting passed into the metadata.
This can happen when using get_attr() to return a dynamic value.
Change-Id: I17eab659e65a51963e510add4d71fbc90a3a3a53
Closes-bug: #1338811
(cherry picked from commit 22df43e2f1e4dd6050e61f0808e6970b0cb05dac)
-rw-r--r-- | heat/engine/clients/os/nova.py | 5 | ||||
-rw-r--r-- | heat/tests/test_nova_client.py | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index 2be0eaf47..564f1c0a0 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -11,6 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. +import collections import email from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText @@ -369,6 +370,10 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers Serialize non-string metadata values before sending them to Nova. """ + if not isinstance(metadata, collections.Mapping): + raise exception.StackValidationFailed(message=_( + "nova server metadata needs to be a Map.")) + return dict((key, (value if isinstance(value, six.string_types) else json.dumps(value)) diff --git a/heat/tests/test_nova_client.py b/heat/tests/test_nova_client.py index dc55437c6..55fcc1843 100644 --- a/heat/tests/test_nova_client.py +++ b/heat/tests/test_nova_client.py @@ -15,6 +15,7 @@ import mock from novaclient import exceptions as nova_exceptions from oslo.config import cfg +import six import uuid from heat.common import exception @@ -232,6 +233,14 @@ class NovaUtilsMetadataTests(NovaClientPluginTestCase): expected = {'test_key': 'null'} self.assertEqual(expected, self.nova_plugin.meta_serialize(original)) + def test_serialize_no_value(self): + """This test is to prove that the user can only pass in a dict to nova + metadata. + """ + excp = self.assertRaises(exception.StackValidationFailed, + self.nova_plugin.meta_serialize, "foo") + self.assertIn('metadata needs to be a Map', six.text_type(excp)) + def test_serialize_combined(self): original = { 'test_key_1': 123, |