From ce3fffda433531666295e5c9b3148e9128e57f16 Mon Sep 17 00:00:00 2001 From: Bin Yang Date: Sat, 10 Nov 2018 12:48:44 +0000 Subject: Support infra_workload api without oof_directives Change-Id: I8eb05ff2acdef8811b3eec8e1a0efe47b12bdd73 Issue-ID: MULTICLOUD-401 Signed-off-by: Bin Yang --- .../resource/tests/tests_infra_workload.py | 62 ++++++++++++++++++++++ .../resource/views/infra_workload.py | 6 +-- 2 files changed, 65 insertions(+), 3 deletions(-) (limited to 'windriver/titanium_cloud/resource') 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() @@ -146,6 +187,27 @@ class InfraWorkloadTest(unittest.TestCase): pass + @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): 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 -- cgit 1.2.3-korg