Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 1 | import os |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 2 | import sysrepo_subscription_py as sr_sub |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 3 | import netconf_cli_py as nc |
| 4 | |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 5 | c = nc.NetconfAccess(socketPath = os.environ['NETOPEER_SOCKET']) |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 6 | data = c.getItems("/ietf-netconf-monitoring:netconf-state/datastores") |
Václav Kubernát | cf9224f | 2020-06-02 09:55:29 +0200 | [diff] [blame] | 7 | for (k, v) in data: |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 8 | print(f"{k}: {type(v)} {v}", flush=True) |
| 9 | |
| 10 | if len(data) == 0: |
| 11 | print("ERROR: No data returned from NETCONF") |
| 12 | exit(1) |
| 13 | |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 14 | subscription = sr_sub.SysrepoSubscription("example-schema") |
| 15 | xpath = "/example-schema:leafInt32" |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 16 | for EXPECTED in (599, 59, "61"): |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 17 | c.setLeaf(xpath, EXPECTED) |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 18 | c.commitChanges() |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 19 | data = c.getItems(xpath) |
| 20 | (_, value) = next(filter(lambda keyValue: keyValue[0] == xpath, data)) |
Václav Kubernát | cf9224f | 2020-06-02 09:55:29 +0200 | [diff] [blame] | 21 | if value != EXPECTED: |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 22 | if isinstance(EXPECTED, str): |
Václav Kubernát | cf9224f | 2020-06-02 09:55:29 +0200 | [diff] [blame] | 23 | if str(value) != EXPECTED: |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 24 | print(f"ERROR: leafInt32 not updated (via string) to {EXPECTED}") |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 25 | exit(1) |
| 26 | else: |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 27 | print(f"ERROR: leafInt32 not updated to {EXPECTED}") |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 28 | exit(1) |
| 29 | try: |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 30 | c.setLeaf(xpath, "blesmrt") |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 31 | c.commitChanges() |
| 32 | print("ERROR: setting integer to a string did not error out") |
| 33 | exit(1) |
| 34 | except RuntimeError: |
| 35 | pass |
| 36 | |
| 37 | exit(0) |