summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/resource/tests
diff options
context:
space:
mode:
authorXiaohua Zhang <xiaohua.zhang@windriver.com>2018-09-18 15:39:30 +0000
committerXiaohua Zhang <xiaohua.zhang@windriver.com>2018-09-18 15:39:30 +0000
commit0b21efd901c3abf4951ab88581225323ae6b2cb1 (patch)
tree896210acdc395cc2d506ee3fb3e37c5eca13a629 /windriver/titanium_cloud/resource/tests
parent809fa3996eaf65736e361eb063260430b11eac5e (diff)
Add UT for infra_workload
Change-Id: I037cc563c373765f1423c655bbc8760f96046abe Issue-ID: MULTICLOUD-358 Signed-off-by: Xiaohua Zhang <xiaohua.zhang@windriver.com>
Diffstat (limited to 'windriver/titanium_cloud/resource/tests')
-rw-r--r--windriver/titanium_cloud/resource/tests/tests_infra_workload.py214
1 files changed, 214 insertions, 0 deletions
diff --git a/windriver/titanium_cloud/resource/tests/tests_infra_workload.py b/windriver/titanium_cloud/resource/tests/tests_infra_workload.py
new file mode 100644
index 00000000..05a9d8d6
--- /dev/null
+++ b/windriver/titanium_cloud/resource/tests/tests_infra_workload.py
@@ -0,0 +1,214 @@
+# Copyright (c) 2017-2018 Wind River Systems, Inc.
+#
+# 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 mock
+
+import unittest
+import json
+from rest_framework import status
+
+from common.utils import restcall
+from common.msapi.helper import Helper as helper
+from titanium_cloud.resource.views.infra_workload import InfraWorkload
+from titanium_cloud.resource.views.infra_workload import APIv1InfraWorkload
+
+MOCK_TOKEN_RESPONSE = {"access":
+ {"token":
+ {"issued_at":"2018-05-10T16:56:56.000000Z",
+ "expires":"2018-05-10T17:56:56.000000Z",
+ "id":"4a832860dd744306b3f66452933f939e",
+ "tenant":{"domain":{"id":"default","name":"Default"},
+ "enabled":"true","id":"0e148b76ee8c42f78d37013bf6b7b1ae",
+ "name":"VIM"}},"serviceCatalog":[],
+ "user":{"domain":{"id":"default","name":"Default"},
+ "id":"ba76c94eb5e94bb7bec6980e5507aae2",
+ "name":"demo"}}}
+
+MOCK_HEAT_CREATE_BODY1 = {
+ "generic-vnf-id":"MOCK_GENERIF_VNF_ID1",
+ "vf-module-id":"MOCK_VF_MODULE_ID1",
+ "oof_directives":{
+ "directives":[
+ {
+ "id":"MOCK_VNFC_ID1",
+ "type": "vnfc",
+ "directives":[{
+ "type":"flavor_directives",
+ "attributes":[
+ {
+ "attribute_name":"flavor1",
+ "attribute_value":"m1.hpa.medium"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "sdnc_directives":{},
+ "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\" &gt; /root/hello-world.txt\n"
+ }
+ }
+ }
+ },
+ "timeout_mins":60
+ }
+}
+
+MOCK_HEAT_CREATE_RESPONSE1 = {
+ 'stack': {
+ 'id': "MOCKED_HEAT_STACK_ID1"
+ }
+}
+
+MOCK_HEAT_LIST_RESPONSE1 = {
+ 'stacks': [
+ {
+ 'resource_status':"CREATE_IN_PROCESS"
+ }
+ ]
+}
+
+class InfraWorkloadTest(unittest.TestCase):
+ def setUp(self):
+ self._InfraWorkload = InfraWorkload()
+ pass
+
+ def tearDown(self):
+ pass
+
+ @mock.patch.object(helper, 'MultiCloudServiceHelper')
+ @mock.patch.object(helper, 'MultiCloudIdentityHelper')
+ def test_post(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper):
+ mock_request = mock.Mock()
+ mock_request.META = {"testkey": "testvalue"}
+ mock_request.data = MOCK_HEAT_CREATE_BODY1
+
+ 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"}
+
+ mock_MultiCloudIdentityHelper.side_effect= [
+ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED)
+ ]
+
+ mock_MultiCloudServiceHelper.side_effect= [
+ (0, MOCK_HEAT_LIST_RESPONSE1, status.HTTP_200_OK)
+ ]
+
+ vimid = "CloudOwner_Region1"
+ mock_stack_id = "MOCKED_HEAT_STACK_ID1"
+
+ response = self._InfraWorkload.get(mock_request, vimid, mock_stack_id)
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ pass
+
+
+class APIv1InfraWorkloadTest(unittest.TestCase):
+ def setUp(self):
+ self._APIv1InfraWorkload = APIv1InfraWorkload()
+ pass
+
+ def tearDown(self):
+ pass
+
+ @mock.patch.object(helper, 'MultiCloudServiceHelper')
+ @mock.patch.object(helper, 'MultiCloudIdentityHelper')
+ def test_post(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper):
+ mock_request = mock.Mock()
+ mock_request.META = {"testkey": "testvalue"}
+ mock_request.data = MOCK_HEAT_CREATE_BODY1
+
+ 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)
+ ]
+
+ cloud_owner = "CloudOwner"
+ cloud_region_id = "Region1"
+
+ response = self._APIv1InfraWorkload.post(mock_request, cloud_owner, cloud_region_id)
+ 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"}
+
+ mock_MultiCloudIdentityHelper.side_effect= [
+ (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED)
+ ]
+
+ mock_MultiCloudServiceHelper.side_effect= [
+ (0, MOCK_HEAT_LIST_RESPONSE1, status.HTTP_200_OK)
+ ]
+
+
+ cloud_owner = "CloudOwner"
+ cloud_region_id = "Region1"
+ mock_stack_id = "MOCKED_HEAT_STACK_ID1"
+
+ response = self._APIv1InfraWorkload.get(mock_request, cloud_owner, cloud_region_id, mock_stack_id)
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ pass \ No newline at end of file