Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 17 | """ |
| 18 | """ |
| 19 | import struct |
| 20 | |
| 21 | import logging |
| 22 | |
| 23 | from oftest import config |
| 24 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 25 | import ofp |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 26 | import oftest.base_tests as base_tests |
| 27 | |
| 28 | from oftest.testutils import * |
| 29 | |
| 30 | @nonstandard |
| 31 | class BSNShellCommand(base_tests.SimpleDataPlane): |
| 32 | """ |
| 33 | Exercise BSN vendor extension for running a shell command on the switch |
| 34 | """ |
| 35 | |
| 36 | def bsn_shell_command(self, cmd): |
| 37 | """ |
| 38 | Use the BSN_SHELL_COMMAND vendor command to run the given command |
| 39 | and receive the output |
| 40 | """ |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 41 | m = ofp.message.bsn_shell_command(service=0, data=cmd) |
| 42 | self.controller.message_send(m) |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 43 | out = "" |
| 44 | while True: |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 45 | m, _ = self.controller.poll(ofp.OFPT_VENDOR, 60) |
| 46 | if isinstance(m, ofp.message.bsn_shell_output): |
| 47 | out += m.data |
| 48 | elif isinstance(m, ofp.message.bsn_shell_status): |
| 49 | return m.status, out |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 50 | else: |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 51 | raise AssertionError("Unexpected message received") |
Ed Swierk | 277875a | 2013-01-08 15:13:46 -0800 | [diff] [blame] | 52 | |
| 53 | def runTest(self): |
| 54 | status, out = self.bsn_shell_command("echo _one space_") |
| 55 | self.assertEqual(status, 0, "Shell command returned %s != 0" % status) |
| 56 | self.assertEqual(out, "_one space_\n", "Shell command output: '%r'" % out) |