diff options
author | Yun Huang <yun.huang@windriver.com> | 2018-03-28 19:17:30 +0800 |
---|---|---|
committer | Yun Huang <yun.huang@windriver.com> | 2018-03-28 19:17:30 +0800 |
commit | ff22bc4df611031244eee04560a2b7f9272c6cfe (patch) | |
tree | d9552415cf13d87951d833f636fa15523441bf65 | |
parent | 6250e808e24eda2746a0ce0a476e6be61472afda (diff) |
ocata test_register_hpa_hugepage_successfully
Change-Id: Ib4b4aa415d32fde8d8ca0736f9b06b754e8757d0
Issue-ID: MULTICLOUD-206
Signed-off-by: Yun Huang <yun.huang@windriver.com>
-rw-r--r-- | ocata/ocata/registration/tests/test_registration.py | 65 | ||||
-rw-r--r-- | ocata/ocata/registration/views/registration.py | 33 |
2 files changed, 82 insertions, 16 deletions
diff --git a/ocata/ocata/registration/tests/test_registration.py b/ocata/ocata/registration/tests/test_registration.py index ffad2b91..fa920cd4 100644 --- a/ocata/ocata/registration/tests/test_registration.py +++ b/ocata/ocata/registration/tests/test_registration.py @@ -21,6 +21,32 @@ from newton_base.tests import mock_info from newton_base.tests import test_base from newton_base.util import VimDriverUtils +OCATA_MOCK_VIM_INFO = { + "createTime": "2017-04-01 02:22:27", + "domain": "Default", + "name": "TiS_R4", + "password": "admin", + "tenant": "admin", + "type": "openstack", + "url": "http://128.224.180.14:5000/v3", + "userName": "admin", + "vendor": "WindRiver", + "version": "newton", + "vimId": "windriver-hudson-dc_RegionOne", + 'cloud_owner': 'windriver-hudson-dc', + 'cloud_region_id': 'RegionOne', + 'cloud_extra_info': + '{' + '"ovsDpdk":{' + '"version": "v1",' + '"arch": "Intel64",' + '"libname":"dataProcessingAccelerationLibrary",' + '"libvalue":"v12.1",' + '}' + '}', + 'insecure': 'True', +} + MOCK_GET_TENANT_RESPONSE = { "projects":[ {"id": "1", "name": "project"}, @@ -147,6 +173,15 @@ MOCK_GET_HPA_FLAVOR_onap_mini_EXTRA_SPECS2_RESPONSE = { } } +# HPA UT3: mem_page_size +MOCK_GET_HPA_FLAVOR_onap_mini_EXTRA_SPECS3_RESPONSE = { + "extra_specs": { + "aggregate_instance_extra_specs:storage": "local_image", + "capabilities:cpu_info:model": "Haswell", + "hw:mem_page_size": "large" + } +} + MOCK_GET_HPA_FLAVOR_onap_mini_EXTRA_SPECS_RESPONSE = { "extra_specs": { "aggregate_instance_extra_specs:storage": "local_image", @@ -288,3 +323,33 @@ class TestRegistration(test_base.TestRequest): self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code) + @mock.patch.object(VimDriverUtils, 'get_session') + @mock.patch.object(VimDriverUtils, 'get_vim_info') + def test_register_hpa_hugepage_successfully( + self, mock_get_vim_info, mock_get_session): + restcall.req_to_aai = mock.Mock() + restcall.req_to_aai.return_value = (0, {}, status.HTTP_200_OK) + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = test_base.get_mock_session( + ["get"], { + "side_effect": [ + self._get_mock_response(MOCK_GET_TENANT_RESPONSE), + self._get_mock_response(MOCK_GET_HPA_FLAVOR_LIST1_RESPONSE), + self._get_mock_response(MOCK_GET_HPA_FLAVOR_onap_mini_EXTRA_SPECS3_RESPONSE), + self._get_mock_response(MOCK_GET_IMAGE_RESPONSE), + self._get_mock_response(), + self._get_mock_response(MOCK_GET_AZ_RESPONSE), + self._get_mock_response(MOCK_HYPERVISOR_RESPONSE), + self._get_mock_response(MOCK_GET_SNAPSHOT_RESPONSE), + self._get_mock_response(MOCK_GET_HYPERVISOR_RESPONSE) + ] + }) + + response = self.client.post(( + "/api/multicloud-ocata/v0/windriver-hudson-dc_RegionOne/" + "registry"), TEST_REGISTER_ENDPOINT_REQUEST, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + + self.assertEquals(status.HTTP_202_ACCEPTED, + response.status_code) + diff --git a/ocata/ocata/registration/views/registration.py b/ocata/ocata/registration/views/registration.py index 6f2f4f24..74b73b3b 100644 --- a/ocata/ocata/registration/views/registration.py +++ b/ocata/ocata/registration/views/registration.py @@ -38,10 +38,6 @@ class Registry(newton_registration.Registry): def _discover_flavors(self, vimid="", session=None, viminfo=None): try: cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) - cloud_extra_info_str = viminfo.get('cloud_extra_info') - if cloud_extra_info_str: - cloud_extra_info = json.loads(cloud_extra_info_str) - cloud_dpdk_info = cloud_extra_info.get("ovsDpdk") for flavor in self._get_list_resources( "/flavors/detail", "compute", session, viminfo, vimid, @@ -68,7 +64,7 @@ class Registry(newton_registration.Registry): req_resouce = "/flavors/%s/os-extra_specs" % flavor['id'] extraResp = self._get_list_resources(req_resouce, "compute", session, viminfo, vimid, "extra_specs") - hpa_capabilities = self._get_hpa_capabilities(flavor, extraResp, cloud_dpdk_info) + hpa_capabilities = self._get_hpa_capabilities(flavor, extraResp, viminfo) flavor_info['hpa_capabilities'] = hpa_capabilities self._update_resoure( @@ -85,7 +81,7 @@ class Registry(newton_registration.Registry): self._logger.error(traceback.format_exc()) return - def _get_hpa_capabilities(self, flavor, extra_specs, cloud_dpdk_info): + def _get_hpa_capabilities(self, flavor, extra_specs, viminfo): hpa_caps = [] # Basic capabilties @@ -137,7 +133,7 @@ class Registry(newton_registration.Registry): hpa_caps.append(caps_dict) # ovsdpdk capabilities - caps_dict = self._get_ovsdpdk_capabilities(cloud_dpdk_info) + caps_dict = self._get_ovsdpdk_capabilities(viminfo) if len(caps_dict) > 0: self._logger.debug("ovsdpdk_capabilities_info: %s" % caps_dict) hpa_caps.append(caps_dict) @@ -304,16 +300,21 @@ class Registry(newton_registration.Registry): return instruction_capability - def _get_ovsdpdk_capabilities(self, cloud_dpdk_info): + def _get_ovsdpdk_capabilities(self, viminfo): ovsdpdk_capability = {} feature_uuid = uuid.uuid4() - ovsdpdk_capability['hpaCapabilityID'] = str(feature_uuid) - ovsdpdk_capability['hpaFeature'] = 'ovsDpdk' - ovsdpdk_capability['hardwareArchitecture'] = 'Intel64' - ovsdpdk_capability['version'] = 'v1' - - ovsdpdk_capability['attributes'] = [] - ovsdpdk_capability['attributes'].append({'hpa-attribute-key': str(cloud_dpdk_info.get("libname")), - 'hpa-attribute-value':{'value': str(cloud_dpdk_info.get("libversion"))}}) + cloud_extra_info_str = viminfo.get('cloud_extra_info') + if cloud_extra_info_str : + cloud_extra_info = json.loads(cloud_extra_info_str) + cloud_dpdk_info = cloud_extra_info.get("ovsDpdk") + if cloud_dpdk_info : + ovsdpdk_capability['hpaCapabilityID'] = str(feature_uuid) + ovsdpdk_capability['hpaFeature'] = 'ovsDpdk' + ovsdpdk_capability['hardwareArchitecture'] = 'Intel64' + ovsdpdk_capability['version'] = 'v1' + + ovsdpdk_capability['attributes'] = [] + ovsdpdk_capability['attributes'].append({'hpa-attribute-key': str(cloud_dpdk_info.get("libname")), + 'hpa-attribute-value':{'value': str(cloud_dpdk_info.get("libversion"))}}) return ovsdpdk_capability |