From e547b8c13697f5d34ba886d8f23f18faa4a9cb78 Mon Sep 17 00:00:00 2001 From: Bart Wensley Date: Tue, 2 Oct 2018 06:59:36 -0500 Subject: [PATCH] Add support for containerized keystone to VIM Adding support to the VIM for containerized keystone. The VIM will now support two keystone instances: - platform: bare metal keystone used to authenticate with platform services (e.g. sysinv, patching) - openstack: containerized keystone used to authenticate with openstack services (e.g. nova, neutron, cinder) For now, the VIM will use the same baremetal keystone for both the platform and openstack, because we still only deploy with the baremetal keystone. Story: 2002876 Task: 26872 Depends-On: If4bd46a4c14cc65978774001cb2887e5d3e3607b Change-Id: Id1ec639aa347e0c4e4019576d3c36c8c72aefedf --- .../nfv_plugins/nfvi_plugins/config.ini | 13 + .../nfv_plugins/nfvi_plugins/config.py | 6 +- .../nfvi_plugins/nfvi_block_storage_api.py | 5 +- .../nfvi_plugins/nfvi_compute_api.py | 5 +- .../nfvi_plugins/nfvi_guest_api.py | 5 +- .../nfvi_plugins/nfvi_identity_api.py | 5 +- .../nfvi_plugins/nfvi_image_api.py | 5 +- .../nfvi_plugins/nfvi_infrastructure_api.py | 598 +++++++++++------- .../nfvi_plugins/nfvi_network_api.py | 5 +- .../nfvi_plugins/nfvi_sw_mgmt_api.py | 5 +- .../nfv_plugins/nfvi_plugins/openstack/fm.py | 8 +- .../nfvi_plugins/openstack/guest.py | 26 +- .../nfv_plugins/nfvi_plugins/openstack/mtc.py | 10 +- .../nfvi_plugins/openstack/objects.py | 54 +- .../nfvi_plugins/openstack/openstack.py | 48 +- .../nfvi_plugins/openstack/patching.py | 10 +- .../nfvi_plugins/openstack/sysinv.py | 40 +- .../nfv_plugins/nfvi_plugins/unit_test.py | 30 +- nfv/nfv-tests/nfv_scenario_tests/config.ini | 11 + nfv/nfv-tests/nfv_scenario_tests/main.py | 8 +- .../nfv_scenario_tests/tests/_hosts.py | 5 +- .../nfv_scenario_tests/tests/_instances.py | 5 +- .../nfv_scenario_tests/tests/_test_hosts.py | 54 +- .../tests/_test_instances.py | 100 +-- nfv/nfv-vim/nfv_vim/api/acl/_application.py | 5 +- .../api/controllers/v1/openstack/_heat_api.py | 5 +- nfv/nfv-vim/nfv_vim/api/openstack/__init__.py | 4 +- nfv/nfv-vim/nfv_vim/api/openstack/_config.py | 6 +- nfv/nfv-vim/nfv_vim/api/openstack/_objects.py | 56 +- .../nfv_vim/api/openstack/_openstack.py | 50 +- nfv/nfv-vim/nfv_vim/webserver/_webserver.py | 5 +- 31 files changed, 768 insertions(+), 424 deletions(-) diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.ini b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.ini index 075c08f0..f111a113 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.ini +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.ini @@ -3,12 +3,25 @@ # # SPDX-License-Identifier: Apache-2.0 # +[platform] +username=admin +tenant=admin +authorization_protocol=http +authorization_ip=192.168.204.2 +authorization_port=5000 +user_domain_name=Default +project_domain_name=Default +keyring_service=CGCS + [openstack] username=admin tenant=admin authorization_protocol=http authorization_ip=192.168.204.2 authorization_port=5000 +user_domain_name=Default +project_domain_name=Default +keyring_service=CGCS [keystone] region_name=RegionOne diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.py index 07a8a410..226f3401 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -33,7 +33,3 @@ def load(config_file): config = Config() config.read(config_file) CONF = config.as_dict() - - password = CONF['openstack'].get('password', None) - if password is None: - CONF['openstack']['password'] = None diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_block_storage_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_block_storage_api.py index 51a9f63b..05738159 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_block_storage_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_block_storage_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -569,7 +569,8 @@ class NFVIBlockStorageAPI(nfvi.api.v1.NFVIBlockStorageAPI): Initialize the plugin """ config.load(config_file) - self._directory = openstack.get_directory(config) + self._directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) def finalize(self): """ diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_compute_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_compute_api.py index 21045d77..eb089616 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_compute_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_compute_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -2902,7 +2902,8 @@ class NFVIComputeAPI(nfvi.api.v1.NFVIComputeAPI): Initialize the plugin """ config.load(config_file) - self._directory = openstack.get_directory(config) + self._directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) self._rpc_listener = rpc_listener.RPCListener( config.CONF['amqp']['host'], config.CONF['amqp']['port'], diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_guest_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_guest_api.py index 36b725bb..622a6725 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_guest_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_guest_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -850,7 +850,8 @@ class NFVIGuestAPI(nfvi.api.v1.NFVIGuestAPI): Initialize the plugin """ config.load(config_file) - self._directory = openstack.get_directory(config) + self._directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.PLATFORM) self._rest_api_server = rest_api.rest_api_get_server( config.CONF['guest-rest-api']['host'], diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_identity_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_identity_api.py index c7488e86..855e47b5 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_identity_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_identity_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -114,7 +114,8 @@ class NFVIIdentityAPI(nfvi.api.v1.NFVIIdentityAPI): Initialize the plugin """ config.load(config_file) - self._directory = openstack.get_directory(config) + self._directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) def finalize(self): """ diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_image_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_image_api.py index ec21daf8..b84d3155 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_image_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_image_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -591,7 +591,8 @@ class NFVIImageAPI(nfvi.api.v1.NFVIImageAPI): Initialize the plugin """ config.load(config_file) - self._directory = openstack.get_directory(config) + self._directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) def finalize(self): """ diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py index eae416fd..c3bca7b4 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -130,8 +130,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): def __init__(self): super(NFVIInfrastructureAPI, self).__init__() - self._token = None - self._directory = None + self._platform_token = None + self._openstack_token = None + self._platform_directory = None + self._openstack_directory = None self._rest_api_server = None self._host_add_callbacks = list() self._host_action_callbacks = list() @@ -145,11 +147,13 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): def _host_supports_neutron(self, personality): return (('compute' in personality or 'controller' in personality) and - (self._directory.get_service_info(OPENSTACK_SERVICE.NEUTRON) is not None)) + (self._openstack_directory.get_service_info( + OPENSTACK_SERVICE.NEUTRON) is not None)) def _host_supports_nova_compute(self, personality): return (('compute' in personality) and - (self._directory.get_service_info(OPENSTACK_SERVICE.NOVA) is not None)) + (self._openstack_directory.get_service_info( + OPENSTACK_SERVICE.NOVA) is not None)) def get_system_info(self, future, callback): """ @@ -162,17 +166,18 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.get_system_info, self._token) + future.work(sysinv.get_system_info, self._platform_token) future.result = (yield) if not future.result.is_complete(): @@ -200,8 +205,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to get system " @@ -226,17 +231,18 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(mtc.system_query, self._token) + future.work(mtc.system_query, self._platform_token) future.result = (yield) if not future.result.is_complete(): @@ -254,8 +260,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to query the " @@ -282,16 +288,17 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.get_hosts, self._token) + future.work(sysinv.get_hosts, self._platform_token) future.result = (yield) if not future.result.is_complete(): @@ -309,7 +316,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if host_data['subfunctions'] is None: continue - future.work(mtc.host_query, self._token, + future.work(mtc.host_query, self._platform_token, host_data['uuid'], host_data['hostname']) future.result = (yield) @@ -384,8 +391,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to get hosts, " @@ -410,8 +417,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -419,9 +427,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.get_host, self._token, host_uuid) + future.work(sysinv.get_host, self._platform_token, host_uuid) future.result = (yield) if not future.result.is_complete(): @@ -429,7 +437,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_data = future.result.data - future.work(mtc.host_query, self._token, + future.work(mtc.host_query, self._platform_token, host_data['uuid'], host_data['hostname']) future.result = (yield) @@ -481,8 +489,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to get host " @@ -507,17 +515,18 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.get_upgrade, self._token) + future.work(sysinv.get_upgrade, self._platform_token) future.result = (yield) if not future.result.is_complete(): @@ -544,8 +553,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to get upgrade " @@ -570,17 +579,18 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.upgrade_start, self._token) + future.work(sysinv.upgrade_start, self._platform_token) future.result = (yield) if not future.result.is_complete(): @@ -599,8 +609,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to start " @@ -625,17 +635,18 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.upgrade_activate, self._token) + future.work(sysinv.upgrade_activate, self._platform_token) future.result = (yield) if not future.result.is_complete(): @@ -654,8 +665,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to activate " @@ -680,17 +691,18 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.upgrade_complete, self._token) + future.work(sysinv.upgrade_complete, self._platform_token) future.result = (yield) if not future.result.is_complete(): @@ -709,8 +721,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to complete " @@ -739,10 +751,11 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if (self._host_supports_neutron(host_personality) or self._host_supports_nova_compute(host_personality)): - response['reason'] = 'failed to get token from keystone' - - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + response['reason'] = 'failed to get openstack token from ' \ + 'keystone' + if self._openstack_token is None or \ + self._openstack_token.is_expired(): + future.work(openstack.get_token, self._openstack_directory) future.result = (yield) if not future.result.is_complete(): @@ -751,12 +764,28 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_name)) return - self._token = future.result.data + self._openstack_token = future.result.data + + if self._host_supports_nova_compute(host_personality): + response['reason'] = 'failed to get platform token from ' \ + 'keystone' + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) + future.result = (yield) + + if not future.result.is_complete(): + DLOG.error("OpenStack get-token did not complete, " + "host_uuid=%s, host_name=%s." % (host_uuid, + host_name)) + return + + self._platform_token = future.result.data if self._host_supports_neutron(host_personality): response['reason'] = 'failed to get neutron extensions' if self._neutron_extensions is None: - future.work(neutron.get_extensions, self._token) + future.work(neutron.get_extensions, self._openstack_token) future.result = (yield) if not future.result.is_complete(): @@ -769,7 +798,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to create nova services' # Send the create request to Nova. - future.work(nova.create_host_services, self._token, host_name) + future.work(nova.create_host_services, self._openstack_token, + host_name) future.result = (yield) if not future.result.is_complete(): @@ -790,7 +820,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to disable nova services' # Send the disable request to Nova. - future.work(nova.disable_host_services, self._token, host_name) + future.work(nova.disable_host_services, self._openstack_token, + host_name) future.result = (yield) if not future.result.is_complete(): @@ -817,7 +848,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = \ 'failed to delete existing neutron services' - future.work(neutron.delete_host_services_by_name, self._token, + future.work(neutron.delete_host_services_by_name, + self._openstack_token, host_name, host_uuid, only_if_changed=True) future.result = (yield) @@ -830,7 +862,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to create neutron services' # Send the create request to Neutron. - future.work(neutron.create_host_services, self._token, + future.work(neutron.create_host_services, + self._openstack_token, host_name, host_uuid) future.result = (yield) @@ -852,7 +885,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to disable neutron services' # Send the disable request to Neutron - future.work(neutron.disable_host_services, self._token, + future.work(neutron.disable_host_services, + self._openstack_token, host_uuid) future.result = (yield) @@ -876,7 +910,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: # Send the create request to Guest. - future.work(guest.host_services_create, self._token, + future.work(guest.host_services_create, + self._platform_token, host_uuid, host_name) future.result = (yield) @@ -889,7 +924,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to disable guest services' # Send the disable request to Guest - future.work(guest.host_services_disable, self._token, + future.work(guest.host_services_disable, + self._platform_token, host_uuid, host_name) future.result = (yield) @@ -911,8 +947,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() + if self._openstack_token is not None: + self._openstack_token.set_expired() else: DLOG.exception("Caught exception while trying to create " @@ -941,10 +979,11 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if (self._host_supports_neutron(host_personality) or self._host_supports_nova_compute(host_personality)): - response['reason'] = 'failed to get token from keystone' - - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + response['reason'] = 'failed to get openstack token from ' \ + 'keystone' + if self._openstack_token is None or \ + self._openstack_token.is_expired(): + future.work(openstack.get_token, self._openstack_directory) future.result = (yield) if not future.result.is_complete(): @@ -953,13 +992,29 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_name)) return - self._token = future.result.data + self._openstack_token = future.result.data + + if self._host_supports_nova_compute(host_personality): + response['reason'] = 'failed to get platform token from ' \ + 'keystone' + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) + future.result = (yield) + + if not future.result.is_complete(): + DLOG.error("OpenStack get-token did not complete, " + "host_uuid=%s, host_name=%s." % (host_uuid, + host_name)) + return + + self._platform_token = future.result.data if self._host_supports_neutron(host_personality): response['reason'] = 'failed to get neutron extensions' if self._neutron_extensions is None: - future.work(neutron.get_extensions, self._token) + future.work(neutron.get_extensions, self._openstack_token) future.result = (yield) if not future.result.is_complete(): @@ -972,7 +1027,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to delete nova services' # Send the delete request to Nova. - future.work(nova.delete_host_services, self._token, host_name) + future.work(nova.delete_host_services, self._openstack_token, + host_name) future.result = (yield) if not future.result.is_complete(): @@ -989,7 +1045,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): # Send the delete request to Neutron. future.work(neutron.delete_host_services, - self._token, host_uuid) + self._openstack_token, host_uuid) try: future.result = (yield) @@ -1007,7 +1063,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to delete guest services' # Send the delete request to Guest. - future.work(guest.host_services_delete, self._token, host_uuid) + future.work(guest.host_services_delete, self._platform_token, + host_uuid) try: future.result = (yield) @@ -1027,8 +1084,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._openstack_token is not None: + self._openstack_token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to delete " @@ -1058,10 +1117,11 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if (self._host_supports_neutron(host_personality) or self._host_supports_nova_compute(host_personality)): - response['reason'] = 'failed to get token from keystone' - - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + response['reason'] = 'failed to get openstack token from ' \ + 'keystone' + if self._openstack_token is None or \ + self._openstack_token.is_expired(): + future.work(openstack.get_token, self._openstack_directory) future.result = (yield) if not future.result.is_complete(): @@ -1070,13 +1130,29 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_name)) return - self._token = future.result.data + self._openstack_token = future.result.data + + if self._host_supports_nova_compute(host_personality): + response['reason'] = 'failed to get platform token from ' \ + 'keystone' + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) + future.result = (yield) + + if not future.result.is_complete(): + DLOG.error("OpenStack get-token did not complete, " + "host_uuid=%s, host_name=%s." % (host_uuid, + host_name)) + return + + self._platform_token = future.result.data if self._host_supports_neutron(host_personality): response['reason'] = 'failed to get neutron extensions' if self._neutron_extensions is None: - future.work(neutron.get_extensions, self._token) + future.work(neutron.get_extensions, self._openstack_token) future.result = (yield) if not future.result.is_complete(): @@ -1089,7 +1165,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to enable nova services' # Send the Enable request to Nova. - future.work(nova.enable_host_services, self._token, host_name) + future.work(nova.enable_host_services, self._openstack_token, + host_name) future.result = (yield) if not future.result.is_complete(): @@ -1114,7 +1191,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): # Send the Enable request to Neutron future.work(neutron.enable_host_services, - self._token, host_uuid) + self._openstack_token, host_uuid) future.result = (yield) if not future.result.is_complete(): @@ -1136,8 +1213,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to enable guest services' # Send the Enable request to Guest - future.work(guest.host_services_enable, self._token, host_uuid, - host_name) + future.work(guest.host_services_enable, self._platform_token, + host_uuid, host_name) future.result = (yield) if not future.result.is_complete(): @@ -1167,8 +1244,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._openstack_token is not None: + self._openstack_token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to enable " @@ -1198,10 +1277,11 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): # The following only applies to compute hosts if self._host_supports_nova_compute(host_personality): - response['reason'] = 'failed to get token from keystone' - - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + response['reason'] = 'failed to get openstack token from ' \ + 'keystone' + if self._openstack_token is None or \ + self._openstack_token.is_expired(): + future.work(openstack.get_token, self._openstack_directory) future.result = (yield) if not future.result.is_complete(): @@ -1210,12 +1290,28 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_name)) return - self._token = future.result.data + self._openstack_token = future.result.data + + response['reason'] = 'failed to get platform token from ' \ + 'keystone' + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) + future.result = (yield) + + if not future.result.is_complete(): + DLOG.error("OpenStack get-token did not complete, " + "host_uuid=%s, host_name=%s." % (host_uuid, + host_name)) + return + + self._platform_token = future.result.data response['reason'] = 'failed to disable nova services' # Send the Disable request to Nova. - future.work(nova.disable_host_services, self._token, host_name) + future.work(nova.disable_host_services, self._openstack_token, + host_name) try: future.result = (yield) @@ -1242,8 +1338,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to disable guest services' # Send the Disable request to Guest. - future.work(guest.host_services_disable, self._token, host_uuid, - host_name) + future.work(guest.host_services_disable, self._platform_token, + host_uuid, host_name) try: future.result = (yield) @@ -1281,8 +1377,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._openstack_token is not None: + self._openstack_token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to disable " @@ -1313,8 +1411,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if (self._host_supports_neutron(host_personality) or self._host_supports_nova_compute(host_personality)): - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._openstack_token is None or \ + self._openstack_token.is_expired(): + future.work(openstack.get_token, self._openstack_directory) future.result = (yield) if not future.result.is_complete(): @@ -1323,10 +1422,24 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_name)) return - self._token = future.result.data + self._openstack_token = future.result.data + + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) + future.result = (yield) + + if not future.result.is_complete(): + DLOG.error("OpenStack get-token did not complete, " + "host_uuid=%s, host_name=%s." % (host_uuid, + host_name)) + return + + self._platform_token = future.result.data + if self._host_supports_neutron(host_personality): if self._neutron_extensions is None: - future.work(neutron.get_extensions, self._token) + future.work(neutron.get_extensions, self._openstack_token) future.result = (yield) if not future.result.is_complete(): @@ -1337,7 +1450,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if self._host_supports_nova_compute(host_personality): # Send Query request to Nova. - future.work(nova.query_host_services, self._token, host_name) + future.work(nova.query_host_services, self._openstack_token, + host_name) future.result = (yield) if not future.result.is_complete(): @@ -1355,7 +1469,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if neutron.lookup_extension(neutron.EXTENSION_NAMES.HOST, self._neutron_extensions): # Send Query request to Neutron - future.work(neutron.query_host_services, self._token, host_name) + future.work(neutron.query_host_services, + self._openstack_token, host_name) future.result = (yield) if not future.result.is_complete(): @@ -1371,8 +1486,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if self._host_supports_nova_compute(host_personality): # Send Query request to Guest - future.work(guest.host_services_query, self._token, host_uuid, - host_name) + future.work(guest.host_services_query, self._platform_token, + host_uuid, host_name) future.result = (yield) if not future.result.is_complete(): @@ -1383,7 +1498,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): else: result_data = future.result.data if 'disabled' == result_data['state']: - future.work(guest.host_services_enable, self._token, + future.work(guest.host_services_enable, + self._platform_token, host_uuid, host_name) future.result = (yield) if not future.result.is_complete(): @@ -1397,8 +1513,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._openstack_token is not None: + self._openstack_token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to query " @@ -1425,8 +1543,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -1434,9 +1553,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.notify_host_services_enabled, self._token, + future.work(sysinv.notify_host_services_enabled, + self._platform_token, host_uuid) future.result = (yield) @@ -1445,7 +1565,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_data = future.result.data - future.work(mtc.host_query, self._token, + future.work(mtc.host_query, self._platform_token, host_data['uuid'], host_data['hostname']) future.result = (yield) @@ -1497,8 +1617,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -1524,8 +1644,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -1533,9 +1654,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.notify_host_services_disabled, self._token, + future.work(sysinv.notify_host_services_disabled, + self._platform_token, host_uuid) future.result = (yield) @@ -1544,7 +1666,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_data = future.result.data - future.work(mtc.host_query, self._token, + future.work(mtc.host_query, self._platform_token, host_data['uuid'], host_data['hostname']) future.result = (yield) @@ -1596,8 +1718,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -1623,8 +1745,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -1632,9 +1755,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.notify_host_services_disable_extend, self._token, + future.work(sysinv.notify_host_services_disable_extend, + self._platform_token, host_uuid) future.result = (yield) @@ -1643,7 +1767,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_data = future.result.data - future.work(mtc.host_query, self._token, + future.work(mtc.host_query, self._platform_token, host_data['uuid'], host_data['hostname']) future.result = (yield) @@ -1694,8 +1818,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -1721,8 +1845,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -1730,10 +1855,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data future.work(sysinv.notify_host_services_disable_failed, - self._token, host_uuid, reason) + self._platform_token, host_uuid, reason) future.result = (yield) if not future.result.is_complete(): @@ -1741,7 +1866,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_data = future.result.data - future.work(mtc.host_query, self._token, + future.work(mtc.host_query, self._platform_token, host_data['uuid'], host_data['hostname']) future.result = (yield) @@ -1792,8 +1917,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -1819,8 +1944,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -1828,9 +1954,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.notify_host_services_deleted, self._token, + future.work(sysinv.notify_host_services_deleted, + self._platform_token, host_uuid) future.result = (yield) @@ -1842,8 +1969,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -1869,8 +1996,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -1878,10 +2006,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data future.work(sysinv.notify_host_services_delete_failed, - self._token, host_uuid, reason) + self._platform_token, host_uuid, reason) future.result = (yield) if not future.result.is_complete(): @@ -1889,7 +2017,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_data = future.result.data - future.work(mtc.host_query, self._token, + future.work(mtc.host_query, self._platform_token, host_data['uuid'], host_data['hostname']) future.result = (yield) @@ -1940,8 +2068,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -1975,8 +2103,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to get token from keystone' - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._openstack_token is None or \ + self._openstack_token.is_expired(): + future.work(openstack.get_token, self._openstack_directory) future.result = (yield) if not future.result.is_complete(): @@ -1984,11 +2113,12 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._openstack_token = future.result.data response['reason'] = 'failed to notify nova that host is enabled' - future.work(nova.notify_host_enabled, self._token, host_name) + future.work(nova.notify_host_enabled, self._openstack_token, + host_name) future.result = (yield) if not future.result.is_complete(): @@ -2000,8 +2130,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._openstack_token is not None: + self._openstack_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -2030,8 +2160,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if (self._host_supports_neutron(host_personality) or self._host_supports_nova_compute(host_personality)): response['reason'] = 'failed to get token from keystone' - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._openstack_token is None or \ + self._openstack_token.is_expired(): + future.work(openstack.get_token, self._openstack_directory) future.result = (yield) if not future.result.is_complete(): @@ -2039,13 +2170,13 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._openstack_token = future.result.data if self._host_supports_neutron(host_personality): response['reason'] = 'failed to get neutron extensions' if self._neutron_extensions is None: - future.work(neutron.get_extensions, self._token) + future.work(neutron.get_extensions, self._openstack_token) future.result = (yield) if not future.result.is_complete(): @@ -2057,7 +2188,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if self._host_supports_nova_compute(host_personality): response['reason'] = 'failed to notify nova that host is disabled' - future.work(nova.notify_host_disabled, self._token, host_name) + future.work(nova.notify_host_disabled, self._openstack_token, + host_name) try: future.result = (yield) @@ -2076,7 +2208,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['reason'] = 'failed to disable neutron services' # Send the Disable request to Neutron - future.work(neutron.disable_host_services, self._token, + future.work(neutron.disable_host_services, + self._openstack_token, host_uuid) future.result = (yield) @@ -2101,8 +2234,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._openstack_token is not None: + self._openstack_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -2133,8 +2266,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): response['completed'] = True return - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -2143,11 +2277,11 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): host_name)) return - self._token = future.result.data + self._platform_token = future.result.data # Send a host failed notification to maintenance - future.work(mtc.notify_host_severity, self._token, host_uuid, - host_name, mtc.HOST_SEVERITY.FAILED) + future.work(mtc.notify_host_severity, self._platform_token, + host_uuid, host_name, mtc.HOST_SEVERITY.FAILED) future.result = (yield) if not future.result.is_complete(): @@ -2161,8 +2295,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to notify " @@ -2189,8 +2323,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -2198,9 +2333,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.lock_host, self._token, host_uuid) + future.work(sysinv.lock_host, self._platform_token, host_uuid) future.result = (yield) if not future.result.is_complete(): @@ -2211,8 +2346,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to lock " @@ -2240,8 +2375,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -2249,9 +2385,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.unlock_host, self._token, host_uuid) + future.work(sysinv.unlock_host, self._platform_token, host_uuid) future.result = (yield) if not future.result.is_complete(): @@ -2262,8 +2398,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to unlock " @@ -2291,8 +2427,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -2300,9 +2437,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.reboot_host, self._token, host_uuid) + future.work(sysinv.reboot_host, self._platform_token, host_uuid) future.result = (yield) if not future.result.is_complete(): @@ -2313,8 +2450,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to reboot " @@ -2342,8 +2479,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -2351,9 +2489,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.upgrade_host, self._token, host_uuid) + future.work(sysinv.upgrade_host, self._platform_token, host_uuid) future.result = (yield) if not future.result.is_complete(): @@ -2364,8 +2502,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to upgrade " @@ -2393,8 +2531,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): @@ -2402,9 +2541,9 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "host_uuid=%s." % host_uuid) return - self._token = future.result.data + self._platform_token = future.result.data - future.work(sysinv.swact_from_host, self._token, host_uuid) + future.work(sysinv.swact_from_host, self._platform_token, host_uuid) future.result = (yield) if not future.result.is_complete(): @@ -2415,8 +2554,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to swact " @@ -2442,17 +2581,18 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(fm.get_alarms, self._token) + future.work(fm.get_alarms, self._platform_token) future.result = (yield) if not future.result.is_complete(): @@ -2474,8 +2614,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to get alarms, " @@ -2500,17 +2640,19 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(fm.get_logs, self._token, start_period, end_period) + future.work(fm.get_logs, self._platform_token, start_period, + end_period) future.result = (yield) if not future.result.is_complete(): @@ -2521,8 +2663,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to get logs, " @@ -2547,18 +2689,19 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): try: future.set_timeouts(config.CONF.get('nfvi-timeouts', None)) - if self._token is None or self._token.is_expired(): - future.work(openstack.get_token, self._directory) + if self._platform_token is None or \ + self._platform_token.is_expired(): + future.work(openstack.get_token, self._platform_directory) future.result = (yield) if not future.result.is_complete(): DLOG.error("OpenStack get-token did not complete.") return - self._token = future.result.data + self._platform_token = future.result.data - future.work(fm.get_alarm_history, self._token, start_period, - end_period) + future.work(fm.get_alarm_history, self._platform_token, + start_period, end_period) future.result = (yield) if not future.result.is_complete(): @@ -2569,8 +2712,8 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): except exceptions.OpenStackRestAPIException as e: if httplib.UNAUTHORIZED == e.http_status_code: response['error-code'] = nfvi.NFVI_ERROR_CODE.TOKEN_EXPIRED - if self._token is not None: - self._token.set_expired() + if self._platform_token is not None: + self._platform_token.set_expired() else: DLOG.exception("Caught exception while trying to get alarm " @@ -2890,7 +3033,10 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): Initialize the plugin """ config.load(config_file) - self._directory = openstack.get_directory(config) + self._platform_directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.PLATFORM) + self._openstack_directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) self._rest_api_server = rest_api.rest_api_get_server( config.CONF['infrastructure-rest-api']['host'], diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_network_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_network_api.py index dfd4128c..470d5106 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_network_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_network_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -759,7 +759,8 @@ class NFVINetworkAPI(nfvi.api.v1.NFVINetworkAPI): Initialize the plugin """ config.load(config_file) - self._directory = openstack.get_directory(config) + self._directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) def finalize(self): """ diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_sw_mgmt_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_sw_mgmt_api.py index f3638b6a..605d03b7 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_sw_mgmt_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_sw_mgmt_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2016 Wind River Systems, Inc. +# Copyright (c) 2016-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -268,7 +268,8 @@ class NFVISwMgmtAPI(nfvi.api.v1.NFVISwMgmtAPI): Initialize the plugin """ config.load(config_file) - self._directory = openstack.get_directory(config) + self._directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.PLATFORM) def finalize(self): """ diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/fm.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/fm.py index 8f283b5e..7b85082a 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/fm.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/fm.py @@ -6,7 +6,7 @@ from nfv_common import debug -from nfv_plugins.nfvi_plugins.openstack.objects import OPENSTACK_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import PLATFORM_SERVICE from nfv_plugins.nfvi_plugins.openstack.rest_api import rest_api_request DLOG = debug.debug_get_logger('nfv_plugins.nfvi_plugins.openstack.fm') @@ -16,7 +16,7 @@ def get_alarms(token): """ Asks Fault Management for customer alarms """ - url = token.get_service_url(OPENSTACK_SERVICE.FM) + url = token.get_service_url(PLATFORM_SERVICE.FM) if url is None: raise ValueError("OpenStack FM URL is invalid") @@ -30,7 +30,7 @@ def get_logs(token, start=None, end=None): """ Asks Fault Management for customer logs """ - url = token.get_service_url(OPENSTACK_SERVICE.FM) + url = token.get_service_url(PLATFORM_SERVICE.FM) if url is None: raise ValueError("OpenStack FM URL is invalid") @@ -59,7 +59,7 @@ def get_alarm_history(token, start=None, end=None): """ Asks Fault Management for customer alarm history """ - url = token.get_service_url(OPENSTACK_SERVICE.FM) + url = token.get_service_url(PLATFORM_SERVICE.FM) if url is None: raise ValueError("OpenStack FM URL is invalid") diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/guest.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/guest.py index 942b4406..ed4200dd 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/guest.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/guest.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -11,7 +11,7 @@ from nfv_common.helpers import Constant from nfv_common.helpers import Constants from nfv_common.helpers import Singleton -from nfv_plugins.nfvi_plugins.openstack.objects import OPENSTACK_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import PLATFORM_SERVICE from nfv_plugins.nfvi_plugins.openstack.rest_api import rest_api_request DLOG = debug.debug_get_logger('nfv_plugins.nfvi_plugins.openstack.guest') @@ -86,7 +86,7 @@ def host_services_create(token, host_uuid, host_name): """ Create host services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -109,7 +109,7 @@ def host_services_enable(token, host_uuid, host_name): """ Enable host services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -132,7 +132,7 @@ def host_services_disable(token, host_uuid, host_name): """ Disable host services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -155,7 +155,7 @@ def host_services_delete(token, host_uuid): """ Delete host services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -173,7 +173,7 @@ def host_services_query(token, host_uuid, host_name): """ Query host services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -196,7 +196,7 @@ def guest_services_create(token, instance_uuid, host_name, services): """ Create guest services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -220,7 +220,7 @@ def guest_services_set(token, instance_uuid, host_name, services): """ Set guest services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -244,7 +244,7 @@ def guest_services_delete(token, instance_uuid): """ Delete guest services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -262,7 +262,7 @@ def guest_services_query(token, instance_uuid): """ Query guest services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -280,7 +280,7 @@ def guest_services_vote(token, instance_uuid, host_name, action): """ Ask guest services to vote """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") @@ -304,7 +304,7 @@ def guest_services_notify(token, instance_uuid, host_name, action): """ Notify guest services """ - url = token.get_service_url(OPENSTACK_SERVICE.GUEST) + url = token.get_service_url(PLATFORM_SERVICE.GUEST) if url is None: raise ValueError("OpenStack Guest URL is invalid") diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/mtc.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/mtc.py index 710ea546..24cfa4ca 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/mtc.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/mtc.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -11,7 +11,7 @@ from nfv_common.helpers import Constant from nfv_common.helpers import Constants from nfv_common.helpers import Singleton -from nfv_plugins.nfvi_plugins.openstack.objects import OPENSTACK_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import PLATFORM_SERVICE from nfv_plugins.nfvi_plugins.openstack.rest_api import rest_api_request DLOG = debug.debug_get_logger('nfv_plugins.nfvi_plugins.openstack.mtc') @@ -35,7 +35,7 @@ def system_query(token): """ Query Maintenance for the system information """ - url = token.get_service_url(OPENSTACK_SERVICE.MTC) + url = token.get_service_url(PLATFORM_SERVICE.MTC) if url is None: raise ValueError("OpenStack Mtc URL is invalid") @@ -53,7 +53,7 @@ def host_query(token, host_uuid, host_name): """ Query Maintenance for the host information """ - url = token.get_service_url(OPENSTACK_SERVICE.MTC) + url = token.get_service_url(PLATFORM_SERVICE.MTC) if url is None: raise ValueError("OpenStack Mtc URL is invalid") @@ -76,7 +76,7 @@ def notify_host_severity(token, host_uuid, host_name, host_severity): """ Notify Maintenance the severity of a host """ - url = token.get_service_url(OPENSTACK_SERVICE.MTC) + url = token.get_service_url(PLATFORM_SERVICE.MTC) if url is None: raise ValueError("OpenStack Mtc URL is invalid") diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/objects.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/objects.py index c0f644ad..e94d345c 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/objects.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/objects.py @@ -16,6 +16,36 @@ from nfv_common.helpers import Singleton DLOG = debug.debug_get_logger('nfv_plugins.nfvi_plugins.openstack.objects') +@six.add_metaclass(Singleton) +class ServiceCategory(Constants): + """ + Service Category Constants + """ + PLATFORM = Constant('platform') + OPENSTACK = Constant('openstack') + + +# Service Category Constant +SERVICE_CATEGORY = ServiceCategory() + + +@six.add_metaclass(Singleton) +class PlatformServices(Constants): + """ + Platform Services Constants + """ + GUEST = Constant('guest') + KEYSTONE = Constant('keystone') + MTC = Constant('mtc') + SYSINV = Constant('sysinv') + PATCHING = Constant('patching') + FM = Constant('fm') + + +# Platform Services Constant +PLATFORM_SERVICE = PlatformServices() + + @six.add_metaclass(Singleton) class OpenStackServices(Constants): """ @@ -24,15 +54,10 @@ class OpenStackServices(Constants): CEILOMETER = Constant('ceilometer') CINDER = Constant('cinder') GLANCE = Constant('glance') - GUEST = Constant('guest') KEYSTONE = Constant('keystone') - MTC = Constant('mtc') NEUTRON = Constant('neutron') NOVA = Constant('nova') - SYSINV = Constant('sysinv') HEAT = Constant('heat') - PATCHING = Constant('patching') - FM = Constant('fm') # OpenStack Services Constant @@ -91,9 +116,12 @@ class Directory(object): """ Directory """ - def __init__(self, auth_protocol, auth_host, auth_port, auth_project, + def __init__(self, service_category, keyring_service, auth_protocol, + auth_host, auth_port, auth_project, auth_username, auth_password, auth_user_domain_name, auth_project_domain_name, auth_uri=None): + self._service_category = service_category + self._keyring_service = keyring_service self._auth_protocol = auth_protocol self._auth_host = auth_host self._auth_port = auth_port @@ -105,6 +133,20 @@ class Directory(object): self._auth_project_domain_name = auth_project_domain_name self._entries = dict() + @property + def service_category(self): + """ + Returns the service category + """ + return self._service_category + + @property + def keyring_service(self): + """ + Returns the keyring service + """ + return self._keyring_service + @property def auth_protocol(self): """ diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/openstack.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/openstack.py index 273ea6a1..28f6fb4b 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/openstack.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/openstack.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -9,6 +9,8 @@ import urllib2 from nfv_common import debug from nfv_plugins.nfvi_plugins.openstack.objects import OPENSTACK_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import PLATFORM_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import SERVICE_CATEGORY from nfv_plugins.nfvi_plugins.openstack.objects import Directory from nfv_plugins.nfvi_plugins.openstack.objects import Token @@ -33,7 +35,8 @@ def get_token(directory): if directory.auth_password is None: import keyring - password = keyring.get_password('CGCS', directory.auth_username) + password = keyring.get_password(directory.keyring_service, + directory.auth_username) else: password = directory.auth_password @@ -75,27 +78,38 @@ def get_token(directory): return None -def get_directory(config): +def get_directory(config, service_category): """ - Get directory information from the given configuration + Get directory information from the given configuration for the given + service category. """ - openstack_info = config.CONF.get('openstack', None) - if openstack_info is not None: - auth_uri = openstack_info.get('authorization_uri', None) + if SERVICE_CATEGORY.PLATFORM == service_category: + services = PLATFORM_SERVICE + elif SERVICE_CATEGORY.OPENSTACK == service_category: + services = OPENSTACK_SERVICE + else: + raise ValueError("service_category is invalid: %s" % service_category) + + auth_info = config.CONF.get(service_category, None) + if auth_info is not None: + auth_uri = auth_info.get('authorization_uri', None) else: auth_uri = None - directory = Directory(config.CONF['openstack']['authorization_protocol'], - config.CONF['openstack']['authorization_ip'], - config.CONF['openstack']['authorization_port'], - config.CONF['openstack']['tenant'], - config.CONF['openstack']['username'], - config.CONF['openstack']['password'], - config.CONF['openstack']['user_domain_name'], - config.CONF['openstack']['project_domain_name'], - auth_uri) + directory = Directory( + service_category, + config.CONF[service_category]['keyring_service'], + config.CONF[service_category]['authorization_protocol'], + config.CONF[service_category]['authorization_ip'], + config.CONF[service_category]['authorization_port'], + config.CONF[service_category]['tenant'], + config.CONF[service_category]['username'], + config.CONF[service_category].get('password', None), + config.CONF[service_category]['user_domain_name'], + config.CONF[service_category]['project_domain_name'], + auth_uri) - for service in OPENSTACK_SERVICE: + for service in services: service_info = config.CONF.get(service, None) if service_info is not None: region_name = service_info.get('region_name', None) diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/patching.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/patching.py index 6507d202..41eb6a83 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/patching.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/patching.py @@ -1,11 +1,11 @@ # -# Copyright (c) 2016 Wind River Systems, Inc. +# Copyright (c) 2016-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # from nfv_common import debug -from nfv_plugins.nfvi_plugins.openstack.objects import OPENSTACK_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import PLATFORM_SERVICE from nfv_plugins.nfvi_plugins.openstack.rest_api import rest_api_request DLOG = debug.debug_get_logger('nfv_plugins.nfvi_plugins.openstack.patching') @@ -15,7 +15,7 @@ def query_patches(token): """ Asks Patch Controller for information about the patches in the system """ - url = token.get_service_url(OPENSTACK_SERVICE.PATCHING, strip_version=True) + url = token.get_service_url(PLATFORM_SERVICE.PATCHING, strip_version=True) if url is None: raise ValueError("OpenStack Patching URL is invalid") @@ -29,7 +29,7 @@ def query_hosts(token): """ Asks Patch Controller for information about the hosts in the system """ - url = token.get_service_url(OPENSTACK_SERVICE.PATCHING, strip_version=True) + url = token.get_service_url(PLATFORM_SERVICE.PATCHING, strip_version=True) if url is None: raise ValueError("OpenStack Patching URL is invalid") @@ -43,7 +43,7 @@ def host_install_async(token, host_name): """ Asks Patch Controller to perform a software upgrade on a host """ - url = token.get_service_url(OPENSTACK_SERVICE.PATCHING, strip_version=True) + url = token.get_service_url(PLATFORM_SERVICE.PATCHING, strip_version=True) if url is None: raise ValueError("OpenStack Patching URL is invalid") diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/sysinv.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/sysinv.py index d432ceda..15ab9392 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/sysinv.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/sysinv.py @@ -6,7 +6,7 @@ import json from nfv_common import debug -from nfv_plugins.nfvi_plugins.openstack.objects import OPENSTACK_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import PLATFORM_SERVICE from nfv_plugins.nfvi_plugins.openstack.rest_api import rest_api_request DLOG = debug.debug_get_logger('nfv_plugins.nfvi_plugins.openstack.sysinv') @@ -17,7 +17,7 @@ def get_system_info(token): Asks System Inventory for information about the system, such as the name of the system """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -31,7 +31,7 @@ def get_hosts(token): """ Asks System Inventory for a list of hosts """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -45,7 +45,7 @@ def get_host(token, host_uuid): """ Asks System Inventory for a host details """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -59,7 +59,7 @@ def get_upgrade(token): """ Asks System Inventory for information about the upgrade """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -73,7 +73,7 @@ def upgrade_start(token): """ Ask System Inventory to start an upgrade """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -95,7 +95,7 @@ def upgrade_activate(token): """ Ask System Inventory to activate an upgrade """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -122,7 +122,7 @@ def upgrade_complete(token): """ Ask System Inventory to complete an upgrade """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -140,7 +140,7 @@ def get_host_lvgs(token, host_uuid): """ Asks System Inventory for a list logical volume groups for a host """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -154,7 +154,7 @@ def notify_host_services_enabled(token, host_uuid): """ Notify System Inventory that host services are enabled """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -181,7 +181,7 @@ def notify_host_services_disabled(token, host_uuid): """ Notify System Inventory that host services are disabled """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -208,7 +208,7 @@ def notify_host_services_disable_extend(token, host_uuid): """ Notify System Inventory that host services disable needs to be extended """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -235,7 +235,7 @@ def notify_host_services_disable_failed(token, host_uuid, reason): """ Notify System Inventory that host services disable failed """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -268,7 +268,7 @@ def notify_host_services_deleted(token, host_uuid): """ Notify System Inventory that host services have been deleted """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -286,7 +286,7 @@ def notify_host_services_delete_failed(token, host_uuid, reason): """ Notify System Inventory that host services delete failed """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -319,7 +319,7 @@ def lock_host(token, host_uuid): """ Ask System Inventory to lock a host """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -346,7 +346,7 @@ def unlock_host(token, host_uuid): """ Ask System Inventory to unlock a host """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -373,7 +373,7 @@ def reboot_host(token, host_uuid): """ Ask System Inventory to reboot a host """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -400,7 +400,7 @@ def upgrade_host(token, host_uuid): """ Ask System Inventory to upgrade a host """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") @@ -422,7 +422,7 @@ def swact_from_host(token, host_uuid): """ Ask System Inventory to swact from a host """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) + url = token.get_service_url(PLATFORM_SERVICE.SYSINV) if url is None: raise ValueError("OpenStack SysInv URL is invalid") diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/unit_test.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/unit_test.py index db10aea8..a4193982 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/unit_test.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/unit_test.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -460,8 +460,12 @@ def do_unit_tests(test_set=None, rest_api_debug=False, test_config=None): opener = urllib2.build_opener(handler) urllib2.install_opener(opener) - directory = openstack.get_directory(config) - token = openstack.get_token(directory) + platform_directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.PLATFORM) + openstack_directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) + platform_token = openstack.get_token(platform_directory) + openstack_token = openstack.get_token(openstack_directory) if test_set is None: test_set = ['keystone', 'ceilometer', 'sysinv', 'glance', 'cinder', @@ -469,43 +473,43 @@ def do_unit_tests(test_set=None, rest_api_debug=False, test_config=None): print("-" * 80) if 'keystone' in test_set: - keystone_unit_tests(token, test_config) + keystone_unit_tests(openstack_token, test_config) print("-" * 80) if 'ceilometer' in test_set: - ceilometer_unit_tests(token, test_config) + ceilometer_unit_tests(openstack_token, test_config) print("-" * 80) if 'sysinv' in test_set: - sysinv_unit_tests(token, test_config) + sysinv_unit_tests(platform_token, test_config) print("-" * 80) if 'glance' in test_set: - glance_unit_tests(token, test_config) + glance_unit_tests(openstack_token, test_config) print("-" * 80) if 'cinder' in test_set: - cinder_unit_tests(token, test_config) + cinder_unit_tests(openstack_token, test_config) print("-" * 80) if 'neutron' in test_set: - neutron_unit_tests(token, test_config) + neutron_unit_tests(openstack_token, test_config) print("-" * 80) if 'nova' in test_set: - nova_unit_tests(token, test_config) + nova_unit_tests(openstack_token, test_config) print("-" * 80) if 'heat' in test_set: - heat_unit_tests(token, test_config) + heat_unit_tests(openstack_token, test_config) print("-" * 80) if 'guest' in test_set: - guest_unit_tests(token, test_config) + guest_unit_tests(platform_token, test_config) print("-" * 80) if 'rest-api' in test_set: - rest_api_unit_tests(token, test_config) + rest_api_unit_tests(platform_token, test_config) print("-" * 80) diff --git a/nfv/nfv-tests/nfv_scenario_tests/config.ini b/nfv/nfv-tests/nfv_scenario_tests/config.ini index faa5e104..999de81c 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/config.ini +++ b/nfv/nfv-tests/nfv_scenario_tests/config.ini @@ -12,6 +12,16 @@ tar_file=/var/log/nfv-vim-test.tar.gz config_file=debug.ini handlers=stdout +[platform] +username=admin +tenant=admin +authorization_protocol=http +authorization_ip=192.168.204.2 +authorization_port=5000 +user_domain_name=Default +project_domain_name=Default +keyring_service=CGCS + [openstack] username=admin tenant=admin @@ -20,6 +30,7 @@ authorization_ip=192.168.204.2 authorization_port=5000 user_domain_name=Default project_domain_name=Default +keyring_service=CGCS [keystone] region_name=RegionOne diff --git a/nfv/nfv-tests/nfv_scenario_tests/main.py b/nfv/nfv-tests/nfv_scenario_tests/main.py index 1934dc38..e429e3e4 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/main.py +++ b/nfv/nfv-tests/nfv_scenario_tests/main.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -80,7 +80,8 @@ def process_do_setup(loads_dir, setup_data): from nfv_plugins.nfvi_plugins.openstack import glance from nfv_plugins.nfvi_plugins.openstack import neutron - directory = openstack.get_directory(config) + directory = openstack.get_directory(config, + openstack.SERVICE_CATEGORY.OPENSTACK) token = openstack.get_token(directory) result = nova.get_flavors(token) @@ -491,7 +492,8 @@ def process_do_teardown(setup_data): from nfv_plugins.nfvi_plugins.openstack import glance from nfv_plugins.nfvi_plugins.openstack import neutron - directory = openstack.get_directory(config) + directory = openstack.get_directory(config, + openstack.SERVICE_CATEGORY.OPENSTACK) token = openstack.get_token(directory) result = nova.get_flavors(token) diff --git a/nfv/nfv-tests/nfv_scenario_tests/tests/_hosts.py b/nfv/nfv-tests/nfv_scenario_tests/tests/_hosts.py index fe7839d4..31065415 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/tests/_hosts.py +++ b/nfv/nfv-tests/nfv_scenario_tests/tests/_hosts.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -24,7 +24,8 @@ def _get_token(): global _directory, _token if _directory is None: - _directory = openstack.get_directory(config) + _directory = openstack.get_directory(config, + openstack.SERVICE_CATEGORY.PLATFORM) if _token is None: _token = openstack.get_token(_directory) diff --git a/nfv/nfv-tests/nfv_scenario_tests/tests/_instances.py b/nfv/nfv-tests/nfv_scenario_tests/tests/_instances.py index e7705817..4dac67b0 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/tests/_instances.py +++ b/nfv/nfv-tests/nfv_scenario_tests/tests/_instances.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -26,7 +26,8 @@ def _get_token(): global _directory, _token if _directory is None: - _directory = openstack.get_directory(config) + _directory = openstack.get_directory(config, + openstack.SERVICE_CATEGORY.OPENSTACK) if _token is None: _token = openstack.get_token(_directory) diff --git a/nfv/nfv-tests/nfv_scenario_tests/tests/_test_hosts.py b/nfv/nfv-tests/nfv_scenario_tests/tests/_test_hosts.py index 9439ad05..6c2fcd9d 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/tests/_test_hosts.py +++ b/nfv/nfv-tests/nfv_scenario_tests/tests/_test_hosts.py @@ -35,11 +35,15 @@ class TestHost(_test_base.Test): self._instance_names = instance_names self._host_data = None self._instances = dict() - self._token = None + self._platform_token = None + self._openstack_token = None self._customer_alarms = None self._customer_logs = None self._customer_alarm_history = None - self._directory = openstack.get_directory(config) + self._platform_directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.PLATFORM) + self._openstack_directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) name = name.replace(' ', '_') self._output_dir = (config.CONF['test-output']['dir'] + '/' + name.translate(None, ''.join(['(', ')'])) + '_' + @@ -68,17 +72,32 @@ class TestHost(_test_base.Test): return _hosts.host_get_id(self._host_data) @property - def token(self): + def platform_token(self): """ - Returns the token + Returns the platform token """ - if self._token is None: - self._token = openstack.get_token(self._directory) + if self._platform_token is None: + self._platform_token = openstack.get_token(self._platform_directory) - elif self._token.is_expired(): - self._token = openstack.get_token(self._directory) + elif self._platform_token.is_expired(): + self._platform_token = openstack.get_token(self._platform_directory) - return self._token + return self._platform_token + + @property + def openstack_token(self): + """ + Returns the openstack token + """ + if self._openstack_token is None: + self._openstack_token = openstack.get_token( + self._openstack_directory) + + elif self._openstack_token.is_expired(): + self._openstack_token = openstack.get_token( + self._openstack_directory) + + return self._openstack_token def _save_debug(self, test_success, test_reason): """ @@ -176,7 +195,7 @@ class TestHost(_test_base.Test): """ Fetch the customer alarms raised """ - self._customer_alarms = fm.get_alarms(self.token).result_data + self._customer_alarms = fm.get_alarms(self.platform_token).result_data return @@ -184,15 +203,18 @@ class TestHost(_test_base.Test): """ Fetch the customer logs """ - self._customer_logs = fm.get_logs(self.token, self.start_datetime, - self.end_datetime).result_data + self._customer_logs = fm.get_logs(self.platform_token, + self.start_datetime, + self.end_datetime).result_data def _refresh_customer_alarm_history(self): """ Fetch the customer alarm history """ self._customer_alarm_history = fm.get_alarm_history( - self.token, self.start_datetime, self.end_datetime).result_data + self.platform_token, + self.start_datetime, + self.end_datetime).result_data class TestHostLock(TestHost): @@ -226,7 +248,7 @@ class TestHostLock(TestHost): success, reason = _instances.instance_on_host(instance_data, self.host_name) if not success: - nova.live_migrate_server(self.token, instance_uuid, + nova.live_migrate_server(self.openstack_token, instance_uuid, to_host_name=self.host_name) max_end_datetime = (self._start_datetime + @@ -262,7 +284,7 @@ class TestHostLock(TestHost): """ Perform the test """ - sysinv.lock_host(self.token, self.host_id) + sysinv.lock_host(self.platform_token, self.host_id) return True, "host locking" def _test_passed(self): @@ -329,7 +351,7 @@ class TestHostUnlock(TestHost): """ Perform the test """ - sysinv.unlock_host(self.token, self.host_id) + sysinv.unlock_host(self.platform_token, self.host_id) return True, "host unlocking" def _test_passed(self): diff --git a/nfv/nfv-tests/nfv_scenario_tests/tests/_test_instances.py b/nfv/nfv-tests/nfv_scenario_tests/tests/_test_instances.py index 561a079d..ae1b4581 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/tests/_test_instances.py +++ b/nfv/nfv-tests/nfv_scenario_tests/tests/_test_instances.py @@ -31,11 +31,15 @@ class TestInstance(_test_base.Test): super(TestInstance, self).__init__(name, timeout_secs) self._instance_name = instance_name self._instance_data = None - self._token = None + self._platform_token = None + self._openstack_token = None self._customer_alarms = None self._customer_logs = None self._customer_alarm_history = None - self._directory = openstack.get_directory(config) + self._platform_directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.PLATFORM) + self._openstack_directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) name = name.replace(' ', '_') self._output_dir = (config.CONF['test-output']['dir'] + '/' + name.translate(None, ''.join(['(', ')'])) + '_' + @@ -66,17 +70,32 @@ class TestInstance(_test_base.Test): return None @property - def token(self): + def platform_token(self): """ - Returns the token + Returns the platform token """ - if self._token is None: - self._token = openstack.get_token(self._directory) + if self._platform_token is None: + self._platform_token = openstack.get_token(self._platform_directory) - elif self._token.is_expired(): - self._token = openstack.get_token(self._directory) + elif self._platform_token.is_expired(): + self._platform_token = openstack.get_token(self._platform_directory) - return self._token + return self._platform_token + + @property + def openstack_token(self): + """ + Returns the openstack token + """ + if self._openstack_token is None: + self._openstack_token = openstack.get_token( + self._openstack_directory) + + elif self._openstack_token.is_expired(): + self._openstack_token = openstack.get_token( + self._openstack_directory) + + return self._openstack_token def _save_debug(self, test_success, test_reason): """ @@ -162,21 +181,24 @@ class TestInstance(_test_base.Test): """ Fetch the customer alarms raised """ - self._customer_alarms = fm.get_alarms(self.token).result_data + self._customer_alarms = fm.get_alarms(self.platform_token).result_data def _refresh_customer_logs(self): """ Fetch the customer logs """ - self._customer_logs = fm.get_logs(self.token, self.start_datetime, - self.end_datetime).result_data + self._customer_logs = fm.get_logs(self.platform_token, + self.start_datetime, + self.end_datetime).result_data def _refresh_customer_alarm_history(self): """ Fetch the customer alarm history """ self._customer_alarm_history = fm.get_alarm_history( - self.token, self.start_datetime, self.end_datetime).result_data + self.platform_token, + self.start_datetime, + self.end_datetime).result_data class TestInstanceStart(TestInstance): @@ -202,7 +224,7 @@ class TestInstanceStart(TestInstance): """ Perform test """ - nova.start_server(self.token, self.instance_uuid) + nova.start_server(self.openstack_token, self.instance_uuid) return True, "instance is starting" def _test_passed(self): @@ -244,7 +266,7 @@ class TestInstanceStop(TestInstance): """ Perform test """ - nova.stop_server(self.token, self.instance_uuid) + nova.stop_server(self.openstack_token, self.instance_uuid) return True, "instance is stopping" def _test_passed(self): @@ -295,7 +317,7 @@ class TestInstancePause(TestInstance): """ Perform test """ - nova.pause_server(self.token, self.instance_uuid) + nova.pause_server(self.openstack_token, self.instance_uuid) return True, "instance is pausing" def _test_passed(self): @@ -337,7 +359,7 @@ class TestInstanceUnpause(TestInstance): """ Perform test """ - nova.unpause_server(self.token, self.instance_uuid) + nova.unpause_server(self.openstack_token, self.instance_uuid) return True, "instance is unpausing" def _test_passed(self): @@ -379,7 +401,7 @@ class TestInstanceSuspend(TestInstance): """ Perform test """ - nova.suspend_server(self.token, self.instance_uuid) + nova.suspend_server(self.openstack_token, self.instance_uuid) return True, "instance is suspending" def _test_passed(self): @@ -424,7 +446,7 @@ class TestInstanceResume(TestInstance): """ Perform test """ - nova.resume_server(self.token, self.instance_uuid) + nova.resume_server(self.openstack_token, self.instance_uuid) return True, "instance is resuming" def _test_passed(self): @@ -482,10 +504,10 @@ class TestInstanceReboot(TestInstance): Perform test """ if self._hard: - nova.reboot_server(self.token, self.instance_uuid, + nova.reboot_server(self.openstack_token, self.instance_uuid, nova.VM_REBOOT_TYPE.HARD) else: - nova.reboot_server(self.token, self.instance_uuid, + nova.reboot_server(self.openstack_token, self.instance_uuid, nova.VM_REBOOT_TYPE.SOFT) return True, "instance is rebooting" @@ -542,7 +564,8 @@ class TestInstanceRebuild(TestInstance): """ # try block added to work around nova bug for now try: - nova.rebuild_server(self.token, self.instance_uuid, self.instance_name, + nova.rebuild_server(self.openstack_token, self.instance_uuid, + self.instance_name, self._instance_data['image']['id']) except ValueError: pass @@ -592,7 +615,8 @@ class TestInstanceLiveMigrate(TestInstance): """ Perform test """ - nova.live_migrate_server(self.token, self.instance_uuid, self._to_host) + nova.live_migrate_server(self.openstack_token, self.instance_uuid, + self._to_host) return True, "instance is live-migrating" def _test_passed(self): @@ -639,7 +663,8 @@ class TestInstanceColdMigrate(TestInstance): """ Perform test """ - nova.cold_migrate_server(self.token, self.instance_uuid, self._to_host) + nova.cold_migrate_server(self.openstack_token, self.instance_uuid, + self._to_host) return True, "instance is cold-migrating" def _test_passed(self): @@ -686,7 +711,7 @@ class TestInstanceColdMigrateConfirm(TestInstance): return False, ("instance needs to be migrated for test, but is not in " "the running state") - nova.cold_migrate_server(self.token, self.instance_uuid) + nova.cold_migrate_server(self.openstack_token, self.instance_uuid) max_end_datetime = (self._start_datetime + datetime.timedelta(seconds=self.timeout_secs)) @@ -711,7 +736,8 @@ class TestInstanceColdMigrateConfirm(TestInstance): """ Perform test """ - nova.cold_migrate_server_confirm(self.token, self.instance_uuid) + nova.cold_migrate_server_confirm(self.openstack_token, + self.instance_uuid) return True, "confirming instance cold-migrate" def _test_passed(self): @@ -757,7 +783,7 @@ class TestInstanceColdMigrateRevert(TestInstance): return False, ("instance needs to be migrated for test, but is not in " "the running state") - nova.cold_migrate_server(self.token, self.instance_uuid) + nova.cold_migrate_server(self.openstack_token, self.instance_uuid) max_end_datetime = (self._start_datetime + datetime.timedelta(seconds=self.timeout_secs)) @@ -782,7 +808,8 @@ class TestInstanceColdMigrateRevert(TestInstance): """ Perform test """ - nova.cold_migrate_server_revert(self.token, self.instance_uuid) + nova.cold_migrate_server_revert(self.openstack_token, + self.instance_uuid) return True, "reverting instance cold-migrate" def _test_passed(self): @@ -820,7 +847,7 @@ class TestInstanceResize(TestInstance): Returns the flavor id associated with the given flavor name """ flavor_id = None - flavors = nova.get_flavors(self.token).result_data + flavors = nova.get_flavors(self.openstack_token).result_data for flavor in flavors['flavors']: if flavor['name'] == flavor_name: flavor_id = flavor['id'] @@ -857,7 +884,8 @@ class TestInstanceResize(TestInstance): """ Perform test """ - nova.resize_server(self.token, self.instance_uuid, self._flavor_id) + nova.resize_server(self.openstack_token, self.instance_uuid, + self._flavor_id) return True, "instance is resizing" def _test_passed(self): @@ -894,7 +922,7 @@ class TestInstanceResizeConfirm(TestInstance): Returns the flavor id associated with the given flavor name """ flavor_id = None - flavors = nova.get_flavors(self.token).result_data + flavors = nova.get_flavors(self.openstack_token).result_data for flavor in flavors['flavors']: if flavor['name'] == flavor_name: flavor_id = flavor['id'] @@ -928,7 +956,7 @@ class TestInstanceResizeConfirm(TestInstance): % (self._name, self.instance_name)) return False, "no valid flavors given" - nova.resize_server(self.token, self.instance_uuid, flavor_id) + nova.resize_server(self.openstack_token, self.instance_uuid, flavor_id) max_end_datetime = (self._start_datetime + datetime.timedelta(seconds=self.timeout_secs)) @@ -953,7 +981,7 @@ class TestInstanceResizeConfirm(TestInstance): """ Perform test """ - nova.resize_server_confirm(self.token, self.instance_uuid) + nova.resize_server_confirm(self.openstack_token, self.instance_uuid) return True, "confirming instance resize" def _test_passed(self): @@ -990,7 +1018,7 @@ class TestInstanceResizeRevert(TestInstance): Returns the flavor id associated with the given flavor name """ flavor_id = None - flavors = nova.get_flavors(self.token).result_data + flavors = nova.get_flavors(self.openstack_token).result_data for flavor in flavors['flavors']: if flavor['name'] == flavor_name: flavor_id = flavor['id'] @@ -1024,7 +1052,7 @@ class TestInstanceResizeRevert(TestInstance): % (self._name, self.instance_name)) return False, "no valid flavors given" - nova.resize_server(self.token, self.instance_uuid, flavor_id) + nova.resize_server(self.openstack_token, self.instance_uuid, flavor_id) max_end_datetime = (self._start_datetime + datetime.timedelta(seconds=self.timeout_secs)) @@ -1049,7 +1077,7 @@ class TestInstanceResizeRevert(TestInstance): """ Perform test """ - nova.resize_server_revert(self.token, self.instance_uuid) + nova.resize_server_revert(self.openstack_token, self.instance_uuid) return True, "reverting instance resize" def _test_passed(self): diff --git a/nfv/nfv-vim/nfv_vim/api/acl/_application.py b/nfv/nfv-vim/nfv_vim/api/acl/_application.py index fe7a2c5c..f2b56433 100755 --- a/nfv/nfv-vim/nfv_vim/api/acl/_application.py +++ b/nfv/nfv-vim/nfv_vim/api/acl/_application.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2016 Wind River Systems, Inc. +# Copyright (c) 2016-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -17,7 +17,8 @@ class AuthenticationApplication(object): self._app = app self._token = None self._config = openstack.config_load() - self._directory = openstack.get_directory(self._config) + self._directory = openstack.get_directory( + self._config, openstack.SERVICE_CATEGORY.PLATFORM) @staticmethod def _get_header_value(env, key, default_value=None): diff --git a/nfv/nfv-vim/nfv_vim/api/controllers/v1/openstack/_heat_api.py b/nfv/nfv-vim/nfv_vim/api/controllers/v1/openstack/_heat_api.py index 6f8aa55b..9a37a351 100755 --- a/nfv/nfv-vim/nfv_vim/api/controllers/v1/openstack/_heat_api.py +++ b/nfv/nfv-vim/nfv_vim/api/controllers/v1/openstack/_heat_api.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -48,7 +48,8 @@ class HeatAPI(object): OpenStack Heat Proxy """ config = openstack.config_load() - directory = openstack.get_directory(config) + directory = openstack.get_directory( + config, openstack.SERVICE_CATEGORY.OPENSTACK) token = openstack.get_token(directory) url_target_index = pecan.request.url.find('/api/openstack/heat') diff --git a/nfv/nfv-vim/nfv_vim/api/openstack/__init__.py b/nfv/nfv-vim/nfv_vim/api/openstack/__init__.py index 3c100bad..75145bf4 100755 --- a/nfv/nfv-vim/nfv_vim/api/openstack/__init__.py +++ b/nfv/nfv-vim/nfv_vim/api/openstack/__init__.py @@ -1,11 +1,13 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # from nfv_vim.api.openstack._config import CONF # noqa: F401 from nfv_vim.api.openstack._config import config_load # noqa: F401 from nfv_vim.api.openstack._openstack import OPENSTACK_SERVICE # noqa: F401 +from nfv_vim.api.openstack._openstack import PLATFORM_SERVICE # noqa: F401 +from nfv_vim.api.openstack._openstack import SERVICE_CATEGORY # noqa: F401 from nfv_vim.api.openstack._openstack import get_directory # noqa: F401 from nfv_vim.api.openstack._openstack import get_token # noqa: F401 from nfv_vim.api.openstack._openstack import validate_token # noqa: F401 diff --git a/nfv/nfv-vim/nfv_vim/api/openstack/_config.py b/nfv/nfv-vim/nfv_vim/api/openstack/_config.py index b33cadf8..a59aff03 100755 --- a/nfv/nfv-vim/nfv_vim/api/openstack/_config.py +++ b/nfv/nfv-vim/nfv_vim/api/openstack/_config.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -35,10 +35,6 @@ def config_load(): nfvi_config.read(config.CONF['nfvi']['config_file']) CONF = nfvi_config.as_dict() - password = CONF['openstack'].get('password', None) - if password is None: - CONF['openstack']['password'] = None - region_name = CONF['openstack'].get('region_name', None) if region_name is None: CONF['openstack']['region_name'] = "RegionOne" diff --git a/nfv/nfv-vim/nfv_vim/api/openstack/_objects.py b/nfv/nfv-vim/nfv_vim/api/openstack/_objects.py index d182aae8..06d02835 100755 --- a/nfv/nfv-vim/nfv_vim/api/openstack/_objects.py +++ b/nfv/nfv-vim/nfv_vim/api/openstack/_objects.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -16,6 +16,36 @@ from nfv_common.helpers import Singleton DLOG = debug.debug_get_logger('nfv_vim.api.openstack') +@six.add_metaclass(Singleton) +class ServiceCategory(Constants): + """ + Service Category Constants + """ + PLATFORM = Constant('platform') + OPENSTACK = Constant('openstack') + + +# Service Category Constant +SERVICE_CATEGORY = ServiceCategory() + + +@six.add_metaclass(Singleton) +class PlatformServices(Constants): + """ + Platform Services Constants + """ + GUEST = Constant('guest') + KEYSTONE = Constant('keystone') + MTC = Constant('mtc') + SYSINV = Constant('sysinv') + PATCHING = Constant('patching') + FM = Constant('fm') + + +# Platform Services Constant +PLATFORM_SERVICE = PlatformServices() + + @six.add_metaclass(Singleton) class OpenStackServices(Constants): """ @@ -24,14 +54,10 @@ class OpenStackServices(Constants): CEILOMETER = Constant('ceilometer') CINDER = Constant('cinder') GLANCE = Constant('glance') - GUEST = Constant('guest') KEYSTONE = Constant('keystone') - MTC = Constant('mtc') NEUTRON = Constant('neutron') NOVA = Constant('nova') - SYSINV = Constant('sysinv') HEAT = Constant('heat') - FM = Constant('fm') # OpenStack Services Constant @@ -90,9 +116,12 @@ class Directory(object): """ Directory """ - def __init__(self, auth_protocol, auth_host, auth_port, auth_project, + def __init__(self, service_category, keyring_service, auth_protocol, + auth_host, auth_port, auth_project, auth_username, auth_password, auth_user_domain_name, auth_project_domain_name, auth_uri=None): + self._service_category = service_category + self._keyring_service = keyring_service self._auth_protocol = auth_protocol self._auth_host = auth_host self._auth_port = auth_port @@ -104,6 +133,20 @@ class Directory(object): self._auth_project_domain_name = auth_project_domain_name self._entries = dict() + @property + def service_category(self): + """ + Returns the service category + """ + return self._service_category + + @property + def keyring_service(self): + """ + Returns the keyring service + """ + return self._keyring_service + @property def auth_protocol(self): """ @@ -271,7 +314,6 @@ class Token(object): for endpoint in catalog['endpoints']: if (endpoint['region'] == region_name and endpoint['interface'] == endpoint_type): - print("HERE HERE HERE") return endpoint['url'] return None diff --git a/nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py b/nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py index 766b2fde..21f91368 100755 --- a/nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py +++ b/nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -9,6 +9,8 @@ import urllib2 from nfv_common import debug from nfv_vim.api.openstack._objects import OPENSTACK_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import PLATFORM_SERVICE +from nfv_plugins.nfvi_plugins.openstack.objects import SERVICE_CATEGORY from nfv_vim.api.openstack._objects import Directory from nfv_vim.api.openstack._objects import Token @@ -17,7 +19,7 @@ DLOG = debug.debug_get_logger('nfv_vim.api.openstack') def validate_token(directory, admin_token, token_id): """ - Ask OpenStack if a token is valid + Ask Keystone if a token is valid """ try: if directory.auth_uri is None: @@ -89,7 +91,8 @@ def get_token(directory): if directory.auth_password is None: import keyring - password = keyring.get_password('CGCS', directory.auth_username) + password = keyring.get_password(directory.keyring_service, + directory.auth_username) else: password = directory.auth_password @@ -131,27 +134,38 @@ def get_token(directory): return None -def get_directory(config): +def get_directory(config, service_category): """ - Get directory information from the given configuration + Get directory information from the given configuration for the given + service category. """ - openstack_info = config.get('openstack', None) - if openstack_info is not None: - auth_uri = openstack_info.get('authorization_uri', None) + if SERVICE_CATEGORY.PLATFORM == service_category: + services = PLATFORM_SERVICE + elif SERVICE_CATEGORY.OPENSTACK == service_category: + services = OPENSTACK_SERVICE + else: + raise ValueError("service_category is invalid: %s" % service_category) + + auth_info = config.get(service_category, None) + if auth_info is not None: + auth_uri = auth_info.get('authorization_uri', None) else: auth_uri = None - directory = Directory(config['openstack']['authorization_protocol'], - config['openstack']['authorization_ip'], - config['openstack']['authorization_port'], - config['openstack']['tenant'], - config['openstack']['username'], - config['openstack']['password'], - config['openstack']['user_domain_name'], - config['openstack']['project_domain_name'], - auth_uri) + directory = Directory( + service_category, + config[service_category]['keyring_service'], + config[service_category]['authorization_protocol'], + config[service_category]['authorization_ip'], + config[service_category]['authorization_port'], + config[service_category]['tenant'], + config[service_category]['username'], + config[service_category].get('password', None), + config[service_category]['user_domain_name'], + config[service_category]['project_domain_name'], + auth_uri) - for service in OPENSTACK_SERVICE: + for service in services: service_info = config.get(service, None) if service_info is not None: region_name = service_info.get('region_name', None) diff --git a/nfv/nfv-vim/nfv_vim/webserver/_webserver.py b/nfv/nfv-vim/nfv_vim/webserver/_webserver.py index d55b76e4..20b99efb 100755 --- a/nfv/nfv-vim/nfv_vim/webserver/_webserver.py +++ b/nfv/nfv-vim/nfv_vim/webserver/_webserver.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -597,7 +597,8 @@ class SimpleHttpServer(object): self.server_thread = None config.load(nfvi_config['config_file']) - _directory = openstack.get_directory(config) + _directory = openstack.get_directory(config, + openstack.SERVICE_CATEGORY.PLATFORM) _vim_api_ip = vim_api_config['host'] if ':' in _vim_api_ip: # Wrap IPv6 address for use in URLs