@@ -6,18 +6,10 @@ open System.Text.RegularExpressions
66open System.Linq
77
88open System.Collections .Specialized
9- open Elasticsearch.Net
10- open Elasticsearch.Net
11- open Elasticsearch.Net .Specification .CatApi
12- open Elasticsearch.Net .Specification .ClusterApi
13- open Elasticsearch.Net .Specification .MachineLearningApi
149open System.IO
15- open Tests.YamlRunner
16- open Tests.YamlRunner .Models
1710open Tests.YamlRunner .Models
1811open Tests.YamlRunner .TestsLocator
1912
20-
2113let private tryPick < 'a > ( map : YamlMap ) key =
2214 let found , value = map.TryGetValue key
2315 if ( found) then
@@ -211,160 +203,11 @@ type YamlTestDocument = {
211203 Tests: YamlTest list
212204}
213205
214- let private DefaultSetup : Operation list = [ Actions( " Setup" , fun ( client , suite ) ->
215- let firstFailure ( responses : DynamicResponse seq ) =
216- responses
217- |> Seq.filter ( fun r -> not r.Success && r.HttpStatusCode <> Nullable.op_ Implicit 404 )
218- |> Seq.tryHead
219-
220- match suite with
221- | Oss ->
222- let deleteAll = client.Indices.Delete< DynamicResponse>( " *" )
223- let templates =
224- client.Cat.Templates< StringResponse>( " *" , CatTemplatesRequestParameters( Headers=[ " name" ]. ToArray()))
225- .Body.Split( " \n " )
226- |> Seq.filter( fun f -> not ( String.IsNullOrWhiteSpace( f)) && not ( f.StartsWith( " ." )) && f <> " security-audit-log" )
227- //TODO template does not accept comma separated list but is documented as such
228- |> Seq.map( fun template -> client.Indices.DeleteTemplateForAll< DynamicResponse>( template))
229- |> Seq.toList
230- firstFailure <| [ deleteAll] @ templates
231-
232- | XPack ->
233- firstFailure <| seq {
234- //delete all templates
235- let templates =
236- client.Cat.Templates< StringResponse>( " *" , CatTemplatesRequestParameters( Headers=[ " name" ]. ToArray()))
237- .Body.Split( " \n " )
238- |> Seq.filter( fun f -> not ( String.IsNullOrWhiteSpace( f)) && not ( f.StartsWith( " ." )) && f <> " security-audit-log" )
239- //TODO template does not accept comma separated list but is documented as such
240- |> Seq.map( fun template -> client.Indices.DeleteTemplateForAll< DynamicResponse>( template))
241-
242- yield ! templates
243-
244- yield client.Watcher.Delete< DynamicResponse>( " my_watch" )
245-
246- let deleteNonReserved ( setup : _ -> DynamicResponse ) ( delete :( _ -> DynamicResponse )) =
247- setup() .Dictionary.GetKeyValues()
248- |> Seq.map ( fun kv ->
249- match kv.Value.Get< bool> " metadata._reserved" with
250- | false -> Some <| delete( kv.Key)
251- | _ -> None
252- )
253- |> Seq.choose id
254- |> Seq.toList
255-
256- yield ! //roles
257- deleteNonReserved
258- ( fun _ -> client.Security.GetRole< DynamicResponse>())
259- ( fun role -> client.Security.DeleteRole< DynamicResponse> role)
260-
261- yield ! //users
262- deleteNonReserved
263- ( fun _ -> client.Security.GetUser< DynamicResponse>())
264- ( fun user -> client.Security.DeleteUser< DynamicResponse> user)
265-
266- yield ! //privileges
267- deleteNonReserved
268- ( fun _ -> client.Security.GetPrivileges< DynamicResponse>())
269- ( fun priv -> client.Security.DeletePrivileges< DynamicResponse>( priv, " _all" ))
270-
271- // deleting feeds before jobs is important
272- let mlDataFeeds =
273- let stopFeeds = client.MachineLearning.StopDatafeed< DynamicResponse>( " _all" )
274- let getFeeds = client.MachineLearning.GetDatafeeds< DynamicResponse> ()
275- let deleteFeeds =
276- getFeeds.Get< string[]> " datafeeds.datafeed_id"
277- |> Seq.map ( fun jobId -> client.MachineLearning.DeleteDatafeed< DynamicResponse>( jobId))
278- |> Seq.toList
279- [ stopFeeds; getFeeds] @ deleteFeeds
280- yield ! mlDataFeeds
281-
282- yield client.IndexLifecycleManagement.RemovePolicy< DynamicResponse>( " _all" )
283-
284- let mlJobs =
285- let closeJobs = client.MachineLearning.CloseJob< DynamicResponse>( " _all" , PostData.Empty)
286- let getJobs = client.MachineLearning.GetJobs< DynamicResponse> " _all"
287- let deleteJobs =
288- getJobs.Get< string[]> " jobs.job_id"
289- |> Seq.map ( fun jobId -> client.MachineLearning.DeleteJob< DynamicResponse>( jobId))
290- |> Seq.toList
291- [ closeJobs; getJobs] @ deleteJobs
292- yield ! mlJobs
293-
294- let rollupJobs =
295- let getJobs = client.Rollup.GetJob< DynamicResponse> " _all"
296- let deleteJobs =
297- getJobs.Get< string[]> " jobs.config.id"
298- |> Seq.collect ( fun jobId -> [
299- client.Rollup.StopJob< DynamicResponse>( jobId)
300- client.Rollup.DeleteJob< DynamicResponse>( jobId)
301- ])
302- |> Seq.toList
303- [ getJobs] @ deleteJobs
304- yield ! rollupJobs
305-
306- let tasks =
307- let getJobs = client.Tasks.List< DynamicResponse> ()
308- let cancelJobs =
309- let dict = getJobs.Get< DynamicDictionary> " nodes"
310- dict.GetKeyValues()
311- |> Seq.collect( fun kv ->
312- let dict = kv.Value.Get< DynamicDictionary> " tasks"
313- dict.GetKeyValues()
314- )
315- |> Seq.map ( fun kv ->
316- match kv.Value.Get< bool> " cancellable" with
317- | true -> Some <| client.Tasks.Cancel< DynamicResponse>( kv.Key)
318- | _ -> None
319- )
320- |> Seq.choose id
321- |> Seq.toList
322-
323- [ getJobs] @ cancelJobs
324- yield ! tasks
325-
326- let transforms =
327- let transforms = client.Transform.Get< DynamicResponse> " _all"
328- let stopTransforms =
329- transforms.Get< string[]> " transforms.id"
330- |> Seq.collect ( fun id -> [
331- client.Transform.Stop< DynamicResponse> id
332- client.Transform.Delete< DynamicResponse> id
333- ])
334- |> Seq.toList
335- [ transforms] @ stopTransforms
336- yield ! transforms
337-
338- let yellowStatus = Nullable.op_ Implicit WaitForStatus.Yellow
339- yield client.Cluster.Health< DynamicResponse>( ClusterHealthRequestParameters( WaitForStatus= yellowStatus))
340-
341- //make sure we don't delete system indices
342- let indices =
343- client.Cat.Indices< StringResponse>( " *" , CatIndicesRequestParameters( Headers=[ " index" ]. ToArray()))
344- .Body.Split( " \n " )
345- |> Seq.filter( fun f -> not ( String.IsNullOrWhiteSpace( f)))
346- |> Seq.filter( fun f -> not ( f.StartsWith( " ." )) || f.StartsWith( " .ml-" ))
347- |> String.concat " ,"
348- |> function
349- | s when String.IsNullOrEmpty( s) -> None
350- | s -> Some <| client.Indices.Delete< DynamicResponse>( s)
351-
352- match indices with Some r -> yield r | None -> ignore()
353-
354- let data = PostData.String @" {"" password"" :"" x-pack-test-password"" , "" roles"" :["" superuser"" ]}"
355- yield client.Security.PutUser< DynamicResponse>( " x_pack_rest_user" , data)
356-
357- yield client.Indices.Refresh< DynamicResponse> " _all"
358-
359- yield client.Cluster.Health< DynamicResponse>( ClusterHealthRequestParameters( WaitForStatus= yellowStatus))
360- }
361- )]
362-
363206let private toDocument ( yamlInfo : YamlFileInfo ) ( sections : YamlTestSection list ) =
364207 let setups = ( sections |> List.tryPick ( fun s -> match s with | Setup s -> Some s | _ -> None))
365208 {
366209 FileInfo = FileInfo yamlInfo.File
367- Setup = Some <| ( DefaultSetup @ ( setups |> Option.defaultValue []))
210+ Setup = Some <| ( TestSuiteBootstrap. DefaultSetup @ ( setups |> Option.defaultValue []))
368211 Teardown = sections |> List.tryPick ( fun s -> match s with | Teardown s -> Some s | _ -> None)
369212 Tests = sections |> List.map ( fun s -> match s with | YamlTest s -> Some s | _ -> None) |> List.choose id
370213 }
0 commit comments