Cleanup utilsfactory map
This change cleans up the utilsfactory map, making it easier to add new classes. Most classes have 6.2 as a minimum version, without having a maximum version cap. For this reason, this change sets those versions as defaults so that we don't have to be explicit every time. At the same time, we're now using a list for each class type, instead of a dict that uses the class name as a key (which is redundant). So, something like this: 'networkutils': { 'NetworkUtils': { 'min_version': 6.2, 'max_version': 6.3, 'path': 'os_win.utils.network.networkutils.NetworkUtils'}, 'NetworkUtilsR2': { 'min_version': 6.3, 'max_version': None, 'path': 'os_win.utils.network.networkutils.NetworkUtilsR2'}}, ... becomes 'networkutils': [ {'max_version': 6.3, 'path': 'os_win.utils.network.networkutils.NetworkUtils'}, {'min_version': 6.3, 'path': 'os_win.utils.network.networkutils.NetworkUtilsR2'}, ], Change-Id: I7919617166b2e872f1b50c0a0f40196fc90e9a82
This commit is contained in:
parent
d139d77167
commit
0857a0eb81
@ -154,14 +154,13 @@ class TestHyperVUtilsFactory(test_base.OsWinBaseTestCase):
|
|||||||
def test_utils_public_signatures(self):
|
def test_utils_public_signatures(self):
|
||||||
for module_name in utilsfactory.utils_map.keys():
|
for module_name in utilsfactory.utils_map.keys():
|
||||||
classes = utilsfactory.utils_map[module_name]
|
classes = utilsfactory.utils_map[module_name]
|
||||||
class_names = list(classes.keys())
|
if len(classes) < 2:
|
||||||
if len(class_names) < 2:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
base_class_dict = classes[class_names[0]]
|
base_class_dict = classes[0]
|
||||||
base_class = importutils.import_object(base_class_dict['path'])
|
base_class = importutils.import_object(base_class_dict['path'])
|
||||||
for i in range(1, len(class_names)):
|
for i in range(1, len(classes)):
|
||||||
tested_class_dict = classes[class_names[i]]
|
tested_class_dict = classes[i]
|
||||||
tested_class = importutils.import_object(
|
tested_class = importutils.import_object(
|
||||||
tested_class_dict['path'])
|
tested_class_dict['path'])
|
||||||
self.assertPublicAPISignatures(base_class, tested_class)
|
self.assertPublicAPISignatures(base_class, tested_class)
|
||||||
|
@ -22,125 +22,80 @@ from os_win.utils.io import namedpipe
|
|||||||
|
|
||||||
utils = hostutils.HostUtils()
|
utils = hostutils.HostUtils()
|
||||||
|
|
||||||
|
DEFAULT_MIN_VERSION = 6.2
|
||||||
|
DEFAULT_MAX_VERSION = None
|
||||||
|
|
||||||
|
|
||||||
utils_map = {
|
utils_map = {
|
||||||
'diskutils': {
|
'diskutils': [
|
||||||
'DiskUtils': {
|
{'path': 'os_win.utils.storage.diskutils.DiskUtils'}
|
||||||
'min_version': 6.2,
|
],
|
||||||
'max_version': None,
|
'hostutils': [
|
||||||
'path': 'os_win.utils.storage.diskutils.DiskUtils'}},
|
{'max_version': 10,
|
||||||
'hostutils': {
|
'path': 'os_win.utils.hostutils.HostUtils'},
|
||||||
'HostUtils': {
|
{'min_version': 10,
|
||||||
'min_version': 6.2,
|
'path': 'os_win.utils.hostutils10.HostUtils10'},
|
||||||
'max_version': 10,
|
],
|
||||||
'path': 'os_win.utils.hostutils.HostUtils'},
|
'iscsi_initiator_utils': [
|
||||||
'HostUtils10': {
|
{'path': 'os_win.utils.storage.initiator.iscsi_utils.'
|
||||||
'min_version': 10,
|
'ISCSIInitiatorUtils'},
|
||||||
'max_version': None,
|
],
|
||||||
'path': 'os_win.utils.hostutils10.HostUtils10'}},
|
'iscsi_target_utils': [
|
||||||
'iscsi_initiator_utils': {
|
{'path': 'os_win.utils.storage.target.iscsi_target_utils.'
|
||||||
'ISCSIInitiatorUtils': {
|
'ISCSITargetUtils'}],
|
||||||
'min_version': 6.2,
|
'fc_utils': [
|
||||||
'max_version': None,
|
{'path': 'os_win.utils.storage.initiator.fc_utils.FCUtils'},
|
||||||
'path': 'os_win.utils.storage.initiator.iscsi_utils.'
|
],
|
||||||
'ISCSIInitiatorUtils'}},
|
'livemigrationutils': [
|
||||||
'iscsi_target_utils': {
|
{'path': 'os_win.utils.compute.livemigrationutils.LiveMigrationUtils'}
|
||||||
'ISCSITargetUtils': {
|
],
|
||||||
'min_version': 6.2,
|
'metricsutils': [
|
||||||
'max_version': None,
|
{'path': 'os_win.utils.metrics.metricsutils.MetricsUtils'},
|
||||||
'path': 'os_win.utils.storage.target.iscsi_target_utils.'
|
],
|
||||||
'ISCSITargetUtils'}},
|
'migrationutils': [
|
||||||
'fc_utils': {
|
{'path': 'os_win.utils.compute.migrationutils.MigrationUtils'},
|
||||||
'FCUtils': {
|
],
|
||||||
'min_version': 6.2,
|
'networkutils': [
|
||||||
'max_version': None,
|
{'max_version': 6.3,
|
||||||
'path': 'os_win.utils.storage.initiator.fc_utils.'
|
'path': 'os_win.utils.network.networkutils.NetworkUtils'},
|
||||||
'FCUtils'}},
|
{'min_version': 6.3,
|
||||||
'livemigrationutils': {
|
'path': 'os_win.utils.network.networkutils.NetworkUtilsR2'},
|
||||||
'LiveMigrationUtils': {
|
],
|
||||||
'min_version': 6.2,
|
'nvgreutils': [
|
||||||
'max_version': None,
|
{'path': 'os_win.utils.network.nvgreutils.NvgreUtils'},
|
||||||
'path': 'os_win.utils.compute.livemigrationutils.'
|
],
|
||||||
'LiveMigrationUtils'}},
|
'pathutils': [
|
||||||
'metricsutils': {
|
{'path': 'os_win.utils.pathutils.PathUtils'},
|
||||||
'MetricsUtils': {
|
],
|
||||||
'min_version': 6.2,
|
'rdpconsoleutils': [
|
||||||
'max_version': None,
|
{'path': 'os_win.utils.compute.rdpconsoleutils.RDPConsoleUtils'},
|
||||||
'path': 'os_win.utils.metrics.metricsutils.MetricsUtils'}},
|
],
|
||||||
'migrationutils': {
|
'smbutils': [
|
||||||
'MigrationUtils': {
|
{'path': 'os_win.utils.storage.smbutils.SMBUtils'},
|
||||||
'min_version': 6.2,
|
],
|
||||||
'max_version': None,
|
'vhdutils': [
|
||||||
'path': 'os_win.utils.compute.migrationutils.MigrationUtils'}},
|
{'path': 'os_win.utils.storage.virtdisk.vhdutils.VHDUtils'},
|
||||||
'networkutils': {
|
],
|
||||||
'NetworkUtils': {
|
'vmutils': [
|
||||||
'min_version': 6.2,
|
{'max_version': 6.3,
|
||||||
'max_version': 6.3,
|
'path': 'os_win.utils.compute.vmutils.VMUtils'},
|
||||||
'path': 'os_win.utils.network.networkutils.NetworkUtils'},
|
{'min_version': 6.3,
|
||||||
'NetworkUtilsR2': {
|
'max_version': 10,
|
||||||
'min_version': 6.3,
|
'path': 'os_win.utils.compute.vmutils.VMUtils6_3'},
|
||||||
'max_version': None,
|
{'min_version': 10,
|
||||||
'path': 'os_win.utils.network.networkutils.NetworkUtilsR2'}},
|
'path': 'os_win.utils.compute.vmutils10.VMUtils10'}],
|
||||||
'nvgreutils': {
|
'clusterutils': [
|
||||||
'NvgreUtils': {
|
{'path': 'os_win.utils.compute.clusterutils.ClusterUtils'},
|
||||||
'min_version': 6.2,
|
],
|
||||||
'max_version': None,
|
'dnsutils': [
|
||||||
'path': 'os_win.utils.network.nvgreutils.NvgreUtils'}},
|
{'path': 'os_win.utils.dns.dnsutils.DNSUtils'},
|
||||||
'pathutils': {
|
],
|
||||||
'PathUtils': {
|
'processutils': [
|
||||||
'min_version': 6.2,
|
{'path': 'os_win.utils.processutils.ProcessUtils'},
|
||||||
'max_version': None,
|
],
|
||||||
'path': 'os_win.utils.pathutils.PathUtils'}},
|
'ioutils': [
|
||||||
'rdpconsoleutils': {
|
{'path': 'os_win.utils.io.ioutils.IOUtils'},
|
||||||
'RDPConsoleUtils': {
|
],
|
||||||
'min_version': 6.2,
|
|
||||||
'max_version': None,
|
|
||||||
'path': 'os_win.utils.compute.rdpconsoleutils.RDPConsoleUtils'}},
|
|
||||||
'smbutils': {
|
|
||||||
'SMBUtils': {
|
|
||||||
'min_version': 6.2,
|
|
||||||
'max_version': None,
|
|
||||||
'path': 'os_win.utils.storage.smbutils.SMBUtils'}},
|
|
||||||
'vhdutils': {
|
|
||||||
'VHDUtils': {
|
|
||||||
'min_version': 6.2,
|
|
||||||
'max_version': None,
|
|
||||||
'path': 'os_win.utils.storage.virtdisk.vhdutils.VHDUtils'}},
|
|
||||||
'vmutils': {
|
|
||||||
'VMUtils': {
|
|
||||||
'min_version': 6.2,
|
|
||||||
'max_version': 6.3,
|
|
||||||
'path': 'os_win.utils.compute.vmutils.VMUtils'},
|
|
||||||
'VMUtils6_3': {
|
|
||||||
'min_version': 6.3,
|
|
||||||
'max_version': 10,
|
|
||||||
'path': 'os_win.utils.compute.vmutils.VMUtils6_3'},
|
|
||||||
'VMUtils10': {
|
|
||||||
'min_version': 10,
|
|
||||||
'max_version': None,
|
|
||||||
'path': 'os_win.utils.compute.vmutils10.VMUtils10'}},
|
|
||||||
'clusterutils': {
|
|
||||||
'ClusterUtils': {
|
|
||||||
'min_version': 6.2,
|
|
||||||
'max_version': None,
|
|
||||||
'path': 'os_win.utils.compute.clusterutils.ClusterUtils'}},
|
|
||||||
'dnsutils': {
|
|
||||||
'DNSUtils': {
|
|
||||||
'min_version': 6.2,
|
|
||||||
'max_version': None,
|
|
||||||
'path': 'os_win.utils.dns.dnsutils.DNSUtils'}},
|
|
||||||
'processutils': {
|
|
||||||
'ProcessUtils': {
|
|
||||||
'min_version': 6.2,
|
|
||||||
'max_version': None,
|
|
||||||
'path': 'os_win.utils.processutils.ProcessUtils'},
|
|
||||||
},
|
|
||||||
'ioutils': {
|
|
||||||
'IOUtils': {
|
|
||||||
'min_version': 6.2,
|
|
||||||
'max_version': None,
|
|
||||||
'path': 'os_win.utils.io.ioutils.IOUtils'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -153,14 +108,14 @@ def _get_class(class_type, *args, **kwargs):
|
|||||||
build = list(map(int, windows_version.split('.')))
|
build = list(map(int, windows_version.split('.')))
|
||||||
windows_version = float("%i.%i" % (build[0], build[1]))
|
windows_version = float("%i.%i" % (build[0], build[1]))
|
||||||
|
|
||||||
existing_classes = utils_map.get(class_type)
|
existing_classes = utils_map.get(class_type, [])
|
||||||
for class_variant in existing_classes.keys():
|
for class_variant in existing_classes:
|
||||||
utils_class = existing_classes.get(class_variant)
|
min_version = class_variant.get('min_version', DEFAULT_MIN_VERSION)
|
||||||
if (utils_class['min_version'] <= windows_version and
|
max_version = class_variant.get('max_version', DEFAULT_MAX_VERSION)
|
||||||
(utils_class['max_version'] is None or
|
class_path = class_variant['path']
|
||||||
windows_version < utils_class['max_version'])):
|
if (min_version <= windows_version and
|
||||||
return importutils.import_object(utils_class['path'],
|
(max_version is None or windows_version < max_version)):
|
||||||
*args, **kwargs)
|
return importutils.import_object(class_path, *args, **kwargs)
|
||||||
|
|
||||||
raise exceptions.HyperVException(_('Could not find any %(class)s class for'
|
raise exceptions.HyperVException(_('Could not find any %(class)s class for'
|
||||||
'this Windows version: %(win_version)s')
|
'this Windows version: %(win_version)s')
|
||||||
|
Loading…
Reference in New Issue
Block a user