refactored get_config_types to get_all_configs and NewConfigurableManager back to ConfigurableManager
This commit is contained in:
		
							parent
							
								
									f6656f0245
								
							
						
					
					
						commit
						52bfd1edf4
					
				
					 5 changed files with 34 additions and 26 deletions
				
			
		|  | @ -129,7 +129,7 @@ class ConfigurableOptions(object): | |||
|         return OrderedDict([(config.id, config.default) for config in cls.configurations()]) | ||||
| 
 | ||||
| 
 | ||||
| class NewConfigurableManager(object): | ||||
| class ConfigurableManager(object): | ||||
|     _default_node = -1 | ||||
|     _default_type = "default" | ||||
| 
 | ||||
|  | @ -153,7 +153,7 @@ class NewConfigurableManager(object): | |||
| 
 | ||||
|     def set_configs(self, config, node_id=_default_node, config_type=_default_type): | ||||
|         logger.debug("setting config for node(%s) type(%s): %s", node_id, config_type, config) | ||||
|         node_configs = self.get_config_types(node_id) | ||||
|         node_configs = self.get_all_configs(node_id) | ||||
|         node_configs[config_type] = config | ||||
| 
 | ||||
|     def get_config(self, _id, node_id=_default_node, config_type=_default_type): | ||||
|  | @ -163,9 +163,9 @@ class NewConfigurableManager(object): | |||
| 
 | ||||
|     def get_configs(self, node_id=_default_node, config_type=_default_type): | ||||
|         logger.debug("getting configs for node(%s) type(%s)", node_id, config_type) | ||||
|         node_map = self.get_config_types(node_id) | ||||
|         node_map = self.get_all_configs(node_id) | ||||
|         return node_map.setdefault(config_type, {}) | ||||
| 
 | ||||
|     def get_config_types(self, node_id=_default_node): | ||||
|     def get_all_configs(self, node_id=_default_node): | ||||
|         logger.debug("getting all configs for node(%s)", node_id) | ||||
|         return self._configuration_maps.setdefault(node_id, {}) | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ from core.api import coreapi | |||
| from core.api import dataconversion | ||||
| from core.conf import ConfigShim | ||||
| from core.conf import Configuration | ||||
| from core.conf import NewConfigurableManager | ||||
| from core.conf import ConfigurableManager | ||||
| from core.emane import emanemanifest | ||||
| from core.emane.bypass import EmaneBypassModel | ||||
| from core.emane.commeffect import EmaneCommEffectModel | ||||
|  | @ -54,7 +54,7 @@ EMANE_MODELS = [ | |||
| ] | ||||
| 
 | ||||
| 
 | ||||
| class EmaneManager(NewConfigurableManager): | ||||
| class EmaneManager(ConfigurableManager): | ||||
|     """ | ||||
|     EMANE controller object. Lives in a Session instance and is used for | ||||
|     building EMANE config files from all of the EmaneNode objects in this | ||||
|  | @ -208,7 +208,7 @@ class EmaneManager(NewConfigurableManager): | |||
|         """ | ||||
|         Used with XML export. | ||||
|         """ | ||||
|         configs = self.get_config_types(node.objid) | ||||
|         configs = self.get_all_configs(node.objid) | ||||
|         models = [] | ||||
|         for model_name, config in configs.iteritems(): | ||||
|             model_class = self._modelclsmap[model_name] | ||||
|  | @ -572,7 +572,7 @@ class EmaneManager(NewConfigurableManager): | |||
| 
 | ||||
|     def setnodemodel(self, node_id): | ||||
|         logger.debug("setting emane models for node: %s", node_id) | ||||
|         node_config_types = self.get_config_types(node_id) | ||||
|         node_config_types = self.get_all_configs(node_id) | ||||
|         if not node_config_types: | ||||
|             logger.debug("no emane node model configuration, leaving: %s", node_id) | ||||
|             return False | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ import time | |||
| from core import logger | ||||
| from core.conf import ConfigurableOptions | ||||
| from core.conf import Configuration | ||||
| from core.conf import NewConfigurableManager | ||||
| from core.conf import ConfigurableManager | ||||
| from core.coreobj import PyCoreNode | ||||
| from core.data import EventData | ||||
| from core.data import LinkData | ||||
|  | @ -26,7 +26,7 @@ from core.misc import utils | |||
| from core.misc.ipaddress import IpAddress | ||||
| 
 | ||||
| 
 | ||||
| class MobilityManager(NewConfigurableManager): | ||||
| class MobilityManager(ConfigurableManager): | ||||
|     """ | ||||
|     Member of session class for handling configuration data for mobility and | ||||
|     range models. | ||||
|  | @ -69,7 +69,7 @@ class MobilityManager(NewConfigurableManager): | |||
|         :return: list of model and values tuples for the network node | ||||
|         :rtype: list | ||||
|         """ | ||||
|         configs = self.get_config_types(node.objid) | ||||
|         configs = self.get_all_configs(node.objid) | ||||
|         models = [] | ||||
|         for model_name, config in configs.iteritems(): | ||||
|             model_class = self._modelclsmap[model_name] | ||||
|  | @ -96,7 +96,7 @@ class MobilityManager(NewConfigurableManager): | |||
|                 logger.warn("skipping mobility configuration for unknown node: %s", node_id) | ||||
|                 continue | ||||
| 
 | ||||
|             node_configs = self.get_config_types(node_id) | ||||
|             node_configs = self.get_all_configs(node_id) | ||||
|             if not node_configs: | ||||
|                 logger.warn("missing mobility configuration for node: %s", node_id) | ||||
|                 continue | ||||
|  |  | |||
|  | @ -22,7 +22,7 @@ from core.broker import CoreBroker | |||
| from core.conf import ConfigShim | ||||
| from core.conf import ConfigurableOptions | ||||
| from core.conf import Configuration | ||||
| from core.conf import NewConfigurableManager | ||||
| from core.conf import ConfigurableManager | ||||
| from core.data import ConfigData | ||||
| from core.data import EventData | ||||
| from core.data import ExceptionData | ||||
|  | @ -1221,7 +1221,7 @@ class Session(object): | |||
|         logger.info("informed GUI about %d nodes and %d links", len(nodes_data), len(links_data)) | ||||
| 
 | ||||
| 
 | ||||
| class SessionConfig(NewConfigurableManager, ConfigurableOptions): | ||||
| class SessionConfig(ConfigurableManager, ConfigurableOptions): | ||||
|     """ | ||||
|     Session configuration object. | ||||
|     """ | ||||
|  | @ -1256,7 +1256,7 @@ class SessionConfig(NewConfigurableManager, ConfigurableOptions): | |||
|         self.set_configs(config) | ||||
| 
 | ||||
| 
 | ||||
| class SessionMetaData(NewConfigurableManager): | ||||
| class SessionMetaData(ConfigurableManager): | ||||
|     """ | ||||
|     Metadata is simply stored in a configs[] dict. Key=value pairs are | ||||
|     passed in from configure messages destined to the "metadata" object. | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| from core.conf import NewConfigurableManager, ConfigurableOptions, Configuration | ||||
| from core.conf import ConfigurableManager, ConfigurableOptions, Configuration | ||||
| from core.enumerations import ConfigDataTypes | ||||
| 
 | ||||
| 
 | ||||
|  | @ -9,8 +9,16 @@ class TestConfigurableOptions(ConfigurableOptions): | |||
|     @classmethod | ||||
|     def configurations(cls): | ||||
|         return [ | ||||
|             Configuration(_id=TestConfigurableOptions.name_one, _type=ConfigDataTypes.STRING, label="value1"), | ||||
|             Configuration(_id=TestConfigurableOptions.name_two, _type=ConfigDataTypes.STRING, label="value2") | ||||
|             Configuration( | ||||
|                 _id=TestConfigurableOptions.name_one, | ||||
|                 _type=ConfigDataTypes.STRING, | ||||
|                 label=TestConfigurableOptions.name_one | ||||
|             ), | ||||
|             Configuration( | ||||
|                 _id=TestConfigurableOptions.name_two, | ||||
|                 _type=ConfigDataTypes.STRING, | ||||
|                 label=TestConfigurableOptions.name_two | ||||
|             ) | ||||
|         ] | ||||
| 
 | ||||
| 
 | ||||
|  | @ -33,7 +41,7 @@ class TestConf: | |||
| 
 | ||||
|     def test_nodes(self): | ||||
|         # given | ||||
|         config_manager = NewConfigurableManager() | ||||
|         config_manager = ConfigurableManager() | ||||
|         test_config = {1: 2} | ||||
|         node_id = 1 | ||||
|         config_manager.set_configs(test_config) | ||||
|  | @ -48,7 +56,7 @@ class TestConf: | |||
| 
 | ||||
|     def test_config_reset_all(self): | ||||
|         # given | ||||
|         config_manager = NewConfigurableManager() | ||||
|         config_manager = ConfigurableManager() | ||||
|         test_config = {1: 2} | ||||
|         node_id = 1 | ||||
|         config_manager.set_configs(test_config) | ||||
|  | @ -62,7 +70,7 @@ class TestConf: | |||
| 
 | ||||
|     def test_config_reset_node(self): | ||||
|         # given | ||||
|         config_manager = NewConfigurableManager() | ||||
|         config_manager = ConfigurableManager() | ||||
|         test_config = {1: 2} | ||||
|         node_id = 1 | ||||
|         config_manager.set_configs(test_config) | ||||
|  | @ -76,7 +84,7 @@ class TestConf: | |||
| 
 | ||||
|     def test_configs_setget(self): | ||||
|         # given | ||||
|         config_manager = NewConfigurableManager() | ||||
|         config_manager = ConfigurableManager() | ||||
|         test_config = {1: 2} | ||||
|         node_id = 1 | ||||
|         config_manager.set_configs(test_config) | ||||
|  | @ -92,7 +100,7 @@ class TestConf: | |||
| 
 | ||||
|     def test_config_setget(self): | ||||
|         # given | ||||
|         config_manager = NewConfigurableManager() | ||||
|         config_manager = ConfigurableManager() | ||||
|         name = "test" | ||||
|         value = "1" | ||||
|         node_id = 1 | ||||
|  | @ -109,7 +117,7 @@ class TestConf: | |||
| 
 | ||||
|     def test_all_configs(self): | ||||
|         # given | ||||
|         config_manager = NewConfigurableManager() | ||||
|         config_manager = ConfigurableManager() | ||||
|         name = "test" | ||||
|         value_one = "1" | ||||
|         value_two = "2" | ||||
|  | @ -126,8 +134,8 @@ class TestConf: | |||
|         defaults_value_two = config_manager.get_config(name, config_type=config_two) | ||||
|         node_value_one = config_manager.get_config(name, node_id=node_id, config_type=config_one) | ||||
|         node_value_two = config_manager.get_config(name, node_id=node_id, config_type=config_two) | ||||
|         default_all_configs = config_manager.get_config_types() | ||||
|         node_all_configs = config_manager.get_config_types(node_id=node_id) | ||||
|         default_all_configs = config_manager.get_all_configs() | ||||
|         node_all_configs = config_manager.get_all_configs(node_id=node_id) | ||||
| 
 | ||||
|         # then | ||||
|         assert defaults_value_one == value_one | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue