Merge "Workflow name can not be in the format of UUID"

This commit is contained in:
Jenkins 2015-12-18 08:59:17 +00:00 committed by Gerrit Code Review
commit a02f65605d
2 changed files with 34 additions and 2 deletions

View File

@ -376,3 +376,25 @@ class WorkflowSpecValidation(base.WorkflowSpecValidationTestCase):
exception = self._parse_dsl_spec(changes=overlay, expect_error=True) exception = self._parse_dsl_spec(changes=overlay, expect_error=True)
self.assertIn("Invalid DSL", exception.message) self.assertIn("Invalid DSL", exception.message)
def test_invalid_name(self):
invalid_wf = {
'version': '2.0',
'b98180ba-48a0-4e26-ab2e-50dc224f6fd1': {
'type': 'direct',
'tasks': {'t1': {'action': 'std.noop'}}
}
}
dsl_yaml = yaml.safe_dump(invalid_wf, default_flow_style=False)
exception = self.assertRaises(
exc.InvalidModelException,
self._spec_parser,
dsl_yaml
)
self.assertIn(
"Workflow name cannot be in the format of UUID",
exception.message
)

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from oslo_utils import uuidutils
import six import six
from mistral import exceptions as exc from mistral import exceptions as exc
@ -80,8 +81,13 @@ class WorkflowSpec(base.BaseSpec):
self.validate_yaql_expr(self._data.get('vars', {})) self.validate_yaql_expr(self._data.get('vars', {}))
def validate_semantics(self): def validate_semantics(self):
# Doesn't do anything by default. super(WorkflowSpec, self).validate_semantics()
pass
# Distinguish workflow name from workflow UUID.
if uuidutils.is_uuid_like(self._name):
raise exc.InvalidModelException(
"Workflow name cannot be in the format of UUID."
)
def _validate_task_link(self, task_name, allow_engine_cmds=True): def _validate_task_link(self, task_name, allow_engine_cmds=True):
valid_task = self._task_exists(task_name) valid_task = self._task_exists(task_name)
@ -142,6 +148,8 @@ class DirectWorkflowSpec(WorkflowSpec):
} }
def validate_semantics(self): def validate_semantics(self):
super(DirectWorkflowSpec, self).validate_semantics()
# Check if there are start tasks. # Check if there are start tasks.
if not self.find_start_tasks(): if not self.find_start_tasks():
raise exc.DSLParsingException( raise exc.DSLParsingException(
@ -300,6 +308,8 @@ class ReverseWorkflowSpec(WorkflowSpec):
} }
def validate_semantics(self): def validate_semantics(self):
super(ReverseWorkflowSpec, self).validate_semantics()
self._check_workflow_integrity() self._check_workflow_integrity()
def _check_workflow_integrity(self): def _check_workflow_integrity(self):