diff options
Diffstat (limited to 'ocata')
-rw-r--r-- | ocata/ocata/proxy/tests/test_identity_proxy.py | 43 | ||||
-rw-r--r-- | ocata/ocata/registration/views/registration.py | 247 |
2 files changed, 174 insertions, 116 deletions
diff --git a/ocata/ocata/proxy/tests/test_identity_proxy.py b/ocata/ocata/proxy/tests/test_identity_proxy.py index 774b0ffb..eeabd987 100644 --- a/ocata/ocata/proxy/tests/test_identity_proxy.py +++ b/ocata/ocata/proxy/tests/test_identity_proxy.py @@ -25,6 +25,7 @@ from keystoneauth1.exceptions import HttpError from newton_base.util import VimDriverUtils from ocata.proxy.views.identityV3 import Tokens +from newton_base.tests import mock_info mock_viminfo = { "createTime": "2017-04-01 02:22:27", @@ -532,3 +533,45 @@ class TestIdentityService(unittest.TestCase): self.assertTrue(response['X-Subject-Token'] == mock_token_id) self.assertTrue(context['token']['catalog'] != None) + + @mock.patch.object(VimDriverUtils, 'get_vim_info') + @mock.patch.object(VimDriverUtils, 'get_session') + @mock.patch.object(VimDriverUtils, 'get_auth_state') + @mock.patch.object(VimDriverUtils, 'update_token_cache') + def test_tokensV2(self, mock_update_token_cache, mock_get_auth_state, + mock_get_session, mock_get_vim_info): + ''' + test API: get token + :param mock_update_token_cache: + :param mock_get_auth_state: + :param mock_get_session: + :param mock_get_vim_info: + :return: + ''' + + # mock VimDriverUtils APIs + mock_session_specs = ["get"] + mock_session_get_response = {'status': 200} + mock_session = mock.Mock(name='mock_session', + spec=mock_session_specs) + mock_session.get.return_value = mock_session_get_response + + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = mock_session + mock_get_auth_state.return_value = json.dumps(mock_auth_state) + mock_update_token_cache.return_value = mock_info.MOCK_TOKEN_ID + + # simulate client to make the request + data = {} + response = self.client.post( + "/api/multicloud-ocata/v0/windriver-hudson-dc_RegionOne/identity/v2.0/tokens", + data=data, format='json') + self.failUnlessEqual(status.HTTP_200_OK, + response.status_code) + context = response.json() + + self.assertIsNotNone(context['access']['token']) + self.assertEqual(mock_info.MOCK_TOKEN_ID, + context['access']['token']["id"]) + self.assertIsNotNone(context['access']['serviceCatalog']) + diff --git a/ocata/ocata/registration/views/registration.py b/ocata/ocata/registration/views/registration.py index ddd856b5..d824b88e 100644 --- a/ocata/ocata/registration/views/registration.py +++ b/ocata/ocata/registration/views/registration.py @@ -38,6 +38,11 @@ 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") + hpa_caps = [] hpa_caps.append("[") for flavor in self._get_list_resources( @@ -65,164 +70,174 @@ class Registry(newton_registration.Registry): if (flavor['name'].find('onap.') == -1): continue - properties = flavor['properties'].split(', ') - uuid4 = uuid.uuid4() - # add hpa capability cpu pinning - if (flavor['name'].find('onap.cpu_pinning') != -1): - hpa_caps.append("{'hpaCapabilityID': '" + str(uuid4) + "', ") - hpa_caps.append("'hpaFeature': 'cpuPinning', ") - hpa_caps.append("'hardwareArchitecture': 'generic', ") - hpa_caps.append("'version': 'v1', ") - - if len(properties): - flavor_info['flavor-properties'] = flavor['properties'] - hpa_caps.append("[") - for p in range(len(properties)): - value = properties[p].split('=')[1] - if (properties[p].find("hw:cpu_policy") != -1) : - hpa_caps.append("{'hpa-attribute-key':'logicalCpuThreadPinningPolicy', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") - if (properties[p].find("hw:cpu_thread_policy") != -1) : - hpa_caps.append("{'hpa-attribute-key':'logicalCpuPinningPolicy', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") - hpa_caps.append("]") - hpa_caps.append("},") + if (flavor['extra_specs'] == ""): + continue - elif (flavor['name'].find('onap.cpu_topology') != -1): - hpa_caps.append("{'hpaCapabilityID': '" + str(uuid4) + "', ") - hpa_caps.append("'hpaFeature': 'cpuTopology', ") - hpa_caps.append("'hardwareArchitecture': 'generic', ") - hpa_caps.append("'version': 'v1', ") + flavor_info['extra_specs'] = flavor['extra_specs'] + extra_specs = flavor['extra_specs'] + extra_arr = extra_specs.split(', ') + uuid4 = uuid.uuid4() - if len(properties): - flavor_info['flavor-properties'] = flavor['properties'] - hpa_caps.append("[") - for p in range(len(properties)): - value = properties[p].split('=')[1] - if (properties[p].find("hw:cpu_sockets") != -1) : - hpa_caps.append("{'hpa-attribute-key':'numCpuSockets', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") - if (properties[p].find("hw:cpu_cores") != -1) : - hpa_caps.append("{'hpa-attribute-key':'numCpuCores', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") - if (properties[p].find("hw:cpu_threads") != -1) : - hpa_caps.append("{'hpa-attribute-key':'numCpuThreads', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") - hpa_caps.append("]") - hpa_caps.append("},") + # add ovs dpdk + hpa_caps.append("{'hpaCapabilityID': '" + str(uuid4) + "', ") + hpa_caps.append("'hpaFeature': 'ovsDpdk', ") + hpa_caps.append("'hardwareArchitecture': '" + cloud_dpdk_info.get("arch") + "', ") + hpa_caps.append("'version': '" + cloud_dpdk_info.get("version") + "', ") + hpa_caps.append("[") + hpa_caps.append("{'hpa-attribute-key':'"+ cloud_dpdk_info.get("libname") + "', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + cloud_dpdk_info.get("libvalue") + "'}}, ") + hpa_caps.append("]") + hpa_caps.append("},") + + # add basic Capabilities + hpa_caps.append("{'hpaCapabilityID': '" + str(uuid4) + "', ") + hpa_caps.append("'hpaFeature': 'baseCapabilities', ") + hpa_caps.append("'hardwareArchitecture': 'generic', ") + hpa_caps.append("'version': 'v1', ") + hpa_caps.append("[") + hpa_caps.append("{'hpa-attribute-key':'numVirtualCpu', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + str(flavor_info['vcpus']) + "'}}, ") + hpa_caps.append("{'hpa-attribute-key':'virtualMemSize', ") + hpa_caps.append("'hpa-attribute-value': {'value':" + str(flavor_info['mem']) + ", unit:'MB'}}, ") + hpa_caps.append("]") + hpa_caps.append("},") + + # add local storage + hpa_caps.append("{'hpaCapabilityID': '" + str(uuid4) + "', ") + hpa_caps.append("'hpaFeature': 'localStorage', ") + hpa_caps.append("'hardwareArchitecture': 'generic', ") + hpa_caps.append("'version': 'v1', ") + hpa_caps.append("[") + hpa_caps.append("{'hpa-attribute-key':'diskSize', ") + hpa_caps.append("'hpa-attribute-value': {'value':" + str(flavor_info['disk']) + ", unit:'MB'}}, ") + hpa_caps.append("{'hpa-attribute-key':'ephemeralDiskSize', ") + hpa_caps.append("'hpa-attribute-value': {'value':" + str(flavor_info['OS-FLV-EXT-DATA:ephemeral']) + ", unit:'MB'}}, ") + hpa_caps.append("{'hpa-attribute-key':'swapMemSize', ") + hpa_caps.append("'hpa-attribute-value': {'value':" + str(flavor_info['swap']) + ", unit:'MB'}}, ") + hpa_caps.append("]") + hpa_caps.append("},") - elif (flavor['name'].find('onap.base_capabilities') != -1): + # add hpa capability cpu pinning + if (extra_specs.find('hw:cpu_policy') != -1): hpa_caps.append("{'hpaCapabilityID': '" + str(uuid4) + "', ") - hpa_caps.append("'hpaFeature': 'baseCapabilities', ") + hpa_caps.append("'hpaFeature': 'cpuPinning', ") hpa_caps.append("'hardwareArchitecture': 'generic', ") hpa_caps.append("'version': 'v1', ") - hpa_caps.append("[") - hpa_caps.append("{'hpa-attribute-key':'numVirtualCpu', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + str(flavor_info['vcpus']) + "'}}, ") - hpa_caps.append("{'hpa-attribute-key':'virtualMemSize', ") - hpa_caps.append("'hpa-attribute-value': {'value':" + str(flavor_info['mem']) + ", unit:'MB'}}, ") + for p in range(len(extra_arr)): + if (extra_arr[p].find("hw:cpu_policy") != -1) : + value = extra_arr[p].split('=')[1] + hpa_caps.append("{'hpa-attribute-key':'logicalCpuThreadPinningPolicy', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") + if (extra_arr[p].find("hw:cpu_thread_policy") != -1) : + value = extra_arr[p].split('=')[1] + hpa_caps.append("{'hpa-attribute-key':'logicalCpuPinningPolicy', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") hpa_caps.append("]") hpa_caps.append("},") - elif (flavor['name'].find('onap.local_storage') != -1): + # add cpu topology + if (extra_specs.find('hw:cpu_sockets') != -1): hpa_caps.append("{'hpaCapabilityID': '" + str(uuid4) + "', ") - hpa_caps.append("'hpaFeature': 'localStorage', ") + hpa_caps.append("'hpaFeature': 'cpuTopology', ") hpa_caps.append("'hardwareArchitecture': 'generic', ") hpa_caps.append("'version': 'v1', ") - hpa_caps.append("[") - hpa_caps.append("{'hpa-attribute-key':'diskSize', ") - hpa_caps.append("'hpa-attribute-value': {'value':" + str(flavor_info['disk']) + ", unit:'MB'}}, ") - hpa_caps.append("{'hpa-attribute-key':'ephemeralDiskSize', ") - hpa_caps.append("'hpa-attribute-value': {'value':" + str(flavor_info['OS-FLV-EXT-DATA:ephemeral']) + ", unit:'MB'}}, ") - hpa_caps.append("{'hpa-attribute-key':'swapMemSize', ") - hpa_caps.append("'hpa-attribute-value': {'value':" + str(flavor_info['swap']) + ", unit:'MB'}}, ") + for p in range(len(extra_arr)): + if (extra_arr[p].find("hw:cpu_sockets") != -1) : + value = extra_specs[p].split('=')[1] + hpa_caps.append("{'hpa-attribute-key':'numCpuSockets', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") + if (extra_arr[p].find("hw:cpu_cores") != -1) : + value = extra_specs[p].split('=')[1] + hpa_caps.append("{'hpa-attribute-key':'numCpuCores', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") + if (extra_arr[p].find("hw:cpu_threads") != -1) : + value = extra_specs[p].split('=')[1] + hpa_caps.append("{'hpa-attribute-key':'numCpuThreads', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") hpa_caps.append("]") hpa_caps.append("},") - elif (flavor['name'].find('onap.numa') != -1): + # add numa + if (extra_specs.find('hw:numa_nodes') != -1): hpa_caps.append("{'hpaCapabilityID': '" + str(uuid4) + "', ") hpa_caps.append("'hpaFeature': 'numa', ") hpa_caps.append("'hardwareArchitecture': 'generic', ") hpa_caps.append("'version': 'v1', ") - - if len(properties): - flavor_info['flavor-properties'] = flavor['properties'] - hpa_caps.append("[") - for p in range(len(properties)): - p_arr = properties[p].split('=') + hpa_caps.append("[") + for p in range(len(extra_arr)): + if (extra_arr[p].find("hw:numa_nodes") != -1) : + p_arr = extra_arr[p].split('=') + value = p_arr[1] + hpa_caps.append("{'hpa-attribute-key':'numNodes', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") + if (extra_arr[p].find("hw:numa_cpus") != -1) : + p_arr = extra_arr[p].split('=') value = p_arr[1] index = p_arr[0].split('.')[1] - if (properties[p].find("hw:numa_nodes") != -1) : - hpa_caps.append("{'hpa-attribute-key':'numNodes', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") - if (properties[p].find("hw:numa_cpus") != -1) : - hpa_caps.append("{'hpa-attribute-key':'numaCpus-" + index + "', ") - hpa_caps.append("'hpa-attribute-value': {'value':'[" + value + "]'}}, ") - if (properties[p] == ("hw:numa_mem") != -1) : - hpa_caps.append("{'hpa-attribute-key':'numaMem-"+ index +"', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value + ", unit:'MB'}}, ") - hpa_caps.append("]") + hpa_caps.append("{'hpa-attribute-key':'numaCpus-" + index + "', ") + hpa_caps.append("'hpa-attribute-value': {'value':'[" + value + "]'}}, ") + if (extra_arr[p] == ("hw:numa_mem") != -1) : + p_arr = extra_arr[p].split('=') + value = p_arr[1] + index = p_arr[0].split('.')[1] + hpa_caps.append("{'hpa-attribute-key':'numaMem-"+ index +"', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value + ", unit:'MB'}}, ") + hpa_caps.append("]") hpa_caps.append("},") - elif (flavor['name'].find('onap.huge_page') != -1): + # add huge page + if (extra_specs.find('hw:mem_page_size') != -1): hpa_caps.append("{'hpaCapabilityId': '" + str(uuid4) + "', ") hpa_caps.append("'hpaFeature': 'hugePages', ") hpa_caps.append("'hardwareArchitecture': 'generic', ") hpa_caps.append("'version': 'v1', ") - - if len(properties): - flavor_info['flavor-properties'] = flavor['properties'] - hpa_caps.append("[") - values = flavor['name'].split('_') - for p in range(len(properties)): - if (properties[p] == "hw:mem_page_size") : - hpa_caps.append("{'hpa-attribute-key':'memoryPageSize', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + values[2] + "'}}, ") - hpa_caps.append("]") + hpa_caps.append("[") + for p in range(len(extra_arr)): + if (extra_arr[p] == "hw:mem_page_size") : + value = extra_specs[p].split('=')[1] + hpa_caps.append("{'hpa-attribute-key':'memoryPageSize', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value + "'}}, ") + hpa_caps.append("]") hpa_caps.append("},") - elif (flavor['name'].find('onap.iax') != -1): + # add instruction set externsions + if (extra_specs.find('w:capabilities:cpu_info:features') != -1): hpa_caps.append("{'hpaCapabilityId': '" + str(uuid4) + "', ") hpa_caps.append("'hpaFeature': 'instructionSetExtensions', ") hpa_caps.append("'hardwareArchitecture': 'Intel64', ") hpa_caps.append("'version': 'v1', ") - - if len(properties): - flavor_info['flavor-properties'] = flavor['properties'] - hpa_caps.append("[") - value = flavor['properties'].split('=')[1] - for p in range(len(properties)): - if (properties[p].find("hw:capabilities:cpu_info:features") != -1) : - hpa_caps.append("{'hpa-attribute-key':'instructionSetExtensions', ") - hpa_caps.append("'hpa-attribute-value': {'value':[" + value + "]}}, ") - hpa_caps.append("]") + hpa_caps.append("[") + for p in range(len(extra_arr)): + if (extra_arr[p].find("hw:capabilities:cpu_info:features") != -1) : + value = extra_arr.split('=')[1] + hpa_caps.append("{'hpa-attribute-key':'instructionSetExtensions', ") + hpa_caps.append("'hpa-attribute-value': {'value':[" + value + "]}}, ") + hpa_caps.append("]") hpa_caps.append("},") - elif (flavor['name'].find('onap.pci_passthrough') != -1) : + # add pci device passthrough + if (extra_specs.find('pci_passthrough:alias') != -1) : hpa_caps.append("{'hpaCapabilityId': '" + str(uuid4) + "', ") hpa_caps.append("'hpaFeature': 'pciPassthrough', ") hpa_caps.append("'version': 'v1', ") - if len(properties): - values = properties[0].split('-') - hpa_caps.append("'hardwareArchitecture': '" + values[2] + "', ") - - flavor_info['flavor-properties'] = flavor['properties'] - hpa_caps.append("[") - value = values[4].split(':') - hpa_caps.append("{'hpa-attribute-key':'pciCount', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value[1] + "'}}, ") - hpa_caps.append("{'hpa-attribute-key':'pciVendorId', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + values[3] + "'}}, ") - hpa_caps.append("{'hpa-attribute-key':'pciDeviceId', ") - hpa_caps.append("'hpa-attribute-value': {'value':'" + value[0] + "'}}, ") - hpa_caps.append("]") + hpa_caps.append("[") + for p in range(len(extra_arr)): + if (extra_arr[p] == "pci_passthrough:alias") : + values = extra_arr[0].split('-') + value = values[4].split(':') + hpa_caps.append("{'hpa-attribute-key':'pciCount', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value[1] + "'}}, ") + hpa_caps.append("{'hpa-attribute-key':'pciVendorId', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + values[3] + "'}}, ") + hpa_caps.append("{'hpa-attribute-key':'pciDeviceId', ") + hpa_caps.append("'hpa-attribute-value': {'value':'" + value[0] + "'}}, ") + hpa_caps.append("]") hpa_caps.append("},") + hpa_caps.append("]") + hpa_caps.append("'hardwareArchitecture': '" + values[2] + "', ") - else: - self._logger.info("can not support this flavor type") - hpa_caps.append("]") str_hpa_caps = '' flavor_info['hpa_capabilities'] = str_hpa_caps.join(hpa_caps) self._logger.debug("flavor_info: %s" % flavor_info) |