blob: ed388f7be36324cc2500ee001b49fc687b9b1f32 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Swierk277875a2013-01-08 15:13:46 -080017"""
18"""
19import struct
20
21import logging
22
23from oftest import config
24import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -080025import ofp
Ed Swierk277875a2013-01-08 15:13:46 -080026import oftest.base_tests as base_tests
27
28from oftest.testutils import *
29
30@nonstandard
31class 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 Lane4b601452013-03-11 23:37:06 -070041 m = ofp.message.bsn_shell_command(service=0, data=cmd)
42 self.controller.message_send(m)
Ed Swierk277875a2013-01-08 15:13:46 -080043 out = ""
44 while True:
Rich Lane4b601452013-03-11 23:37:06 -070045 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 Swierk277875a2013-01-08 15:13:46 -080050 else:
Rich Lane4b601452013-03-11 23:37:06 -070051 raise AssertionError("Unexpected message received")
Ed Swierk277875a2013-01-08 15:13:46 -080052
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)