refactored configuration managers and options into a single class, now the models that can be configured will deal with and handle configurations for nodes themselves
This commit is contained in:
parent
1b843e2868
commit
52230bc026
22 changed files with 284 additions and 422 deletions
|
@ -214,6 +214,12 @@ def session():
|
|||
# return created session
|
||||
yield session_fixture
|
||||
|
||||
# clear session configurations
|
||||
session_fixture.location.reset()
|
||||
session_fixture.services.reset()
|
||||
session_fixture.mobility.config_reset()
|
||||
session_fixture.emane.config_reset()
|
||||
|
||||
# shutdown coreemu
|
||||
coreemu.shutdown()
|
||||
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
from random import shuffle
|
||||
|
||||
import pytest
|
||||
|
||||
from core.conf import ConfigurableManager
|
||||
from core.conf import ConfigurableOptions
|
||||
from core.conf import Configuration
|
||||
from core.enumerations import ConfigDataTypes
|
||||
|
@ -11,6 +6,7 @@ from core.enumerations import ConfigDataTypes
|
|||
class TestConfigurableOptions(ConfigurableOptions):
|
||||
name_one = "value1"
|
||||
name_two = "value2"
|
||||
configuration_maps = {}
|
||||
|
||||
@classmethod
|
||||
def configurations(cls):
|
||||
|
@ -47,7 +43,7 @@ class TestConf:
|
|||
|
||||
def test_nodes(self):
|
||||
# given
|
||||
config_manager = ConfigurableManager()
|
||||
config_manager = TestConfigurableOptions()
|
||||
test_config = {1: 2}
|
||||
node_id = 1
|
||||
config_manager.set_configs(test_config)
|
||||
|
@ -58,11 +54,11 @@ class TestConf:
|
|||
|
||||
# then
|
||||
assert len(nodes) == 1
|
||||
assert nodes[0] == node_id
|
||||
assert node_id in nodes
|
||||
|
||||
def test_config_reset_all(self):
|
||||
# given
|
||||
config_manager = ConfigurableManager()
|
||||
config_manager = TestConfigurableOptions()
|
||||
test_config = {1: 2}
|
||||
node_id = 1
|
||||
config_manager.set_configs(test_config)
|
||||
|
@ -72,11 +68,11 @@ class TestConf:
|
|||
config_manager.config_reset()
|
||||
|
||||
# then
|
||||
assert not config_manager._configuration_maps
|
||||
assert not config_manager.configuration_maps
|
||||
|
||||
def test_config_reset_node(self):
|
||||
# given
|
||||
config_manager = ConfigurableManager()
|
||||
config_manager = TestConfigurableOptions()
|
||||
test_config = {1: 2}
|
||||
node_id = 1
|
||||
config_manager.set_configs(test_config)
|
||||
|
@ -86,11 +82,12 @@ class TestConf:
|
|||
config_manager.config_reset(node_id)
|
||||
|
||||
# then
|
||||
assert not config_manager.get_configs(node_id)
|
||||
assert node_id not in config_manager.configuration_maps
|
||||
assert config_manager.get_configs()
|
||||
|
||||
def test_configs_setget(self):
|
||||
# given
|
||||
config_manager = ConfigurableManager()
|
||||
config_manager = TestConfigurableOptions()
|
||||
test_config = {1: 2}
|
||||
node_id = 1
|
||||
config_manager.set_configs(test_config)
|
||||
|
@ -106,7 +103,7 @@ class TestConf:
|
|||
|
||||
def test_config_setget(self):
|
||||
# given
|
||||
config_manager = ConfigurableManager()
|
||||
config_manager = TestConfigurableOptions()
|
||||
name = "test"
|
||||
value = "1"
|
||||
node_id = 1
|
||||
|
@ -120,56 +117,3 @@ class TestConf:
|
|||
# then
|
||||
assert defaults_value == value
|
||||
assert node_value == value
|
||||
|
||||
def test_all_configs(self):
|
||||
# given
|
||||
config_manager = ConfigurableManager()
|
||||
name = "test"
|
||||
value_one = "1"
|
||||
value_two = "2"
|
||||
node_id = 1
|
||||
config_one = "config1"
|
||||
config_two = "config2"
|
||||
config_manager.set_config(name, value_one, config_type=config_one)
|
||||
config_manager.set_config(name, value_two, config_type=config_two)
|
||||
config_manager.set_config(name, value_one, node_id=node_id, config_type=config_one)
|
||||
config_manager.set_config(name, value_two, node_id=node_id, config_type=config_two)
|
||||
|
||||
# when
|
||||
defaults_value_one = config_manager.get_config(name, config_type=config_one)
|
||||
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_all_configs()
|
||||
node_all_configs = config_manager.get_all_configs(node_id=node_id)
|
||||
|
||||
# then
|
||||
assert defaults_value_one == value_one
|
||||
assert defaults_value_two == value_two
|
||||
assert node_value_one == value_one
|
||||
assert node_value_two == value_two
|
||||
assert len(default_all_configs) == 2
|
||||
assert config_one in default_all_configs
|
||||
assert config_two in default_all_configs
|
||||
assert len(node_all_configs) == 2
|
||||
assert config_one in node_all_configs
|
||||
assert config_two in node_all_configs
|
||||
|
||||
@pytest.mark.parametrize("_", xrange(10))
|
||||
def test_config_last_key(self, _):
|
||||
# given
|
||||
config_manager = ConfigurableManager()
|
||||
config = {1: 2}
|
||||
node_id = 1
|
||||
config_types = [1, 2, 3]
|
||||
shuffle(config_types)
|
||||
config_manager.set_configs(config, node_id=node_id, config_type=config_types[0])
|
||||
config_manager.set_configs(config, node_id=node_id, config_type=config_types[1])
|
||||
config_manager.set_configs(config, node_id=node_id, config_type=config_types[2])
|
||||
|
||||
# when
|
||||
keys = config_manager.get_all_configs(node_id=node_id).keys()
|
||||
|
||||
# then
|
||||
assert keys
|
||||
assert keys[-1] == config_types[2]
|
||||
|
|
|
@ -12,15 +12,17 @@ from mock import MagicMock
|
|||
|
||||
from core.emulator.emudata import NodeOptions
|
||||
from core.enumerations import MessageFlags, NodeTypes
|
||||
from core.mobility import BasicRangeModel
|
||||
from core.mobility import Ns2ScriptedMobility
|
||||
from core.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||
from core.netns.vnodeclient import VnodeClient
|
||||
from core.service import ServiceManager
|
||||
|
||||
_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
_SERVICES_PATH = os.path.join(_PATH, "myservices")
|
||||
_MOBILITY_FILE = os.path.join(_PATH, "mobility.scen")
|
||||
_XML_VERSIONS = ["0.0", "1.0"]
|
||||
_XML_VERSIONS = [
|
||||
"0.0",
|
||||
"1.0"
|
||||
]
|
||||
_WIRED = [
|
||||
NodeTypes.PEER_TO_PEER,
|
||||
NodeTypes.HUB,
|
||||
|
@ -101,7 +103,6 @@ class TestCore:
|
|||
:param str version: xml version to write and parse
|
||||
:param ip_prefixes: generates ip addresses for nodes
|
||||
"""
|
||||
|
||||
# create ptp
|
||||
ptp_node = session.add_node(_type=NodeTypes.PEER_TO_PEER)
|
||||
|
||||
|
@ -256,7 +257,7 @@ class TestCore:
|
|||
|
||||
# create wlan
|
||||
wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
session.set_wireless_model(wlan_node, BasicRangeModel)
|
||||
wlan_node.setmodel(BasicRangeModel)
|
||||
|
||||
# create nodes
|
||||
node_options = NodeOptions()
|
||||
|
@ -289,7 +290,7 @@ class TestCore:
|
|||
|
||||
# create wlan
|
||||
wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
session.set_wireless_model(wlan_node, BasicRangeModel)
|
||||
wlan_node.setmodel(BasicRangeModel)
|
||||
|
||||
# create nodes
|
||||
node_options = NodeOptions()
|
||||
|
@ -316,7 +317,7 @@ class TestCore:
|
|||
"script_pause": "",
|
||||
"script_stop": "",
|
||||
}
|
||||
session.mobility.set_configs(config, wlan_node.objid, Ns2ScriptedMobility.name)
|
||||
wlan_node.setmodel(Ns2ScriptedMobility, config)
|
||||
|
||||
# add handler for receiving node updates
|
||||
event = threading.Event()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue