@@ -24,7 +24,20 @@ impl HaEnvironment {
2424 pub fn new_ha ( test_id : String , agent_binary_path : & str , manager_binary_path : & str ) -> Self {
2525 let ports = get_ports ( ) ;
2626 let env = TestEnvironment :: new ( "ha" , & test_id, agent_binary_path, manager_binary_path) ;
27- let config = ha_config ( ports, test_id. clone ( ) ) ;
27+ let config = ha_config ( ports, & test_id) ;
28+ env. write_out_config ( & config) ;
29+ Self {
30+ env,
31+ test_id,
32+ ports,
33+ config,
34+ }
35+ }
36+
37+ pub fn new_shared ( test_id : String , agent_binary_path : & str , manager_binary_path : & str ) -> Self {
38+ let ports = get_ports ( ) ;
39+ let env = TestEnvironment :: new ( "shared" , & test_id, agent_binary_path, manager_binary_path) ;
40+ let config = shared_config ( ports, & test_id) ;
2841 env. write_out_config ( & config) ;
2942 Self {
3043 env,
@@ -146,7 +159,7 @@ impl HaEnvironment {
146159 . unwrap ( ) ;
147160 }
148161
149- fn get_status ( & self ) -> http:: ClusterJson {
162+ pub fn get_status ( & self ) -> http:: ClusterJson {
150163 let status = commands:: status:: get_status ( Some ( & self . socket_path ( ) ) ) . unwrap ( ) ;
151164 eprintln ! ( "{status:?}" ) ;
152165 status
@@ -334,6 +347,16 @@ impl Drop for HaEnvironment {
334347 /// is, started on both hosts in a pair.
335348 fn drop ( & mut self ) {
336349 for resource in self . config . resources . iter ( ) {
350+ // The following resource types are not exclusive and are allowed to be double-started.
351+ // XXX: Come up with a more robust way to detect this in arbitrary configs rather than
352+ // just hard-coding this list?
353+ if matches ! (
354+ resource. kind. as_str( ) ,
355+ "heartbeat/route" | "heartbeat/filesystem" | "heartbeat/export"
356+ ) {
357+ continue ;
358+ }
359+
337360 if self . env . resource_is_started ( resource, 0 )
338361 && self . env . resource_is_started ( resource, 1 )
339362 {
@@ -344,7 +367,7 @@ impl Drop for HaEnvironment {
344367}
345368
346369/// Creates an HA-pair config for use in the ha tests.
347- fn ha_config ( ports : [ u16 ; 2 ] , test_id : String ) -> Config {
370+ fn ha_config ( ports : [ u16 ; 2 ] , test_id : & str ) -> Config {
348371 let mut config = Config {
349372 hosts : Vec :: new ( ) ,
350373 resources : Vec :: new ( ) ,
@@ -399,3 +422,41 @@ fn ha_config(ports: [u16; 2], test_id: String) -> Config {
399422
400423 config
401424}
425+
426+ fn shared_config ( ports : [ u16 ; 2 ] , test_id : & str ) -> Config {
427+ let path = test_path ( "configs/nfs.yaml" ) ;
428+ let config = std:: fs:: read_to_string ( path) . unwrap ( ) ;
429+
430+ // Use the existing NFS example config...
431+ let mut config: Config = serde_yaml:: from_str ( & config) . unwrap ( ) ;
432+ // ...but the hosts and resource groups need to be fixed up to reference the specific test
433+ // ports. so strip them out, just keeping the resources.
434+ std:: mem:: take ( & mut config. hosts ) ;
435+ std:: mem:: take ( & mut config. resource_groups ) ;
436+
437+ for ( i, port) in ports. iter ( ) . enumerate ( ) {
438+ let my_hostname = || -> String { format ! ( "127.0.0.1:{}" , port) } ;
439+ let partner_hostname =
440+ || -> String { format ! ( "127.0.0.1:{}" , if i == 0 { ports[ 1 ] } else { ports[ 0 ] } ) } ;
441+
442+ let host = config:: Host {
443+ hostname : my_hostname ( ) ,
444+ fence_agent : Some ( "fence_test" . to_string ( ) ) ,
445+ fence_parameters : Some ( HashMap :: from ( [
446+ ( "target" . to_string ( ) , format ! ( "{test_id}_{i}" ) ) ,
447+ ( "test_id" . to_string ( ) , format ! ( "shared/{test_id}" ) ) ,
448+ ] ) ) ,
449+ } ;
450+
451+ let resource_group = config:: ResourceGroup {
452+ home_host : my_hostname ( ) ,
453+ failover_hosts : vec ! [ partner_hostname( ) ] ,
454+ root : format ! ( "ip_addr_{i}" ) ,
455+ } ;
456+
457+ config. hosts . push ( host) ;
458+ config. resource_groups . push ( resource_group) ;
459+ }
460+
461+ config
462+ }
0 commit comments