MCPcopy Create free account
hub / github.com/consensus-shipyard/ipc / remove

Method remove

fendermint/testing/materializer/src/docker/mod.rs:216–279  ·  view source on GitHub ↗

Remove all traces of a testnet.

(&mut self, testnet_name: &TestnetName)

Source from the content-addressed store, hash-verified

214
215 /// Remove all traces of a testnet.
216 pub async fn remove(&mut self, testnet_name: &TestnetName) -> anyhow::Result<()> {
217 let testnet = testnet_name.path_string();
218
219 let mut filters = HashMap::new();
220 filters.insert("label".to_string(), vec![format!("testnet={}", testnet)]);
221
222 let containers: Vec<ContainerSummary> = self
223 .docker
224 .list_containers(Some(ListContainersOptions {
225 all: true,
226 filters,
227 ..Default::default()
228 }))
229 .await
230 .context("failed to list docker containers")?;
231
232 let ids = containers.into_iter().filter_map(|c| c.id);
233
234 for id in ids {
235 eprintln!("removing docker container {id}");
236 self.docker
237 .remove_container(
238 &id,
239 Some(RemoveContainerOptions {
240 force: true,
241 v: true,
242 ..Default::default()
243 }),
244 )
245 .await
246 .with_context(|| format!("failed to remove container {id}"))?;
247 }
248
249 let mut filters = HashMap::new();
250 filters.insert("name".to_string(), vec![testnet]);
251
252 let networks: Vec<Network> = self
253 .docker
254 .list_networks(Some(ListNetworksOptions { filters }))
255 .await
256 .context("failed to list networks")?;
257
258 let ids = networks.into_iter().filter_map(|n| n.id);
259
260 for id in ids {
261 eprintln!("removing docker network {id}");
262 self.docker
263 .remove_network(&id)
264 .await
265 .context("failed to remove network")?;
266 }
267
268 let dir = self.dir.join(testnet_name.path());
269 if let Err(e) = fs::remove_dir_all(&dir) {
270 if !e.to_string().contains("No such file") {
271 bail!(
272 "failed to remove testnet directory {}: {e:?}",
273 dir.to_string_lossy()

Callers 3

updateMethod · 0.45
topo_sortFunction · 0.45
make_testnetFunction · 0.45

Calls 9

remove_dir_allFunction · 0.85
path_stringMethod · 0.80
to_stringMethod · 0.80
contextMethod · 0.80
with_contextMethod · 0.80
insertMethod · 0.45
joinMethod · 0.45
pathMethod · 0.45
containsMethod · 0.45

Tested by 3

updateMethod · 0.36
topo_sortFunction · 0.36
make_testnetFunction · 0.36