diff options
6 files changed, 193 insertions, 9 deletions
diff --git a/ocata/ocata/resource/tests/tests_infra_workload.py b/ocata/ocata/resource/tests/tests_infra_workload.py index c522c190..ed39da9d 100644 --- a/ocata/ocata/resource/tests/tests_infra_workload.py +++ b/ocata/ocata/resource/tests/tests_infra_workload.py @@ -107,6 +107,46 @@ MOCK_HEAT_LIST_RESPONSE1 = { ] } + +MOCK_HEAT_CREATE_BODY2 = { + "generic-vnf-id":"MOCK_GENERIF_VNF_ID1", + "vf-module-id":"MOCK_VF_MODULE_ID1", + "template_type":"HEAT", + "template_data":{ + "files":{ }, + "disable_rollback":True, + "parameters":{ + "flavor1":"m1.heat" + }, + "stack_name":"teststack", + "template":{ + "heat_template_version":"2013-05-23", + "description":"Simple template to test heat commands", + "parameters": + { + "flavor":{ + "default":"m1.tiny", + "type":"string" + } + }, + "resources":{ + "hello_world":{ + "type":"OS::Nova::Server", + "properties":{ + "key_name":"heat_key", + "flavor":{ + "get_param":"flavor" + }, + "image":"40be8d1a-3eb9-40de-8abd-43237517384f", + "user_data":"#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" + } + } + } + }, + "timeout_mins":60 + } +} + class InfraWorkloadTest(unittest.TestCase): def setUp(self): self._InfraWorkload = InfraWorkload() @@ -139,6 +179,27 @@ class InfraWorkloadTest(unittest.TestCase): @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') + def test_post_wo_oof_directive(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + mock_request = mock.Mock() + mock_request.META = {"testkey": "testvalue"} + mock_request.data = MOCK_HEAT_CREATE_BODY2 + + mock_MultiCloudIdentityHelper.side_effect= [ + (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) + ] + + mock_MultiCloudServiceHelper.side_effect= [ + (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED) + ] + + vimid = "CloudOwner_Region1" + + response = self._InfraWorkload.post(mock_request, vimid) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + pass + + @mock.patch.object(helper, 'MultiCloudServiceHelper') + @mock.patch.object(helper, 'MultiCloudIdentityHelper') def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} diff --git a/ocata/ocata/resource/views/infra_workload.py b/ocata/ocata/resource/views/infra_workload.py index e25c6d15..d78e3cee 100644 --- a/ocata/ocata/resource/views/infra_workload.py +++ b/ocata/ocata/resource/views/infra_workload.py @@ -43,9 +43,9 @@ class InfraWorkload(APIView): try : data = request.data - oof_directive = data["oof_directives"] - template_type = data["template_type"] - template_data = data["template_data"] + oof_directive = data.get("oof_directives", {}) + template_type = data.get("template_type", None) + template_data = data.get("template_data", {}) resp_template = None if template_type and "heat" == template_type.lower(): diff --git a/pike/pike/resource/tests/tests_infra_workload.py b/pike/pike/resource/tests/tests_infra_workload.py index e473c84f..73d4ffca 100644 --- a/pike/pike/resource/tests/tests_infra_workload.py +++ b/pike/pike/resource/tests/tests_infra_workload.py @@ -117,6 +117,46 @@ MOCK_HEAT_LIST_RESPONSE1 = { ] } + +MOCK_HEAT_CREATE_BODY2 = { + "generic-vnf-id":"MOCK_GENERIF_VNF_ID1", + "vf-module-id":"MOCK_VF_MODULE_ID1", + "template_type":"HEAT", + "template_data":{ + "files":{ }, + "disable_rollback":True, + "parameters":{ + "flavor1":"m1.heat" + }, + "stack_name":"teststack", + "template":{ + "heat_template_version":"2013-05-23", + "description":"Simple template to test heat commands", + "parameters": + { + "flavor":{ + "default":"m1.tiny", + "type":"string" + } + }, + "resources":{ + "hello_world":{ + "type":"OS::Nova::Server", + "properties":{ + "key_name":"heat_key", + "flavor":{ + "get_param":"flavor" + }, + "image":"40be8d1a-3eb9-40de-8abd-43237517384f", + "user_data":"#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" + } + } + } + }, + "timeout_mins":60 + } +} + class InfraWorkloadTest(unittest.TestCase): def setUp(self): self._InfraWorkload = InfraWorkload() @@ -149,6 +189,27 @@ class InfraWorkloadTest(unittest.TestCase): @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') + def test_post_wo_oof_directive(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + mock_request = mock.Mock() + mock_request.META = {"testkey": "testvalue"} + mock_request.data = MOCK_HEAT_CREATE_BODY2 + + mock_MultiCloudIdentityHelper.side_effect= [ + (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) + ] + + mock_MultiCloudServiceHelper.side_effect= [ + (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED) + ] + + vimid = "CloudOwner_Region1" + + response = self._InfraWorkload.post(mock_request, vimid) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + pass + + @mock.patch.object(helper, 'MultiCloudServiceHelper') + @mock.patch.object(helper, 'MultiCloudIdentityHelper') def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} diff --git a/pike/pike/resource/views/infra_workload.py b/pike/pike/resource/views/infra_workload.py index e25c6d15..d78e3cee 100644 --- a/pike/pike/resource/views/infra_workload.py +++ b/pike/pike/resource/views/infra_workload.py @@ -43,9 +43,9 @@ class InfraWorkload(APIView): try : data = request.data - oof_directive = data["oof_directives"] - template_type = data["template_type"] - template_data = data["template_data"] + oof_directive = data.get("oof_directives", {}) + template_type = data.get("template_type", None) + template_data = data.get("template_data", {}) resp_template = None if template_type and "heat" == template_type.lower(): diff --git a/windriver/titanium_cloud/resource/tests/tests_infra_workload.py b/windriver/titanium_cloud/resource/tests/tests_infra_workload.py index 2d75e595..1ace4f99 100644 --- a/windriver/titanium_cloud/resource/tests/tests_infra_workload.py +++ b/windriver/titanium_cloud/resource/tests/tests_infra_workload.py @@ -116,6 +116,47 @@ MOCK_HEAT_LIST_RESPONSE1 = { ] } + +MOCK_HEAT_CREATE_BODY2 = { + "generic-vnf-id":"MOCK_GENERIF_VNF_ID1", + "vf-module-id":"MOCK_VF_MODULE_ID1", + "template_type":"HEAT", + "template_data":{ + "files":{ }, + "disable_rollback":True, + "parameters":{ + "flavor1":"m1.heat" + }, + "stack_name":"teststack", + "template":{ + "heat_template_version":"2013-05-23", + "description":"Simple template to test heat commands", + "parameters": + { + "flavor":{ + "default":"m1.tiny", + "type":"string" + } + }, + "resources":{ + "hello_world":{ + "type":"OS::Nova::Server", + "properties":{ + "key_name":"heat_key", + "flavor":{ + "get_param":"flavor" + }, + "image":"40be8d1a-3eb9-40de-8abd-43237517384f", + "user_data":"#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" + } + } + } + }, + "timeout_mins":60 + } +} + + class InfraWorkloadTest(unittest.TestCase): def setUp(self): self._InfraWorkload = InfraWorkload() @@ -148,6 +189,27 @@ class InfraWorkloadTest(unittest.TestCase): @mock.patch.object(helper, 'MultiCloudServiceHelper') @mock.patch.object(helper, 'MultiCloudIdentityHelper') + def test_post_wo_oof_directive(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): + mock_request = mock.Mock() + mock_request.META = {"testkey": "testvalue"} + mock_request.data = MOCK_HEAT_CREATE_BODY2 + + mock_MultiCloudIdentityHelper.side_effect= [ + (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED) + ] + + mock_MultiCloudServiceHelper.side_effect= [ + (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED) + ] + + vimid = "CloudOwner_Region1" + + response = self._InfraWorkload.post(mock_request, vimid) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + pass + + @mock.patch.object(helper, 'MultiCloudServiceHelper') + @mock.patch.object(helper, 'MultiCloudIdentityHelper') def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper): mock_request = mock.Mock() mock_request.META = {"testkey": "testvalue"} diff --git a/windriver/titanium_cloud/resource/views/infra_workload.py b/windriver/titanium_cloud/resource/views/infra_workload.py index ef57e657..ec1e5744 100644 --- a/windriver/titanium_cloud/resource/views/infra_workload.py +++ b/windriver/titanium_cloud/resource/views/infra_workload.py @@ -47,9 +47,9 @@ class InfraWorkload(APIView): try : data = request.data - oof_directive = data["oof_directives"] - template_type = data["template_type"] - template_data = data["template_data"] + oof_directive = data.get("oof_directives", {}) + template_type = data.get("template_type", None) + template_data = data.get("template_data", {}) resp_template = None if template_type and "heat" == template_type.lower(): # update heat parameters from oof_directive |