11use crate :: agent_control:: config_repository:: store:: AgentControlConfigStore ;
2- use crate :: agent_control:: defaults:: {
3- AGENT_CONTROL_DATA_DIR , AGENT_CONTROL_LOCAL_DATA_DIR , SUB_AGENT_DIR ,
4- } ;
2+ use crate :: agent_control:: defaults:: { AGENT_CONTROL_DATA_DIR , AGENT_CONTROL_LOCAL_DATA_DIR } ;
53use crate :: agent_type:: agent_type_id:: AgentTypeID ;
64use crate :: cli:: error:: CliError ;
75use crate :: cli:: on_host:: config_gen:: region:: Region ;
@@ -97,8 +95,7 @@ impl InfraConfigGenerator {
9795 } ;
9896
9997 for ( agent_id, _) in sub_agents_cfg. agents {
100- let infra_values_persister =
101- ValuesPersisterFile :: new ( self . local_dir . join ( SUB_AGENT_DIR ) ) ;
98+ let infra_values_persister = ValuesPersisterFile :: new ( self . local_dir . clone ( ) ) ;
10299 infra_values_persister
103100 . persist_values_file (
104101 & agent_id,
@@ -126,7 +123,7 @@ impl InfraConfigGenerator {
126123 let config_migrator = ConfigMigrator :: new (
127124 ConfigConverter :: default ( ) ,
128125 AgentConfigGetter :: new ( sa_local_config_loader) ,
129- ValuesPersisterFile :: new ( self . local_dir . join ( SUB_AGENT_DIR ) ) ,
126+ ValuesPersisterFile :: new ( self . local_dir . clone ( ) ) ,
130127 ) ;
131128
132129 let legacy_config_renamer = LegacyConfigRenamer :: default ( ) ;
@@ -169,7 +166,12 @@ impl InfraConfigGenerator {
169166#[ cfg( test) ]
170167mod tests {
171168 use super :: * ;
169+ use crate :: agent_control:: defaults:: {
170+ AGENT_CONTROL_ID , FOLDER_NAME_LOCAL_DATA , STORE_KEY_LOCAL_DATA_CONFIG ,
171+ } ;
172+ use crate :: opamp:: instance_id:: on_host:: storer:: build_config_name;
172173 use std:: fs;
174+ use std:: fs:: create_dir_all;
173175 use tempfile:: TempDir ;
174176
175177 const INITIAL_INFRA_CONFIG : & str = r#"
@@ -187,20 +189,27 @@ agents:
187189 agent_type: "newrelic/com.newrelic.infrastructure:0.1.0"
188190"# ;
189191
190- const INFRA_AGENT_VALUES : & str = "fleet/agents.d/ infra-test/values/values .yaml" ;
192+ const INFRA_AGENT_VALUES : & str = "local-data/ infra-test/local_config .yaml" ;
191193
192194 #[ cfg( target_family = "unix" ) ] //TODO This should be removed when Windows support is added (DirectoryManager unimplemented)
193195 #[ test]
194196 fn test_migrate_old_infra_config ( ) {
195197 // Create a temporary directory
196198 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
197199 let infra_file_path = temp_dir. path ( ) . join ( "newrelic-infra.yml" ) ;
198- let agents_file_path = temp_dir. path ( ) . join ( "config.yaml" ) ;
199-
200+ let agents_file_path = temp_dir
201+ . path ( )
202+ . join ( FOLDER_NAME_LOCAL_DATA )
203+ . join ( AGENT_CONTROL_ID ) ;
204+ create_dir_all ( & agents_file_path) . unwrap ( ) ;
200205 // Emulate the existence of the file by creating it
201206 fs:: write ( & infra_file_path, INITIAL_INFRA_CONFIG ) . unwrap ( ) ;
202207
203- fs:: write ( & agents_file_path, AGENTS_CONFIG ) . unwrap ( ) ;
208+ fs:: write (
209+ agents_file_path. join ( build_config_name ( STORE_KEY_LOCAL_DATA_CONFIG ) ) ,
210+ AGENTS_CONFIG ,
211+ )
212+ . unwrap ( ) ;
204213
205214 // Format the string using dynamic file path
206215 let config_mapping = format ! (
@@ -256,9 +265,17 @@ config_agent:
256265 #[ test]
257266 fn test_generate_new_infra_config ( ) {
258267 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
259- let agents_file_path = temp_dir. path ( ) . join ( "config.yaml" ) ;
260-
261- fs:: write ( & agents_file_path, AGENTS_CONFIG ) . unwrap ( ) ;
268+ let agents_file_path = temp_dir
269+ . path ( )
270+ . join ( FOLDER_NAME_LOCAL_DATA )
271+ . join ( AGENT_CONTROL_ID ) ;
272+ create_dir_all ( & agents_file_path) . unwrap ( ) ;
273+
274+ fs:: write (
275+ agents_file_path. join ( build_config_name ( STORE_KEY_LOCAL_DATA_CONFIG ) ) ,
276+ AGENTS_CONFIG ,
277+ )
278+ . unwrap ( ) ;
262279
263280 let infra_config_generator = InfraConfigGenerator :: new (
264281 temp_dir. path ( ) . to_path_buf ( ) ,
0 commit comments