Skip to content

Commit 912a002

Browse files
committed
client: make phd and cli read-write by default
1 parent dd6693c commit 912a002

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

bin/propolis-cli/src/main.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ enum Command {
125125
/// Defaults to the most recent 16 KiB of console output (-16384).
126126
#[clap(long, short)]
127127
byte_offset: Option<i64>,
128+
129+
/// True if the serial console connection should be read-only.
130+
#[clap(long, action)]
131+
readonly: bool,
128132
},
129133

130134
/// Migrate instance to new propolis-server
@@ -604,9 +608,11 @@ async fn stdin_to_websockets_task(
604608
async fn serial(
605609
addr: SocketAddr,
606610
byte_offset: Option<i64>,
611+
readonly: bool,
607612
log: Logger,
608613
) -> anyhow::Result<()> {
609-
let mut ws_console = serial_connect(addr, byte_offset, log).await?;
614+
let mut ws_console =
615+
serial_connect(addr, byte_offset, readonly, log).await?;
610616

611617
let _raw_guard = RawTermiosGuard::stdio_guard()
612618
.with_context(|| anyhow!("failed to set raw mode"))?;
@@ -699,6 +705,7 @@ async fn serial(
699705
async fn serial_connect(
700706
addr: SocketAddr,
701707
byte_offset: Option<i64>,
708+
readonly: bool,
702709
log: Logger,
703710
) -> anyhow::Result<InstanceSerialConsoleHelper> {
704711
let offset = match byte_offset {
@@ -707,7 +714,8 @@ async fn serial_connect(
707714
None => WSClientOffset::MostRecent(16384),
708715
};
709716

710-
Ok(InstanceSerialConsoleHelper::new(addr, offset, Some(log)).await?)
717+
Ok(InstanceSerialConsoleHelper::new(addr, offset, readonly, Some(log))
718+
.await?)
711719
}
712720

713721
async fn migrate_instance(
@@ -914,8 +922,8 @@ async fn main() -> anyhow::Result<()> {
914922
}
915923
Command::Get => get_instance(&client).await?,
916924
Command::State { state } => put_instance(&client, state).await?,
917-
Command::Serial { byte_offset } => {
918-
serial(addr, byte_offset, log).await?
925+
Command::Serial { byte_offset, readonly } => {
926+
serial(addr, byte_offset, readonly, log).await?
919927
}
920928
Command::Migrate { dst_server, dst_port, dst_uuid, crucible_disks } => {
921929
let dst_addr = SocketAddr::new(dst_server, dst_port);

lib/propolis-client/src/support.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -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 {
191195
pub 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

phd-tests/framework/src/test_vm/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ impl TestVm {
349349
.server_addr(),
350350
),
351351
WSClientOffset::MostRecent(0),
352+
false,
352353
None,
353354
)
354355
.await?;

0 commit comments

Comments
 (0)