GlennRC | b3202c5 | 2015-08-24 14:43:30 -0700 | [diff] [blame] | 1 | ''' |
| 2 | Wrapper functions for maxIntent |
| 3 | ''' |
| 4 | |
| 5 | import json |
| 6 | import time |
| 7 | |
| 8 | def __init__( self ): |
| 9 | self.default = "" |
| 10 | |
| 11 | def getIntents( main, state="INSTALLED", sleep=1, timeout=120 ): |
| 12 | cmd = "intents | grep " + state + " | wc -l" |
| 13 | main.log.info("Sending: " + cmd) |
| 14 | main.CLIs[0].handle.sendline(cmd) |
| 15 | |
| 16 | time.sleep(sleep) |
| 17 | |
| 18 | main.CLIs[0].handle.expect("onos>", timeout=timeout) |
| 19 | raw = main.CLIs[0].handle.before |
| 20 | intents = int(main.CLIs[0].handle.before.split()[7]) |
| 21 | main.log.info(state + "intents: " + str(intents)) |
| 22 | return intents |
| 23 | |
| 24 | |
| 25 | def getFlows( main, state="ADDED", sleep=1, timeout=120 ): |
| 26 | cmd = "flows | grep " + state + " | wc -l" |
| 27 | main.log.info("Sending: " + cmd) |
| 28 | main.CLIs[0].handle.sendline(cmd) |
| 29 | |
| 30 | time.sleep(sleep) |
| 31 | |
| 32 | main.CLIs[0].handle.expect("onos>", timeout=timeout) |
| 33 | raw = main.CLIs[0].handle.before |
| 34 | flows = int(main.CLIs[0].handle.before.split()[7]) |
| 35 | main.log.info(state + "flows: " + str(flows)) |
| 36 | return flows |
| 37 | |
| 38 | |
| 39 | def pushIntents( main, |
| 40 | switch, |
| 41 | ingress, |
| 42 | egress, |
| 43 | batch, |
| 44 | offset, |
| 45 | sleep=1, |
| 46 | options="", |
| 47 | timeout=120): |
| 48 | ''' |
| 49 | Description |
| 50 | ''' |
| 51 | cmd = "push-test-intents " + options + " " + switch + ingress + " " +\ |
| 52 | switch + egress + " " + str(batch) + " " + str(offset) |
| 53 | main.log.info("Installing " + str(offset+batch) + " intents") |
| 54 | main.log.debug("Sending: " + cmd) |
| 55 | main.CLIs[0].handle.sendline(cmd) |
| 56 | time.sleep(sleep) |
| 57 | main.CLIs[0].handle.expect("onos>", timeout=timeout) |
| 58 | |
| 59 | raw = main.CLIs[0].handle.before |
| 60 | if "Failure:" in raw or "GC" in raw: |
| 61 | return main.FALSE |
| 62 | return main.TRUE |
| 63 | |
| 64 | def verifyFlows( main, expectedFlows, state="ADDED", sleep=1, timeout=120): |
| 65 | ''' |
| 66 | This function returns main.TRUE if the number of expected flows are in |
| 67 | the specified state |
| 68 | |
| 69 | @params |
| 70 | expectedFlows: the flows you expect to see in the specified state |
| 71 | state: the state of the flow to check for |
| 72 | timeout: the timeout for pexpect |
| 73 | ''' |
| 74 | cmd = "flows | grep " + state + " | wc -l" |
| 75 | for i in range(10): |
| 76 | flows = getFlows( main, state, sleep, timeout ) |
| 77 | if expectedFlows == flows: |
| 78 | return main.TRUE |
| 79 | |
| 80 | return main.FALSE |
| 81 | |
| 82 | def verifyIntents( main, expectedIntents, state="INSTALLED", sleep=1, timeout=120): |
| 83 | ''' |
| 84 | This function returns main.TRUE if the number of expected intents are in |
| 85 | the specified state |
| 86 | |
| 87 | @params |
| 88 | expectedFlows: the intents you expect to see in the specified state |
| 89 | state: the state of the intent to check for |
| 90 | timeout: the timeout for pexpect |
| 91 | ''' |
| 92 | cmd = "intents | grep " + state + " | wc -l" |
| 93 | for i in range(10): |
| 94 | intents = getIntents( main, state, sleep, timeout ) |
| 95 | if expectedIntents == intents: |
| 96 | return main.TRUE |
| 97 | |
| 98 | return main.FALSE |