From 24ec8517fff9ee5c7a1fd21ecc2664a0fe2850c1 Mon Sep 17 00:00:00 2001 From: Bart Wensley Date: Wed, 16 Jan 2019 12:55:50 -0600 Subject: [PATCH 1/2] Remove use of storage extra spec from VIM The setting of the storage extra spec on each flavor was removed from nova recently. However, the VIM still relies on this extra spec being set and this results in the VIM not making proper decisions on whether to live migrate, cold migrate or evacuate instances during various system events (e.g. a host lock). The solution is to remove the storage extra spec from the VIM. Live migration is now supported for instances, regardless of the storage type. The cold migrate and evacuate decisions will assume local storage is being used until support for remote storage has been added to the containers configuration. Change-Id: I42d2d755c5cc61acb8e23bc278cd920a3b782562 Story: 2004386 Task: 28911 Signed-off-by: Bart Wensley --- .../nfvi_plugins/nfvi_compute_api.py | 18 +++----- .../nfv_unit_tests/tests/test_instance.py | 3 +- .../tests/test_instance_director.py | 3 +- .../tests/test_sw_patch_strategy.py | 3 +- .../tests/test_sw_upgrade_strategy.py | 3 +- nfv/nfv-tests/nfv_unit_tests/tests/utils.py | 3 -- .../nfv_vim/audits/_vim_nfvi_audits.py | 6 +-- .../database/_database_compute_module.py | 16 +++---- .../nfv_vim/database/_database_migrate.py | 23 ++++++++++ .../nfv_vim/database/model/__init__.py | 1 + .../nfv_vim/database/model/_instance_type.py | 45 +++++++++++++++++++ .../nfv_vim/directors/_instance_director.py | 3 +- .../nfv_vim/nfvi/objects/v1/__init__.py | 1 - .../nfv_vim/nfvi/objects/v1/_instance.py | 13 ------ .../nfv_vim/nfvi/objects/v1/_instance_type.py | 12 ++--- nfv/nfv-vim/nfv_vim/objects/__init__.py | 1 - nfv/nfv-vim/nfv_vim/objects/_instance.py | 42 +++++------------ nfv/nfv-vim/nfv_vim/objects/_instance_type.py | 12 ++--- .../templates/instance_types.handlebars | 2 - 19 files changed, 106 insertions(+), 104 deletions(-) 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 11a238b4..2b2fd859 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 @@ -336,12 +336,8 @@ def flavor_data_extra_get(flavor_data_extra): nfvi_objs.INSTANCE_TYPE_EXTENSION.LIVE_MIGRATION_MAX_DOWNTIME, None) - storage_type = flavor_data_extra.get( - nfvi_objs.INSTANCE_TYPE_EXTENSION.STORAGE_TYPE, - None) - return (guest_heartbeat, auto_recovery, live_migration_timeout, - live_migration_max_downtime, storage_type) + live_migration_max_downtime) class NFVIComputeAPI(nfvi.api.v1.NFVIComputeAPI): @@ -1322,7 +1318,6 @@ class NFVIComputeAPI(nfvi.api.v1.NFVIComputeAPI): auto_recovery = None live_migration_timeout = None live_migration_max_downtime = None - storage_type = None if extra_specs: future.work(nova.set_flavor_extra_specs, self._token, @@ -1335,7 +1330,7 @@ class NFVIComputeAPI(nfvi.api.v1.NFVIComputeAPI): flavor_data_extra = future.result.data['extra_specs'] (guest_heartbeat, auto_recovery, live_migration_timeout, - live_migration_max_downtime, storage_type) = \ + live_migration_max_downtime) = \ flavor_data_extra_get(flavor_data_extra) if guest_heartbeat is not None: @@ -1346,8 +1341,7 @@ class NFVIComputeAPI(nfvi.api.v1.NFVIComputeAPI): ephemeral_gb, swap_gb, guest_services=guest_services, auto_recovery=auto_recovery, live_migration_timeout=live_migration_timeout, - live_migration_max_downtime=live_migration_max_downtime, - storage_type=storage_type) + live_migration_max_downtime=live_migration_max_downtime) response['result-data'] = instance_type_obj response['completed'] = True @@ -1469,14 +1463,13 @@ class NFVIComputeAPI(nfvi.api.v1.NFVIComputeAPI): auto_recovery = None live_migration_timeout = None live_migration_max_downtime = None - storage_type = None if future.result.is_complete(): flavor_data_extra = future.result.data.get('extra_specs') if flavor_data_extra is not None: (guest_heartbeat, auto_recovery, live_migration_timeout, - live_migration_max_downtime, storage_type) = \ + live_migration_max_downtime) = \ flavor_data_extra_get(flavor_data_extra) if guest_heartbeat is not None: @@ -1497,8 +1490,7 @@ class NFVIComputeAPI(nfvi.api.v1.NFVIComputeAPI): ephemeral_gb, swap_gb, guest_services=guest_services, auto_recovery=auto_recovery, live_migration_timeout=live_migration_timeout, - live_migration_max_downtime=live_migration_max_downtime, - storage_type=storage_type) + live_migration_max_downtime=live_migration_max_downtime) response['result-data'] = instance_type_obj response['completed'] = True diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_instance.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_instance.py index a5d48dc0..21425307 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_instance.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_instance.py @@ -145,8 +145,7 @@ class TestInstance(testcase.NFVTestCase): swap_gb=0, guest_services=None, auto_recovery=True, live_migration_timeout=live_migration_timeout, - live_migration_max_downtime=500, - storage_type='local_image') + live_migration_max_downtime=500) self._instance_type_table[instance_type_uuid] = instance_type def create_image(self, image_name, properties=None): diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_instance_director.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_instance_director.py index b52f8d13..64419e52 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_instance_director.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_instance_director.py @@ -101,8 +101,7 @@ class TestInstanceDirector(testcase.NFVTestCase): guest_services=None, auto_recovery=True, live_migration_timeout=800, - live_migration_max_downtime=500, - storage_type='local_image') + live_migration_max_downtime=500) self._instance_type_table[instance_type_uuid] = instance_type self._director = InstanceDirector( diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_patch_strategy.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_patch_strategy.py index bbd8e07d..b7013f91 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_patch_strategy.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_patch_strategy.py @@ -196,8 +196,7 @@ class TestSwPatchStrategy(testcase.NFVTestCase): guest_services=None, auto_recovery=True, live_migration_timeout=800, - live_migration_max_downtime=500, - storage_type='local_image') + live_migration_max_downtime=500) self._instance_type_table[instance_type_uuid] = instance_type def tearDown(self): diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_upgrade_strategy.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_upgrade_strategy.py index 6abab393..84a10c98 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_upgrade_strategy.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_upgrade_strategy.py @@ -174,8 +174,7 @@ class TestSwUpgradeStrategy(testcase.NFVTestCase): guest_services=None, auto_recovery=True, live_migration_timeout=800, - live_migration_max_downtime=500, - storage_type='local_image') + live_migration_max_downtime=500) self._instance_type_table[instance_type_uuid] = instance_type def tearDown(self): diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/utils.py b/nfv/nfv-tests/nfv_unit_tests/tests/utils.py index 99e5e0c7..8fc6bf88 100644 --- a/nfv/nfv-tests/nfv_unit_tests/tests/utils.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/utils.py @@ -22,9 +22,6 @@ def instance_type_to_flavor_dict(instance_type): extra_specs[ nfvi.objects.v1.INSTANCE_TYPE_EXTENSION.LIVE_MIGRATION_MAX_DOWNTIME] = \ instance_type.live_migration_max_downtime - extra_specs[ - nfvi.objects.v1.INSTANCE_TYPE_EXTENSION.STORAGE_TYPE] = \ - instance_type.storage_type flavor['extra_specs'] = extra_specs return flavor diff --git a/nfv/nfv-vim/nfv_vim/audits/_vim_nfvi_audits.py b/nfv/nfv-vim/nfv_vim/audits/_vim_nfvi_audits.py index e692b29b..6e47d898 100755 --- a/nfv/nfv-vim/nfv_vim/audits/_vim_nfvi_audits.py +++ b/nfv/nfv-vim/nfv_vim/audits/_vim_nfvi_audits.py @@ -356,8 +356,7 @@ def _audit_nfvi_instance_types_callback(timer_id): nfvi_instance_type.guest_services, nfvi_instance_type.auto_recovery, nfvi_instance_type.live_migration_timeout, - nfvi_instance_type.live_migration_max_downtime, - nfvi_instance_type.storage_type) + nfvi_instance_type.live_migration_max_downtime) if _nfvi_instance_types_paging.done: for instance_type_uuid in _deletable_instance_types: @@ -1075,8 +1074,7 @@ def _audit_nfvi_instance_type_callback(instance_type_uuid): instance_type.swap_gb, instance_type.guest_services, instance_type.auto_recovery, instance_type.live_migration_timeout, - instance_type.live_migration_max_downtime, - instance_type.storage_type) + instance_type.live_migration_max_downtime) instance_type_table = tables.tables_get_instance_type_table() instance_type_table[instance_type.uuid] = instance_type_obj diff --git a/nfv/nfv-vim/nfv_vim/database/_database_compute_module.py b/nfv/nfv-vim/nfv_vim/database/_database_compute_module.py index e0c7d966..54928a02 100755 --- a/nfv/nfv-vim/nfv_vim/database/_database_compute_module.py +++ b/nfv/nfv-vim/nfv_vim/database/_database_compute_module.py @@ -164,11 +164,11 @@ def database_instance_type_add(instance_type_obj): """ db = database_get() session = db.session() - query = session.query(model.InstanceType) - query = query.filter(model.InstanceType.uuid == instance_type_obj.uuid) + query = session.query(model.InstanceType_v5) + query = query.filter(model.InstanceType_v5.uuid == instance_type_obj.uuid) instance_type = query.first() if not instance_type: - instance_type = model.InstanceType() + instance_type = model.InstanceType_v5() instance_type.uuid = instance_type_obj.uuid instance_type.name = instance_type_obj.name if instance_type_obj.have_details(): @@ -186,7 +186,6 @@ def database_instance_type_add(instance_type_obj): = instance_type_obj.live_migration_timeout instance_type.live_migration_max_downtime \ = instance_type_obj.live_migration_max_downtime - instance_type.storage_type = instance_type_obj.storage_type session.add(instance_type) else: if instance_type_obj.have_details(): @@ -204,7 +203,6 @@ def database_instance_type_add(instance_type_obj): = instance_type_obj.live_migration_timeout instance_type.live_migration_max_downtime \ = instance_type_obj.live_migration_max_downtime - instance_type.storage_type = instance_type_obj.storage_type db.commit() @@ -214,8 +212,8 @@ def database_instance_type_delete(instance_type_uuid): """ db = database_get() session = db.session() - query = session.query(model.InstanceType) - query.filter(model.InstanceType.uuid == instance_type_uuid).delete() + query = session.query(model.InstanceType_v5) + query.filter(model.InstanceType_v5.uuid == instance_type_uuid).delete() session.commit() @@ -225,7 +223,7 @@ def database_instance_type_get_list(): """ db = database_get() session = db.session() - query = session.query(model.InstanceType) + query = session.query(model.InstanceType_v5) instance_type_objs = list() for instance_type in query.all(): @@ -237,7 +235,7 @@ def database_instance_type_get_list(): instance_type.vcpus, instance_type.mem_mb, instance_type.disk_gb, instance_type.ephemeral_gb, instance_type.swap_gb, guest_services, instance_type.auto_recovery, instance_type.live_migration_timeout, - instance_type.live_migration_max_downtime, instance_type.storage_type) + instance_type.live_migration_max_downtime) instance_type_objs.append(instance_type_obj) return instance_type_objs diff --git a/nfv/nfv-vim/nfv_vim/database/_database_migrate.py b/nfv/nfv-vim/nfv_vim/database/_database_migrate.py index 3c4a9259..4d654b56 100755 --- a/nfv/nfv-vim/nfv_vim/database/_database_migrate.py +++ b/nfv/nfv-vim/nfv_vim/database/_database_migrate.py @@ -27,6 +27,19 @@ def _migrate_hosts_v5_to_v6(session, hosts_v5, hosts_v6): session.add(host_v6) +def _migrate_instance_types_v4_to_v5(session, instance_types_v4, + instance_types_v5): + """ + Migrate instance_types_v4 table to instance_types_v5 table + """ + if 0 == len(instance_types_v5): + for instance_type_v4 in instance_types_v4: + instance_type_v5 = model.InstanceType_v5() + del instance_type_v4.data['storage_type'] + instance_type_v5.data = instance_type_v4.data + session.add(instance_type_v5) + + def migrate_tables(session, table_names): """ Migrate database tables @@ -38,3 +51,13 @@ def migrate_tables(session, table_names): hosts_v6 = hosts_v6_query.all() _migrate_hosts_v5_to_v6(session, hosts_v5, hosts_v6) hosts_v5_query.delete() + + if 'instance_types_v4' in table_names and \ + 'instance_types_v5' in table_names: + instance_types_v4_query = session.query(model.InstanceType) + instance_types_v4 = instance_types_v4_query.all() + instance_types_v5_query = session.query(model.InstanceType_v5) + instance_types_v5 = instance_types_v5_query.all() + _migrate_instance_types_v4_to_v5(session, instance_types_v4, + instance_types_v5) + instance_types_v4_query.delete() diff --git a/nfv/nfv-vim/nfv_vim/database/model/__init__.py b/nfv/nfv-vim/nfv_vim/database/model/__init__.py index a868d031..8cfbafe5 100755 --- a/nfv/nfv-vim/nfv_vim/database/model/__init__.py +++ b/nfv/nfv-vim/nfv_vim/database/model/__init__.py @@ -15,6 +15,7 @@ from nfv_vim.database.model._instance import Instance_v4 # noqa: F401 from nfv_vim.database.model._instance import Instance_v5 # noqa: F401 from nfv_vim.database.model._instance_group import InstanceGroup # noqa: F401 from nfv_vim.database.model._instance_type import InstanceType # noqa: F401 +from nfv_vim.database.model._instance_type import InstanceType_v5 # noqa: F401 from nfv_vim.database.model._network import Network # noqa: F401 from nfv_vim.database.model._service_host import ServiceHost # noqa: F401 from nfv_vim.database.model._subnet import Subnet # noqa: F401 diff --git a/nfv/nfv-vim/nfv_vim/database/model/_instance_type.py b/nfv/nfv-vim/nfv_vim/database/model/_instance_type.py index bd597695..e6028103 100755 --- a/nfv/nfv-vim/nfv_vim/database/model/_instance_type.py +++ b/nfv/nfv-vim/nfv_vim/database/model/_instance_type.py @@ -12,6 +12,51 @@ from nfv_vim.database.model._base import AsDictMixin from nfv_vim.database.model._base import Base +class InstanceType_v5(AsDictMixin, Base): + """ + Instance Type Database Table + """ + __tablename__ = 'instance_types_v5' + + uuid = Column(String(64), nullable=False, primary_key=True) + name = Column(String(64), nullable=False) + have_details = Column(Boolean, nullable=False) + vcpus = Column(Integer, nullable=False) + mem_mb = Column(Integer, nullable=False) + disk_gb = Column(Integer, nullable=False) + ephemeral_gb = Column(Integer, nullable=False) + swap_gb = Column(Integer, nullable=False) + guest_services = Column(String(2048), nullable=False) + auto_recovery = Column(Boolean, nullable=True) + live_migration_timeout = Column(Integer, nullable=True) + live_migration_max_downtime = Column(Integer, nullable=True) + + def __init__(self): + """ + Default some of the settings of the flavor + """ + self.have_details = False + self.vcpus = 0 + self.mem_mb = 0 + self.disk_gb = 0 + self.ephemeral_gb = 0 + self.swap_gb = 0 + self.guest_services = "{}" + self.auto_recovery = None + self.live_migration_timeout = None + self.live_migration_max_downtime = None + + def __repr__(self): + if self.have_details: + return ("" + % (self.uuid, self.name, self.vcpus, self.mem_mb, + self.disk_gb, self.ephemeral_gb, self.swap_gb, + self.guest_services, self.auto_recovery, + self.live_migration_timeout, + self.live_migration_max_downtime)) + return "" % (self.uuid, self.name) + + class InstanceType(AsDictMixin, Base): """ Instance Type Database Table diff --git a/nfv/nfv-vim/nfv_vim/directors/_instance_director.py b/nfv/nfv-vim/nfv_vim/directors/_instance_director.py index b3caaa61..2dd05d85 100755 --- a/nfv/nfv-vim/nfv_vim/directors/_instance_director.py +++ b/nfv/nfv-vim/nfv_vim/directors/_instance_director.py @@ -1555,8 +1555,7 @@ class InstanceDirector(object): instance_type_attributes = \ nfvi.objects.v1.InstanceTypeAttributes( vcpus, mem_mb, disk_gb, ephemeral_gb, swap_gb, None, auto_recovery, - live_migration_timeout, live_migration_max_downtime, - nfvi.objects.v1.STORAGE_TYPE.LOCAL_IMAGE_BACKED) + live_migration_timeout, live_migration_max_downtime) nfvi.nfvi_create_instance_type(instance_type_uuid, instance_type_name, instance_type_attributes, instance_type_create_callback) diff --git a/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/__init__.py b/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/__init__.py index 9fa68225..dacc842c 100755 --- a/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/__init__.py +++ b/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/__init__.py @@ -47,7 +47,6 @@ from nfv_vim.nfvi.objects.v1._instance_group import InstanceGroup # noqa: F401 from nfv_vim.nfvi.objects.v1._instance_type import INSTANCE_TYPE_EXTENSION # noqa: F401 from nfv_vim.nfvi.objects.v1._instance_type import InstanceType # noqa: F401 from nfv_vim.nfvi.objects.v1._instance_type import InstanceTypeAttributes # noqa: F401 -from nfv_vim.nfvi.objects.v1._instance_type import STORAGE_TYPE # noqa: F401 from nfv_vim.nfvi.objects.v1._network import Network # noqa: F401 from nfv_vim.nfvi.objects.v1._network import NETWORK_ADMIN_STATE # noqa: F401 from nfv_vim.nfvi.objects.v1._network import NETWORK_AVAIL_STATUS # noqa: F401 diff --git a/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/_instance.py b/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/_instance.py index 21fb1d45..f39233d5 100755 --- a/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/_instance.py +++ b/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/_instance.py @@ -523,16 +523,3 @@ class Instance(ObjectData): INSTANCE_TYPE_EXTENSION.LIVE_MIGRATION_MAX_DOWNTIME, None) return live_migration_max_downtime - - @property - def instance_type_storage_type(self): - """ - Returns the storage type from the flavor extra specs - """ - storage_type = None - flavor_data_extra = self.get('instance_type').get('extra_specs', None) - if flavor_data_extra is not None: - storage_type = flavor_data_extra.get( - INSTANCE_TYPE_EXTENSION.STORAGE_TYPE, None) - - return storage_type diff --git a/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/_instance_type.py b/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/_instance_type.py index 51c0d39c..52b29393 100755 --- a/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/_instance_type.py +++ b/nfv/nfv-vim/nfv_vim/nfvi/objects/v1/_instance_type.py @@ -26,7 +26,6 @@ class InstanceTypeExtension(Constants): """ Instance Type Extension Constants """ - STORAGE_TYPE = Constant('aggregate_instance_extra_specs:storage') INSTANCE_AUTO_RECOVERY = Constant('sw:wrs:auto_recovery') LIVE_MIGRATION_TIMEOUT = Constant('hw:wrs:live_migration_timeout') LIVE_MIGRATION_MAX_DOWNTIME = Constant('hw:wrs:live_migration_max_downtime') @@ -34,7 +33,6 @@ class InstanceTypeExtension(Constants): # Instance Type Constant Instantiation -STORAGE_TYPE = InstanceTypeStorage() INSTANCE_TYPE_EXTENSION = InstanceTypeExtension() @@ -44,15 +42,14 @@ class InstanceTypeAttributes(ObjectData): """ def __init__(self, vcpus, mem_mb, disk_gb, ephemeral_gb, swap_gb, guest_services, auto_recovery, live_migration_timeout, - live_migration_max_downtime, storage_type): + live_migration_max_downtime): super(InstanceTypeAttributes, self).__init__('1.0.0') self.update(dict(vcpus=vcpus, mem_mb=mem_mb, disk_gb=disk_gb, ephemeral_gb=ephemeral_gb, swap_gb=swap_gb, guest_services=guest_services, auto_recovery=auto_recovery, live_migration_timeout=live_migration_timeout, - live_migration_max_downtime=live_migration_max_downtime, - storage_type=storage_type)) + live_migration_max_downtime=live_migration_max_downtime)) class InstanceType(ObjectData): @@ -65,14 +62,13 @@ class InstanceType(ObjectData): def update_details(self, vcpus, mem_mb, disk_gb, ephemeral_gb, swap_gb, guest_services, auto_recovery, live_migration_timeout, - live_migration_max_downtime, storage_type): + live_migration_max_downtime): self.update(dict(vcpus=vcpus, mem_mb=mem_mb, disk_gb=disk_gb, ephemeral_gb=ephemeral_gb, swap_gb=swap_gb, guest_services=guest_services, auto_recovery=auto_recovery, live_migration_timeout=live_migration_timeout, - live_migration_max_downtime=live_migration_max_downtime, - storage_type=storage_type)) + live_migration_max_downtime=live_migration_max_downtime)) def have_details(self): return self.get('vcpus', None) is not None diff --git a/nfv/nfv-vim/nfv_vim/objects/__init__.py b/nfv/nfv-vim/nfv_vim/objects/__init__.py index ccfb5353..5ed5c29d 100755 --- a/nfv/nfv-vim/nfv_vim/objects/__init__.py +++ b/nfv/nfv-vim/nfv_vim/objects/__init__.py @@ -25,7 +25,6 @@ from nfv_vim.objects._instance_group import InstanceGroup # noqa: F401 from nfv_vim.objects._instance_type import INSTANCE_TYPE_EXTENSION # noqa: F401 from nfv_vim.objects._instance_type import InstanceType # noqa: F401 from nfv_vim.objects._instance_type import InstanceTypeAttributes # noqa: F401 -from nfv_vim.objects._instance_type import STORAGE_TYPE # noqa: F401 from nfv_vim.objects._network import Network # noqa: F401 from nfv_vim.objects._network import NetworkProviderData # noqa: F401 from nfv_vim.objects._service_host import ServiceHost # noqa: F401 diff --git a/nfv/nfv-vim/nfv_vim/objects/_instance.py b/nfv/nfv-vim/nfv_vim/objects/_instance.py index 362fcd21..02e86327 100755 --- a/nfv/nfv-vim/nfv_vim/objects/_instance.py +++ b/nfv/nfv-vim/nfv_vim/objects/_instance.py @@ -26,7 +26,6 @@ from nfv_vim import instance_fsm from nfv_vim import nfvi from nfv_vim.objects._guest_services import GuestServices -from nfv_vim.objects._instance_type import STORAGE_TYPE DLOG = debug.debug_get_logger('nfv_vim.objects.instance') MAX_EVENT_REASON_LENGTH = 255 @@ -1465,18 +1464,13 @@ class Instance(ObjectData): # Always allow cold migration when booted from a volume return True - storage_type = self._nfvi_instance.instance_type_storage_type + # TODO(bwensley): Always allow cold migration for instances using + # remote storage. There is currently no way to determine this, but we + # should eventually be able to check for a label on the compute host. - if STORAGE_TYPE.REMOTE_BACKED == storage_type: - # Always allow cold migration with remote storage - return True + config_option = 'max_cold_migrate_local_image_disk_gb' - config_option = None - if STORAGE_TYPE.LOCAL_IMAGE_BACKED == storage_type: - config_option = 'max_cold_migrate_local_image_disk_gb' - - if (config_option is not None and - config.section_exists('instance-configuration')): + if config.section_exists('instance-configuration'): section = config.CONF['instance-configuration'] max_disk_gb = int(section.get(config_option, 20)) else: @@ -1501,18 +1495,13 @@ class Instance(ObjectData): # Always allow evacuate when booted from a volume return True - storage_type = self._nfvi_instance.instance_type_storage_type + # TODO(bwensley): Always allow evacuate for instances using remote + # storage. There is currently no way to determine this, but we should + # eventually be able to check for a label on the compute host. - if STORAGE_TYPE.REMOTE_BACKED == storage_type: - # Always allow evacuate with remote storage - return True + config_option = 'max_evacuate_local_image_disk_gb' - config_option = None - if STORAGE_TYPE.LOCAL_IMAGE_BACKED == storage_type: - config_option = 'max_evacuate_local_image_disk_gb' - - if (config_option is not None and - config.section_exists('instance-configuration')): + if config.section_exists('instance-configuration'): section = config.CONF['instance-configuration'] max_disk_gb = int(section.get(config_option, 20)) else: @@ -1533,17 +1522,6 @@ class Instance(ObjectData): if not self._live_migration_support: return False - if self.image_uuid is None: - if (self._nfvi_instance.instance_type_swap_gb or - self._nfvi_instance.instance_type_ephemeral_gb): - return (STORAGE_TYPE.REMOTE_BACKED == - self._nfvi_instance.instance_type_storage_type) - return True - else: - return (self._nfvi_instance.instance_type_storage_type in [ - STORAGE_TYPE.LOCAL_IMAGE_BACKED, - STORAGE_TYPE.REMOTE_BACKED]) - return True def is_locked(self): diff --git a/nfv/nfv-vim/nfv_vim/objects/_instance_type.py b/nfv/nfv-vim/nfv_vim/objects/_instance_type.py index c3aba029..066432e1 100755 --- a/nfv/nfv-vim/nfv_vim/objects/_instance_type.py +++ b/nfv/nfv-vim/nfv_vim/objects/_instance_type.py @@ -29,7 +29,6 @@ class InstanceTypeExtension(Constants): """ Instance Type Extension Constants """ - STORAGE_TYPE = Constant('aggregate_instance_extra_specs:storage') INSTANCE_AUTO_RECOVERY = Constant('sw:wrs:auto_recovery') LIVE_MIGRATION_TIMEOUT = Constant('hw:wrs:live_migration_timeout') LIVE_MIGRATION_MAX_DOWNTIME = Constant('hw:wrs:live_migration_max_downtime') @@ -37,7 +36,6 @@ class InstanceTypeExtension(Constants): # Instance Type Constant Instantiation -STORAGE_TYPE = InstanceTypeStorage() INSTANCE_TYPE_EXTENSION = InstanceTypeExtension() @@ -47,15 +45,14 @@ class InstanceTypeAttributes(ObjectData): """ def __init__(self, vcpus, mem_mb, disk_gb, ephemeral_gb, swap_gb, guest_services, auto_recovery, live_migration_timeout, - live_migration_max_downtime, storage_type): + live_migration_max_downtime): super(InstanceTypeAttributes, self).__init__('1.0.0') self.update(dict(vcpus=vcpus, mem_mb=mem_mb, disk_gb=disk_gb, ephemeral_gb=ephemeral_gb, swap_gb=swap_gb, guest_services=guest_services, auto_recovery=auto_recovery, live_migration_timeout=live_migration_timeout, - live_migration_max_downtime=live_migration_max_downtime, - storage_type=storage_type)) + live_migration_max_downtime=live_migration_max_downtime)) class InstanceType(ObjectData): @@ -68,14 +65,13 @@ class InstanceType(ObjectData): def update_details(self, vcpus, mem_mb, disk_gb, ephemeral_gb, swap_gb, guest_services, auto_recovery, live_migration_timeout, - live_migration_max_downtime, storage_type): + live_migration_max_downtime): self.update(dict(vcpus=vcpus, mem_mb=mem_mb, disk_gb=disk_gb, ephemeral_gb=ephemeral_gb, swap_gb=swap_gb, guest_services=guest_services, auto_recovery=auto_recovery, live_migration_timeout=live_migration_timeout, - live_migration_max_downtime=live_migration_max_downtime, - storage_type=storage_type)) + live_migration_max_downtime=live_migration_max_downtime)) def have_details(self): return self.get('vcpus', None) is not None diff --git a/nfv/nfv-vim/nfv_vim/webserver/templates/instance_types.handlebars b/nfv/nfv-vim/nfv_vim/webserver/templates/instance_types.handlebars index fb4b95ae..b106d515 100755 --- a/nfv/nfv-vim/nfv_vim/webserver/templates/instance_types.handlebars +++ b/nfv/nfv-vim/nfv_vim/webserver/templates/instance_types.handlebars @@ -19,7 +19,6 @@ Disk Ephemeral Swap - Storage-Type @@ -32,7 +31,6 @@ {{disk_gb}}GB {{ephemeral_gb}}GB {{swap_gb}}GB - {{storage_type}} {{/instance_types}} From 90100b72eefa1faec75fd31b8dd8eef461cbceeb Mon Sep 17 00:00:00 2001 From: SidneyAn Date: Tue, 18 Dec 2018 10:05:38 +0800 Subject: [PATCH 2/2] Fix import(s) related issues for Python 2/3 compatible code. fix http/socketserver module import issues e.g. before: import SocketServer import httplib import BaseHTTPServer after: from six.moves import socketserver from six.moves import http_client as httplib from six.moves import BaseHTTPServer Story: 2003427 Task: 24609 Change-Id: I82132ab91f56a9038afdd931624559d8c370e231 Signed-off-by: SidneyAn --- .../nfv_plugins/nfvi_plugins/openstack/rest_api.py | 6 +++--- nfv/nfv-vim/nfv_vim/webserver/_webserver.py | 14 ++++++-------- nfv/pylint.rc | 14 ++++++++++++-- nfv/tox.ini | 1 - .../nova-api-proxy/nova_api_proxy/apps/proxy.py | 2 +- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/rest_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/rest_api.py index 611553d7..64551b45 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/rest_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/rest_api.py @@ -5,14 +5,14 @@ # import json import re +from six.moves import BaseHTTPServer from six.moves import http_client as httplib +from six.moves import socketserver as SocketServer from six.moves import urllib + import socket import struct -import BaseHTTPServer -import SocketServer - from nfv_common import debug from nfv_common import selobj from nfv_common import timers diff --git a/nfv/nfv-vim/nfv_vim/webserver/_webserver.py b/nfv/nfv-vim/nfv_vim/webserver/_webserver.py index 44133cd8..01964756 100755 --- a/nfv/nfv-vim/nfv_vim/webserver/_webserver.py +++ b/nfv/nfv-vim/nfv_vim/webserver/_webserver.py @@ -6,14 +6,12 @@ import datetime import json import re +from six.moves import BaseHTTPServer from six.moves import http_client as httplib +from six.moves import socketserver import socket import threading -from BaseHTTPServer import BaseHTTPRequestHandler -from BaseHTTPServer import HTTPServer -from SocketServer import ThreadingMixIn - from nfv_common import debug from nfv_plugins.nfvi_plugins import config from nfv_plugins.nfvi_plugins.openstack import fm @@ -38,10 +36,10 @@ def _bare_address_string(self): return "%s" % host -BaseHTTPRequestHandler.address_string = _bare_address_string +BaseHTTPServer.BaseHTTPRequestHandler.address_string = _bare_address_string -class HTTPRequestHandler(BaseHTTPRequestHandler): +class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """ HTTP Request Handler """ @@ -569,7 +567,7 @@ class HTTPRequestHandler(BaseHTTPRequestHandler): self.wfile.write(f.read()) -class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): +class ThreadedHTTPServer(socketserver.ThreadingMixIn, BaseHTTPServer.HTTPServer): """ Threaded HTTP Server """ @@ -577,7 +575,7 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): def shutdown(self): self.socket.close() - HTTPServer.shutdown(self) + BaseHTTPServer.HTTPServer.shutdown(self) class SimpleHttpServer(object): diff --git a/nfv/pylint.rc b/nfv/pylint.rc index d07e8d54..881e9ce3 100755 --- a/nfv/pylint.rc +++ b/nfv/pylint.rc @@ -26,6 +26,7 @@ load-plugins= # can either give multiple identifier separated by comma (,) or put this option # multiple time (only on the command line, not in the configuration file where # it should appear only once). +# W0107: Unnecessary pass statement (unnecessary-pass) # W0120 useless-else-on-loop # W0125 using-constant-test # W0212 protected-access var starting with _ used outside class or descendant @@ -42,9 +43,12 @@ load-plugins= # W0621 redefined-outer-name # W0622 redefined-builtin # W0703 broad except warning +# W0706: The except handler raises immediately (try-except-raise) # W1401 anomalous-backslash-in-string +# W1505: Using deprecated method getargspec() (deprecated-method) disable=C, R, W0120, W0125, W0212, W0221, W0223, W0231, W0235, - W0401, W0404, W0511, W0603, W0612, W0613, W0621, W0622, W0703, W1401 + W0401, W0404, W0511, W0603, W0612, W0613, W0621, W0622, W0703, W1401, + W0107, W0706, W1505 [REPORTS] @@ -98,7 +102,13 @@ ignore-mixin-members=yes # List of classes names for which member attributes should not be checked # (useful for classes with attributes dynamically set). # The following VIM objects are ignored: ObjectData, GuestService, Network, SwUpdate -ignored-classes=SQLObject,sqlalchemy,scoped_session,_socketobject,ObjectData,GuestService,Network,SwUpdate +# The following Openstack plugin object is ignored: OpenStackRestAPIException +ignored-classes=SQLObject,sqlalchemy,scoped_session,_socketobject,ObjectData,GuestService, + Network,SwUpdate,OpenStackRestAPIException + +# For compatibility of python2 and python 3, we import six.moves module, and +# the following py3 modules are ignored: http.client, urllib.request +ignored-modules=http.client,urllib.request # List of members which are set dynamically and missed by pylint inference # system, and so shouldn't trigger E0201 when accessed. Python regular diff --git a/nfv/tox.ini b/nfv/tox.ini index 07f9aa7c..0d76b63c 100755 --- a/nfv/tox.ini +++ b/nfv/tox.ini @@ -97,7 +97,6 @@ deps = {[nfv]deps} mock testtools pylint -basepython = python2.7 commands = pylint {[nfv]nfv_client_src_dir} \ {[nfv]nfv_common_src_dir} \ {[nfv]nfv_plugins_src_dir} \ diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py index 80e8b97b..3793bff7 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py @@ -12,9 +12,9 @@ # SPDX-License-Identifier: Apache-2.0 # -import httplib from paste.proxy import parse_headers from paste.proxy import TransparentProxy +from six.moves import http_client as httplib import urllib from oslo_log import log as logging