@@ -1981,6 +1981,106 @@ def test_compose_1so_namedvolumes(self):
19811981 # Check Splunkd on all the containers
19821982 assert self .check_splunkd ("admin" , self .password )
19831983
1984+ def test_compose_1deployment1cm (self ):
1985+ # Tar the app before spinning up the scenario
1986+ with tarfile .open (EXAMPLE_APP_TGZ , "w:gz" ) as tar :
1987+ tar .add (EXAMPLE_APP , arcname = os .path .basename (EXAMPLE_APP ))
1988+
1989+ # Generate default.yml
1990+ cid = self .client .create_container (self .SPLUNK_IMAGE_NAME , tty = True , command = "create-defaults" )
1991+ self .client .start (cid .get ("Id" ))
1992+ output = self .get_container_logs (cid .get ("Id" ))
1993+ self .client .remove_container (cid .get ("Id" ), v = True , force = True )
1994+ # Add a custom conf file
1995+ output = re .sub (r' group: splunk' , r''' group: splunk
1996+ conf:
1997+ - key: user-prefs
1998+ value:
1999+ directory: /opt/splunk/etc/users/admin/user-prefs/local
2000+ content:
2001+ general:
2002+ default_namespace: appboilerplate
2003+ search_syntax_highlighting: dark
2004+ search_assistant:
2005+ "serverClass:secrets:app:test": {}''' , output )
2006+ # Write the default.yml to a file
2007+ with open (os .path .join (SCENARIOS_DIR , "defaults" , "default.yml" ), "w" ) as f :
2008+ f .write (output )
2009+ # Standup deployment
2010+ try :
2011+ self .compose_file_name = "1deployment1cm.yaml"
2012+ self .project_name = generate_random_string ()
2013+ container_count , rc = self .compose_up ()
2014+ assert rc == 0
2015+ # Wait for containers to come up
2016+ assert self .wait_for_containers (container_count , label = "com.docker.compose.project={}" .format (self .project_name ))
2017+ # Get container logs
2018+ container_mapping = {"cm1" : "cm" , "depserver1" : "deployment_server" }
2019+ for container in container_mapping :
2020+ # Check ansible version & configs
2021+ ansible_logs = self .get_container_logs (container )
2022+ self .check_ansible (ansible_logs )
2023+ # Check values in log output
2024+ inventory_json = self .extract_json (container )
2025+ self .check_common_keys (inventory_json , container_mapping [container ])
2026+ # Check Splunkd on all the containers
2027+ assert self .check_splunkd ("admin" , self .password )
2028+ # Make sure apps are installed and certain subdirectories are excluded
2029+ containers = self .client .containers (filters = {"label" : "com.docker.compose.project={}" .format (self .project_name )})
2030+ assert len (containers ) == 3
2031+ for container in containers :
2032+ # Skip the nginx container
2033+ if "nginx" in container ["Image" ]:
2034+ continue
2035+ container_name = container ["Names" ][0 ].strip ("/" )
2036+ splunkd_port = self .client .port (container ["Id" ], 8089 )[0 ]["HostPort" ]
2037+ if container_name == "depserver1" :
2038+ # Check the app and version
2039+ url = "https://localhost:{}/servicesNS/nobody/splunk_app_example/configs/conf-app/launcher?output_mode=json" .format (splunkd_port )
2040+ resp = requests .get (url , auth = ("admin" , self .password ), verify = False )
2041+ # Deployment server should *not* install the app
2042+ assert resp .status_code == 404
2043+ # Check that the app exists in etc/apps
2044+ exec_command = self .client .exec_create (container ["Id" ], "ls /opt/splunk/etc/apps/splunk_app_example/local/" , user = "splunk" )
2045+ std_out = self .client .exec_start (exec_command )
2046+ assert "savedsearches.conf" in std_out
2047+ # Check that the app exists in etc/deployment-apps
2048+ exec_command = self .client .exec_create (container ["Id" ], "ls /opt/splunk/etc/deployment-apps/splunk_app_example/local/" , user = "splunk" )
2049+ std_out = self .client .exec_start (exec_command )
2050+ assert "savedsearches.conf" not in std_out
2051+ if container_name == "cm1" :
2052+ # Check if the created file exists
2053+ exec_command = self .client .exec_create (container ["Id" ], "cat /opt/splunk/etc/users/admin/user-prefs/local/user-prefs.conf" , user = "splunk" )
2054+ std_out = self .client .exec_start (exec_command )
2055+ assert "[serverClass:secrets:app:test]" in std_out
2056+ assert "[general]" in std_out
2057+ assert "default_namespace = appboilerplate" in std_out
2058+ assert "search_syntax_highlighting = dark" in std_out
2059+ assert "search_assistant" in std_out
2060+ RETRIES = 5
2061+ for i in range (RETRIES ):
2062+ try :
2063+ # Check the app and version
2064+ url = "https://localhost:{}/servicesNS/nobody/splunk_app_example/configs/conf-app/launcher?output_mode=json" .format (splunkd_port )
2065+ kwargs = {"auth" : ("admin" , self .password ), "verify" : False }
2066+ status , content = self .handle_request_retry ("GET" , url , kwargs )
2067+ assert status == 200
2068+ assert json .loads (content )["entry" ][0 ]["content" ]["version" ] == "0.0.1"
2069+ except Exception as e :
2070+ self .logger .error (e )
2071+ if i < RETRIES - 1 :
2072+ time .sleep (30 )
2073+ continue
2074+ raise e
2075+ except Exception as e :
2076+ self .logger .error (e )
2077+ raise e
2078+ finally :
2079+ try :
2080+ os .remove (EXAMPLE_APP_TGZ )
2081+ except OSError as e :
2082+ pass
2083+
19842084 def test_compose_1deployment1so (self ):
19852085 # Tar the app before spinning up the scenario
19862086 with tarfile .open (EXAMPLE_APP_TGZ , "w:gz" ) as tar :
0 commit comments