示例#1
0
 def test_move_last_first(self):
     conn = sr.Connection("move_test4")
     self.session = sr.Session(conn, sr.SR_DS_STARTUP)
     self.session.move_item("/test-module:user[name='nameC']",
                            sr.SR_MOVE_LAST)
     items = self.session.get_items("/test-module:user")
     self.compareListItems(items, ["A", "B", "D", "C"])
示例#2
0
 def test_move_after_unknown(self):
     conn = sr.Connection("move_test3")
     self.session = sr.Session(conn, sr.SR_DS_STARTUP)
     with self.assertRaises(RuntimeError):
         self.session.move_item("/test-module:user[name='nameB']",
                                sr.SR_MOVE_AFTER,
                                "/test-module:user[name='nameXY']")
示例#3
0
 def test_move_before_first(self):
     conn = sr.Connection("move_test2")
     self.session = sr.Session(conn, sr.SR_DS_STARTUP)
     self.session.move_item("/test-module:user[name='nameC']",
                            sr.SR_MOVE_BEFORE,
                            "/test-module:user[name='nameA']")
     items = self.session.get_items("/test-module:user")
     self.compareListItems(items, ["C", "A", "B", "D"])
示例#4
0
 def test_move_after_last(self):
     conn = sr.Connection("move_test1")
     self.session = sr.Session(conn, sr.SR_DS_STARTUP)
     print("move")
     self.session.move_item("/test-module:user[name='nameB']",
                            sr.SR_MOVE_AFTER,
                            "/test-module:user[name='nameD']")
     items = self.session.get_items("/test-module:user")
     self.compareListItems(items, ["A", "C", "D", "B"])
示例#5
0
 def setUp(self):
     conn = sr.Connection("move_test")
     session = sr.Session(conn, sr.SR_DS_STARTUP)
     session.delete_item("/test-module:*")
     session.set_item("/test-module:user[name='nameA']", None)
     session.set_item("/test-module:user[name='nameB']", None)
     session.set_item("/test-module:user[name='nameC']", None)
     session.set_item("/test-module:user[name='nameD']", None)
     session.commit()
示例#6
0
 def restartConnection(self):
     try:
         self.sr = sr.Connection(self.name, self.conn)
     except RuntimeError as r:
         if self.conn == sr.SR_CONN_DAEMON_REQUIRED and r.message == "The peer disconnected":
             sleep(1)  #wait for daemon to start
             self.sr = sr.Connection(self.name, self.conn)
         else:
             raise r
     self.session = sr.Session(self.sr, self.ds)
示例#7
0
def perf_get_items_test(state, op_num, items):

    conn = state["connection"]
    assert conn is not None, "Unable to get connection."
    sess = sr.Session(conn, state['datastore'])
    assert sess is not None, "Unable to get session."

    xpath = "/example-module:container/list/leaf"

    for i in xrange(op_num):
        val = sess.get_items(xpath)

    return 1
示例#8
0
 def test_commit_empty(self):
     TestModule.create_test_module()
     connection = sr.Connection("name")
     session = sr.Session(self.conn, sr.SR_DS_STARTUP)
     v_old = self.session.get_item("/test-module:main/string")
     self.session.delete_item("/test-module:*")
     self.session.commit()
     #test random leaf that was deleted
     v_none = self.session.get_item("/test-module:main/string")
     self.assertIsNone(v_none)
     self.session.set_item("/test-module:main/string", v_old)
     self.session.commit()
     TestModule.create_test_module()
示例#9
0
def perf_get_item_with_data_load_test(state, op_num, items):

    conn = state["connection"]
    assert conn is not None, "Unable to get connection."

    xpath = "/example-module:container/list[key1='key0'][key2='key0']/leaf"

    for i in xrange(op_num):
        sess = sr.Session(conn, state['datastore'])

        val = sess.get_item(xpath)
        assert val.type() is sr.SR_STRING_T, "check value type"

    return 1
示例#10
0
def perf_get_item_first_test(state, op_num, items):

    conn = state["connection"]
    assert conn is not None, "Unable to get connection."
    sess = sr.Session(conn, state['datastore'])
    assert sess is not None, "Unable to get session."

    xpath = "/example-module:container"

    for i in xrange(op_num):
        val = sess.get_item(xpath)
        assert val.type() is sr.SR_CONTAINER_T, "check value type"

    return 1
示例#11
0
def createDataTreeLargeExampleModule(count, datastore):
    """
    Add data to example-module.
    """
    conn = sr.Connection("load test")
    sess = sr.Session(conn, datastore)
    subs = sr.Subscribe(sess)

    for i in xrange(count):
        xpath = "/example-module:container/list[key1='key" + str(i) + "'][key2='key" + str(i) +"']/leaf"
        val = sr.Val("leaf" + str(i), sr.SR_STRING_T)

        sess.set_item(xpath, val)

    sess.commit()
示例#12
0
def perf_get_ietf_interfaces_test(state, op_num, items):

    conn = state["connection"]
    assert conn is not None, "Unable to get connection."
    sess = sr.Session(conn, state['datastore'])
    assert sess is not None, "Unable to get session."

    xpath = "/ietf-interfaces:interfaces//*"

    count = 0
    for i in xrange(op_num):
        it = sess.get_items_iter(xpath)
        assert it is not None, "Iterator not found"
        while True:
            val = sess.get_item_next(it)
            if val == None: break
            count = count + 1

    return count
示例#13
0
def perf_get_items_iter_test(state, op_num, items):

    conn = state["connection"]
    assert conn is not None, "Unable to get connection."
    sess = sr.Session(conn, state['datastore'])
    assert sess is not None, "Unable to get session."

    xpath = "/example-module:container/list/leaf"

    count = 0
    for i in xrange(op_num):
        it = sess.get_items_iter(xpath)
        assert it is not None, "Iterator not found"
        while True:
            val = sess.get_item_next(it)
            if val == None: break
            count = count + 1

    return count
示例#14
0
def clearDataTree(module_name, datastore):
    """
    Clear yang model.
    """

    conn = sr.Connection("clear")
    sess = sr.Session(conn, datastore)
    subs = sr.Subscribe(sess)

    xpath = "/" + module_name + ":*//*"

    values = sess.get_items(xpath)

    if values == None:
        return

    for i in xrange(values.val_cnt()):
        sess.delete_item(values.val(i).xpath())

    sess.commit()
示例#15
0
 def setUp(self):
     TestModule.create_test_module()
     self.session = sr.Session(self.conn, sr.SR_DS_STARTUP)
示例#16
0
 def setup(self):
     if self.autoconnect:
         self.sr = sr.Connection(self.name, self.conn)
         self.session = sr.Session(self.sr, self.ds)