summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/resource/tests
diff options
context:
space:
mode:
authorXiaohua Zhang <xiaohua.zhang@windriver.com>2018-11-27 10:30:56 +0000
committerXiaohua Zhang <xiaohua.zhang@windriver.com>2018-11-27 10:30:56 +0000
commit78ead3c00e16cf9e4fd24535a925d3766c6f6aa8 (patch)
tree3486a41b4717e75f07f1ce714e4a945f205c8907 /windriver/titanium_cloud/resource/tests
parent0d045c0bb7ee6e6162d2c1fc3e8031a3b067f49f (diff)
Fix pep8 errors in windriver plugin
Fix errors in resource module Change-Id: I59d43b3c62928bdacffc7fcd6f4c1c8055412e59 Issue-ID: MULTICLOUD-420 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/__init__.py1
-rw-r--r--windriver/titanium_cloud/resource/tests/test_capacity.py82
-rw-r--r--windriver/titanium_cloud/resource/tests/tests_infra_workload.py287
3 files changed, 184 insertions, 186 deletions
diff --git a/windriver/titanium_cloud/resource/tests/__init__.py b/windriver/titanium_cloud/resource/tests/__init__.py
index afa702d3..ae1ce9db 100644
--- a/windriver/titanium_cloud/resource/tests/__init__.py
+++ b/windriver/titanium_cloud/resource/tests/__init__.py
@@ -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.
-
diff --git a/windriver/titanium_cloud/resource/tests/test_capacity.py b/windriver/titanium_cloud/resource/tests/test_capacity.py
index 51785308..baca720f 100644
--- a/windriver/titanium_cloud/resource/tests/test_capacity.py
+++ b/windriver/titanium_cloud/resource/tests/test_capacity.py
@@ -17,30 +17,30 @@ import json
from rest_framework import status
-from common.utils import restcall
+# 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 = {
@@ -66,8 +66,8 @@ MOCK_GET_TENANT_LIMIT_RESPONSE_OUTOFRAM = {
"limits": {
"rate": [],
"absolute": {
- "maxTotalRAMSize": 128 * 1024,
- "totalRAMUsed": 1 * 1024,
+ "maxTotalRAMSize": 12 * 1024,
+ "totalRAMUsed": 10 * 1024,
"totalCoresUsed": 4,
"maxTotalCores": 20,
}
@@ -75,31 +75,31 @@ MOCK_GET_TENANT_LIMIT_RESPONSE_OUTOFRAM = {
}
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_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_STORAGE_RESPONSE = {
- "limits" : {
- "rate" : [],
- "absolute" : {
- "totalGigabytesUsed" : 200,
- "maxTotalVolumeGigabytes" : 500,
- }
- }
+ "limits": {
+ "rate": [],
+ "absolute": {
+ "totalGigabytesUsed": 200,
+ "maxTotalVolumeGigabytes": 500,
+ }
+ }
}
TEST_REQ_SUCCESS_SOURCE = {
@@ -108,13 +108,13 @@ TEST_REQ_SUCCESS_SOURCE = {
"Storage": "200"
}
-
TEST_REQ_FAILED_SOURCE = {
"vCPU": "17",
"Memory": "4096",
"Storage": "200"
}
+
class TestCapacity(test_base.TestRequest):
def setUp(self):
super(TestCapacity, self).setUp()
@@ -163,7 +163,7 @@ class TestCapacity(test_base.TestRequest):
"/api/multicloud-titaniumcloud/v0/windriver-hudson-dc_RegionOne/capacity_check",
TEST_REQ_FAILED_SOURCE,
HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
+
self.assertEquals(status.HTTP_200_OK, response.status_code)
self.assertEqual({"result": False}, response.data)
@@ -252,6 +252,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": False}, 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):
@@ -273,4 +276,3 @@ class TestCapacity(test_base.TestRequest):
self.assertEquals(status.HTTP_200_OK, response.status_code)
self.assertEqual({"result": False}, response.data)
-
diff --git a/windriver/titanium_cloud/resource/tests/tests_infra_workload.py b/windriver/titanium_cloud/resource/tests/tests_infra_workload.py
index 1ace4f99..c6991837 100644
--- a/windriver/titanium_cloud/resource/tests/tests_infra_workload.py
+++ b/windriver/titanium_cloud/resource/tests/tests_infra_workload.py
@@ -15,91 +15,93 @@
import mock
import unittest
-import json
+# import json
from rest_framework import status
-from common.utils import restcall
+# 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"
- }
- ]
- },
- {
- "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"
+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"
+ }]
}
- }
- }
- },
- "timeout_mins":60
- }
+ ]
+ }
+ ]
+ },
+ "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 = {
@@ -111,49 +113,47 @@ 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
+ }
}
@@ -167,18 +167,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"
@@ -186,21 +186,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"
@@ -210,17 +209,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"
@@ -240,18 +239,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"
@@ -260,21 +259,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"