@@ -74,6 +74,7 @@ pub(crate) trait SerialConsoleStreamBuilder: Send {
7474 & mut self ,
7575 address : SocketAddr ,
7676 offset : WSClientOffset ,
77+ readonly : bool ,
7778 ) -> Result < Box < dyn SerialConsoleStream > , WSError > ;
7879}
7980
@@ -95,6 +96,7 @@ impl SerialConsoleStreamBuilder for PropolisSerialBuilder {
9596 & mut self ,
9697 address : SocketAddr ,
9798 offset : WSClientOffset ,
99+ readonly : bool ,
98100 ) -> Result < Box < dyn SerialConsoleStream > , WSError > {
99101 let client = PropolisClient :: new ( & format ! ( "http://{}" , address) ) ;
100102 let mut req = client. instance_serial ( ) ;
@@ -108,6 +110,7 @@ impl SerialConsoleStreamBuilder for PropolisSerialBuilder {
108110 }
109111 }
110112
113+ req = req. writable ( !readonly) ;
111114 let upgraded = req
112115 . send ( )
113116 . await
@@ -157,6 +160,7 @@ impl<St: SerialConsoleStream + 'static> SerialConsoleStreamBuilder
157160 // offset is currently unused by this builder. Worth testing in
158161 // the future.
159162 _offset : WSClientOffset ,
163+ _readonly : bool ,
160164 ) -> Result < Box < dyn SerialConsoleStream > , WSError > {
161165 if let Some ( ( delay, stream) ) =
162166 self . client_conns_and_delays . remove ( & address)
@@ -191,6 +195,7 @@ pub enum WSClientOffset {
191195pub struct InstanceSerialConsoleHelper {
192196 stream_builder : Box < dyn SerialConsoleStreamBuilder > ,
193197 ws_stream : WebSocketStream < Box < dyn SerialConsoleStream > > ,
198+ readonly : bool ,
194199 log : Option < Logger > ,
195200}
196201
@@ -202,10 +207,12 @@ impl InstanceSerialConsoleHelper {
202207 pub async fn new (
203208 address : SocketAddr ,
204209 offset : WSClientOffset ,
210+ readonly : bool ,
205211 log : Option < Logger > ,
206212 ) -> Result < Self , WSError > {
207213 let stream_builder = PropolisSerialBuilder :: new ( ) ;
208- Self :: new_with_builder ( stream_builder, address, offset, log) . await
214+ Self :: new_with_builder ( stream_builder, address, offset, readonly, log)
215+ . await
209216 }
210217
211218 /// Creates a new serial console helper for testing.
@@ -217,14 +224,16 @@ impl InstanceSerialConsoleHelper {
217224 connections : impl IntoIterator < Item = ( SocketAddr , St ) > ,
218225 address : SocketAddr ,
219226 offset : WSClientOffset ,
227+ readonly : bool ,
220228 log : Option < Logger > ,
221229 ) -> Result < Self , WSError > {
222230 let stream_builder = TestSerialBuilder :: new (
223231 connections
224232 . into_iter ( )
225233 . map ( |( addr, stream) | ( addr, Duration :: ZERO , stream) ) ,
226234 ) ;
227- Self :: new_with_builder ( stream_builder, address, offset, log) . await
235+ Self :: new_with_builder ( stream_builder, address, offset, readonly, log)
236+ . await
228237 }
229238
230239 /// Creates a new serial console helper for testing, with delays before
@@ -238,23 +247,31 @@ impl InstanceSerialConsoleHelper {
238247 connections : impl IntoIterator < Item = ( SocketAddr , Duration , St ) > ,
239248 address : SocketAddr ,
240249 offset : WSClientOffset ,
250+ readonly : bool ,
241251 log : Option < Logger > ,
242252 ) -> Result < Self , WSError > {
243253 let stream_builder = TestSerialBuilder :: new ( connections) ;
244- Self :: new_with_builder ( stream_builder, address, offset, log) . await
254+ Self :: new_with_builder ( stream_builder, address, offset, readonly, log)
255+ . await
245256 }
246257
247258 // Currently used for testing, and not exposed to clients.
248259 pub ( crate ) async fn new_with_builder (
249260 mut stream_builder : impl SerialConsoleStreamBuilder + ' static ,
250261 address : SocketAddr ,
251262 offset : WSClientOffset ,
263+ readonly : bool ,
252264 log : Option < Logger > ,
253265 ) -> Result < Self , WSError > {
254- let stream = stream_builder. build ( address, offset) . await ?;
266+ let stream = stream_builder. build ( address, offset, readonly ) . await ?;
255267 let ws_stream =
256268 WebSocketStream :: from_raw_socket ( stream, Role :: Client , None ) . await ;
257- Ok ( Self { stream_builder : Box :: new ( stream_builder) , ws_stream, log } )
269+ Ok ( Self {
270+ stream_builder : Box :: new ( stream_builder) ,
271+ ws_stream,
272+ readonly,
273+ log,
274+ } )
258275 }
259276
260277 /// Receives the next [WSMessage] from the server, holding it in
@@ -401,6 +418,7 @@ impl InstanceSerialConsoleMessage<'_> {
401418 . build (
402419 destination,
403420 WSClientOffset :: FromStart ( from_start) ,
421+ self . helper . readonly ,
404422 )
405423 . await ?;
406424 self . helper . ws_stream = WebSocketStream :: from_raw_socket (
@@ -463,6 +481,7 @@ mod test {
463481 [ ( address, client_conn) ] ,
464482 address,
465483 WSClientOffset :: FromStart ( 0 ) ,
484+ false ,
466485 None ,
467486 )
468487 . await
@@ -514,6 +533,7 @@ mod test {
514533 ] ,
515534 address_1,
516535 WSClientOffset :: FromStart ( 0 ) ,
536+ false ,
517537 None ,
518538 )
519539 . await
0 commit comments