blob: d686cd0ed91afbe3afffa5dd29c80975f6772ce3 [file] [log] [blame]
Václav Kubernátd1beedc2020-09-07 12:09:05 +02001import os
Václav Kubernát654303f2020-07-31 13:16:54 +02002import sysrepo_subscription_py as sr_sub
Jan Kundrátcf5c6362020-01-16 22:54:47 +01003import netconf_cli_py as nc
4
Václav Kubernátd1beedc2020-09-07 12:09:05 +02005c = nc.NetconfAccess(socketPath = os.environ['NETOPEER_SOCKET'])
Václav Kubernát654303f2020-07-31 13:16:54 +02006data = c.getItems("/ietf-netconf-monitoring:netconf-state/datastores")
Václav Kubernátcf9224f2020-06-02 09:55:29 +02007for (k, v) in data:
Jan Kundrátcf5c6362020-01-16 22:54:47 +01008 print(f"{k}: {type(v)} {v}", flush=True)
9
10if len(data) == 0:
11 print("ERROR: No data returned from NETCONF")
12 exit(1)
13
Václav Kubernát654303f2020-07-31 13:16:54 +020014subscription = sr_sub.SysrepoSubscription("example-schema")
15xpath = "/example-schema:leafInt32"
Jan Kundrátcf5c6362020-01-16 22:54:47 +010016for EXPECTED in (599, 59, "61"):
Václav Kubernát654303f2020-07-31 13:16:54 +020017 c.setLeaf(xpath, EXPECTED)
Jan Kundrátcf5c6362020-01-16 22:54:47 +010018 c.commitChanges()
Václav Kubernát654303f2020-07-31 13:16:54 +020019 data = c.getItems(xpath)
20 (_, value) = next(filter(lambda keyValue: keyValue[0] == xpath, data))
Václav Kubernátcf9224f2020-06-02 09:55:29 +020021 if value != EXPECTED:
Jan Kundrátcf5c6362020-01-16 22:54:47 +010022 if isinstance(EXPECTED, str):
Václav Kubernátcf9224f2020-06-02 09:55:29 +020023 if str(value) != EXPECTED:
Václav Kubernát654303f2020-07-31 13:16:54 +020024 print(f"ERROR: leafInt32 not updated (via string) to {EXPECTED}")
Jan Kundrátcf5c6362020-01-16 22:54:47 +010025 exit(1)
26 else:
Václav Kubernát654303f2020-07-31 13:16:54 +020027 print(f"ERROR: leafInt32 not updated to {EXPECTED}")
Jan Kundrátcf5c6362020-01-16 22:54:47 +010028 exit(1)
29try:
Václav Kubernát654303f2020-07-31 13:16:54 +020030 c.setLeaf(xpath, "blesmrt")
Jan Kundrátcf5c6362020-01-16 22:54:47 +010031 c.commitChanges()
32 print("ERROR: setting integer to a string did not error out")
33 exit(1)
34except RuntimeError:
35 pass
36
37exit(0)