Ejemplo n.º 1
0
def t4_list_remove(yobj, tree=False):
  del_tree = False
  if not tree:
    del_tree = True
    tree = YANGPathHelper()

  for b in ["steam", "liberty", "california-lager", "porter", "ipa", "foghorn"]:
    yobj.container.t4.add(b)

  for b in [("steam", 1), ("liberty", 1), ("pygmy-owl", 0)]:
    path = "/container/t4[keyval=%s]" % b[0]
    retr = tree.get(path)
    assert len(retr) == b[1], "Retreive of a list element returned the wrong number of elements (%s -> %d != %d)" % (b[0], len(retr), b[1])
    rem = False
    try:
      yobj.container.t4.delete(b[0])
      rem = True
    except KeyError:
      pass
    assert rem == bool(b[1]), "Removal of a list element did not return expected result (%s -> %s != %s)" % (b[0], rem, bool(b[1]))
    new_retr = tree.get(path)
    assert len(new_retr) == 0, "An element was not correctly removed from the list (%s -> len(%s) = %d)" % (b[0], path, len(new_retr))

  if del_tree:
    del tree
Ejemplo n.º 2
0
def t4_list_remove(yobj, tree=False):
    del_tree = False
    if not tree:
        del_tree = True
        tree = YANGPathHelper()

    for b in [
            "steam", "liberty", "california-lager", "porter", "ipa", "foghorn"
    ]:
        yobj.container.t4.add(b)

    for b in [("steam", 1), ("liberty", 1), ("pygmy-owl", 0)]:
        path = "/container/t4[keyval=%s]" % b[0]
        retr = tree.get(path)
        assert len(retr) == b[
            1], "Retreive of a list element returned the wrong number of elements (%s -> %d != %d)" % (
                b[0], len(retr), b[1])
        rem = False
        try:
            yobj.container.t4.delete(b[0])
            rem = True
        except KeyError:
            pass
        assert rem == bool(
            b[1]
        ), "Removal of a list element did not return expected result (%s -> %s != %s)" % (
            b[0], rem, bool(b[1]))
        new_retr = tree.get(path)
        assert len(
            new_retr
        ) == 0, "An element was not correctly removed from the list (%s -> len(%s) = %d)" % (
            b[0], path, len(new_retr))

    if del_tree:
        del tree
Ejemplo n.º 3
0
def t3_leaflist_remove(yobj, tree=False):
    del_tree = False
    if not tree:
        del_tree = True
        tree = YANGPathHelper()

    for b in [
            "oatmeal-stout", "amber-ale", "pale-ale", "pils", "ipa",
            "session-ipa"
    ]:
        yobj.container.t3.append(b)

    for b in [("session-ipa", 1), ("amber-ale", 1), ("moose-drool", 0)]:
        path = "/container/t3"
        retr = tree.get(path)
        passed = False
        assert len(retr) == 1, "Looking up a leaf-list element returned multiple elements erroneously (%s -> %d elements (%s))" \
          % (b[0], len(retr), retr)

        found = False
        try:
            v = retr[0].index(b[0])
            found = 1
        except ValueError:
            found = 0

        assert found == b[
            1], "When retrieving a leaf-list element, a known value was not in the list (%s -> %s (%s))" % (
                b[0], b[1], retr[0])

        rem = False
        try:
            yobj.container.t3.remove(b[0])
            rem = True
        except ValueError:
            pass
        assert rem == bool(
            b[1]
        ), "Removal of a leaflist element did not return expected result (%s -> %s != %s)" % (
            b[0], rem, bool(b[1]))
        new_retr = tree.get(path)

        found = False
        try:
            v = new_retr[0].index(b[0])
            found = 1
        except ValueError:
            found = 0
        assert found == 0, "An element was not correctly removed from the leaf-list (%s -> %s [%s])" % (
            b[0], path, new_retr[0])

    if del_tree:
        del tree
Ejemplo n.º 4
0
def t5_typedef_leaflist_add_del(yobj,tree=False):
  del_tree = False
  if not tree:
    del_tree = True
    tree = YANGPathHelper()

  for a in ["quebec-city", "montreal", "laval", "gatineau"]:
    yobj.container.t5.append(a)

  for tc in [("quebec-city", True), ("montreal", True), ("dallas", False)]:
    validref = False
    try:
      yobj.reference.t5_ptr = tc[0]
      validref = True
    except ValueError:
      pass
    assert validref == tc[1], "Reference was incorrectly set for a leaflist" + \
        " (%s not in %s -> %s != %s)" % (tc[0], str(yobj.container.t5), validref, tc[1])

  for a in ["vancouver", "burnaby", "surrey", "richmond"]:
    yobj.container.t5.append(a)

  for tc in [("vancouver", True), ("burnaby", True), ("san-francisco", False), ("surrey", True), ("richmond", True)]:
    path = "/container/t5"
    retr = tree.get(path)
    assert (tc[0] in retr[0]) == tc[1], "Retrieve of a leaf-list element did not return expected result (%s->%s %s)" % (tc[0], tc[1], (retr[0]))
    rem = False
    try:
      retr[0].remove(tc[0])
      rem = True
    except ValueError:
      pass
    new_retr = tree.get(path)
    assert rem == bool(tc[1]), "An element was not correctly removed from a leaf-list (%s -> len(%s) = %d)" % (tc[0], path, len(new_retr))


  for tc in [("gatineau", True), ("laval", True), ("new-york-city", False), ("quebec-city", True)]:
    path = "/container/t5"
    retr = tree.get(path)
    assert (tc[0] in retr[0]) == tc[1], "Retrieve of a leaf-list element did not return expected result (%s->%s %s)" % (tc[0], tc[1], (retr[0]))
    popped_obj = retr[0].pop()
    if popped_obj == tc[0]:
      expected_obj = True
    else:
      expected_obj = False
    assert expected_obj == bool(tc[1]), "Popped object was not the object that was expected (%s != %s)" % (tc[0],popped_obj)
    new_retr = tree.get(path)
    assert (tc[0] in new_retr[0]) == False, "Retrieve of a leaf-list element did not return expected result (%s->%s %s)" % (tc[0], tc[1], (new_retr[0]))

  if del_tree:
    del tree
Ejemplo n.º 5
0
def t3_leaflist_remove(yobj, tree=False):
  del_tree = False
  if not tree:
    del_tree = True
    tree = YANGPathHelper()

  for b in ["oatmeal-stout", "amber-ale", "pale-ale", "pils", "ipa", "session-ipa"]:
    yobj.container.t3.append(b)

  for b in [("session-ipa", 1), ("amber-ale", 1), ("moose-drool", 0)]:
    path = "/container/t3"
    retr = tree.get(path)
    passed = False
    assert len(retr) == 1, "Looking up a leaf-list element returned multiple elements erroneously (%s -> %d elements (%s))" \
      % (b[0], len(retr), retr)

    found = False
    try:
      v = retr[0].index(b[0])
      found = 1
    except ValueError:
      found = 0

    assert found == b[1], "When retrieving a leaf-list element, a known value was not in the list (%s -> %s (%s))" % (b[0], b[1], retr[0])

    rem = False
    try:
      yobj.container.t3.remove(b[0])
      rem = True
    except ValueError:
      pass
    assert rem == bool(b[1]), "Removal of a leaflist element did not return expected result (%s -> %s != %s)" % (b[0], rem, bool(b[1]))
    new_retr = tree.get(path)

    found = False
    try:
      v = new_retr[0].index(b[0])
      found = 1
    except ValueError:
      found = 0
    assert found == 0, "An element was not correctly removed from the leaf-list (%s -> %s [%s])" % (b[0], path, new_retr[0])

  if del_tree:
    del tree
Ejemplo n.º 6
0
def t5_typedef_leaflist_add_del(yobj, tree=False):
    del_tree = False
    if not tree:
        del_tree = True
        tree = YANGPathHelper()

    for a in ["quebec-city", "montreal", "laval", "gatineau"]:
        yobj.container.t5.append(a)

    for tc in [("quebec-city", True), ("montreal", True), ("dallas", False)]:
        validref = False
        try:
            yobj.reference.t5_ptr = tc[0]
            validref = True
        except ValueError:
            pass
        assert validref == tc[1], "Reference was incorrectly set for a leaflist" + \
            " (%s not in %s -> %s != %s)" % (tc[0], str(yobj.container.t5), validref, tc[1])

    for a in ["vancouver", "burnaby", "surrey", "richmond"]:
        yobj.container.t5.append(a)

    for tc in [("vancouver", True), ("burnaby", True),
               ("san-francisco", False), ("surrey", True), ("richmond", True)]:
        path = "/container/t5"
        retr = tree.get(path)
        assert (tc[0] in retr[0]) == tc[
            1], "Retrieve of a leaf-list element did not return expected result (%s->%s %s)" % (
                tc[0], tc[1], (retr[0]))
        rem = False
        try:
            retr[0].remove(tc[0])
            rem = True
        except ValueError:
            pass
        new_retr = tree.get(path)
        assert rem == bool(
            tc[1]
        ), "An element was not correctly removed from a leaf-list (%s -> len(%s) = %d)" % (
            tc[0], path, len(new_retr))

    for tc in [("gatineau", True), ("laval", True), ("new-york-city", False),
               ("quebec-city", True)]:
        path = "/container/t5"
        retr = tree.get(path)
        assert (tc[0] in retr[0]) == tc[
            1], "Retrieve of a leaf-list element did not return expected result (%s->%s %s)" % (
                tc[0], tc[1], (retr[0]))
        popped_obj = retr[0].pop()
        if popped_obj == tc[0]:
            expected_obj = True
        else:
            expected_obj = False
        assert expected_obj == bool(
            tc[1]
        ), "Popped object was not the object that was expected (%s != %s)" % (
            tc[0], popped_obj)
        new_retr = tree.get(path)
        assert (
            tc[0] in new_retr[0]
        ) == False, "Retrieve of a leaf-list element did not return expected result (%s->%s %s)" % (
            tc[0], tc[1], (new_retr[0]))

    if del_tree:
        del tree