diff --git a/sahara/exceptions.py b/sahara/exceptions.py index 28d8c72f..3a5d4bd9 100644 --- a/sahara/exceptions.py +++ b/sahara/exceptions.py @@ -74,14 +74,14 @@ class InvalidCredentials(SaharaException): super(InvalidCredentials, self).__init__() -class InvalidException(SaharaException): +class InvalidReferenceException(SaharaException): message = _("Invalid object reference") def __init__(self, message=None): self.code = "INVALID_REFERENCE" if message: self.message = message - super(InvalidException, self).__init__() + super(InvalidReferenceException, self).__init__() class RemoteCommandException(SaharaException): diff --git a/sahara/plugins/hdp/versions/version_1_3_2/versionhandler.py b/sahara/plugins/hdp/versions/version_1_3_2/versionhandler.py index eacf083f..9c6b4886 100644 --- a/sahara/plugins/hdp/versions/version_1_3_2/versionhandler.py +++ b/sahara/plugins/hdp/versions/version_1_3_2/versionhandler.py @@ -626,9 +626,9 @@ class AmbariClient(object): def decommission_cluster_instances(self, cluster, clusterspec, instances, ambari_info): - raise exc.InvalidException(_('The HDP plugin does not support ' - 'the decommissioning of nodes ' - 'for HDP version 1.3.2')) + raise exc.InvalidDataException(_('The HDP plugin does not support ' + 'the decommissioning of nodes ' + 'for HDP version 1.3.2')) def provision_cluster(self, cluster_spec, servers, ambari_info, name): self._add_cluster(ambari_info, name) diff --git a/sahara/plugins/hdp/versions/version_2_0_6/versionhandler.py b/sahara/plugins/hdp/versions/version_2_0_6/versionhandler.py index 35ac7f11..5fccdb63 100644 --- a/sahara/plugins/hdp/versions/version_2_0_6/versionhandler.py +++ b/sahara/plugins/hdp/versions/version_2_0_6/versionhandler.py @@ -658,7 +658,7 @@ class AmbariClient(object): if result.status_code != 202: LOG.error(_LE('AmbariClient: error while making decommission post ' 'request. Error is = %s'), result.text) - raise exc.InvalidException( + raise ex.DecommissionError( _('An error occurred while trying to ' 'decommission the DataNode instances that are ' 'being shut down. ' diff --git a/sahara/service/validations/base.py b/sahara/service/validations/base.py index 07b80d44..8ab4fef2 100644 --- a/sahara/service/validations/base.py +++ b/sahara/service/validations/base.py @@ -53,20 +53,20 @@ def _get_plugin_configs(plugin_name, hadoop_version, scope=None): def check_plugin_name_exists(name): if name not in [p.name for p in api.get_plugins()]: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Sahara doesn't contain plugin with name '%s'") % name) def check_plugin_supports_version(p_name, version): if version not in plugin_base.PLUGINS.get_plugin(p_name).get_versions(): - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Requested plugin '%(name)s' doesn't support version " "'%(version)s'") % {'name': p_name, 'version': version}) def check_image_registered(image_id): if image_id not in [i.id for i in nova.client().images.list_registered()]: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Requested image '%s' is not registered") % image_id) @@ -77,12 +77,12 @@ def check_node_group_configs(plugin_name, hadoop_version, ng_configs, hadoop_version) for app_target, configs in ng_configs.items(): if app_target not in pl_confs: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Plugin doesn't contain applicable target '%s'") % app_target) for name, values in configs.items(): if name not in pl_confs[app_target]: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Plugin's applicable target '%(target)s' doesn't " "contain config with name '%(name)s'") % {'target': app_target, 'name': name}) @@ -151,8 +151,8 @@ def check_node_group_basic_fields(plugin_name, hadoop_version, ng, def check_flavor_exists(flavor_id): flavor_list = nova.client().flavors.list() if flavor_id not in [flavor.id for flavor in flavor_list]: - raise ex.InvalidException( - _("Requested flavor '%s' not found") % flavor_id) + raise ex.NotFoundException( + flavor_id, _("Requested flavor '%s' not found")) def check_security_groups_exist(security_groups): @@ -162,7 +162,8 @@ def check_security_groups_exist(security_groups): for sg in security_group_list], [])) for sg in security_groups: if sg not in allowed_groups: - raise ex.InvalidException(_("Security group '%s' not found") % sg) + raise ex.NotFoundException( + sg, _("Security group '%s' not found")) def check_floatingip_pool_exists(ng_name, pool_id): @@ -176,14 +177,12 @@ def check_floatingip_pool_exists(ng_name, pool_id): break if not network: - raise ex.InvalidException( - _("Floating IP pool %(pool)s for node group '%(group)s' " - "not found") % {'pool': pool_id, 'group': ng_name}) + raise ex.NotFoundException(pool_id, _("Floating IP pool %s not found")) def check_node_processes(plugin_name, version, node_processes): if len(set(node_processes)) != len(node_processes): - raise ex.InvalidException( + raise ex.InvalidDataException( _("Duplicates in node processes have been detected")) plugin_processes = [] for process in plugin_base.PLUGINS.get_plugin( @@ -191,7 +190,7 @@ def check_node_processes(plugin_name, version, node_processes): plugin_processes += process if not set(node_processes).issubset(set(plugin_processes)): - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Plugin supports the following node procesess: %s") % sorted(plugin_processes)) @@ -199,7 +198,7 @@ def check_node_processes(plugin_name, version, node_processes): def check_duplicates_node_groups_names(node_groups): ng_names = [ng['name'] for ng in node_groups] if len(set(ng_names)) < len(node_groups): - raise ex.InvalidException( + raise ex.InvalidDataException( _("Duplicates in node group names are detected")) @@ -207,16 +206,16 @@ def check_availability_zone_exist(az): az_list = nova.client().availability_zones.list(False) az_names = [a.zoneName for a in az_list] if az not in az_names: - raise ex.InvalidException(_("Nova availability zone '%s' not found") - % az) + raise ex.NotFoundException( + az, _("Nova availability zone '%s' not found")) def check_volume_availability_zone_exist(az): az_list = cinder.client().availability_zones.list() az_names = [a.zoneName for a in az_list] if az not in az_names: - raise ex.InvalidException(_("Cinder availability zone '%s' not found") - % az) + raise ex.NotFoundException( + az, _("Cinder availability zone '%s' not found")) def check_volume_type_exists(volume_type): @@ -224,7 +223,7 @@ def check_volume_type_exists(volume_type): volume_type}) if len(volume_types) == 1 and volume_types[0] == volume_type: return - raise ex.NotFoundException(_("Volume type '%s' not found") % volume_type) + raise ex.NotFoundException(volume_type, _("Volume type '%s' not found")) # Cluster creation related checks @@ -252,7 +251,7 @@ def check_cluster_hostnames_lengths(cluster_name, node_groups): longest_hostname += '.' longest_hostname += CONF.node_domain if len(longest_hostname) > MAX_HOSTNAME_LENGTH: - raise ex.InvalidException( + raise ex.InvalidDataException( _("Composite hostname %(host)s in provisioned cluster exceeds" " maximum limit %(limit)s characters") % {'host': longest_hostname, @@ -263,13 +262,13 @@ def check_keypair_exists(keypair): try: nova.client().keypairs.get(keypair) except nova_ex.NotFound: - raise ex.InvalidException( - _("Requested keypair '%s' not found") % keypair) + raise ex.NotFoundException( + keypair, _("Requested keypair '%s' not found")) def check_network_exists(net_id): if not nova.get_network(id=net_id): - raise ex.InvalidException(_("Network %s not found") % net_id) + raise ex.NotFoundException(net_id, _("Network %s not found")) # Cluster templates related checks @@ -282,9 +281,9 @@ def check_cluster_template_unique_name(name): def check_cluster_template_exists(cluster_template_id): if not api.get_cluster_template(id=cluster_template_id): - raise ex.InvalidException( - _("Cluster template with id '%s' doesn't exist") - % cluster_template_id) + raise ex.NotFoundException( + cluster_template_id, + _("Cluster template with id '%s' not found")) def check_node_groups_in_cluster_templates(cluster_name, plugin_name, @@ -308,8 +307,8 @@ def check_node_group_template_unique_name(name): def check_node_group_template_exists(ng_tmpl_id): if not api.get_node_group_template(id=ng_tmpl_id): - raise ex.InvalidException( - _("NodeGroup template with id '%s' doesn't exist") % ng_tmpl_id) + raise ex.NotFoundException( + ng_tmpl_id, _("NodeGroup template with id '%s' not found")) def check_network_config(node_groups): @@ -343,7 +342,7 @@ def check_resize(cluster, r_node_groups): for ng in r_node_groups: if ng['name'] not in cluster_ng_names: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Cluster doesn't contain node group with name '%s'") % ng['name']) @@ -357,7 +356,7 @@ def check_add_node_groups(cluster, add_node_groups): for ng in add_node_groups: if ng['name'] in cluster_ng_names: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Can't add new nodegroup. Cluster already has nodegroup with" " name '%s'") % ng['name']) @@ -371,7 +370,7 @@ def check_cinder_exists(): services = [service.name for service in keystone.client_for_admin().services.list()] if 'cinder' not in services: - raise ex.InvalidException(_("Cinder is not supported")) + raise ex.InvalidReferenceException(_("Cinder is not supported")) # Tags @@ -382,7 +381,7 @@ def check_required_image_tags(plugin_name, hadoop_version, image_id): plugin = plugin_base.PLUGINS.get_plugin(plugin_name) req_tags = set(plugin.get_required_image_tags(hadoop_version)) if not req_tags.issubset(set(image.tags)): - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Tags of requested image '%(image)s' don't contain required" " tags ['%(name)s', '%(version)s']") % {'image': image_id, 'name': plugin_name, diff --git a/sahara/service/validations/cluster_templates.py b/sahara/service/validations/cluster_templates.py index f38b648b..f1ab94a0 100644 --- a/sahara/service/validations/cluster_templates.py +++ b/sahara/service/validations/cluster_templates.py @@ -133,7 +133,7 @@ def check_cluster_template_usage(cluster_template_id, **kwargs): users.append(cluster.name) if users: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Cluster template %(id)s in use by %(clusters)s") % {'id': cluster_template_id, 'clusters': ', '.join(users)}) diff --git a/sahara/service/validations/clusters.py b/sahara/service/validations/clusters.py index f48f3fbf..50314222 100644 --- a/sahara/service/validations/clusters.py +++ b/sahara/service/validations/clusters.py @@ -87,7 +87,7 @@ def check_cluster_create(data, **kwargs): neutron_net_id = _get_cluster_field(data, 'neutron_management_network') if neutron_net_id: if not CONF.use_neutron: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("'neutron_management_network' field can't be used " "with 'use_neutron=False'")) b.check_network_exists(neutron_net_id) diff --git a/sahara/service/validations/clusters_scaling.py b/sahara/service/validations/clusters_scaling.py index d863131b..90ecf0c2 100644 --- a/sahara/service/validations/clusters_scaling.py +++ b/sahara/service/validations/clusters_scaling.py @@ -76,14 +76,14 @@ def check_cluster_scaling(data, cluster_id, **kwargs): engine_type_and_version = api.OPS.get_engine_type_and_version() if (not cluster_engine and not engine_type_and_version.startswith('direct')): - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Cluster created before Juno release " "can't be scaled with %(engine)s engine") % {"engine": engine_type_and_version}) if (cluster.sahara_info and cluster_engine != engine_type_and_version): - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Cluster created with %(old_engine)s infrastructure engine " "can't be scaled with %(new_engine)s engine") % {"old_engine": cluster.sahara_info.get('infrastructure_engine'), @@ -93,12 +93,12 @@ def check_cluster_scaling(data, cluster_id, **kwargs): 'scale_cluster') and ( plugin_base.PLUGINS.is_plugin_implements(cluster.plugin_name, 'decommission_nodes'))): - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Requested plugin '%s' doesn't support cluster scaling feature") % cluster.plugin_name) if cluster.status != 'Active': - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Cluster cannot be scaled not in 'Active' status. " "Cluster status: %s") % cluster.status) diff --git a/sahara/service/validations/edp/base.py b/sahara/service/validations/edp/base.py index a2143b5d..eea78ee3 100644 --- a/sahara/service/validations/edp/base.py +++ b/sahara/service/validations/edp/base.py @@ -56,8 +56,8 @@ def check_data_source_unique_name(name): def check_data_source_exists(data_source_id): if not conductor.data_source_get(context.ctx(), data_source_id): - raise ex.InvalidException(_("DataSource with id '%s'" - " doesn't exist") % data_source_id) + raise ex.InvalidReferenceException( + _("DataSource with id '%s' doesn't exist") % data_source_id) def check_job_unique_name(name): @@ -68,8 +68,8 @@ def check_job_unique_name(name): def check_job_binary_internal_exists(jbi_id): if not conductor.job_binary_internal_get(context.ctx(), jbi_id): - raise ex.InvalidException(_("JobBinaryInternal with id '%s'" - " doesn't exist") % jbi_id) + raise ex.InvalidReferenceException( + _("JobBinaryInternal with id '%s' doesn't exist") % jbi_id) def check_data_sources_are_different(data_source_1_id, data_source_2_id): diff --git a/sahara/service/validations/edp/data_source.py b/sahara/service/validations/edp/data_source.py index 1b088e16..2fd0e0b7 100644 --- a/sahara/service/validations/edp/data_source.py +++ b/sahara/service/validations/edp/data_source.py @@ -67,10 +67,10 @@ def check_data_source_create(data, **kwargs): def _check_swift_data_source_create(data): if len(data['url']) == 0: - raise ex.InvalidException(_("Swift url must not be empty")) + raise ex.InvalidDataException(_("Swift url must not be empty")) url = urlparse.urlparse(data['url']) if url.scheme != "swift": - raise ex.InvalidException(_("URL scheme must be 'swift'")) + raise ex.InvalidDataException(_("URL scheme must be 'swift'")) # The swift url suffix does not have to be included in the netloc. # However, if the swift suffix indicator is part of the netloc then @@ -78,7 +78,7 @@ def _check_swift_data_source_create(data): # Additionally, the path must be more than '/' if (su.SWIFT_URL_SUFFIX_START in url.netloc and not url.netloc.endswith( su.SWIFT_URL_SUFFIX)) or len(url.path) <= 1: - raise ex.InvalidException( + raise ex.InvalidDataException( _("URL must be of the form swift://container%s/object") % su.SWIFT_URL_SUFFIX) @@ -96,20 +96,20 @@ def _check_swift_data_source_create(data): def _check_hdfs_data_source_create(data): if len(data['url']) == 0: - raise ex.InvalidException(_("HDFS url must not be empty")) + raise ex.InvalidDataException(_("HDFS url must not be empty")) url = urlparse.urlparse(data['url']) if url.scheme: if url.scheme != "hdfs": - raise ex.InvalidException(_("URL scheme must be 'hdfs'")) + raise ex.InvalidDataException(_("URL scheme must be 'hdfs'")) if not url.hostname: - raise ex.InvalidException(_("HDFS url is incorrect, " - "cannot determine a hostname")) + raise ex.InvalidDataException( + _("HDFS url is incorrect, cannot determine a hostname")) def _check_maprfs_data_source_create(data): if len(data['url']) == 0: - raise ex.InvalidException(_("MapR FS url must not be empty")) + raise ex.InvalidDataException(_("MapR FS url must not be empty")) url = urlparse.urlparse(data['url']) if url.scheme: if url.scheme != "maprfs": - raise ex.InvalidException(_("URL scheme must be 'maprfs'")) + raise ex.InvalidDataException(_("URL scheme must be 'maprfs'")) diff --git a/sahara/service/validations/edp/job_execution.py b/sahara/service/validations/edp/job_execution.py index 4f4081c5..c87efc38 100644 --- a/sahara/service/validations/edp/job_execution.py +++ b/sahara/service/validations/edp/job_execution.py @@ -79,7 +79,7 @@ def check_job_execution(data, job_id): cluster = conductor.cluster_get(ctx, data['cluster_id']) if not cluster: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Cluster with id '%s' doesn't exist") % data['cluster_id']) job = conductor.job_get(ctx, job_id) @@ -87,7 +87,7 @@ def check_job_execution(data, job_id): plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name) edp_engine = plugin.get_edp_engine(cluster, job.type) if not edp_engine: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Cluster with id '%(cluster_id)s' doesn't support job type " "'%(job_type)s'") % {"cluster_id": cluster.id, "job_type": job.type}) diff --git a/sahara/service/validations/node_group_templates.py b/sahara/service/validations/node_group_templates.py index e4936c78..415637b4 100644 --- a/sahara/service/validations/node_group_templates.py +++ b/sahara/service/validations/node_group_templates.py @@ -125,7 +125,7 @@ def check_node_group_template_usage(node_group_template_id, **kwargs): template_users += [cluster_template.name] if cluster_users or template_users: - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Node group template %(template)s is in use by " "cluster templates: %(users)s; and clusters: %(clusters)s") % {'template': node_group_template_id, diff --git a/sahara/service/validations/plugins.py b/sahara/service/validations/plugins.py index efff5347..540dab26 100644 --- a/sahara/service/validations/plugins.py +++ b/sahara/service/validations/plugins.py @@ -23,6 +23,6 @@ CONVERT_TO_TEMPLATE_SCHEMA = None def check_convert_to_template(plugin_name, version, **kwargs): if not plugin_base.PLUGINS.is_plugin_implements(plugin_name, 'convert'): - raise ex.InvalidException( + raise ex.InvalidReferenceException( _("Requested plugin '%s' doesn't support converting config files " "to cluster templates") % plugin_name) diff --git a/sahara/tests/unit/service/validation/edp/test_data_source.py b/sahara/tests/unit/service/validation/edp/test_data_source.py index ef62e37e..71c433a2 100644 --- a/sahara/tests/unit/service/validation/edp/test_data_source.py +++ b/sahara/tests/unit/service/validation/edp/test_data_source.py @@ -119,7 +119,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "swift", "description": "incorrect url schema" } - with testtools.ExpectedException(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidDataException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -152,7 +152,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "swift", "description": "incorrect url schema" } - with testtools.ExpectedException(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidDataException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -167,7 +167,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "swift", "description": "incorrect url schema" } - with testtools.ExpectedException(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidDataException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -181,7 +181,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "hdfs", "description": "incorrect url schema" } - with testtools.ExpectedException(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidDataException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." @@ -232,7 +232,7 @@ class TestDataSourceValidation(u.ValidationTestCase): "type": "maprfs", "description": "incorrect url schema" } - with testtools.ExpectedException(ex.InvalidException): + with testtools.ExpectedException(ex.InvalidDataException): ds.check_data_source_create(data) @mock.patch("sahara.service.validations." diff --git a/sahara/tests/unit/service/validation/test_cluster_create_validation.py b/sahara/tests/unit/service/validation/test_cluster_create_validation.py index 2183236e..64e15dd7 100644 --- a/sahara/tests/unit/service/validation/test_cluster_create_validation.py +++ b/sahara/tests/unit/service/validation/test_cluster_create_validation.py @@ -117,7 +117,7 @@ class TestClusterCreateValidation(u.ValidationTestCase): 'hadoop_version': "1.2.1", 'user_keypair_id': 'wrong_keypair' }, - bad_req_i=(1, 'INVALID_REFERENCE', + bad_req_i=(1, 'NOT_FOUND', "Requested keypair 'wrong_keypair' not found") ) @@ -178,8 +178,8 @@ class TestClusterCreateValidation(u.ValidationTestCase): 'neutron_management_network': '53a36917-ab9f-4589-' '94ce-b6df85a68332' }, - bad_req_i=(1, 'INVALID_REFERENCE', "Network 53a36917-ab9f-4589-" - "94ce-b6df85a68332 not found") + bad_req_i=(1, 'NOT_FOUND', "Network 53a36917-ab9f-4589-" + "94ce-b6df85a68332 not found") ) def test_cluster_create_mixed_nova_neutron(self): @@ -228,7 +228,7 @@ class TestClusterCreateValidation(u.ValidationTestCase): } ] }, - bad_req_i=(1, 'INVALID_REFERENCE', + bad_req_i=(1, 'INVALID_DATA', "Composite hostname long-long-cluster-name-long-long-" "long-very-long-node-group-name-100.novalocal " "in provisioned cluster exceeds maximum limit 64 " @@ -333,7 +333,7 @@ class TestClusterCreateValidation(u.ValidationTestCase): } ] }, - bad_req_i=(1, 'INVALID_REFERENCE', + bad_req_i=(1, 'NOT_FOUND', "Security group 'group3' not found") ) @@ -389,7 +389,7 @@ class TestClusterCreateValidation(u.ValidationTestCase): } ] }, - bad_req_i=(1, 'INVALID_REFERENCE', + bad_req_i=(1, 'NOT_FOUND', "Nova availability zone 'nonexistent' not found") ) @@ -418,7 +418,7 @@ class TestClusterCreateValidation(u.ValidationTestCase): } ] }, - bad_req_i=(1, 'INVALID_REFERENCE', + bad_req_i=(1, 'NOT_FOUND', "Cinder availability zone 'nonexistent' not found") ) @@ -551,11 +551,12 @@ class TestClusterCreateFlavorValidation(base.SaharaWithDbTestCase): 'default_image_id': '550e8400-e29b-41d4-a716-446655440000' } for values in [data, data1]: - with testtools.ExpectedException(exceptions.InvalidException): + with testtools.ExpectedException( + exceptions.NotFoundException): patchers = u.start_patch(False) try: c.check_cluster_create(values) - except exceptions.InvalidException as e: + except exceptions.NotFoundException as e: message = six.text_type(e).split('\n')[0] self.assertEqual("Requested flavor '10' not found", message) @@ -613,12 +614,12 @@ class TestClusterCreateFlavorValidation(base.SaharaWithDbTestCase): ], 'default_image_id': '550e8400-e29b-41d4-a716-446655440000' } - with testtools.ExpectedException(exceptions.InvalidException): + with testtools.ExpectedException(exceptions.NotFoundException): try: patchers = u.start_patch(False) c.check_cluster_create(data) u.stop_patch(patchers) - except exceptions.InvalidException as e: + except exceptions.NotFoundException as e: message = six.text_type(e).split('\n')[0] self.assertEqual("Requested flavor '23' not found", message) diff --git a/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py b/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py index fbb4e72e..c22dec49 100644 --- a/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py +++ b/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py @@ -44,15 +44,16 @@ class TestScalingValidation(u.ValidationTestCase): get_plugin_p=None, get_cluster_p=None, data=None, cluster=None, - expected_message=None): + expected_message=None, + expected_exception=ex.InvalidReferenceException): get_cluster_p.return_value = cluster get_plugin_p.side_effect = _get_plugin - with testtools.ExpectedException(ex.InvalidException): + with testtools.ExpectedException(expected_exception): try: c_s.check_cluster_scaling(data, cluster.id) - except ex.InvalidException as e: + except expected_exception as e: message = six.text_type(e).split('\n')[0] self.assertEqual(expected_message, message) raise e @@ -101,7 +102,8 @@ class TestScalingValidation(u.ValidationTestCase): self._assert_check_scaling( data=data, cluster=cluster, expected_message='Duplicates in node ' - 'group names are detected') + 'group names are detected', + expected_exception=ex.InvalidDataException) @mock.patch("sahara.service.api.OPS") def test_check_cluster_scaling_add_ng(self, ops): @@ -127,7 +129,8 @@ class TestScalingValidation(u.ValidationTestCase): self._assert_check_scaling( data=data, cluster=cluster, expected_message='Duplicates in node ' - 'group names are detected') + 'group names are detected', + expected_exception=ex.InvalidDataException) data = { 'add_node_groups': [ { @@ -159,7 +162,8 @@ class TestScalingValidation(u.ValidationTestCase): expected_message="Composite hostname test-cluster-very-" "very-very-very-very-very-long-ng-name-" "010.novalocal in provisioned cluster exceeds " - "maximum limit 64 characters") + "maximum limit 64 characters", + expected_exception=ex.InvalidDataException) u.stop_patch(patchers) @mock.patch("sahara.utils.api.request_data") diff --git a/sahara/tests/unit/service/validation/test_cluster_template_create_validation.py b/sahara/tests/unit/service/validation/test_cluster_template_create_validation.py index 81560f51..8e8448bb 100644 --- a/sahara/tests/unit/service/validation/test_cluster_template_create_validation.py +++ b/sahara/tests/unit/service/validation/test_cluster_template_create_validation.py @@ -94,7 +94,7 @@ class TestClusterTemplateCreateValidation(u.ValidationTestCase): } ] }, - bad_req_i=(1, "INVALID_REFERENCE", + bad_req_i=(1, "INVALID_DATA", "Duplicates in node group names are detected") ) @@ -235,8 +235,8 @@ class TestClusterTemplateCreateValidation(u.ValidationTestCase): } self._assert_create_object_validation( data=data, - bad_req_i=(1, 'INVALID_REFERENCE', "Network 53a36917-ab9f-4589-" - "94ce-b6df85a68332 not found") + bad_req_i=(1, 'NOT_FOUND', "Network 53a36917-ab9f-4589-" + "94ce-b6df85a68332 not found") ) def test_cluster_create_v_default_image_required_tags(self): 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 d065abbe..94293bd4 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 @@ -89,7 +89,7 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase): 'hadoop_version': '1.2.1', 'node_processes': ["namenode", "namenode"] }, - bad_req_i=(1, 'INVALID_REFERENCE', + bad_req_i=(1, 'INVALID_DATA', 'Duplicates in node processes have been detected') ) self._assert_create_object_validation( @@ -188,7 +188,7 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase): 'hadoop_version': '1.2.1', 'node_processes': ['namenode'] }, - bad_req_i=(1, 'INVALID_REFERENCE', + bad_req_i=(1, 'NOT_FOUND', "Requested flavor '1' not found") ) @@ -289,6 +289,6 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase): 'node_processes': ['datanode', 'tasktracker'], 'floating_ip_pool': 'network_bad' }, - bad_req_i=(1, 'INVALID_REFERENCE', "Floating IP pool network_bad " - "for node group 'a' not found") + bad_req_i=(1, 'NOT_FOUND', "Floating IP pool network_bad " + "not found") )