From f90193376fb4eb50ab7ceb5a0bd8f5014675887a Mon Sep 17 00:00:00 2001 From: Michael Ionkin Date: Fri, 18 Dec 2015 14:28:11 +0300 Subject: [PATCH] Added check for images tags The check that the image contains required tags is needed because of we added ability to chose base image for node group template Closes-bug: 1528182 Change-Id: I285fb0ba0df22b8c17c1cb6ea60469fc85fc3b0f --- .../validations/node_group_templates.py | 11 ++++ .../test_ng_template_validation_create.py | 53 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/sahara/service/validations/node_group_templates.py b/sahara/service/validations/node_group_templates.py index 8352a647..d2f02985 100644 --- a/sahara/service/validations/node_group_templates.py +++ b/sahara/service/validations/node_group_templates.py @@ -28,6 +28,11 @@ def check_node_group_template_create(data, **kwargs): data['hadoop_version']) b.check_node_group_basic_fields(data['plugin_name'], data['hadoop_version'], data) + if data.get('image_id'): + b.check_image_registered(data['image_id']) + b.check_required_image_tags(data['plugin_name'], + data['hadoop_version'], + data['image_id']) if data.get('shares'): shares.check_shares(data['shares']) @@ -77,6 +82,12 @@ def check_node_group_template_update(node_group_template_id, data, **kwargs): else: version = ngt.hadoop_version + if data.get('image_id'): + b.check_image_registered(data['image_id']) + b.check_required_image_tags(plugin, + version, + data['image_id']) + b.check_node_group_basic_fields(plugin, version, data) if data.get('shares'): diff --git a/sahara/tests/unit/service/validation/test_ng_template_validation_create.py b/sahara/tests/unit/service/validation/test_ng_template_validation_create.py index a50dce39..39a88c39 100644 --- a/sahara/tests/unit/service/validation/test_ng_template_validation_create.py +++ b/sahara/tests/unit/service/validation/test_ng_template_validation_create.py @@ -236,6 +236,59 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase): "Requested flavor '1' not found") ) + def test_ng_template_create_validate_image(self): + self._assert_create_object_validation( + data={ + 'name': 'test-ng', + 'flavor_id': '42', + 'plugin_name': 'fake', + 'hadoop_version': '0.1', + 'node_processes': ['namenode'], + 'image_id': '12345' + }, + bad_req_i=(1, 'VALIDATION_ERROR', + "'12345' is not a 'uuid'") + ) + self._assert_create_object_validation( + data={ + 'name': 'test-ng', + 'flavor_id': '42', + 'plugin_name': 'fake', + 'hadoop_version': '0.1', + 'node_processes': ['namenode'], + 'image_id': '12345678-1234-1234-1234-123456789000' + }, + bad_req_i=(1, 'INVALID_REFERENCE', + "Requested image " + "'12345678-1234-1234-1234-123456789000' " + "is not registered") + ) + self._assert_create_object_validation( + data={ + 'name': 'test-ng', + 'flavor_id': '42', + 'plugin_name': 'fake', + 'hadoop_version': '0.1', + 'node_processes': ['namenode'], + 'image_id': '813fe450-40d2-4acc-ade5-ea753a1bd5bc' + }, + bad_req_i=(1, 'INVALID_REFERENCE', + "Requested image " + "'813fe450-40d2-4acc-ade5-ea753a1bd5bc' " + "doesn't contain required tags: " + "['0.1']") + ) + self._assert_create_object_validation( + data={ + 'name': 'test-ng', + 'flavor_id': '42', + 'plugin_name': 'fake', + 'hadoop_version': '0.1', + 'node_processes': ['namenode'], + 'image_id': '550e8400-e29b-41d4-a716-446655440000' + } + ) + def test_ng_template_create_v_ng_configs(self): self._assert_create_object_validation( data={