diff options
Diffstat (limited to 'windriver')
10 files changed, 181 insertions, 10 deletions
diff --git a/windriver/titanium_cloud/extensions/views/epacaps.py b/windriver/titanium_cloud/extensions/views/epacaps.py index 7efb71a6..025d55df 100644 --- a/windriver/titanium_cloud/extensions/views/epacaps.py +++ b/windriver/titanium_cloud/extensions/views/epacaps.py @@ -23,7 +23,7 @@ from newton_base.extensions import epacaps as newton_epacaps logger = logging.getLogger(__name__) -#DEBUG=True +# DEBUG=True class EpaCaps(newton_epacaps.EpaCaps): diff --git a/windriver/titanium_cloud/extensions/views/extensions.py b/windriver/titanium_cloud/extensions/views/extensions.py index d331b7b5..2cd91bf5 100644 --- a/windriver/titanium_cloud/extensions/views/extensions.py +++ b/windriver/titanium_cloud/extensions/views/extensions.py @@ -27,7 +27,7 @@ from newton_base.extensions import extensions as newton_extensions logger = logging.getLogger(__name__) -#DEBUG=True +# DEBUG=True class Extensions(newton_extensions.Extensions): diff --git a/windriver/titanium_cloud/extensions/views/fcaps.py b/windriver/titanium_cloud/extensions/views/fcaps.py index c36b2642..a093a361 100644 --- a/windriver/titanium_cloud/extensions/views/fcaps.py +++ b/windriver/titanium_cloud/extensions/views/fcaps.py @@ -35,7 +35,7 @@ from common.msapi import extsys logger = logging.getLogger(__name__) -#DEBUG=True +# DEBUG=True #dict to store running worker threads running_threads = {} diff --git a/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py b/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py index 5dc061fa..cd7dd23c 100644 --- a/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py +++ b/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py @@ -25,6 +25,7 @@ from keystoneauth1.exceptions import HttpError from newton_base.util import VimDriverUtils from titanium_cloud.proxy.views.identityV3 import Tokens +from newton_base.tests import mock_info mock_viminfo = { "createTime": "2017-04-01 02:22:27", @@ -532,3 +533,44 @@ 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-titanium_cloud/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/windriver/titanium_cloud/proxy/views/identityV3.py b/windriver/titanium_cloud/proxy/views/identityV3.py index c831d017..eaeeca47 100644 --- a/windriver/titanium_cloud/proxy/views/identityV3.py +++ b/windriver/titanium_cloud/proxy/views/identityV3.py @@ -19,7 +19,7 @@ from newton_base.proxy import identityV3 as newton_identityV3 logger = logging.getLogger(__name__) -#DEBUG=True +# DEBUG=True class Tokens(newton_identityV3.Tokens): diff --git a/windriver/titanium_cloud/proxy/views/services.py b/windriver/titanium_cloud/proxy/views/services.py index c1d4f194..d7c1dc05 100644 --- a/windriver/titanium_cloud/proxy/views/services.py +++ b/windriver/titanium_cloud/proxy/views/services.py @@ -21,7 +21,7 @@ from newton_base.proxy import services as newton_services logger = logging.getLogger(__name__) -#DEBUG=True +# DEBUG=True class Services(newton_services.Services): diff --git a/windriver/titanium_cloud/registration/tests/test_registration.py b/windriver/titanium_cloud/registration/tests/test_registration.py index 231a4358..0b3a516d 100644 --- a/windriver/titanium_cloud/registration/tests/test_registration.py +++ b/windriver/titanium_cloud/registration/tests/test_registration.py @@ -54,7 +54,15 @@ MOCK_GET_FLAVOR_EXTRA_SPECS_RESPONSE = { "hw:cpu_sockets" : "2", "hw:cpu_cores" : "4", "hw:cpu_threads" : "16", - "hw:mem_page_size" : "large" + "hw:mem_page_size" : "large", + "hw:numa_nodes" : "2", + "hw:numa_cpus.0" : "0,1", + "hw:numa_cpus.1" : "2,3,4,5", + "hw:numa_mem.0" : "2048", + "hw:numa_mem.1" : "2048", + "hw:capabilities:cpu_info:features":"avx,acpi", + "pci_passthrough:alias":"sriov-vf-intel-8086-15b3:4" + } } diff --git a/windriver/titanium_cloud/registration/views/registration.py b/windriver/titanium_cloud/registration/views/registration.py index 7fce48a6..769040ff 100644 --- a/windriver/titanium_cloud/registration/views/registration.py +++ b/windriver/titanium_cloud/registration/views/registration.py @@ -26,7 +26,7 @@ from keystoneauth1.exceptions import HttpError logger = logging.getLogger(__name__) -DEBUG=True +# DEBUG=True class Registry(newton_registration.Registry): @@ -106,6 +106,30 @@ class Registry(newton_registration.Registry): self._logger.debug("hugepages_capabilities_info: %s" % caps_dict) hpa_caps.append(caps_dict) + # numa capabilities + caps_dict = self._get_numa_capabilities(extra_specs) + if len(caps_dict) > 0: + self._logger.debug("numa_capabilities_info: %s" % caps_dict) + hpa_caps.append(caps_dict) + + # storage capabilities + caps_dict = self._get_storage_capabilities(flavor) + if len(caps_dict) > 0: + self._logger.debug("storage_capabilities_info: %s" % caps_dict) + hpa_caps.append(caps_dict) + + # CPU instruction set extension capabilities + caps_dict = self._get_instruction_set_capabilities(extra_specs) + if len(caps_dict) > 0: + self._logger.debug("instruction_set_capabilities_info: %s" % caps_dict) + hpa_caps.append(caps_dict) + + # PCI passthrough capabilities + caps_dict = self._get_pci_passthrough_capabilities(extra_specs) + if len(caps_dict) > 0: + self._logger.debug("pci_passthrough_capabilities_info: %s" % caps_dict) + hpa_caps.append(caps_dict) + return hpa_caps def _get_hpa_basic_capabilities(self, flavor): @@ -182,3 +206,88 @@ class Registry(newton_registration.Registry): hugepages_capability['attributes'].append({'hpa-attribute-key': 'memoryPageSize', 'hpa-attribute-value':{'value': str(extra_specs['hw:mem_page_size'])}}) return hugepages_capability + + def _get_numa_capabilities(self, extra_specs): + numa_capability = {} + feature_uuid = uuid.uuid4() + + if extra_specs.has_key('hw:numa_nodes'): + numa_capability['hpaCapabilityID'] = str(feature_uuid) + numa_capability['hpaFeature'] = 'numa' + numa_capability['hardwareArchitecture'] = 'generic' + numa_capability['version'] = 'v1' + + numa_capability['attributes'] = [] + numa_capability['attributes'].append({'hpa-attribute-key': 'numaNodes', + 'hpa-attribute-value':{'value': str(extra_specs['hw:numa_nodes'])}}) + + for num in range(0, int(extra_specs['hw:numa_nodes'])): + numa_cpu_node = "hw:numa_cpus.%s" % num + numa_mem_node = "hw:numa_mem.%s" % num + numacpu_key = "numaCpu-%s" % num + numamem_key = "numaMem-%s" % num + + if extra_specs.has_key(numa_cpu_node) and extra_specs.has_key(numa_mem_node): + numa_capability['attributes'].append({'hpa-attribute-key': numacpu_key, + 'hpa-attribute-value':{'value': str(extra_specs[numa_cpu_node])}}) + numa_capability['attributes'].append({'hpa-attribute-key': numamem_key, + 'hpa-attribute-value':{'value': str(extra_specs[numa_mem_node]),'unit':'MB'}}) + + return numa_capability + + def _get_storage_capabilities(self, flavor): + storage_capability = {} + feature_uuid = uuid.uuid4() + + storage_capability['hpaCapabilityID'] = str(feature_uuid) + storage_capability['hpaFeature'] = 'localStorage' + storage_capability['hardwareArchitecture'] = 'generic' + storage_capability['version'] = 'v1' + + storage_capability['attributes'] = [] + storage_capability['attributes'].append({'hpa-attribute-key': 'diskSize', + 'hpa-attribute-value':{'value': str(flavor['disk']), 'unit':'GB'}}) + storage_capability['attributes'].append({'hpa-attribute-key': 'swapMemSize', + 'hpa-attribute-value':{'value': str(flavor['swap']), 'unit':'MB'}}) + storage_capability['attributes'].append({'hpa-attribute-key': 'ephemeralDiskSize', + 'hpa-attribute-value':{'value': str(flavor['OS-FLV-EXT-DATA:ephemeral']), 'unit':'GB'}}) + return storage_capability + + def _get_instruction_set_capabilities(self, extra_specs): + instruction_capability = {} + feature_uuid = uuid.uuid4() + + if extra_specs.has_key('hw:capabilities:cpu_info:features'): + instruction_capability['hpaCapabilityID'] = str(feature_uuid) + instruction_capability['hpaFeature'] = 'instructionSetExtensions' + instruction_capability['hardwareArchitecture'] = 'Intel64' + instruction_capability['version'] = 'v1' + + instruction_capability['attributes'] = [] + instruction_capability['attributes'].append({'hpa-attribute-key': 'instructionSetExtensions', + 'hpa-attribute-value':{'value': str(extra_specs['hw:capabilities:cpu_info:features'])}}) + return instruction_capability + + def _get_pci_passthrough_capabilities(self, extra_specs): + instruction_capability = {} + feature_uuid = uuid.uuid4() + + if extra_specs.has_key('pci_passthrough:alias'): + value1 = extra_specs['pci_passthrough:alias'].split(':') + value2 = value1[0].split('-') + + instruction_capability['hpaCapabilityID'] = str(feature_uuid) + instruction_capability['hpaFeature'] = 'pciePassthrough' + instruction_capability['hardwareArchitecture'] = str(value2[2]) + instruction_capability['version'] = 'v1' + + + instruction_capability['attributes'] = [] + instruction_capability['attributes'].append({'hpa-attribute-key': 'pciCount', + 'hpa-attribute-value':{'value': str(value1[1])}}) + instruction_capability['attributes'].append({'hpa-attribute-key': 'pciVendorId', + 'hpa-attribute-value':{'value': str(value2[3])}}) + instruction_capability['attributes'].append({'hpa-attribute-key': 'pciDeviceId', + 'hpa-attribute-value':{'value': str(value2[4])}}) + + return instruction_capability diff --git a/windriver/titanium_cloud/resource/views/capacity.py b/windriver/titanium_cloud/resource/views/capacity.py index d73cc0fb..0d44d0c4 100644 --- a/windriver/titanium_cloud/resource/views/capacity.py +++ b/windriver/titanium_cloud/resource/views/capacity.py @@ -38,8 +38,8 @@ class CapacityCheck(APIView): self._logger = logger def post(self, request, vimid=""): - self._logger.info("CapacityCheck--post::vimid, data> %s, %s" % (vimid, request.data)) - self._logger.debug("CapacityCheck--post::META> %s" % request.META) + self._logger.info("vimid, data> %s, %s" % (vimid, request.data)) + self._logger.debug("META> %s" % request.META) hasEnoughResource = False try : @@ -58,22 +58,31 @@ class CapacityCheck(APIView): #get limit for this tenant req_resouce = "/limits" + self._logger.info("check limits> URI:%s" % req_resouce) resp = sess.get(req_resouce, endpoint_filter=service) + self._logger.info("check limits> status:%s" % resp.status_code) content = resp.json() compute_limits = content['limits']['absolute'] + self._logger.debug("check limits> resp data:%s" % content) #get total resource of this cloud region req_resouce = "/os-hypervisors/statistics" + self._logger.info("check os-hypervisors statistics> URI:%s" % req_resouce) resp = sess.get(req_resouce, endpoint_filter=service) + self._logger.info("check os-hypervisors statistics> status:%s" % resp.status_code) content = resp.json() hypervisor_statistics = content['hypervisor_statistics'] + self._logger.debug("check os-hypervisors statistics> resp data:%s" % content) #get storage limit for this tenant service['service_type'] = 'volumev2' req_resouce = "/limits" + self._logger.info("check volumev2 limits> URI:%s" % req_resouce) resp = sess.get(req_resouce, endpoint_filter=service) + self._logger.info("check volumev2> status:%s" % resp.status_code) content = resp.json() storage_limits = content['limits']['absolute'] + self._logger.debug("check volumev2> resp data:%s" % content) # compute actual available resource for this tenant remainVCPU = compute_limits['maxTotalCores'] - compute_limits['totalCoresUsed'] @@ -102,8 +111,11 @@ class CapacityCheck(APIView): else: hasEnoughResource = True + self._logger.info("RESP with data> result:%s" % hasEnoughResource) return Response(data={'result': hasEnoughResource}, 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': 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())) diff --git a/windriver/titanium_cloud/settings.py b/windriver/titanium_cloud/settings.py index f05991a9..c3da724f 100644 --- a/windriver/titanium_cloud/settings.py +++ b/windriver/titanium_cloud/settings.py @@ -32,7 +32,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = '3o-wney!99y)^h3v)0$j16l9=fdjxcb+a8g+q3tfbahcnu2b0o' # SECURITY WARNING: don't run with debug turned on in production! -#DEBUG = True +# DEBUG = True ALLOWED_HOSTS = ['*'] |