Fix resource pep8 error for ocata 94/75794/1
authorHaibin Huang <haibin.huang@intel.com>
Tue, 15 Jan 2019 02:51:39 +0000 (10:51 +0800)
committerHaibin Huang <haibin.huang@intel.com>
Tue, 15 Jan 2019 02:54:08 +0000 (10:54 +0800)
This patch is only fixing the pep8 issues under the resource
folder for ocata release, which is only triggered by tox mannually.

Change-Id: I9d0eaa7f130141e61d50be15d93fe8054f11941e
Issue-ID: MULTICLOUD-434
Signed-off-by: Haibin Huang <haibin.huang@intel.com>
ocata/ocata/resource/__init__.py
ocata/ocata/resource/tests/__init__.py
ocata/ocata/resource/tests/test_capacity.py
ocata/ocata/resource/tests/test_events.py
ocata/ocata/resource/tests/tests_infra_workload.py
ocata/ocata/resource/views/__init__.py
ocata/ocata/resource/views/capacity.py
ocata/ocata/resource/views/events.py
ocata/ocata/resource/views/infra_workload.py

index afa702d..ae1ce9d 100644 (file)
@@ -11,4 +11,3 @@
 # 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.
-
index afa702d..ae1ce9d 100644 (file)
@@ -11,4 +11,3 @@
 # 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.
-
index 0f1fc16..926b5a0 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2018 Wind River Systems, Inc.
+# 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.
@@ -17,30 +17,29 @@ import json
 
 from rest_framework import status
 
-from common.utils import restcall
 from newton_base.tests import mock_info
 from newton_base.tests import test_base
 from newton_base.util import VimDriverUtils
 
 MOCK_GET_TENANT_LIMIT_RESPONSE = {
-   "limits" : {
-      "rate" : [],
-      "absolute" : {
-         "maxTotalRAMSize" : 128*1024,
-         "totalRAMUsed" : 8*1024,
-         "totalCoresUsed" : 4,
-         "maxTotalCores" : 20,
-      }
-   }
+    "limits": {
+        "rate": [],
+        "absolute": {
+            "maxTotalRAMSize": 128 * 1024,
+            "totalRAMUsed": 8 * 1024,
+            "totalCoresUsed": 4,
+            "maxTotalCores": 20,
+        }
+    }
 }
 
 MOCK_GET_HYPER_STATATICS_RESPONSE = {
-   "hypervisor_statistics" : {
-      "vcpus_used" : 4,
-      "free_ram_mb" : 120*1024,
-      "vcpus" : 10,
-      "free_disk_gb" : 300
-   }
+    "hypervisor_statistics": {
+        "vcpus_used": 4,
+        "free_ram_mb": 120 * 1024,
+        "vcpus": 10,
+        "free_disk_gb": 300
+    }
 }
 
 MOCK_GET_STORAGE_RESPONSE_OOS = {
@@ -75,31 +74,31 @@ MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFVCPU = {
 }
 
 MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFSTORAGE = {
-   "hypervisor_statistics" : {
-      "vcpus_used" : 4,
-      "free_ram_mb" : 120*1024,
-      "vcpus" : 10,
-      "free_disk_gb" : 3
-   }
+    "hypervisor_statistics": {
+        "vcpus_used": 4,
+        "free_ram_mb": 120 * 1024,
+        "vcpus": 10,
+        "free_disk_gb": 3
+    }
 }
 
 MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFRAM = {
-   "hypervisor_statistics" : {
-      "vcpus_used" : 4,
-      "free_ram_mb" : 1*1024,
-      "vcpus" : 10,
-      "free_disk_gb" : 300
-   }
+    "hypervisor_statistics": {
+        "vcpus_used": 4,
+        "free_ram_mb": 1 * 1024,
+        "vcpus": 10,
+        "free_disk_gb": 300
+    }
 }
 
 MOCK_GET_STORAGE_RESPONSE = {
-   "limits" : {
-      "rate" : [],
-      "absolute" : {
-         "totalGigabytesUsed" : 200,
-         "maxTotalVolumeGigabytes" : 500,
-      }
-   }
+    "limits": {
+        "rate": [],
+        "absolute": {
+            "totalGigabytesUsed": 200,
+            "maxTotalVolumeGigabytes": 500,
+        }
+    }
 }
 
 TEST_REQ_SUCCESS_SOURCE = {
@@ -114,6 +113,7 @@ TEST_REQ_FAILED_SOURCE = {
     "Storage": "200"
 }
 
+
 class TestCapacity(test_base.TestRequest):
     def setUp(self):
         super(TestCapacity, self).setUp()
@@ -251,6 +251,9 @@ class TestCapacity(test_base.TestRequest):
             content_type='application/json',
             HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
 
+        self.assertEquals(status.HTTP_200_OK, response.status_code)
+        self.assertEqual({"result": True}, response.data)
+
     @mock.patch.object(VimDriverUtils, 'get_session')
     @mock.patch.object(VimDriverUtils, 'get_vim_info')
     def test_capacity_check_volume_limits_outofstorage(self, mock_get_vim_info, mock_get_session):
@@ -272,4 +275,3 @@ class TestCapacity(test_base.TestRequest):
 
         self.assertEquals(status.HTTP_200_OK, response.status_code)
         self.assertEqual({"result": False}, response.data)
-
index f09f638..238559f 100644 (file)
@@ -16,323 +16,311 @@ import mock
 
 from rest_framework import status
 
-from common.utils import restcall
 from newton_base.tests import mock_info
 from newton_base.tests import test_base
 from newton_base.util import VimDriverUtils
 
 MOCK_GET_SERVERS_DETAIL_RESPONSE = {
-   "servers" : [
-      {
-         "accessIPv4" : "",
-         "OS-EXT-SRV-ATTR:instance_name" : "instance-0000000a",
-         "OS-SRV-USG:terminated_at" : "",
-         "accessIPv6" : "",
-         "config_drive" : "",
-         "OS-DCF:diskConfig" : "AUTO",
-         "updated" : "2018-03-27T02:17:12Z",
-         "metadata" : {},
-         "id" : "12f5b1d0-fe5c-469f-a7d4-b62a91134bf8",
-         "flavor" : {
-            "id" : "60edb520-5826-4ae7-9e07-709b19ba6f39",
-            "links" : [
-               {
-                  "rel" : "bookmark",
-                  "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/flavors/60edb520-5826-4ae7-9e07-709b19ba6f39"
-               }
-            ]
-         },
-         "links" : [
-            {
-               "rel" : "self",
-               "href" : "http://192.168.100.100:8774/v2.1/ad979139d5ea4a84b21b3620c0e4761e/servers/12f5b1d0-fe5c-469f-a7d4-b62a91134bf8"
+    "servers": [
+        {
+            "accessIPv4": "",
+            "OS-EXT-SRV-ATTR:instance_name": "instance-0000000a",
+            "OS-SRV-USG:terminated_at": "",
+            "accessIPv6": "",
+            "config_drive": "",
+            "OS-DCF:diskConfig": "AUTO",
+            "updated": "2018-03-27T02:17:12Z",
+            "metadata": {},
+            "id": "12f5b1d0-fe5c-469f-a7d4-b62a91134bf8",
+            "flavor": {
+                "id": "60edb520-5826-4ae7-9e07-709b19ba6f39",
+                "links": [
+                    {
+                        "rel": "bookmark",
+                        "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/flavors/60edb520-5826-4ae7-9e07-709b19ba6f39"
+                    }
+                ]
+            },
+            "links": [
+                {
+                    "rel": "self",
+                    "href": "http://192.168.100.100:8774/v2.1/ad979139d5ea4a84b21b3620c0e4761e/servers/12f5b1d0-fe5c-469f-a7d4-b62a91134bf8"
+                },
+                {
+                    "rel": "bookmark",
+                    "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/servers/12f5b1d0-fe5c-469f-a7d4-b62a91134bf8"
+                }
+            ],
+            "OS-EXT-SRV-ATTR:host": "compute-0",
+            "OS-EXT-AZ:availability_zone": "nova",
+            "name": "test1",
+            "wrs-res:pci_devices": "",
+            "hostId": "b3479a460f5effda10c6fdb860e824be631026c1d09f551479180577",
+            "user_id": "777155411f3042c9b7e3194188d6f85d",
+            "status": "PAUSED",
+            "OS-EXT-STS:power_state": 3,
+            "OS-EXT-SRV-ATTR:hypervisor_hostname": "compute-0",
+            "tenant_id": "ad979139d5ea4a84b21b3620c0e4761e",
+            "OS-SRV-USG:launched_at": "2018-03-27T02:16:40.000000",
+            "OS-EXT-STS:vm_state": "paused",
+            "wrs-if:nics": [
+                {
+                    "nic1": {
+                        "mac_address": "fa:16:3e:5f:1a:76",
+                        "network": "mgmt",
+                        "port_id": "6c225c23-abe3-42a8-8909-83471503d5d4",
+                        "vif_model": "virtio",
+                        "vif_pci_address": "",
+                        "mtu": 9216
+                    }
+                },
+                {
+                    "nic2": {
+                        "mac_address": "fa:16:3e:7c:7b:d7",
+                        "network": "data0",
+                        "port_id": "cbea2fec-c9b8-48ec-a964-0e3e255841bc",
+                        "vif_model": "virtio",
+                        "vif_pci_address": "",
+                        "mtu": 9216
+                    }
+                }
+            ],
+            "wrs-sg:server_group": "",
+            "OS-EXT-STS:task_state": "",
+            "wrs-res:topology": "node:0,  1024MB, pgsize:2M, 1s,1c,2t, vcpus:0,1, pcpus:5,21, siblings:{0,1}, pol:ded, thr:pre\nnode:1,  1024MB, pgsize:2M, 1s,1c,2t, vcpus:2,3, pcpus:8,24, siblings:{2,3}, pol:ded, thr:pre",
+            "wrs-res:vcpus": [4, 4, 4],
+            "key_name": "",
+            "image": {
+                "id": "7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb",
+                "links": [
+                    {
+                        "rel": "bookmark",
+                        "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/images/7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb"
+                    }
+                ]
             },
-            {
-               "rel" : "bookmark",
-               "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/servers/12f5b1d0-fe5c-469f-a7d4-b62a91134bf8"
-            }
-         ],
-         "OS-EXT-SRV-ATTR:host" : "compute-0",
-         "OS-EXT-AZ:availability_zone" : "nova",
-         "name" : "test1",
-         "wrs-res:pci_devices" : "",
-         "hostId" : "b3479a460f5effda10c6fdb860e824be631026c1d09f551479180577",
-         "user_id" : "777155411f3042c9b7e3194188d6f85d",
-         "status" : "PAUSED",
-         "OS-EXT-STS:power_state" : 3,
-         "OS-EXT-SRV-ATTR:hypervisor_hostname" : "compute-0",
-         "tenant_id" : "ad979139d5ea4a84b21b3620c0e4761e",
-         "OS-SRV-USG:launched_at" : "2018-03-27T02:16:40.000000",
-         "OS-EXT-STS:vm_state" : "paused",
-         "wrs-if:nics" : [
-            {
-               "nic1" : {
-                  "mac_address" : "fa:16:3e:5f:1a:76",
-                  "network" : "mgmt",
-                  "port_id" : "6c225c23-abe3-42a8-8909-83471503d5d4",
-                  "vif_model" : "virtio",
-                  "vif_pci_address" : "",
-                  "mtu" : 9216
-               }
+            "created": "2018-03-27T02:16:32Z",
+            "addresses": {
+                "data0": [
+                    {
+                        "OS-EXT-IPS:type": "fixed",
+                        "version": 4,
+                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:7c:7b:d7",
+                        "addr": "192.168.2.8"
+                    }
+                ],
+                "mgmt": [
+                    {
+                        "OS-EXT-IPS:type": "fixed",
+                        "version": 4,
+                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:5f:1a:76",
+                        "addr": "192.168.1.6"
+                    }
+                ]
             },
-            {
-               "nic2" : {
-                  "mac_address" : "fa:16:3e:7c:7b:d7",
-                  "network" : "data0",
-                  "port_id" : "cbea2fec-c9b8-48ec-a964-0e3e255841bc",
-                  "vif_model" : "virtio",
-                  "vif_pci_address" : "",
-                  "mtu" : 9216
-               }
-            }
-         ],
-         "wrs-sg:server_group" : "",
-         "OS-EXT-STS:task_state" : "",
-         "wrs-res:topology" : "node:0,  1024MB, pgsize:2M, 1s,1c,2t, vcpus:0,1, pcpus:5,21, siblings:{0,1}, pol:ded, thr:pre\nnode:1,  1024MB, pgsize:2M, 1s,1c,2t, vcpus:2,3, pcpus:8,24, siblings:{2,3}, pol:ded, thr:pre",
-         "wrs-res:vcpus" : [
-            4,
-            4,
-            4
-         ],
-         "key_name" : "",
-         "image" : {
-            "id" : "7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb",
-            "links" : [
-               {
-                  "rel" : "bookmark",
-                  "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/images/7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb"
-               }
-            ]
-         },
-         "created" : "2018-03-27T02:16:32Z",
-         "addresses" : {
-            "data0" : [
-               {
-                  "OS-EXT-IPS:type" : "fixed",
-                  "version" : 4,
-                  "OS-EXT-IPS-MAC:mac_addr" : "fa:16:3e:7c:7b:d7",
-                  "addr" : "192.168.2.8"
-               }
+            "os-extended-volumes:volumes_attached": []
+        },
+        {
+            "accessIPv4": "",
+            "OS-EXT-SRV-ATTR:instance_name": "instance-00000009",
+            "OS-SRV-USG:terminated_at": "",
+            "accessIPv6": "",
+            "config_drive": "",
+            "OS-DCF:diskConfig": "AUTO",
+            "updated": "2018-03-27T02:12:21Z",
+            "metadata": {},
+            "id": "3f1b0375-a1db-4d94-b336-f32c82c0d7ec",
+            "flavor": {
+                "id": "0d3b1381-1626-4f6b-869b-4a4d5d42085e",
+                "links": [
+                    {
+                        "rel": "bookmark",
+                        "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/flavors/0d3b1381-1626-4f6b-869b-4a4d5d42085e"
+                    }
+                ]
+            },
+            "links": [
+                {
+                    "rel": "self",
+                    "href": "http://192.168.100.100:8774/v2.1/ad979139d5ea4a84b21b3620c0e4761e/servers/3f1b0375-a1db-4d94-b336-f32c82c0d7ec"
+                },
+                {
+                    "rel": "bookmark",
+                    "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/servers/3f1b0375-a1db-4d94-b336-f32c82c0d7ec"
+                }
+            ],
+            "OS-EXT-SRV-ATTR:host": "compute-0",
+            "OS-EXT-AZ:availability_zone": "nova",
+            "name": "test2",
+            "wrs-res:pci_devices": "",
+            "hostId": "b3479a460f5effda10c6fdb860e824be631026c1d09f551479180577",
+            "user_id": "777155411f3042c9b7e3194188d6f85d",
+            "status": "ACTIVE",
+            "OS-EXT-STS:power_state": 1,
+            "OS-EXT-SRV-ATTR:hypervisor_hostname": "compute-0",
+            "tenant_id": "ad979139d5ea4a84b21b3620c0e4761e",
+            "OS-SRV-USG:launched_at": "2018-03-27T02:12:21.000000",
+            "OS-EXT-STS:vm_state": "active",
+            "wrs-if:nics": [
+                {
+                    "nic1": {
+                        "mac_address": "fa:16:3e:54:f8:a6",
+                        "network": "mgmt",
+                        "port_id": "30e2f51c-4473-4650-9ae9-a35e5d7ad452",
+                        "vif_model": "avp",
+                        "vif_pci_address": "",
+                        "mtu": 9216
+                    }
+                }
             ],
-            "mgmt" : [
-               {
-                  "OS-EXT-IPS:type" : "fixed",
-                  "version" : 4,
-                  "OS-EXT-IPS-MAC:mac_addr" : "fa:16:3e:5f:1a:76",
-                  "addr" : "192.168.1.6"
-               }
-            ]
-         },
-         "os-extended-volumes:volumes_attached" : []
-      },
-      {
-         "accessIPv4" : "",
-         "OS-EXT-SRV-ATTR:instance_name" : "instance-00000009",
-         "OS-SRV-USG:terminated_at" : "",
-         "accessIPv6" : "",
-         "config_drive" : "",
-         "OS-DCF:diskConfig" : "AUTO",
-         "updated" : "2018-03-27T02:12:21Z",
-         "metadata" : {},
-         "id" : "3f1b0375-a1db-4d94-b336-f32c82c0d7ec",
-         "flavor" : {
-            "id" : "0d3b1381-1626-4f6b-869b-4a4d5d42085e",
-            "links" : [
-               {
-                  "rel" : "bookmark",
-                  "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/flavors/0d3b1381-1626-4f6b-869b-4a4d5d42085e"
-               }
-            ]
-         },
-         "links" : [
-            {
-               "rel" : "self",
-               "href" : "http://192.168.100.100:8774/v2.1/ad979139d5ea4a84b21b3620c0e4761e/servers/3f1b0375-a1db-4d94-b336-f32c82c0d7ec"
+            "wrs-sg:server_group": "",
+            "OS-EXT-STS:task_state": "",
+            "wrs-res:topology": "node:0,  4096MB, pgsize:2M, 1s,3c,1t, vcpus:0-2, pcpus:4,20,7, pol:ded, thr:pre",
+            "progress": 0,
+            "wrs-res:vcpus": [3, 3, 3],
+            "key_name": "",
+            "image": {
+                "id": "7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb",
+                "links": [
+                    {
+                        "rel": "bookmark",
+                        "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/images/7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb"
+                    }
+                ]
             },
-            {
-               "rel" : "bookmark",
-               "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/servers/3f1b0375-a1db-4d94-b336-f32c82c0d7ec"
-            }
-         ],
-         "OS-EXT-SRV-ATTR:host" : "compute-0",
-         "OS-EXT-AZ:availability_zone" : "nova",
-         "name" : "test2",
-         "wrs-res:pci_devices" : "",
-         "hostId" : "b3479a460f5effda10c6fdb860e824be631026c1d09f551479180577",
-         "user_id" : "777155411f3042c9b7e3194188d6f85d",
-         "status" : "ACTIVE",
-         "OS-EXT-STS:power_state" : 1,
-         "OS-EXT-SRV-ATTR:hypervisor_hostname" : "compute-0",
-         "tenant_id" : "ad979139d5ea4a84b21b3620c0e4761e",
-         "OS-SRV-USG:launched_at" : "2018-03-27T02:12:21.000000",
-         "OS-EXT-STS:vm_state" : "active",
-         "wrs-if:nics" : [
-            {
-               "nic1" : {
-                  "mac_address" : "fa:16:3e:54:f8:a6",
-                  "network" : "mgmt",
-                  "port_id" : "30e2f51c-4473-4650-9ae9-a35e5d7ad452",
-                  "vif_model" : "avp",
-                  "vif_pci_address" : "",
-                  "mtu" : 9216
-               }
-            }
-         ],
-         "wrs-sg:server_group" : "",
-         "OS-EXT-STS:task_state" : "",
-         "wrs-res:topology" : "node:0,  4096MB, pgsize:2M, 1s,3c,1t, vcpus:0-2, pcpus:4,20,7, pol:ded, thr:pre",
-         "progress" : 0,
-         "wrs-res:vcpus" : [
-            3,
-            3,
-            3
-         ],
-         "key_name" : "",
-         "image" : {
-            "id" : "7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb",
-            "links" : [
-               {
-                  "rel" : "bookmark",
-                  "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/images/7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb"
-               }
-            ]
-         },
-         "created" : "2018-03-27T02:10:26Z",
-         "addresses" : {
-            "mgmt" : [
-               {
-                  "OS-EXT-IPS:type" : "fixed",
-                  "version" : 4,
-                  "OS-EXT-IPS-MAC:mac_addr" : "fa:16:3e:54:f8:a6",
-                  "addr" : "192.168.1.11"
-               }
-            ]
-         },
-         "os-extended-volumes:volumes_attached" : []
-      },
-      {
-         "accessIPv4" : "",
-         "OS-EXT-SRV-ATTR:instance_name" : "instance-00000008",
-         "OS-SRV-USG:terminated_at" : "",
-         "accessIPv6" : "",
-         "config_drive" : "",
-         "OS-DCF:diskConfig" : "AUTO",
-         "updated" : "2018-03-27T02:12:15Z",
-         "metadata" : {},
-         "id" : "1b6f6671-b680-42cd-89e9-fc4ddd5d2e02",
-         "flavor" : {
-            "id" : "0d3b1381-1626-4f6b-869b-4a4d5d42085e",
-            "links" : [
-               {
-                  "rel" : "bookmark",
-                  "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/flavors/0d3b1381-1626-4f6b-869b-4a4d5d42085e"
-               }
-            ]
-         },
-         "links" : [
-            {
-               "rel" : "self",
-               "href" : "http://192.168.100.100:8774/v2.1/ad979139d5ea4a84b21b3620c0e4761e/servers/1b6f6671-b680-42cd-89e9-fc4ddd5d2e02"
+            "created": "2018-03-27T02:10:26Z",
+            "addresses": {
+                "mgmt": [
+                    {
+                        "OS-EXT-IPS:type": "fixed",
+                        "version": 4,
+                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:54:f8:a6",
+                        "addr": "192.168.1.11"
+                    }
+                ]
             },
-            {
-               "rel" : "bookmark",
-               "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/servers/1b6f6671-b680-42cd-89e9-fc4ddd5d2e02"
-            }
-         ],
-         "OS-EXT-SRV-ATTR:host" : "compute-0",
-         "OS-EXT-AZ:availability_zone" : "nova",
-         "name" : "test3",
-         "wrs-res:pci_devices" : "",
-         "hostId" : "b3479a460f5effda10c6fdb860e824be631026c1d09f551479180577",
-         "user_id" : "777155411f3042c9b7e3194188d6f85d",
-         "status" : "ACTIVE",
-         "OS-EXT-STS:power_state" : 1,
-         "OS-EXT-SRV-ATTR:hypervisor_hostname" : "compute-0",
-         "tenant_id" : "ad979139d5ea4a84b21b3620c0e4761e",
-         "OS-SRV-USG:launched_at" : "2018-03-27T02:12:15.000000",
-         "OS-EXT-STS:vm_state" : "active",
-         "wrs-if:nics" : [
-            {
-               "nic1" : {
-                  "mac_address" : "fa:16:3e:4e:9b:75",
-                  "network" : "mgmt",
-                  "port_id" : "72d13987-1d94-4a64-aa1a-973869ae1cad",
-                  "vif_model" : "avp",
-                  "vif_pci_address" : "",
-                  "mtu" : 9216
-               }
-            }
-         ],
-         "wrs-sg:server_group" : "",
-         "OS-EXT-STS:task_state" : "",
-         "wrs-res:topology" : "node:0,  4096MB, pgsize:2M, 1s,3c,1t, vcpus:0-2, pcpus:19,3,22, pol:ded, thr:pre",
-         "progress" : 0,
-         "wrs-res:vcpus" : [
-            3,
-            3,
-            3
-         ],
-         "key_name" : "",
-         "image" : {
-            "id" : "7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb",
-            "links" : [
-               {
-                  "rel" : "bookmark",
-                  "href" : "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/images/7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb"
-               }
-            ]
-         },
-         "created" : "2018-03-27T02:10:01Z",
-         "addresses" : {
-            "mgmt" : [
-               {
-                  "OS-EXT-IPS:type" : "fixed",
-                  "version" : 4,
-                  "OS-EXT-IPS-MAC:mac_addr" : "fa:16:3e:4e:9b:75",
-                  "addr" : "192.168.1.8"
-               }
-            ]
-         },
-         "os-extended-volumes:volumes_attached" : []
-      }
-   ]
+            "os-extended-volumes:volumes_attached": []
+        },
+        {
+            "accessIPv4": "",
+            "OS-EXT-SRV-ATTR:instance_name": "instance-00000008",
+            "OS-SRV-USG:terminated_at": "",
+            "accessIPv6": "",
+            "config_drive": "",
+            "OS-DCF:diskConfig": "AUTO",
+            "updated": "2018-03-27T02:12:15Z",
+            "metadata": {},
+            "id": "1b6f6671-b680-42cd-89e9-fc4ddd5d2e02",
+            "flavor": {
+                "id": "0d3b1381-1626-4f6b-869b-4a4d5d42085e",
+                "links": [
+                    {
+                        "rel": "bookmark",
+                        "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/flavors/0d3b1381-1626-4f6b-869b-4a4d5d42085e"
+                    }
+                ]
+            },
+            "links": [
+                {
+                    "rel": "self",
+                    "href": "http://192.168.100.100:8774/v2.1/ad979139d5ea4a84b21b3620c0e4761e/servers/1b6f6671-b680-42cd-89e9-fc4ddd5d2e02"
+                },
+                {
+                    "rel": "bookmark",
+                    "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/servers/1b6f6671-b680-42cd-89e9-fc4ddd5d2e02"
+                }
+            ],
+            "OS-EXT-SRV-ATTR:host": "compute-0",
+            "OS-EXT-AZ:availability_zone": "nova",
+            "name": "test3",
+            "wrs-res:pci_devices": "",
+            "hostId": "b3479a460f5effda10c6fdb860e824be631026c1d09f551479180577",
+            "user_id": "777155411f3042c9b7e3194188d6f85d",
+            "status": "ACTIVE",
+            "OS-EXT-STS:power_state": 1,
+            "OS-EXT-SRV-ATTR:hypervisor_hostname": "compute-0",
+            "tenant_id": "ad979139d5ea4a84b21b3620c0e4761e",
+            "OS-SRV-USG:launched_at": "2018-03-27T02:12:15.000000",
+            "OS-EXT-STS:vm_state": "active",
+            "wrs-if:nics": [
+                {
+                    "nic1": {
+                        "mac_address": "fa:16:3e:4e:9b:75",
+                        "network": "mgmt",
+                        "port_id": "72d13987-1d94-4a64-aa1a-973869ae1cad",
+                        "vif_model": "avp",
+                        "vif_pci_address": "",
+                        "mtu": 9216
+                    }
+                }
+            ],
+            "wrs-sg:server_group": "",
+            "OS-EXT-STS:task_state": "",
+            "wrs-res:topology": "node:0,  4096MB, pgsize:2M, 1s,3c,1t, vcpus:0-2, pcpus:19,3,22, pol:ded, thr:pre",
+            "progress": 0,
+            "wrs-res:vcpus": [3, 3, 3],
+            "key_name": "",
+            "image": {
+                "id": "7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb",
+                "links": [
+                    {
+                        "rel": "bookmark",
+                        "href": "http://192.168.100.100:8774/ad979139d5ea4a84b21b3620c0e4761e/images/7ba636ef-5dfd-4e67-ad32-cd23ee74e1eb"
+                    }
+                ]
+            },
+            "created": "2018-03-27T02:10:01Z",
+            "addresses": {
+                "mgmt": [
+                    {
+                        "OS-EXT-IPS:type": "fixed",
+                        "version": 4,
+                        "OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:4e:9b:75",
+                        "addr": "192.168.1.8"
+                    }
+                ]
+            },
+            "os-extended-volumes:volumes_attached": []
+        }
+    ]
 }
 
 SUCCESS_VMSTATE_RESPONSE = {
-'result':[
-    {
-        'name': 'test1',
-        'power_state': 3,
-        'id': '12f5b1d0-fe5c-469f-a7d4-b62a91134bf8',
-        'state': 'paused',
-        'tenant_id': 'ad979139d5ea4a84b21b3620c0e4761e',
-        'host': 'compute-0',
-        'availability_zone': 'nova',
-        'launched_at': '2018-03-27T02:16:40.000000'
-    },
-    {
-        'name': 'test2',
-        'power_state': 1,
-        'id': '3f1b0375-a1db-4d94-b336-f32c82c0d7ec',
-        'state': 'active',
-        'tenant_id': 'ad979139d5ea4a84b21b3620c0e4761e',
-        'host': 'compute-0',
-        'availability_zone': 'nova',
-        'launched_at': '2018-03-27T02:12:21.000000'
-    },
-    {
-        'name': 'test3',
-        'power_state': 1,
-        'id': '1b6f6671-b680-42cd-89e9-fc4ddd5d2e02',
-        'state': 'active',
-        'tenant_id': 'ad979139d5ea4a84b21b3620c0e4761e',
-        'host': 'compute-0',
-        'availability_zone': 'nova',
-        'launched_at': '2018-03-27T02:12:15.000000'
-    }
+    'result': [
+        {
+            'name': 'test1',
+            'power_state': 3,
+            'id': '12f5b1d0-fe5c-469f-a7d4-b62a91134bf8',
+            'state': 'paused',
+            'tenant_id': 'ad979139d5ea4a84b21b3620c0e4761e',
+            'host': 'compute-0',
+            'availability_zone': 'nova',
+            'launched_at': '2018-03-27T02:16:40.000000'
+        },
+        {
+            'name': 'test2',
+            'power_state': 1,
+            'id': '3f1b0375-a1db-4d94-b336-f32c82c0d7ec',
+            'state': 'active',
+            'tenant_id': 'ad979139d5ea4a84b21b3620c0e4761e',
+            'host': 'compute-0',
+            'availability_zone': 'nova',
+            'launched_at': '2018-03-27T02:12:21.000000'
+        },
+        {
+            'name': 'test3',
+            'power_state': 1,
+            'id': '1b6f6671-b680-42cd-89e9-fc4ddd5d2e02',
+            'state': 'active',
+            'tenant_id': 'ad979139d5ea4a84b21b3620c0e4761e',
+            'host': 'compute-0',
+            'availability_zone': 'nova',
+            'launched_at': '2018-03-27T02:12:15.000000'
+        }
     ]
 }
 
+
 class TestEvents(test_base.TestRequest):
     def setUp(self):
         super(TestEvents, self).setUp()
index ed39da9..c608865 100644 (file)
 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 ocata.resource.views.infra_workload import InfraWorkload
 from ocata.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_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"
+                            }
+                        ]
+                    },
+                    {
+                        "type": "sriovNetNetwork_directives",
+                        "attributes": [
+                            {
+                                "attribute_name": "physnetwork_label",
+                                "attribute_value": "physnet1"
+                            }
+                        ]
+                    }
+                ]
+            }
+        ]
+    },
+    "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 = {
@@ -102,51 +119,51 @@ MOCK_HEAT_CREATE_RESPONSE1 = {
 MOCK_HEAT_LIST_RESPONSE1 = {
     'stacks': [
         {
-            'stack_status':"CREATE_IN_PROCESS"
+            'stack_status': "CREATE_IN_PROCESS"
         }
     ]
 }
 
 
-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\" &gt; /root/hello-world.txt\n"
-                     }
-                 }
-             }
-         },
-         "timeout_mins":60
-     }
+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\" &gt; /root/hello-world.txt\n"
+                    }
+                }
+            }
+        },
+        "timeout_mins": 60
+    }
 }
 
+
 class InfraWorkloadTest(unittest.TestCase):
     def setUp(self):
         self._InfraWorkload = InfraWorkload()
@@ -157,18 +174,18 @@ class InfraWorkloadTest(unittest.TestCase):
 
     @mock.patch.object(helper, 'MultiCloudServiceHelper')
     @mock.patch.object(helper, 'MultiCloudIdentityHelper')
-    def test_post(self,  mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper):
+    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= [
+        mock_MultiCloudIdentityHelper.side_effect = [
             (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED)
-                ]
+        ]
 
-        mock_MultiCloudServiceHelper.side_effect= [
+        mock_MultiCloudServiceHelper.side_effect = [
             (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED)
-                ]
+        ]
 
         vimid = "CloudOwner_Region1"
 
@@ -176,21 +193,20 @@ class InfraWorkloadTest(unittest.TestCase):
         self.assertEqual(response.status_code, status.HTTP_201_CREATED)
         pass
 
-
     @mock.patch.object(helper, 'MultiCloudServiceHelper')
     @mock.patch.object(helper, 'MultiCloudIdentityHelper')
-    def test_post_wo_oof_directive(self,  mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper):
+    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= [
+        mock_MultiCloudIdentityHelper.side_effect = [
             (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED)
-                ]
+        ]
 
-        mock_MultiCloudServiceHelper.side_effect= [
+        mock_MultiCloudServiceHelper.side_effect = [
             (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED)
-                ]
+        ]
 
         vimid = "CloudOwner_Region1"
 
@@ -200,17 +216,17 @@ class InfraWorkloadTest(unittest.TestCase):
 
     @mock.patch.object(helper, 'MultiCloudServiceHelper')
     @mock.patch.object(helper, 'MultiCloudIdentityHelper')
-    def test_get(self,  mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper):
+    def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper):
         mock_request = mock.Mock()
         mock_request.META = {"testkey": "testvalue"}
 
-        mock_MultiCloudIdentityHelper.side_effect= [
+        mock_MultiCloudIdentityHelper.side_effect = [
             (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED)
-                ]
+        ]
 
-        mock_MultiCloudServiceHelper.side_effect= [
+        mock_MultiCloudServiceHelper.side_effect = [
             (0, MOCK_HEAT_LIST_RESPONSE1, status.HTTP_200_OK)
-                ]
+        ]
 
         vimid = "CloudOwner_Region1"
         mock_stack_id = "MOCKED_HEAT_STACK_ID1"
@@ -219,6 +235,27 @@ class InfraWorkloadTest(unittest.TestCase):
         self.assertEqual(response.status_code, status.HTTP_200_OK)
         pass
 
+    @mock.patch.object(helper, 'MultiCloudServiceHelper')
+    @mock.patch.object(helper, 'MultiCloudIdentityHelper')
+    def test_delete(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.delete(mock_request, vimid, mock_stack_id)
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        pass
+
 
 class APIv1InfraWorkloadTest(unittest.TestCase):
     def setUp(self):
@@ -230,18 +267,18 @@ class APIv1InfraWorkloadTest(unittest.TestCase):
 
     @mock.patch.object(helper, 'MultiCloudServiceHelper')
     @mock.patch.object(helper, 'MultiCloudIdentityHelper')
-    def test_post(self,  mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper):
+    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= [
+        mock_MultiCloudIdentityHelper.side_effect = [
             (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED)
-                ]
+        ]
 
-        mock_MultiCloudServiceHelper.side_effect= [
+        mock_MultiCloudServiceHelper.side_effect = [
             (0, MOCK_HEAT_CREATE_RESPONSE1, status.HTTP_201_CREATED)
-                ]
+        ]
 
         cloud_owner = "CloudOwner"
         cloud_region_id = "Region1"
@@ -250,21 +287,19 @@ class APIv1InfraWorkloadTest(unittest.TestCase):
         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):
+    def test_get(self, mock_MultiCloudIdentityHelper, mock_MultiCloudServiceHelper):
         mock_request = mock.Mock()
         mock_request.META = {"testkey": "testvalue"}
 
-        mock_MultiCloudIdentityHelper.side_effect= [
+        mock_MultiCloudIdentityHelper.side_effect = [
             (0, MOCK_TOKEN_RESPONSE, status.HTTP_201_CREATED)
-                ]
+        ]
 
-        mock_MultiCloudServiceHelper.side_effect= [
+        mock_MultiCloudServiceHelper.side_effect = [
             (0, MOCK_HEAT_LIST_RESPONSE1, status.HTTP_200_OK)
-                ]
-
+        ]
 
         cloud_owner = "CloudOwner"
         cloud_region_id = "Region1"
@@ -273,3 +308,25 @@ class APIv1InfraWorkloadTest(unittest.TestCase):
         response = self._APIv1InfraWorkload.get(mock_request, cloud_owner, cloud_region_id, mock_stack_id)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
         pass
+
+    @mock.patch.object(helper, 'MultiCloudServiceHelper')
+    @mock.patch.object(helper, 'MultiCloudIdentityHelper')
+    def test_delete(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.delete(mock_request, cloud_owner, cloud_region_id, mock_stack_id)
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        pass
index afa702d..ae1ce9d 100644 (file)
@@ -11,4 +11,3 @@
 # 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.
-
index b9d263e..e76c93a 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2018 Wind River Systems, Inc.
+# 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.
 # limitations under the License.
 
 import logging
-import json
 import traceback
 
-from rest_framework import status
-
-from django.conf import settings
 from common.exceptions import VimDriverNewtonException
 from newton_base.util import VimDriverUtils
 
@@ -42,30 +38,29 @@ class CapacityCheck(APIView):
         self._logger.debug("CapacityCheck--post::META> %s" % request.META)
 
         hasEnoughResource = False
-        try :
+        try:
             resource_demand = request.data
 
             tenant_name = None
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenant_name)
 
-            #get token:
+            # get token:
             cloud_owner, regionid = extsys.decode_vim_id(vimid)
             interface = 'public'
             service = {'service_type': 'compute',
                        'interface': interface,
                        'region_name': vim['openstack_region_id']
-                           if vim.get('openstack_region_id')
-                           else vim['cloud_region_id']}
-
+                       if vim.get('openstack_region_id')
+                       else vim['cloud_region_id']}
 
-            #get limit for this tenant
+            # get limit for this tenant
             req_resouce = "/limits"
             resp = sess.get(req_resouce, endpoint_filter=service)
             content = resp.json()
             compute_limits = content['limits']['absolute']
 
-            #get total resource of this cloud region
+            # get total resource of this cloud region
             try:
                 req_resouce = "/os-hypervisors/statistics"
                 self._logger.info("check os-hypervisors statistics> URI:%s" % req_resouce)
@@ -82,12 +77,12 @@ class CapacityCheck(APIView):
                     conFreeRamMB = int(resource_demand['Memory'])
                     conFreeDiskGB = int(resource_demand['Storage'])
                     self._logger.info("Non administator forbidden to access hypervisor statistics data")
-                    hypervisor_statistics = {'vcpus_used':0, 'vcpus':conVCPUS, 'free_ram_mb':conFreeRamMB, 'free_disk_gb':conFreeDiskGB}
+                    hypervisor_statistics = {'vcpus_used': 0, 'vcpus': conVCPUS, 'free_ram_mb': conFreeRamMB, 'free_disk_gb': conFreeDiskGB}
                 else:
                     # non forbiden exeption will be redirected
                     raise e
 
-            #get storage limit for this tenant
+            # get storage limit for this tenant
             service['service_type'] = 'volumev2'
             req_resouce = "/limits"
             resp = sess.get(req_resouce, endpoint_filter=service)
@@ -123,7 +118,7 @@ class CapacityCheck(APIView):
 
             return Response(data={'result': hasEnoughResource}, status=status.HTTP_200_OK)
         except VimDriverNewtonException as e:
-            return Response(data={'result': hasEnoughResource,'error': e.content}, status=e.status_code)
+            return Response(data={'result': hasEnoughResource, 'error': e.content}, status=e.status_code)
         except HttpError as e:
             self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
             resp = e.response.json()
@@ -134,6 +129,7 @@ class CapacityCheck(APIView):
             return Response(data={'result': hasEnoughResource, 'error': str(e)},
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
 
+
 class APIv1CapacityCheck(CapacityCheck):
 
     def __init__(self):
@@ -146,4 +142,3 @@ class APIv1CapacityCheck(CapacityCheck):
 
         vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
         return super(APIv1CapacityCheck, self).post(request, vimid)
-
index a5b7d82..6b48f2d 100644 (file)
 # limitations under the License.
 
 import logging
-import json
 import traceback
 
-from rest_framework import status
-
-from django.conf import settings
 from common.exceptions import VimDriverNewtonException
 from newton_base.util import VimDriverUtils
 
@@ -41,9 +37,7 @@ class EventsCheck(APIView):
         self._logger.info("vimid, data> %s, %s" % (vimid, request.data))
         self._logger.debug("META> %s" % request.META)
 
-        try :
-            resource_demand = request.data
-
+        try:
             tenant_name = None
             vim = VimDriverUtils.get_vim_info(vimid)
             sess = VimDriverUtils.get_session(vim, tenant_name)
@@ -51,12 +45,13 @@ class EventsCheck(APIView):
             # get token:
             cloud_owner, regionid = extsys.decode_vim_id(vimid)
             interface = 'public'
-            service = {'service_type': 'compute',
-                       'interface': interface,
-                       'region_name': vim['openstack_region_id']
-                           if vim.get('openstack_region_id')
-                           else vim['cloud_region_id']}
-
+            service = {
+                'service_type': 'compute',
+                'interface': interface,
+                'region_name': vim['openstack_region_id']
+                if vim.get('openstack_region_id')
+                else vim['cloud_region_id']
+            }
 
             # get servers detail info
             req_resouce = "/servers/detail"
@@ -67,19 +62,19 @@ class EventsCheck(APIView):
             self._logger.debug("check servers detail> resp data:%s" % content)
 
             # extract server status info
-            if len(content['servers']): 
+            if len(content['servers']):
                 servers = content['servers']
                 resp_vmstate = []
                 for num in range(0, len(servers)):
                     vmstate = {
-                        'name' : servers[num]['name'],
-                        'state' : servers[num]['OS-EXT-STS:vm_state'],
-                        'power_state' : servers[num]['OS-EXT-STS:power_state'],
-                        'launched_at' : servers[num]['OS-SRV-USG:launched_at'],
-                        'id' : servers[num]['id'],
-                        'host' : servers[num]['OS-EXT-SRV-ATTR:host'],
-                        'availability_zone' : servers[num]['OS-EXT-AZ:availability_zone'],
-                        'tenant_id' : servers[num]['tenant_id']
+                        'name': servers[num]['name'],
+                        'state': servers[num]['OS-EXT-STS:vm_state'],
+                        'power_state': servers[num]['OS-EXT-STS:power_state'],
+                        'launched_at': servers[num]['OS-SRV-USG:launched_at'],
+                        'id': servers[num]['id'],
+                        'host': servers[num]['OS-EXT-SRV-ATTR:host'],
+                        'availability_zone': servers[num]['OS-EXT-AZ:availability_zone'],
+                        'tenant_id': servers[num]['tenant_id']
                     }
 
                     resp_vmstate.append(vmstate)
@@ -88,9 +83,9 @@ class EventsCheck(APIView):
             return Response(data={'result': resp_vmstate}, status=status.HTTP_200_OK)
 
         except VimDriverNewtonException as e:
-            self._logger.error("Plugin exception> status:%s,error:%s"
-                                  % (e.status_code, e.content))
-            return Response(data={'result': resp_vmstate,'error': e.content}, status=e.status_code)
+            self._logger.error("Plugin exception> status:%s,error:%s" %
+                               (e.status_code, e.content))
+            return Response(data={'result': resp_vmstate, 'error': e.content}, status=e.status_code)
 
         except HttpError as e:
             self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
@@ -102,4 +97,3 @@ class EventsCheck(APIView):
             self._logger.error(traceback.format_exc())
             return Response(data={'result': resp_vmstate, 'error': str(e)},
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
index b9d754b..0a3a574 100644 (file)
@@ -26,7 +26,6 @@ from common.msapi import extsys
 from common.msapi.helper import Helper as helper
 from common.utils import restcall
 from common.exceptions import VimDriverNewtonException
-from newton_base.util import VimDriverUtils
 
 logger = logging.getLogger(__name__)
 
@@ -67,15 +66,15 @@ class InfraWorkload(APIView):
                 # update parameters
                 template_data["parameters"] = parameters
 
-                #reset to make sure "files" are empty
+                # reset to make sure "files" are empty
                 template_data["file"] = {}
 
-                #authenticate
+                # authenticate
                 cloud_owner, regionid = extsys.decode_vim_id(vimid)
                 # should go via multicloud proxy so that the selflink is updated by multicloud
                 retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper(
-                                                 settings.MULTICLOUD_API_V1_PREFIX,
-                                                 cloud_owner, regionid, "/v2.0/tokens")
+                    settings.MULTICLOUD_API_V1_PREFIX,
+                    cloud_owner, regionid, "/v2.0/tokens")
                 if retcode > 0 or not v2_token_resp_json:
                     logger.error("authenticate fails:%s,%s, %s" %
                                  (cloud_owner, regionid, v2_token_resp_json))
@@ -85,8 +84,12 @@ class InfraWorkload(APIView):
                 resource_uri = "/stacks"
                 self._logger.info("retrieve stack resources, URI:%s" % resource_uri)
                 retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner,
-                                                         regionid, v2_token_resp_json, service_type,
-                                                         resource_uri, template_data, "POST")
+                                                                             regionid,
+                                                                             v2_token_resp_json,
+                                                                             service_type,
+                                                                             resource_uri,
+                                                                             template_data,
+                                                                             "POST")
                 stack1 = content.get('stack', None) if retcode == 0 and content else None
                 resp_template = {
                     "template_type": template_type,
@@ -100,11 +103,11 @@ class InfraWorkload(APIView):
             else:
                 msg = "The template type %s is not supported" % (template_type)
                 self._logger.warn(msg)
-                return Response(data={"error":msg}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+                return Response(data={"error": msg}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
 
         except VimDriverNewtonException as e:
             self._logger.error("Plugin exception> status:%s,error:%s"
-                                  % (e.status_code, e.content))
+                               % (e.status_code, e.content))
             return Response(data={'error': e.content}, status=e.status_code)
         except HttpError as e:
             self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
@@ -114,7 +117,6 @@ class InfraWorkload(APIView):
             return Response(data={'error': str(e)},
                             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
 
-
     def get(self, request, vimid="", requri=""):
         self._logger.info("vimid, requri: %s, %s" % (vimid, requri))
         self._logger.debug("META: %s" % request.META)
@@ -128,7 +130,7 @@ class InfraWorkload(APIView):
             retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper(
                 settings.MULTICLOUD_API_V1_PREFIX,
                 cloud_owner, regionid, "/v2.0/tokens")
-            if retcode > 0  or not v2_token_resp_json:
+            if retcode > 0 or not v2_token_resp_json:
                 logger.error("authenticate fails:%s, %s, %s" % (cloud_owner, regionid, v2_token_resp_json))
                 return
 
@@ -139,7 +141,7 @@ class InfraWorkload(APIView):
             retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, regionid, v2_token_resp_json,
                                                                          service_type, resource_uri, None, "GET")
             stacks = content.get('stacks', []) if retcode == 0 and content else []
-            stack_status = stacks[0]["stack_status"] if len(stacks)>0 else ""
+            stack_status = stacks[0]["stack_status"] if len(stacks) > 0 else ""
 
             resp_template = {
                 "template_type": template_type,
@@ -157,7 +159,7 @@ class InfraWorkload(APIView):
             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))
+                               % (e.status_code, e.content))
             return Response(data={'error': e.content}, status=e.status_code)
         except HttpError as e:
             self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
@@ -180,7 +182,7 @@ class InfraWorkload(APIView):
         cloud_owner, regionid = extsys.decode_vim_id(vimid)
         # should go via multicloud proxy so that the selflink is updated by multicloud
         retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper(settings.MULTICLOUD_API_V1_PREFIX,
-                                                             cloud_owner, regionid, "/v2.0/tokens")
+                                                                                 cloud_owner, regionid, "/v2.0/tokens")
         if retcode > 0:
             logger.error("authenticate fails:%s, %s, %s" % (cloud_owner, regionid, v2_token_resp_json))
             return None
@@ -189,16 +191,16 @@ class InfraWorkload(APIView):
 
         # common prefix
         aai_cloud_region = "/cloud-infrastructure/cloud-regions/cloud-region/%s/%s/tenants/tenant/%s" \
-                                  % (cloud_owner, regionid, tenant_id)
+                           % (cloud_owner, regionid, tenant_id)
 
         # get stack resource
         service_type = "orchestration"
-        resource_uri = "/stacks/%s/resources"%(stack_id)
+        resource_uri = "/stacks/%s/resources" % (stack_id)
         self._logger.info("retrieve stack resources, URI:%s" % resource_uri)
         retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, regionid, v2_token_resp_json, service_type, resource_uri, None, "GET")
         resources = content.get('resources', []) if retcode == 0 and content else []
 
-        #find and update resources
+        # find and update resources
         transactions = []
         for resource in resources:
             if resource.get('resource_status', None) != "CREATED_COMPLETE":
@@ -209,7 +211,7 @@ class InfraWorkload(APIView):
                 resource_uri = "/servers/%s" % (resource['physical_resource_id'])
                 self._logger.info("retrieve vserver detail, URI:%s" % resource_uri)
                 retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, regionid, v2_token_resp_json, service_type,
-                                                       resource_uri, None, "GET")
+                                                                             resource_uri, None, "GET")
                 self._logger.debug(" resp data:%s" % content)
                 vserver_detail = content.get('server', None) if retcode == 0 and content else None
                 if vserver_detail:
@@ -232,8 +234,9 @@ class InfraWorkload(APIView):
                             "vserver-selflink": vserver_link,
                             "prov-status": vserver_detail['status']
                         },
-                        "uri": aai_cloud_region + "/vservers/vserver/%s"\
-                                                             % ( vserver_detail['id'])}
+                        "uri": aai_cloud_region + "/vservers/vserver/%s"
+                                                  % (vserver_detail['id'])
+                    }
 
                     try:
                         # then update the resource
@@ -244,12 +247,12 @@ class InfraWorkload(APIView):
                             content = json.JSONDecoder().decode(content)
                             self._logger.debug("AAI update %s response: %s" % (aai_resource['uri'], content))
                     except Exception as e:
-                        self._logger.error(traceback.format_exc())
+                        self._logger.error(traceback.format_exc(e))
                         pass
 
                     aai_resource_transactions = {"put": [aai_resource]}
                     transactions.append(aai_resource_transactions)
-                    #self._logger.debug("aai_resource :%s" % aai_resource_transactions)
+                    # self._logger.debug("aai_resource :%s" % aai_resource_transactions)
                     pass
 
         for resource in resources:
@@ -260,8 +263,13 @@ class InfraWorkload(APIView):
                 service_type = "network"
                 resource_uri = "/v2.0/ports/%s" % (resource['physical_resource_id'])
                 self._logger.info("retrieve vserver detail, URI:%s" % resource_uri)
-                retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner, regionid, v2_token_resp_json, service_type,
-                                                       resource_uri, None, "GET")
+                retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner,
+                                                                             regionid,
+                                                                             v2_token_resp_json,
+                                                                             service_type,
+                                                                             resource_uri,
+                                                                             None,
+                                                                             "GET")
                 self._logger.debug(" resp data:%s" % content)
 
                 vport_detail = content.get('port', None) if retcode == 0 and content else None
@@ -275,7 +283,7 @@ class InfraWorkload(APIView):
                             "interface-id": vport_detail['id'],
                             "macaddr": vport_detail['mac_address']
                         },
-                        'uri': aai_cloud_region + "/vservers/vserver/%s/l-interfaces/l-interface/%s" \
+                        'uri': aai_cloud_region + "/vservers/vserver/%s/l-interfaces/l-interface/%s"
                                                   % (vport_detail['device_id'], vport_detail['name'])
                     }
                     try:
@@ -287,7 +295,7 @@ class InfraWorkload(APIView):
                             content = json.JSONDecoder().decode(content)
                             self._logger.debug("AAI update %s response: %s" % (aai_resource['uri'], content))
                     except Exception as e:
-                        self._logger.error(traceback.format_exc())
+                        self._logger.error(traceback.format_exc(e))
                         pass
 
                     aai_resource_transactions = {"put": [aai_resource]}
@@ -320,7 +328,7 @@ class InfraWorkload(APIView):
             retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper(
                 settings.MULTICLOUD_API_V1_PREFIX,
                 cloud_owner, regionid, "/v2.0/tokens")
-            if retcode > 0  or not v2_token_resp_json:
+            if retcode > 0 or not v2_token_resp_json:
                 logger.error("authenticate fails:%s, %s, %s" % (cloud_owner, regionid, v2_token_resp_json))
                 return
             # tenant_id = v2_token_resp_json["access"]["token"]["tenant"]["id"]
@@ -361,7 +369,7 @@ class InfraWorkload(APIView):
             return Response(status=os_status)
         except VimDriverNewtonException as e:
             self._logger.error("Plugin exception> status:%s,error:%s"
-                                  % (e.status_code, e.content))
+                               % (e.status_code, e.content))
             return Response(data={'error': e.content}, status=e.status_code)
         except HttpError as e:
             self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
@@ -391,22 +399,22 @@ class APIv1InfraWorkload(InfraWorkload):
         # self._logger = logger
 
     def post(self, request, cloud_owner="", cloud_region_id="", requri=""):
-        #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
-        #self._logger.debug("META: %s" % request.META)
+        # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
+        # self._logger.debug("META: %s" % request.META)
 
         vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
         return super(APIv1InfraWorkload, self).post(request, vimid, requri)
 
     def get(self, request, cloud_owner="", cloud_region_id="", requri=""):
-        #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
-        #self._logger.debug("META: %s" % request.META)
+        # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
+        # self._logger.debug("META: %s" % request.META)
 
         vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
         return super(APIv1InfraWorkload, self).get(request, vimid, requri)
 
     def delete(self, request, cloud_owner="", cloud_region_id="", requri=""):
-        #self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
-        #self._logger.debug("META: %s" % request.META)
+        # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
+        # self._logger.debug("META: %s" % request.META)
 
         vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
         return super(APIv1InfraWorkload, self).delete(request, vimid, requri)