def set_new_controller_role(session):
    xml_config = utils.get_config_as_xml(session)
    config_map = {key: utils.get_config_value_from_xml(key, xml_config)
                  for key in CONFIG_KEYS}
    current_role = new_role = config_map['controller_role']
    while current_role == new_role:
        new_role = random.choice(utils.get_controller_roles())
    config_map['controller_role'] = new_role
    utils.edit_running_config_by_xml_string(SWITCH_CONTROLLER % config_map, session)
    return new_role
def set_new_controller_role(session):
    xml_config = utils.get_config_as_xml(session)
    config_map = {
        key: utils.get_config_value_from_xml(key, xml_config)
        for key in CONFIG_KEYS
    }
    current_role = new_role = config_map['controller_role']
    while current_role == new_role:
        new_role = random.choice(utils.get_controller_roles())
    config_map['controller_role'] = new_role
    utils.edit_running_config_by_xml_string(SWITCH_CONTROLLER % config_map,
                                            session)
    return new_role
{controllers_listener,disabled},
{queues_status,enabled},
{ports,[{port,1,{queues,[]}}, {port,2,{queues,[1,2]}}]}
]
}
]
}]},
...].
'''

ASSERT_MSG = 'Queue {0} is {1}. Should be {2}.'
REQUEST = {'resource' : 'queue',
           'id': 'LogicalSwitch0-Port2-Queue1',
           'value' : None}

def assert_min_max_rate_was_set(min_rate, max_rate):
 for tag, expected_value in [('min-rate', min_rate), ('max-rate', max_rate)]:
        REQUEST['value'] = './/' + tag
        config = utils.get_config_as_xml(sess)
        actual_value = utils.get_config_value_from_resources(REQUEST, config)
        assert str(expected_value) == actual_value, ASSERT_MSG.format(
            tag, actual_value, expected_value)

sess = utils.connect_to_switch('localhost', 1830, 'linc', 'linc')
for i in range(1, 10):
    min_rate = random.randint(1,1000)
    max_rate = random.randint(1,1000)
    queue_config = QUEUE_CONFIG % {'min-rate' : min_rate, 'max-rate': max_rate}
    utils.edit_running_config_by_xml_string(queue_config, sess)
    assert_min_max_rate_was_set(min_rate, max_rate)
import utils
import ncclient

QUEUE_CONFIG = """
<nc:config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<capable-switch>
<id>CapableSwitch0</id>
<resources>
<queue operation="replace">
<resource-id>Queue2</resource-id>
<id>2</id>
<port>LogicalSwitch0-Port7</port>
<properties>
<min-rate>10</min-rate>
<max-rate>500</max-rate>
<experimenter>123498</experimenter>
</properties>
</queue>
</resources>
</capable-switch>
</nc:config>
"""
sess = utils.connect_to_switch("localhost", 1830, "linc", "linc")
try:
    utils.edit_running_config_by_xml_string(QUEUE_CONFIG, sess)
except ncclient.operations.rpc.RPCError as e:
    assert e.tag == "data-missing"
Example #5
0
]
}]},
...].
'''

ASSERT_MSG = 'Queue {0} is {1}. Should be {2}.'
REQUEST = {
    'resource': 'queue',
    'id': 'LogicalSwitch0-Port2-Queue1',
    'value': None
}


def assert_min_max_rate_was_set(min_rate, max_rate):
    for tag, expected_value in [('min-rate', min_rate),
                                ('max-rate', max_rate)]:
        REQUEST['value'] = './/' + tag
        config = utils.get_config_as_xml(sess)
        actual_value = utils.get_config_value_from_resources(REQUEST, config)
        assert str(expected_value) == actual_value, ASSERT_MSG.format(
            tag, actual_value, expected_value)


sess = utils.connect_to_switch('localhost', 1830, 'linc', 'linc')
for i in range(1, 10):
    min_rate = random.randint(1, 1000)
    max_rate = random.randint(1, 1000)
    queue_config = QUEUE_CONFIG % {'min-rate': min_rate, 'max-rate': max_rate}
    utils.edit_running_config_by_xml_string(queue_config, sess)
    assert_min_max_rate_was_set(min_rate, max_rate)
import utils
import ncclient

QUEUE_CONFIG = '''
<nc:config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<capable-switch>
<id>CapableSwitch0</id>
<resources>
<queue operation="replace">
<resource-id>Queue2</resource-id>
<id>2</id>
<port>LogicalSwitch0-Port7</port>
<properties>
<min-rate>10</min-rate>
<max-rate>500</max-rate>
<experimenter>123498</experimenter>
</properties>
</queue>
</resources>
</capable-switch>
</nc:config>
'''
sess = utils.connect_to_switch('localhost', 1830, 'linc', 'linc')
try:
    utils.edit_running_config_by_xml_string(QUEUE_CONFIG, sess)
except ncclient.operations.rpc.RPCError as e:
    assert e.tag == 'data-missing'