forked from elastic/e2e-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocesses.go
More file actions
101 lines (83 loc) · 2.89 KB
/
processes.go
File metadata and controls
101 lines (83 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"strconv"
"github.com/cucumber/godog"
"github.com/elastic/e2e-testing/internal/common"
"github.com/elastic/e2e-testing/internal/deploy"
"github.com/elastic/e2e-testing/internal/installer"
"github.com/elastic/e2e-testing/internal/process"
log "github.com/sirupsen/logrus"
)
func (fts *FleetTestSuite) processStateChangedOnTheHost(pr string, state string) error {
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
agentInstaller, _ := installer.Attach(fts.currentContext, fts.getDeployer(), agentService, fts.InstallerType)
if state == "started" {
err := agentInstaller.Start(fts.currentContext)
return err
} else if state == "restarted" {
err := agentInstaller.Restart(fts.currentContext)
if err != nil {
return err
}
return nil
} else if state == "uninstalled" {
err := agentInstaller.Uninstall(fts.currentContext)
if err != nil {
return err
}
// signal that the elastic-agent was uninstalled
if pr == common.ElasticAgentProcessName {
fts.ElasticAgentStopped = true
}
return nil
} else if state != "stopped" {
return godog.ErrPending
}
log.WithFields(log.Fields{
"service": agentService.Name,
"process": pr,
}).Trace("Stopping process on the service")
err := agentInstaller.Stop(fts.currentContext)
if err != nil {
log.WithFields(log.Fields{
"action": state,
"error": err,
"service": agentService.Name,
"process": pr,
}).Error("Could not stop process on the host")
return err
}
manifest, _ := fts.getDeployer().GetServiceManifest(fts.currentContext, agentService)
var srv deploy.ServiceRequest
if fts.StandAlone {
srv = deploy.NewServiceContainerRequest(manifest.Name)
} else {
srv = deploy.NewServiceRequest(manifest.Name)
}
return process.CheckState(fts.currentContext, fts.getDeployer(), srv, pr, "stopped", 0)
}
func (fts *FleetTestSuite) processStateOnTheHost(pr string, state string) error {
ocurrences := "1"
if state == "uninstalled" || state == "stopped" {
ocurrences = "0"
}
return fts.thereAreInstancesOfTheProcessInTheState(ocurrences, pr, state)
}
func (fts *FleetTestSuite) thereAreInstancesOfTheProcessInTheState(ocurrences string, pr string, state string) error {
agentService := deploy.NewServiceRequest(common.ElasticAgentServiceName)
manifest, _ := fts.deployer.GetServiceManifest(fts.currentContext, agentService)
count, err := strconv.Atoi(ocurrences)
if err != nil {
return err
}
var srv deploy.ServiceRequest
if fts.StandAlone {
srv = deploy.NewServiceContainerRequest(manifest.Name)
} else {
srv = deploy.NewServiceRequest(manifest.Name)
}
return process.CheckState(fts.currentContext, fts.deployer, srv, pr, state, count)
}