# See the License for the specific language governing permissions and
# limitations under the License.
+
TASK_STAUS = (STARTED, PROCESSING, FINISHED, ERROR) = ("started", "processing", "finished", "error")
TIMEOUT_DEFAULT = 10
-
-# from lcm.workflows.graphflow.flow.flow import GraphFlow
-# from lcm.workflows.graphflow.task.task import Task
-# from lcm.workflows.graphflow.task.sync_task import SyncTask
-# from lcm.workflows.graphflow.task.sync_rest_task import SyncRestTask
-# from lcm.workflows.graphflow.task.async_task import AsyncTask
-# from lcm.workflows.graphflow.task.async_rest_task import ASyncRestTask
-# from lcm.workflows.graphflow.task.lcm_async_rest_task import LcmASyncRestTask
-# from lcm.workflows.graphflow.task.lcm_sync_rest_task import LcmSyncRestTask
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import mock
+import json
+from lcm.pub.utils import restcall
+from lcm.workflows.graphflow.flow.flow import GraphFlow
+
+
+config = {
+ "CreateSynVNF": {"module": "lcm.workflows.graphflow.tests.task_tests", "class": "CreateSynVNF"},
+ "CreateAsynVNF": {"module": "lcm.workflows.graphflow.tests.task_tests", "class": "CreateAsynVNF"},
+ "CreateASynRestVNF": {"module": "lcm.workflows.graphflow.tests.task_tests", "class": "CreateASynRestVNF"}
+}
+
+
+class test(object):
+ def execute(self, args):
+ print "test args %s" % args
+
+
+class GraphFlowTest(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_sync_task(self):
+ deploy_graph = {
+ "ran-cu-00": ["ran-du-00"],
+ "ran-du-00": [],
+ }
+ TaskSet = {
+ 'ran-cu-00': {
+ "type": "CreateSynVNF",
+ "input": {
+ "nsInstanceId": 1,
+ "vnfId": 1
+ },
+ "timeOut": 10
+ },
+ 'ran-du-00': {
+ "type": "CreateSynVNF",
+ "input": {
+ "nsInstanceId": 1,
+ "vnfId": 1
+ },
+ "timeOut": 10
+ }
+ }
+ gf = GraphFlow(deploy_graph, TaskSet, config)
+ gf.start()
+ gf.join()
+ gf.task_manager.wait_tasks_done(gf.sort_nodes)
+ task_set = gf.task_manager.get_all_task()
+ for task in task_set.itervalues():
+ self.assertEqual(task.FINISHED, task.status)
+
+ def test_async_task(self):
+ deploy_graph = {
+ "ran-cu-01": ["ran-du-01"],
+ "ran-du-01": [],
+ }
+ TaskSet = {
+ 'ran-cu-01': {
+ "type": "CreateAsynVNF",
+ "input": {
+ "nsInstanceId": 1,
+ "vnfId": 1
+ },
+ "timeOut": 10
+ },
+ 'ran-du-01': {
+ "type": "CreateAsynVNF",
+ "input": {
+ "nsInstanceId": 1,
+ "vnfId": 1
+ },
+ "timeOut": 10
+ }
+ }
+ gf = GraphFlow(deploy_graph, TaskSet, config)
+ gf.start()
+ gf.join()
+ gf.task_manager.wait_tasks_done(gf.sort_nodes)
+ task_set = gf.task_manager.get_all_task()
+ for task in task_set.itervalues():
+ self.assertEqual(task.FINISHED, task.status)
+
+ @mock.patch.object(restcall, 'call_req')
+ def test_async_rest_task(self, mock_call_req):
+ mock_call_req.return_value = [0, json.JSONEncoder().encode({
+ 'jobId': "1",
+ "responseDescriptor": {"progress": 100}
+ }), '200']
+
+ deploy_graph = {
+ "ran-cu-02": ["ran-du-02"],
+ "ran-du-02": [],
+ }
+ TaskSet = {
+ 'ran-cu-02': {
+ "type": "CreateASynRestVNF",
+ "input": {
+ "url": "/test/",
+ "method": "POST",
+ "content": {}
+ },
+ "timeOut": 10
+ },
+ 'ran-du-02': {
+ "type": "CreateASynRestVNF",
+ "input": {
+ "url": "/test/",
+ "method": "POST",
+ "content": {}
+ },
+ "timeOut": 10
+ }
+ }
+ gf = GraphFlow(deploy_graph, TaskSet, config)
+ gf.start()
+ gf.join()
+ gf.task_manager.wait_tasks_done(gf.sort_nodes)
+ task_set = gf.task_manager.get_all_task()
+ for task in task_set.itervalues():
+ self.assertEqual(task.FINISHED, task.status)
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import logging
+
+from django.test import TestCase
+from lcm.workflows.graphflow.flow.graph import Graph
+
+logger = logging.getLogger(__name__)
+
+
+class TestToscaparser(TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_graph(self):
+ data = {
+ "cucp": [],
+ "du": [],
+ "vl_flat_net": ["cucp", "cuup"],
+ "vl_ext_net": ["cucp", "cuup"],
+ "cuup": []
+ }
+ graph = Graph(data)
+ self.assertEqual(['vl_ext_net', 'vl_flat_net'].sort(), graph.get_pre_nodes("cucp").sort())
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from lcm.workflows.graphflow.task.async_task import AsyncTask
+from lcm.workflows.graphflow.task.sync_task import SyncTask
+from lcm.workflows.graphflow.task.lcm_async_rest_task import LcmASyncRestTask
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class CreateSynVNF(SyncTask):
+ def __init__(self, *args):
+ super(CreateSynVNF, self).__init__(*args)
+
+ def run(self):
+ logger.debug("test CreateSynVNF %s" % self.key)
+ return self.FINISHED, {}
+
+
+class CreateAsynVNF(AsyncTask):
+ def __init__(self, *args):
+ super(CreateAsynVNF, self).__init__(*args)
+
+ def run(self):
+ logger.debug("test CreateAsynVNF %s" % self.key)
+ return self.PROCESSING, None
+
+ def get_ext_status(self):
+ return self.FINISHED
+
+
+class CreateASynRestVNF(LcmASyncRestTask):
+
+ def __init__(self, *args):
+ super(CreateASynRestVNF, self).__init__(*args)
+ self.url = "/api/nslcm/v1/vnfs"
+ self.method = self.POST