@@ -126,30 +126,6 @@ def test_load_only_index_patterns(self):
126126
127127 assert self .log_contains ("Kibana dashboards successfully loaded" ) is True
128128
129- @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
130- @pytest .mark .tag ('integration' )
131- def test_export_dashboard_cmd_export_dashboard_by_id_and_decoding (self ):
132- """
133- Test testbeat export dashboard can export dashboards
134- and removes unsupported characters
135- """
136- self .render_config_template ()
137- self .test_load_dashboard ()
138- beat = self .start_beat (
139- logging_args = ["-e" , "-d" , "*" ],
140- extra_args = ["export" ,
141- "dashboard" ,
142- "-E" , "setup.kibana.protocol=http" ,
143- "-E" , "setup.kibana.host=" + self .get_kibana_host (),
144- "-E" , "setup.kibana.port=" + self .get_kibana_port (),
145- "-decode" ,
146- "-id" , "Metricbeat-system-overview" ]
147- )
148-
149- beat .check_wait (exit_code = 0 )
150-
151- assert self .log_contains ("\" id\" : \" Metricbeat-system-overview\" ," ) is True
152-
153129 @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
154130 @pytest .mark .tag ('integration' )
155131 def test_export_dashboard_cmd_export_dashboard_by_id (self ):
@@ -165,12 +141,12 @@ def test_export_dashboard_cmd_export_dashboard_by_id(self):
165141 "-E" , "setup.kibana.protocol=http" ,
166142 "-E" , "setup.kibana.host=" + self .get_kibana_host (),
167143 "-E" , "setup.kibana.port=" + self .get_kibana_port (),
168- "-id" , "Metricbeat-system-overview" ]
144+ "-id" , "Metricbeat-system-overview" ,
145+ "-folder" , "system-overview" ]
169146 )
170147
171148 beat .check_wait (exit_code = 0 )
172-
173- assert self .log_contains ("\" id\" : \" Metricbeat-system-overview\" ," ) is True
149+ self ._check_if_dashboard_exported ("system-overview" )
174150
175151 @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
176152 @pytest .mark .tag ('integration' )
@@ -186,69 +162,15 @@ def test_export_dashboard_cmd_export_dashboard_by_id_unknown_id(self):
186162 "-E" , "setup.kibana.protocol=http" ,
187163 "-E" , "setup.kibana.host=" + self .get_kibana_host (),
188164 "-E" , "setup.kibana.port=" + self .get_kibana_port (),
189- "-id" , "No-such-dashboard" ]
165+ "-id" , "No-such-dashboard" ,
166+ "-folder" , "system-overview" ]
190167 )
191168
192169 beat .check_wait (exit_code = 1 )
193170
194171 expected_error = re .compile ("error exporting dashboard:.*not found" , re .IGNORECASE )
195172 assert self .log_contains (expected_error )
196173
197- @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
198- @pytest .mark .tag ('integration' )
199- def test_export_dashboard_cmd_export_dashboard_from_yml (self ):
200- """
201- Test testbeat export dashboard can export dashboards from dashboards YAML file
202- and removes unsupported characters
203- """
204-
205- self .render_config_template ()
206- self .test_load_dashboard ()
207- beat = self .start_beat (
208- logging_args = ["-e" , "-d" , "*" ],
209- extra_args = ["export" ,
210- "dashboard" ,
211- "-E" , "setup.kibana.protocol=http" ,
212- "-E" , "setup.kibana.host=" + self .get_kibana_host (),
213- "-E" , "setup.kibana.port=" + self .get_kibana_port (),
214- "-yml" , os .path .join (self .beat_path , "tests" , "files" , "dashboards.yml" )]
215- )
216-
217- beat .check_wait (exit_code = 0 )
218-
219- version = self .get_version ()
220- kibana_semver = semver .VersionInfo .parse (version )
221- exported_dashboard_path = os .path .join (self .beat_path , "tests" , "files" , "_meta" ,
222- "kibana" , str (kibana_semver .major ), "dashboard" , "Metricbeat-system-test-overview.ndjson" )
223-
224- with open (exported_dashboard_path ) as f :
225- content = f .read ()
226- assert "Metricbeat-system-overview" in content
227-
228- os .remove (exported_dashboard_path )
229-
230- @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
231- @pytest .mark .tag ('integration' )
232- def test_export_dashboard_cmd_export_dashboard_from_not_existent_yml (self ):
233- """
234- Test testbeat export dashboard fails gracefully when cannot find YAML file
235- """
236-
237- self .render_config_template ()
238- beat = self .start_beat (
239- logging_args = ["-e" , "-d" , "*" ],
240- extra_args = ["export" ,
241- "dashboard" ,
242- "-E" , "setup.kibana.protocol=http" ,
243- "-E" , "setup.kibana.host=" + self .get_kibana_host (),
244- "-E" , "setup.kibana.port=" + self .get_kibana_port (),
245- "-yml" , os .path .join (self .beat_path , "tests" , "files" , "no-such-file.yml" )]
246- )
247-
248- beat .check_wait (exit_code = 1 )
249- assert self .log_contains ("Error exporting dashboards from yml" )
250- assert self .log_contains ("error opening the list of dashboards" )
251-
252174 @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
253175 @pytest .mark .tag ('integration' )
254176 def test_dev_tool_export_dashboard_by_id (self ):
@@ -258,60 +180,17 @@ def test_dev_tool_export_dashboard_by_id(self):
258180
259181 self .test_load_dashboard ()
260182
261- path = os .path .normpath (self .beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go" )
262- command = path + " -kibana http://" + self .get_kibana_host () + ":" + self .get_kibana_port ()
263- command = "go run " + command + " -dashboard Metricbeat-system-overview"
264-
265- p = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
266- content , err = p .communicate ()
267-
268- assert p .returncode == 0
269-
270- assert os .path .isfile ("output.ndjson" ) is True
271-
272- with open ('output.ndjson' ) as f :
273- content = f .read ()
274- assert "Metricbeat-system-overview" in content
275-
276- os .remove ("output.ndjson" )
277-
278- @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
279- @pytest .mark .tag ('integration' )
280- def test_dev_tool_export_dashboard_by_id_to_folder (self ):
281- """
282- Test dev-tools/cmd/dashboards exports dashboard and removes unsupported characters
283- and separates each asset into a file under the appropriate folder
284- """
285-
286- self .test_load_dashboard ()
287-
288- folder_name = "my-system"
183+ folder_name = "system-overview"
289184 path = os .path .normpath (self .beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go" )
290185 command = path + " -kibana http://" + self .get_kibana_host () + ":" + self .get_kibana_port ()
291186 command = "go run " + command + " -dashboard Metricbeat-system-overview -folder " + folder_name
292187
293188 p = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
294189 content , err = p .communicate ()
295- print (content , err )
296190
297191 assert p .returncode == 0
298192
299- assert os .path .isfile ("output.ndjson" ) is False
300- assert os .path .isdir (folder_name ) is True
301-
302- kibana_semver = semver .VersionInfo .parse (self .get_version ())
303- assets_root = os .path .join (folder_name , "_meta" , "kibana" , str (kibana_semver .major ))
304- assert os .path .isdir (assets_root ) is True
305- assert os .path .isdir (os .path .join (assets_root , "dashboard" )) is True
306- assert os .path .isdir (os .path .join (assets_root , "visualization" )) is True
307-
308- with open (os .path .join (assets_root , "dashboard" , "Metricbeat-system-overview.json" )) as dashboard_file :
309- dashboard = json .load (dashboard_file )
310- for reference in dashboard ["references" ]:
311- reference_path = os .path .join (assets_root , reference ["type" ], reference ["id" ]+ ".json" )
312- assert os .path .isfile (reference_path )
313-
314- shutil .rmtree (folder_name )
193+ self ._check_if_dashboard_exported (folder_name )
315194
316195 @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
317196 @pytest .mark .tag ('integration' )
@@ -343,52 +222,28 @@ def test_dev_tool_export_dashboard_by_id_from_space(self):
343222
344223 self .test_load_dashboard_into_space (False )
345224
225+ folder_name = "system-overview"
346226 path = os .path .normpath (self .beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go" )
347227 command = path + " -kibana http://" + self .get_kibana_host () + ":" + self .get_kibana_port ()
348- command = "go run " + command + " -dashboard Metricbeat-system-overview -space-id foo-bar"
228+ command = "go run " + command + " -dashboard Metricbeat-system-overview -space-id foo-bar -folder " + folder_name
349229
350230 p = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
351231 content , err = p .communicate ()
352232
353233 assert p .returncode == 0
354234
355- assert os .path .isfile ("output.ndjson" ) is True
356-
357- with open ('output.ndjson' ) as f :
358- content = f .read ()
359- assert "Metricbeat-system-overview" in content
360-
361- os .remove ("output.ndjson" )
362-
363- @unittest .skipUnless (INTEGRATION_TESTS , "integration test" )
364- @pytest .mark .tag ('integration' )
365- def test_dev_tool_export_dashboard_from_yml (self ):
366- """
367- Test dev-tools/cmd/dashboards exports dashboard from dashboards YAML file
368- and removes unsupported characters
369- """
370-
371- self .test_load_dashboard ()
372-
373- path = os .path .normpath (self .beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go" )
374- command = path + " -kibana http://" + self .get_kibana_host () + ":" + self .get_kibana_port ()
375- command = "go run " + command + " -yml " + os .path .join (self .beat_path , "tests" , "files" , "dashboards.yml" )
376-
377- p = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
378- content , err = p .communicate ()
379-
380- assert p .returncode == 0
235+ self ._check_if_dashboard_exported (folder_name )
381236
382- version = self . get_version ()
383- kibana_semver = semver .VersionInfo .parse (version )
384- exported_dashboard_path = os .path .join (self . beat_path , "tests " , "files " , "_meta" ,
385- "kibana" , str ( kibana_semver . major ), "dashboard" , "Metricbeat-system-test-overview.ndjson" )
237+ def _check_if_dashboard_exported ( self , folder_name ):
238+ kibana_semver = semver .VersionInfo .parse (self . get_version () )
239+ dashboard_folder = os .path .join (folder_name , "_meta " , "kibana " , str ( kibana_semver . major ), "dashboard" )
240+ assert os . path . isdir ( dashboard_folder )
386241
387- with open (exported_dashboard_path ) as f :
242+ with open (os . path . join ( dashboard_folder , "Metricbeat-system-overview.json" ) ) as f :
388243 content = f .read ()
389244 assert "Metricbeat-system-overview" in content
390245
391- os . remove ( exported_dashboard_path )
246+ shutil . rmtree ( folder_name )
392247
393248 def get_host (self ):
394249 return os .getenv ('ES_HOST' , 'localhost' ) + ':' + os .getenv ('ES_PORT' , '9200' )
0 commit comments