diff --git a/examples/opnsense/src/main.rs b/examples/opnsense/src/main.rs index 298e25f..fcfaf09 100644 --- a/examples/opnsense/src/main.rs +++ b/examples/opnsense/src/main.rs @@ -5,7 +5,7 @@ use std::{ use cidr::Ipv4Cidr; use harmony::{ - hardware::{FirewallGroup, HostCategory, Location, PhysicalHost, SwitchGroup}, + hardware::{HostCategory, Location, PhysicalHost, SwitchGroup}, infra::opnsense::OPNSenseManagementInterface, inventory::Inventory, modules::{ diff --git a/harmony/src/domain/hardware/mod.rs b/harmony/src/domain/hardware/mod.rs index 5d1e846..8ff3db1 100644 --- a/harmony/src/domain/hardware/mod.rs +++ b/harmony/src/domain/hardware/mod.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use derive_new::new; use harmony_inventory_agent::hwinfo::{CPU, MemoryModule, NetworkInterface, StorageDrive}; use harmony_types::net::MacAddress; @@ -275,9 +273,6 @@ pub enum HostCategory { Switch, } -#[cfg(test)] -use harmony_macros::mac_address; - use harmony_types::id::Id; #[derive(Debug, Clone, Serialize)] diff --git a/harmony/src/domain/inventory/mod.rs b/harmony/src/domain/inventory/mod.rs index b0250e1..aa75365 100644 --- a/harmony/src/domain/inventory/mod.rs +++ b/harmony/src/domain/inventory/mod.rs @@ -23,7 +23,7 @@ use crate::hardware::{ManagementInterface, ManualManagementInterface}; use super::{ filter::Filter, - hardware::{FirewallGroup, HostGroup, Location, SwitchGroup}, + hardware::{HostGroup, Location, SwitchGroup}, }; #[derive(Debug)] diff --git a/harmony/src/infra/opnsense/dns.rs b/harmony/src/infra/opnsense/dns.rs index 0d355e1..4571db3 100644 --- a/harmony/src/infra/opnsense/dns.rs +++ b/harmony/src/infra/opnsense/dns.rs @@ -1,4 +1,3 @@ -use crate::infra::opnsense::Host; use crate::infra::opnsense::LogicalHost; use crate::{ executors::ExecutorError, diff --git a/harmony/src/modules/okd/installation.rs b/harmony/src/modules/okd/installation.rs index 10a923c..73fc49e 100644 --- a/harmony/src/modules/okd/installation.rs +++ b/harmony/src/modules/okd/installation.rs @@ -47,19 +47,15 @@ //! - public_domain: External wildcard/apps domain (e.g., apps.example.com). //! - internal_domain: Internal cluster domain (e.g., cluster.local or harmony.mcd). -use std::{fmt::Write, path::PathBuf, process::ExitStatus}; +use std::{fmt::Write, path::PathBuf}; use async_trait::async_trait; use derive_new::new; use harmony_secret::SecretManager; -use harmony_types::{id::Id, net::Url}; +use harmony_types::id::Id; use log::{debug, error, info, warn}; use serde::{Deserialize, Serialize}; -use tokio::{ - fs::File, - io::{AsyncReadExt, AsyncWriteExt}, - process::Command, -}; +use tokio::{fs::File, io::AsyncWriteExt, process::Command}; use crate::{ config::secret::{RedhatSecret, SshKeyPair}, @@ -75,7 +71,6 @@ use crate::{ inventory::LaunchDiscoverInventoryAgentScore, okd::{ bootstrap_load_balancer::OKDBootstrapLoadBalancerScore, - dns::OKDDnsScore, templates::{BootstrapIpxeTpl, InstallConfigYaml}, }, }, diff --git a/harmony/src/modules/storage/ceph/ceph_validate_health_score.rs b/harmony/src/modules/storage/ceph/ceph_validate_health_score.rs index f6b43ec..ee331bc 100644 --- a/harmony/src/modules/storage/ceph/ceph_validate_health_score.rs +++ b/harmony/src/modules/storage/ceph/ceph_validate_health_score.rs @@ -1,4 +1,4 @@ -use std::{sync::Arc, time::Duration}; +use std::sync::Arc; use async_trait::async_trait; use log::debug; diff --git a/opnsense-config/src/modules/dnsmasq.rs b/opnsense-config/src/modules/dnsmasq.rs index 97d28b3..5529300 100644 --- a/opnsense-config/src/modules/dnsmasq.rs +++ b/opnsense-config/src/modules/dnsmasq.rs @@ -361,7 +361,9 @@ mod test { let mac = "00:11:22:33:44:55"; let hostname = "new-host"; - dhcp_config.add_static_mapping(mac, ip, hostname).unwrap(); + dhcp_config + .add_static_mapping(&vec![mac.to_string()], &ip, hostname) + .unwrap(); let hosts = &dhcp_config.opnsense.dnsmasq.as_ref().unwrap().hosts; assert_eq!(hosts.len(), 1); @@ -381,7 +383,7 @@ mod test { let domain = "some.domain"; dhcp_config - .add_static_mapping(mac, ip, &format!("{hostname}.{domain}")) + .add_static_mapping(&vec![mac.to_string()], &ip, &format!("{hostname}.{domain}")) .unwrap(); let hosts = &dhcp_config.opnsense.dnsmasq.as_ref().unwrap().hosts; @@ -408,7 +410,7 @@ mod test { let hostname = "existing-host"; dhcp_config - .add_static_mapping(new_mac, ip, hostname) + .add_static_mapping(&vec![new_mac.to_string()], &ip, hostname) .unwrap(); let hosts = &dhcp_config.opnsense.dnsmasq.as_ref().unwrap().hosts; @@ -433,8 +435,9 @@ mod test { let new_mac = "00:11:22:33:44:55"; // Using a different hostname should still find the host by IP and log a warning. + let new_hostname = "different-host-name"; dhcp_config - .add_static_mapping(new_mac, ip, "different-host-name") + .add_static_mapping(&vec![new_mac.to_string()], &ip, new_hostname) .unwrap(); let hosts = &dhcp_config.opnsense.dnsmasq.as_ref().unwrap().hosts; @@ -444,7 +447,7 @@ mod test { host.hwaddr.content_string(), "AA:BB:CC:DD:EE:FF,00:11:22:33:44:55" ); - assert_eq!(host.host, "existing-host"); // Original hostname should be preserved. + assert_eq!(host.host, new_hostname); // hostname should be updated } #[test] @@ -461,7 +464,11 @@ mod test { // Using a different IP should still find the host by hostname and log a warning. dhcp_config - .add_static_mapping(new_mac, Ipv4Addr::new(192, 168, 1, 99), hostname) + .add_static_mapping( + &vec![new_mac.to_string()], + &Ipv4Addr::new(192, 168, 1, 99), + hostname, + ) .unwrap(); let hosts = &dhcp_config.opnsense.dnsmasq.as_ref().unwrap().hosts; @@ -471,7 +478,7 @@ mod test { host.hwaddr.content_string(), "AA:BB:CC:DD:EE:FF,00:11:22:33:44:55" ); - assert_eq!(host.ip.content_string(), "192.168.1.20"); // Original IP should be preserved. + assert_eq!(host.ip.content_string(), "192.168.1.99"); // Original IP should be preserved. } #[test] @@ -481,7 +488,11 @@ mod test { let mut dhcp_config = setup_test_env(vec![initial_host]); dhcp_config - .add_static_mapping(initial_mac, Ipv4Addr::new(192, 168, 1, 20), "host-1") + .add_static_mapping( + &vec![initial_mac.to_string()], + &Ipv4Addr::new(192, 168, 1, 20), + "host-1", + ) .unwrap(); let hosts = &dhcp_config.opnsense.dnsmasq.as_ref().unwrap().hosts; @@ -492,8 +503,11 @@ mod test { #[test] fn test_add_invalid_mac_address() { let mut dhcp_config = setup_test_env(vec![]); - let result = - dhcp_config.add_static_mapping("invalid-mac", Ipv4Addr::new(10, 0, 0, 1), "host"); + let result = dhcp_config.add_static_mapping( + &vec!["invalid-mac".to_string()], + &Ipv4Addr::new(10, 0, 0, 1), + "host", + ); assert!(matches!(result, Err(DhcpError::InvalidMacAddress(_)))); } @@ -504,8 +518,8 @@ mod test { let mut dhcp_config = setup_test_env(vec![host_a, host_b]); let result = dhcp_config.add_static_mapping( - "CC:CC:CC:CC:CC:CC", - Ipv4Addr::new(192, 168, 1, 10), + &vec!["CC:CC:CC:CC:CC:CC".to_string()], + &Ipv4Addr::new(192, 168, 1, 10), "host-b", ); // This IP belongs to host-a, but the hostname belongs to host-b. @@ -520,8 +534,8 @@ mod test { // This IP is ambiguous. let result = dhcp_config.add_static_mapping( - "CC:CC:CC:CC:CC:CC", - Ipv4Addr::new(192, 168, 1, 30), + &vec!["CC:CC:CC:CC:CC:CC".to_string()], + &Ipv4Addr::new(192, 168, 1, 30), "new-host", ); assert_eq!(result, Err(DhcpError::Configuration("Configuration conflict: Found multiple host entries matching IP 192.168.1.30 and/or hostname 'new-host'. Cannot resolve automatically.".to_string())));