Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 1 | """ |
| 2 | """ |
| 3 | import struct |
| 4 | |
| 5 | import logging |
| 6 | |
| 7 | from oftest import config |
| 8 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 9 | import ofp |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 10 | import oftest.base_tests as base_tests |
| 11 | |
| 12 | from oftest.testutils import * |
| 13 | |
| 14 | @nonstandard |
| 15 | class BSNShellCommand(base_tests.SimpleDataPlane): |
| 16 | """ |
| 17 | Exercise BSN vendor extension for running a shell command on the switch |
| 18 | """ |
| 19 | |
| 20 | def bsn_shell_command(self, cmd): |
| 21 | """ |
| 22 | Use the BSN_SHELL_COMMAND vendor command to run the given command |
| 23 | and receive the output |
| 24 | """ |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 25 | m = ofp.message.bsn_shell_command(service=0, data=cmd) |
| 26 | self.controller.message_send(m) |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 27 | out = "" |
| 28 | while True: |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 29 | m, _ = self.controller.poll(ofp.OFPT_VENDOR, 60) |
| 30 | if isinstance(m, ofp.message.bsn_shell_output): |
| 31 | out += m.data |
| 32 | elif isinstance(m, ofp.message.bsn_shell_status): |
| 33 | return m.status, out |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 34 | else: |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 35 | raise AssertionError("Unexpected message received") |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 36 | |
| 37 | def runTest(self): |
| 38 | status, out = self.bsn_shell_command("echo _one space_") |
| 39 | self.assertEqual(status, 0, "Shell command returned %s != 0" % status) |
| 40 | self.assertEqual(out, "_one space_\n", "Shell command output: '%r'" % out) |