blob: 2ac2f08d68f1c35c6de6fbc2a52b13a71dda128e [file] [log] [blame]
Ed Swierk277875a2013-01-08 15:13:46 -08001"""
2"""
3import struct
4
5import logging
6
7from oftest import config
8import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -08009import ofp
Ed Swierk277875a2013-01-08 15:13:46 -080010import oftest.base_tests as base_tests
11
12from oftest.testutils import *
13
14@nonstandard
15class 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 Lane4b601452013-03-11 23:37:06 -070025 m = ofp.message.bsn_shell_command(service=0, data=cmd)
26 self.controller.message_send(m)
Ed Swierk277875a2013-01-08 15:13:46 -080027 out = ""
28 while True:
Rich Lane4b601452013-03-11 23:37:06 -070029 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 Swierk277875a2013-01-08 15:13:46 -080034 else:
Rich Lane4b601452013-03-11 23:37:06 -070035 raise AssertionError("Unexpected message received")
Ed Swierk277875a2013-01-08 15:13:46 -080036
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)