(&self, tmp_dir: &TempDir, network: &GuestNetworkConfig)
| 440 | |
| 441 | impl DiskConfig for UbuntuDiskConfig { |
| 442 | fn prepare_cloudinit(&self, tmp_dir: &TempDir, network: &GuestNetworkConfig) -> String { |
| 443 | let cloudinit_file_path = |
| 444 | String::from(tmp_dir.as_path().join("cloudinit").to_str().unwrap()); |
| 445 | |
| 446 | let cloud_init_directory = tmp_dir.as_path().join("cloud-init").join("ubuntu"); |
| 447 | |
| 448 | fs::create_dir_all(&cloud_init_directory) |
| 449 | .expect("Expect creating cloud-init directory to succeed"); |
| 450 | |
| 451 | let source_file_dir = workspace_root() |
| 452 | .join("test_data") |
| 453 | .join("cloud-init") |
| 454 | .join("ubuntu") |
| 455 | .join("ci"); |
| 456 | |
| 457 | ["meta-data"].iter().for_each(|x| { |
| 458 | let source_file = source_file_dir.join(x); |
| 459 | let cloud_init = cloud_init_directory.join(x); |
| 460 | rate_limited_copy(source_file, cloud_init) |
| 461 | .expect("Expect copying cloud-init meta-data to succeed"); |
| 462 | }); |
| 463 | |
| 464 | let mut user_data_string = String::new(); |
| 465 | fs::File::open(source_file_dir.join("user-data")) |
| 466 | .unwrap() |
| 467 | .read_to_string(&mut user_data_string) |
| 468 | .expect("Expected reading user-data file to succeed"); |
| 469 | user_data_string = user_data_string.replace( |
| 470 | "@DEFAULT_TCP_LISTENER_MESSAGE", |
| 471 | DEFAULT_TCP_LISTENER_MESSAGE, |
| 472 | ); |
| 473 | user_data_string = user_data_string.replace("@NOTIFY_IP", &network.notify_ip); |
| 474 | user_data_string = |
| 475 | user_data_string.replace("@TCP_LISTENER_PORT", &network.tcp_listener_port.to_string()); |
| 476 | |
| 477 | fs::File::create(cloud_init_directory.join("user-data")) |
| 478 | .unwrap() |
| 479 | .write_all(user_data_string.as_bytes()) |
| 480 | .expect("Expected writing out user-data to succeed"); |
| 481 | |
| 482 | let mut network_config_string = String::new(); |
| 483 | |
| 484 | fs::File::open(source_file_dir.join("network-config")) |
| 485 | .unwrap() |
| 486 | .read_to_string(&mut network_config_string) |
| 487 | .expect("Expected reading network-config file to succeed"); |
| 488 | |
| 489 | network_config_string = network_config_string.replace("192.168.2.1", &network.host_ip0); |
| 490 | network_config_string = network_config_string.replace("192.168.2.2", &network.guest_ip0); |
| 491 | network_config_string = network_config_string.replace("192.168.2.129", &network.host_ip1); |
| 492 | network_config_string = network_config_string.replace("192.168.2.130", &network.guest_ip1); |
| 493 | network_config_string = network_config_string.replace("192.168.2.3", &network.l2_guest_ip1); |
| 494 | network_config_string = network_config_string.replace("192.168.2.4", &network.l2_guest_ip2); |
| 495 | network_config_string = network_config_string.replace("192.168.2.5", &network.l2_guest_ip3); |
| 496 | network_config_string = |
| 497 | network_config_string.replace("12:34:56:78:90:ab", &network.guest_mac0); |
| 498 | network_config_string = |
| 499 | network_config_string.replace("de:ad:be:ef:78:90", &network.guest_mac1); |
no test coverage detected