MCPcopy Create free account
hub / github.com/ChainSafe/Delorean-Protocol / remove

Method remove

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

Remove all traces of a testnet.

(&mut self, testnet_name: &TestnetName)

Source from the content-addressed store, hash-verified

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

Callers 3

updateMethod · 0.45
topo_sortFunction · 0.45
with_testnetFunction · 0.45

Calls 8

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
with_testnetFunction · 0.36