summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pike/pike/resource/tests/tests_infra_workload.py214
-rw-r--r--pike/pike/resource/views/infra_workload.py10
-rw-r--r--pike/pike/settings.py3
3 files changed, 223 insertions, 4 deletions
diff --git a/pike/pike/resource/tests/tests_infra_workload.py b/pike/pike/resource/tests/tests_infra_workload.py
new file mode 100644
index 00000000..92d1b4bb
--- /dev/null
+++ b/pike/pike/resource/tests/tests_infra_workload.py
@@ -0,0 +1,214 @@
+# Copyright (c) 2018 Intel 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 mock
+
+import unittest
+import json
+from rest_framework import status
+
+from common.utils import restcall
+from common.msapi.helper import Helper as helper
+from pike.resource.views.infra_workload import InfraWorkload
+from pike.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\" > /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
diff --git a/pike/pike/resource/views/infra_workload.py b/pike/pike/resource/views/infra_workload.py
index 38c2a920..415bf0d2 100644
--- a/pike/pike/resource/views/infra_workload.py
+++ b/pike/pike/resource/views/infra_workload.py
@@ -55,10 +55,11 @@ class InfraWorkload(APIView):
for directive in oof_directive.get("directives", []):
if directive["type"] == "vnfc":
for directive2 in directive.get("directives", []):
- if directive2["type"] in ["flavor_directives", "sriovNICNetwork_directives"]:
- for attr in directives2.get("attributes", []):
- label_name = directive2[0]["attribute_name"]
- label_value = directive2[0]["attribute_value"]
+ #if directive2["type"] in ["flavor_directives", "sriovNICNetwork_directives"]:
+ if directive2["type"] == "flavor_directives":
+ for attr in directive2.get("attributes", []):
+ label_name = attr["attribute_name"]
+ label_value = attr["attribute_value"]
if parameters.has_key(label_name):
template_data["parameters"][label_name] = label_value
else:
@@ -154,6 +155,7 @@ class InfraWorkload(APIView):
self.heatbridge_update(request, vimid, stack_id)
self._logger.info("RESP with data> result:%s" % resp_template)
+ return Response(data=resp_template, status=status.HTTP_200_OK)
except VimDriverNewtonException as e:
self._logger.error("Plugin exception> status:%s,error:%s"
% (e.status_code, e.content))
diff --git a/pike/pike/settings.py b/pike/pike/settings.py
index 39c83d47..d40c9870 100644
--- a/pike/pike/settings.py
+++ b/pike/pike/settings.py
@@ -97,6 +97,9 @@ MSB_SERVICE_PORT = os.environ.get('MSB_PORT', "80")
MULTICLOUD_PREFIX = "http://%s:%s/api/multicloud-pike/v0" % (
MSB_SERVICE_ADDR, MSB_SERVICE_PORT)
+MULTICLOUD_API_V1_PREFIX = "http://%s:%s/api/multicloud-pike/v1" % (
+ MSB_SERVICE_ADDR, MSB_SERVICE_PORT)
+
# [A&AI]
AAI_ADDR = os.environ.get('AAI_ADDR', "aai.api.simpledemo.openecomp.org")
AAI_PORT = os.environ.get('AAI_PORT', "8443")