Skip to content

Commit

Permalink
Merge pull request #692 from kernelkit/update-tests
Browse files Browse the repository at this point in the history
Update some tests
  • Loading branch information
mattiaswal authored Oct 10, 2024
2 parents c44621b + f1d7304 commit dc0a68a
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/confd/src/ietf-system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ static int auth_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *modul
lyd_new_path(*parent, NULL, xpath, spwd->sp_pwdp, 0, 0);
}

endspent();
return SR_ERR_OK;
}

Expand Down
2 changes: 2 additions & 0 deletions test/case/ietf_interfaces/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ include::ipv4_address/Readme.adoc[]

include::ipv6_address/Readme.adoc[]

include::ipv4_autoconf/Readme.adoc[]

include::iface_phys_address/Readme.adoc[]

include::routing_basic/Readme.adoc[]
Expand Down
3 changes: 2 additions & 1 deletion test/case/ietf_interfaces/iface_phys_address/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ endif::topdoc[]
. Initialize
. Set custom MAC address to '02:01:00:c0:ff:ee' on target:mgmt
. Verify target:mgmt has MAC address '02:01:00:c0:ff:ee'
. Verify that target:mgmt has its origil MAC address again
. Remove custom MAC address '02:01:00:c0:ff:ee'
. Verify that target:mgmt has the original MAC address again


<<<
Expand Down
4 changes: 2 additions & 2 deletions test/case/ietf_interfaces/iface_phys_address/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
print(f"Target iface {tport} current mac: {mac}")
assert mac == cmac

with test.step(f"Remove custom MAC address '02:01:00:c0:ff:ee'"):
with test.step("Remove custom MAC address '02:01:00:c0:ff:ee'"):
xpath=iface.get_iface_xpath(tport, "phys-address")
target.delete_xpath(xpath)

with test.step("Verify that target:mgmt has its origil MAC address again"):
with test.step("Verify that target:mgmt has the original MAC address again"):
until(lambda: iface.get_phys_address(target, tport) == pmac)

test.succeed()
3 changes: 2 additions & 1 deletion test/case/ietf_interfaces/ipv4_address/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ image::topology.png[Interface with IPv4 topology]
endif::testgroup[]
endif::topdoc[]
==== Test sequence
. Connect to target
. Set up topology and attach to target DUT
. Configure IPv4 address 10.10.10.20/24 on target:mgmt
. Verify '10.10.10.20/24' exist on target:mgmt
. Remove all IPv4 addresses from target:mgmt
. Verify target:mgmt no longer has the address 10.10.10.20


Expand Down
5 changes: 3 additions & 2 deletions test/case/ietf_interfaces/ipv4_address/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
new_prefix_length = 24

with infamy.Test() as test:
with test.step("Connect to target"):
with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
target = env.attach("target", "mgmt")
_, interface_name = env.ltop.xlate("target", "mgmt")
Expand All @@ -42,8 +42,9 @@
with test.step("Verify '10.10.10.20/24' exist on target:mgmt"):
until(lambda: iface.address_exist(target, interface_name, new_ip_address, proto='static'))

with test.step(f"Remove all IPv4 addresses from target:mgmt"):
with test.step("Remove all IPv4 addresses from target:mgmt"):
target.delete_xpath(f"/ietf-interfaces:interfaces/interface[name='{interface_name}']/ietf-ip:ipv4")

with test.step("Verify target:mgmt no longer has the address 10.10.10.20"):
until(lambda: iface.address_exist(target, interface_name, new_ip_address) == False)

Expand Down
9 changes: 5 additions & 4 deletions test/case/ietf_interfaces/ipv4_autoconf/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ image::topology.png[IPv4 link-local topology]
endif::testgroup[]
endif::topdoc[]
==== Test sequence
. Initialize
. Configure an interface with IPv4 ZeroConf IP
. Verify link local address exist on target:mgmt
. Set up topology and attach to target DUT
. Configure interface target:mgmt with IPv4 ZeroConf IP
. Verify link-local address exist on target:mgmt
. Configure target:mgmt with a specific IPv4 ZeroConf IP
. Verify target:mgmt has link local address 169.254.42.42
. Verify target:mgmt has link-local address 169.254.42.42
. Remove IPv4 link-local addresses from target:mgmt
. Verify link-local addresses has been removed from target:mgmt


<<<
Expand Down
10 changes: 6 additions & 4 deletions test/case/ietf_interfaces/ipv4_autoconf/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def no_linklocal(target, iface):


with infamy.Test() as test:
with test.step("Initialize"):
with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
target = env.attach("target", "mgmt")

with test.step("Configure an interface with IPv4 ZeroConf IP"):
with test.step("Configure interface target:mgmt with IPv4 ZeroConf IP"):
_, tport = env.ltop.xlate("target", "data")

target.put_config_dict("ietf-interfaces", {
Expand All @@ -68,7 +68,7 @@ def no_linklocal(target, iface):
}
})

with test.step("Verify link local address exist on target:mgmt"):
with test.step("Verify link-local address exist on target:mgmt"):
until(lambda: has_linklocal(target, tport), attempts=30)

with test.step("Configure target:mgmt with a specific IPv4 ZeroConf IP"):
Expand All @@ -91,14 +91,16 @@ def no_linklocal(target, iface):
}
})

with test.step("Verify target:mgmt has link local address 169.254.42.42"):
with test.step("Verify target:mgmt has link-local address 169.254.42.42"):
until(lambda: has_linklocal(target, tport, request="169.254.42.42"),
attempts=30)

with test.step("Remove IPv4 link-local addresses from target:mgmt"):
xpath = f"/ietf-interfaces:interfaces/interface[name='{tport}']" \
"/ietf-ip:ipv4/infix-ip:autoconf"
target.delete_xpath(xpath)

with test.step("Verify link-local addresses has been removed from target:mgmt"):
until(lambda: no_linklocal(target, tport), attempts=30)

test.succeed()
7 changes: 6 additions & 1 deletion test/case/ietf_routing/ospf_multiarea/Readme.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
=== OSPF with multiple areas
==== Description
This test test alot of features inside OSPF using 3 areas (one NSSA area)
This test test alot of features inside OSPF using 3 areas (one NSSA area, with no summary)
to test the distribution of routes is deterministic (using cost), also test
link breaks using BFD (not implemented in infamy though)

This test also verify broadcast and point-to-point interface type on /30 network and
explicit router-id.

==== Topology
ifdef::topdoc[]
image::../../test/case/ietf_routing/ospf_multiarea/topology.png[OSPF with multiple areas topology]
Expand All @@ -21,6 +24,8 @@ endif::topdoc[]
. Wait for all neighbor to peer
. Wait for routes from OSPF on all routers
. Verify Area 0.0.0.1 on R3 is NSSA area
. Verify R1:ring2 is of type point-to-point
. Verify R4:ring1 is of type point-to-point
. Verify on R3, there are no routes beyond 10.0.23.1, just a default route
. Testing connectivitiy through NSSA area, from PC:data3 to 11.0.8.1
. Verify that the route to 10.0.0.3 from PC:data4, go through 10.0.41.2
Expand Down
21 changes: 16 additions & 5 deletions test/case/ietf_routing/ospf_multiarea/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
"""
OSPF with multiple areas
This test test alot of features inside OSPF using 3 areas (one NSSA area)
This test test alot of features inside OSPF using 3 areas (one NSSA area, with no summary)
to test the distribution of routes is deterministic (using cost), also test
link breaks using BFD (not implemented in infamy though)
This test also verify broadcast and point-to-point interface type on /30 network and
explicit router-id.
"""
import infamy

Expand Down Expand Up @@ -137,7 +140,8 @@ def config_target1(target, ring1, ring2, cross):
},
"name": ring2,
"hello-interval": 1,
"enabled": True
"enabled": True,
"interface-type": "point-to-point"
},
{
"name": "lo",
Expand Down Expand Up @@ -239,7 +243,7 @@ def config_target2(target, ring1, ring2, cross):
"type": "infix-routing:ospfv2",
"name": "default",
"ospf": {
"explicit-router-id": "10.0.0.2",
"explicit-router-id": "1.1.1.1",
"areas": {
"area": [{
"area-id": "0.0.0.0",
Expand Down Expand Up @@ -471,7 +475,8 @@ def config_target4(target, ring1, cross, link):
},
"name": ring1,
"hello-interval": 1,
"enabled": True
"enabled": True,
"interface-type": "point-to-point"
}, {
"bfd": {
"enabled": True
Expand Down Expand Up @@ -536,7 +541,7 @@ def disable_link(target, link):

with test.step("Wait for all neighbor to peer"):
print("Waiting for neighbors to peer")
until(lambda: route.ospf_get_neighbor(R1, "0.0.0.0", R1ring1, "10.0.0.2"), attempts=200)
until(lambda: route.ospf_get_neighbor(R1, "0.0.0.0", R1ring1, "1.1.1.1"), attempts=200)
until(lambda: route.ospf_get_neighbor(R1, "0.0.0.1", R1cross, "10.0.0.3"), attempts=200)
until(lambda: route.ospf_get_neighbor(R2, "0.0.0.1", R2ring1, "10.0.0.3"), attempts=200)
until(lambda: route.ospf_get_neighbor(R2, "0.0.0.0", R2ring2, "10.0.0.1"), attempts=200)
Expand All @@ -559,6 +564,12 @@ def disable_link(target, link):
with test.step("Verify Area 0.0.0.1 on R3 is NSSA area"):
assert(route.ospf_is_area_nssa(R3, "0.0.0.1"))

with test.step("Verify R1:ring2 is of type point-to-point"):
assert(route.ospf_get_interface_type(R1, "0.0.0.2", R1ring2) == "point-to-point")

with test.step("Verify R4:ring1 is of type point-to-point"):
assert(route.ospf_get_interface_type(R4, "0.0.0.2", R4ring1) == "point-to-point")

with test.step("Verify on R3, there are no routes beyond 10.0.23.1, just a default route"):
# Should be only default route out of the area.
parallel(until(lambda: route.ipv4_route_exist(R3, "0.0.0.0/0"), attempts=200),
Expand Down
9 changes: 7 additions & 2 deletions test/case/ietf_system/add_delete_user/Readme.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
=== Add/delete user
==== Description
Verify that it is possible to add/delete a user.
Verify that it is possible to add/delete a user. The user password is hashed
with yescrypt.

==== Topology
ifdef::topdoc[]
Expand All @@ -15,8 +16,12 @@ image::topology.png[Add/delete user topology]
endif::testgroup[]
endif::topdoc[]
==== Test sequence
. Connect to device
. Set up topology and attach to target DUT
. Add new user 'newuser01' with password 'newuser01password'
. Verify user 'newuser01' exist in operational
. Verify user 'newuser01' can login with SSH
. Delete user 'newuser01'
. Verify erasure of user 'newuser01'
. Verify that 'newuser01' is removed from /etc/passwd


Expand Down
20 changes: 11 additions & 9 deletions test/case/ietf_system/add_delete_user/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"""
Add/delete user
Verify that it is possible to add/delete a user.
Verify that it is possible to add/delete a user. The user password is hashed
with yescrypt.
"""
import infamy
import copy
from passlib.hash import sha256_crypt
import random
import string
import re
Expand All @@ -15,16 +15,14 @@

username = "newuser01"
password = "newuser01password"

hashed_password = "$y$j9T$SALT$gx4K1wugXsm3JDLwYZtnbr37FGGvljotXwIBGOxaGf2"
with infamy.Test() as test:
with test.step("Connect to device"):
with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
target = env.attach("target", "mgmt")
tgtssh = env.attach("target", "mgmt", "ssh")

with test.step("Add new user 'newuser01' with password 'newuser01password'"):
hashed_password = sha256_crypt.using(rounds=5000).hash(password)

target.put_config_dict("ietf-system", {
"system": {
"authentication": {
Expand All @@ -39,7 +37,7 @@
}
})

with test.step(f"Verify user 'newuser01' exist in operational"):
with test.step("Verify user 'newuser01' exist in operational"):
running = target.get_config_dict("/ietf-system:system")
users = running["system"]["authentication"]["user"]
user_found = False
Expand All @@ -50,10 +48,14 @@
break
assert user_found, f"User 'newuser01' not found"

with test.step(f"Delete user 'newuser01'"):
with test.step("Verify user 'newuser01' can login with SSH"):
newssh = env.attach("target", "mgmt", "ssh", None, username, password)
util.until(lambda: newssh.run("ls").returncode == 0, attempts=200)

with test.step("Delete user 'newuser01'"):
target.delete_xpath(f"/ietf-system:system/authentication/user[name='{username}']")

with test.step(f"Verify erasure of user 'newuser01'"):
with test.step("Verify erasure of user 'newuser01'"):
running = target.get_config_dict("/ietf-system:system")
users = running["system"]["authentication"]["user"]
for user in users:
Expand Down
14 changes: 12 additions & 2 deletions test/case/ietf_system/hostname/Readme.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
=== Set hostname
==== Description
Verify that it is possible to change hostname.
Verify that it is possible to change hostname both normal
and using format %h-%m.

The format exapnds to <default hostname>-<MAC>,
where MAC is the last three bytes of the base MAC address.

e.g. ix-01-01-01.

==== Topology
ifdef::topdoc[]
Expand All @@ -15,8 +21,12 @@ image::topology.png[Set hostname topology]
endif::testgroup[]
endif::topdoc[]
==== Test sequence
. Connect to device
. Set up topology and attach to target DUT
. Set hostname to 'h0stn4m3'
. Verify new hostname 'h0stn4m3'
. Set hostname to to '%h-%m'
. Verify hostname is %h-%m in running configuration
. Verify hostname format in operational, according to format


<<<
Expand Down
19 changes: 12 additions & 7 deletions test/case/ietf_system/hostname/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
"""
Set hostname
Verify that it is possible to change hostname.
Verify that it is possible to change hostname both normal
and using format %h-%m.
The format exapnds to <default hostname>-<MAC>,
where MAC is the last three bytes of the base MAC address.
e.g. ix-01-01-01.
"""
import random
import string
import re
import infamy

with infamy.Test() as test:
with test.step("Connect to device"):
with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
target = env.attach("target", "mgmt")
tgtssh = env.attach("target", "mgmt", "ssh")
Expand All @@ -24,27 +30,26 @@
}
})

with test.step(f"Verify new hostname 'h0stn4m3'"):
with test.step("Verify new hostname 'h0stn4m3'"):
running = target.get_config_dict("/ietf-system:system")
assert running["system"]["hostname"] == new

with test.step(f"Set hostname format: %h-%m"):
with test.step("Set hostname to to '%h-%m'"):
target.put_config_dict("ietf-system", {
"system": {
"hostname": fmt,
}
})

with test.step(f"Verify hostname format in running: %h-%m"):
with test.step("Verify hostname is %h-%m in running configuration"):
running = target.get_config_dict("/ietf-system:system")
if running["system"]["hostname"] != fmt:
test.fail()

with test.step("Verify hostname format in operational, according to format"):
cmd = tgtssh.runsh("sed -n s/^DEFAULT_HOSTNAME=//p /etc/os-release")
default = cmd.stdout.rstrip()

with test.step(f"Verify hostname format in operational, according to format"):

oper = target.get_data("/ietf-system:system")
name = oper["system"]["hostname"]
pattern = rf'^{default}-([0-9a-fA-F]{{2}}-){{2}}[0-9a-fA-F]{{2}}$'
Expand Down
2 changes: 1 addition & 1 deletion test/case/ietf_system/timezone/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ image::topology.png[Set timezone topology]
endif::testgroup[]
endif::topdoc[]
==== Test sequence
. Connect to device
. Set up topology and attach to target DUT
. Set timezone to Australia/Perth
. Verify current time offset is +08:00

Expand Down
Loading

0 comments on commit dc0a68a

Please sign in to comment.