From 90ee28e58f95f500d1d9e7a3bca3b668fec9e092 Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Thu, 27 Jun 2024 11:58:46 +0200 Subject: [PATCH 1/7] Use the aip to parse versions --- test/new-e2e/tests/installer/host/host.go | 24 ++++++ .../tests/installer/upgrade_scenario_test.go | 80 ++++++++++--------- 2 files changed, 66 insertions(+), 38 deletions(-) diff --git a/test/new-e2e/tests/installer/host/host.go b/test/new-e2e/tests/installer/host/host.go index f50c006469fce..d3f0c3a46644c 100644 --- a/test/new-e2e/tests/installer/host/host.go +++ b/test/new-e2e/tests/installer/host/host.go @@ -7,6 +7,7 @@ package host import ( + "encoding/json" "fmt" "io/fs" "os/user" @@ -170,6 +171,29 @@ func (h *Host) InstallerVersion() string { return strings.TrimSpace(h.remote.MustExecute("sudo datadog-installer version")) } +func (h *Host) AgentVersion() string { + // Needs sudo to read the auth token + authTokenRaw := h.remote.MustExecute("sudo cat /etc/datadog-agent/auth_token") + authToken := strings.TrimSpace(string(authTokenRaw)) + + requestHeader := fmt.Sprintf(" -H 'Content-Type: application/json' -H 'Authorization: Bearer %s' ", authToken) + response := h.remote.MustExecute(fmt.Sprintf( + "curl -s --insecure https://localhost:5001/agent/version %s", + requestHeader, + )) + + var versionParsed struct { + Major int `json:"Major"` + Minor int `json:"Minor"` + Patch int `json:"Patch"` + } + require.NoError(h.t, json.Unmarshal([]byte(response), &versionParsed)) + + ver := fmt.Sprintf("%d.%d.%d", versionParsed.Major, versionParsed.Minor, versionParsed.Patch) + + return ver +} + // AssertPackageInstalledByInstaller checks if a package is installed by the installer on the host. func (h *Host) AssertPackageInstalledByInstaller(pkgs ...string) { for _, pkg := range pkgs { diff --git a/test/new-e2e/tests/installer/upgrade_scenario_test.go b/test/new-e2e/tests/installer/upgrade_scenario_test.go index c6d4cc9c4f28b..a4a9c6e8937d1 100644 --- a/test/new-e2e/tests/installer/upgrade_scenario_test.go +++ b/test/new-e2e/tests/installer/upgrade_scenario_test.go @@ -8,7 +8,6 @@ package installer import ( "encoding/json" "fmt" - "regexp" "strings" "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/host" @@ -31,9 +30,14 @@ type catalog struct { } type packageStatus struct { - State string `json:"state"` - StableVersion string `json:"stable_version"` - ExperimentVersion string `json:"experiment_version"` + State string `json:"State"` + StableVersion string `json:"Stable"` + ExperimentVersion string `json:"Experiment"` +} + +type installerStatus struct { + Version string `json:"version"` + Packages map[string]packageStatus `json:"packages"` } var testCatalog = catalog{ @@ -46,14 +50,6 @@ var testCatalog = catalog{ }, } -// datadog-agent -// -// State: OK -// Installed versions: -// ● stable: v7.52.0-rc.1.git.15.6c19b17.pipeline.28815219-1 -// ● experiment: none -var installerStatusRegex = regexp.MustCompile(`([a-zA-Z-]+)\n[ \t]+State:.([a-zA-Z-]+)\n[ \t]+Installed versions:\n[ \t]+..stable:.([a-zA-Z0-9-\.]+)\n[ \t]+..experiment:.([a-zA-Z0-9-\.]+)`) - const ( latestAgentVersion = "7.54.1" latestAgentImageVersion = "7.54.1-1" @@ -78,6 +74,9 @@ func (s *upgradeScenarioSuite) TestUpgradeSuccessful() { _, err := s.setCatalog(testCatalog) require.NoError(s.T(), err) + _, err = s.stopExperimentCommand() + require.NoError(s.T(), err) + timestamp := s.host.LastJournaldTimestamp() _, err = s.startExperimentCommand(latestAgentImageVersion) require.NoError(s.T(), err) @@ -139,7 +138,11 @@ func (s *upgradeScenarioSuite) assertSuccessfulStartExperiment(timestamp host.Jo ) installerStatus := s.getInstallerStatus() - require.Equal(s.T(), version, installerStatus["datadog-agent"].ExperimentVersion) + require.Equal(s.T(), version, installerStatus.Packages["datadog-agent"].ExperimentVersion) + + // Assert running version + v := s.host.AgentVersion() + require.Equal(s.T(), strings.TrimSuffix(version, "-1"), v) } func (s *upgradeScenarioSuite) assertSuccessfulPromoteExperiment(timestamp host.JournaldTimestamp, version string) { @@ -160,8 +163,12 @@ func (s *upgradeScenarioSuite) assertSuccessfulPromoteExperiment(timestamp host. ) installerStatus := s.getInstallerStatus() - require.Equal(s.T(), version, installerStatus["datadog-agent"].StableVersion) - require.Equal(s.T(), "none", installerStatus["datadog-agent"].ExperimentVersion) + require.Equal(s.T(), version, installerStatus.Packages["datadog-agent"].StableVersion) + require.Equal(s.T(), "", installerStatus.Packages["datadog-agent"].ExperimentVersion) + + // Assert running version + v := s.host.AgentVersion() + require.Equal(s.T(), strings.TrimSuffix(version, "-1"), v) } //lint:ignore U1000 Ignore unused function for now @@ -181,29 +188,26 @@ func (s *upgradeScenarioSuite) assertSuccessfulStopExperiment(timestamp host.Jou ) installerStatus := s.getInstallerStatus() - require.Equal(s.T(), "none", installerStatus["datadog-agent"].ExperimentVersion) -} - -func (s *upgradeScenarioSuite) getInstallerStatus() map[string]packageStatus { - // Datadog Installer v7.55.0-devel+git.1079.69749ed - // datadog-agent - // State: OK - // Installed versions: - // ● stable: v7.52.0-rc.1.git.15.6c19b17.pipeline.28815219-1 - // ● experiment: none - resp := s.Env().RemoteHost.MustExecute("sudo datadog-installer status") - status := make(map[string]packageStatus) - - statusResponse := installerStatusRegex.FindAllStringSubmatch(resp, -1) - for _, st := range statusResponse { - if len(st) != 5 { - s.T().Fatal("unexpected status response") - } - status[st[1]] = packageStatus{ - State: st[2], - StableVersion: strings.TrimPrefix(st[3], "v"), - ExperimentVersion: strings.TrimPrefix(st[4], "v"), - } + require.Equal(s.T(), "", installerStatus.Packages["datadog-agent"].ExperimentVersion) +} + +func (s *upgradeScenarioSuite) getInstallerStatus() installerStatus { + socketPath := "/var/run/datadog-installer/installer.sock" + + requestHeader := " -H 'Content-Type: application/json' -H 'Accept: application/json' " + response := s.Env().RemoteHost.MustExecute(fmt.Sprintf( + "sudo curl -s --unix-socket %s %s http://daemon/status", + socketPath, + requestHeader, + )) + + // {"version":"7.56.0-devel+git.446.acf2836","packages":{ + // "datadog-agent":{"Stable":"7.56.0-devel.git.446.acf2836.pipeline.37567760-1","Experiment":"7.54.1-1"}, + // "datadog-installer":{"Stable":"7.56.0-devel.git.446.acf2836.pipeline.37567760-1","Experiment":""}}} + var status installerStatus + err := json.Unmarshal([]byte(response), &status) + if err != nil { + s.T().Fatal(err) } return status From a97f9e1dd155cc53cbd1167f965c64c5096f0fc3 Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Thu, 27 Jun 2024 11:59:22 +0200 Subject: [PATCH 2/7] Cleanup --- test/new-e2e/tests/installer/upgrade_scenario_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/new-e2e/tests/installer/upgrade_scenario_test.go b/test/new-e2e/tests/installer/upgrade_scenario_test.go index a4a9c6e8937d1..1e2025e8be919 100644 --- a/test/new-e2e/tests/installer/upgrade_scenario_test.go +++ b/test/new-e2e/tests/installer/upgrade_scenario_test.go @@ -74,9 +74,6 @@ func (s *upgradeScenarioSuite) TestUpgradeSuccessful() { _, err := s.setCatalog(testCatalog) require.NoError(s.T(), err) - _, err = s.stopExperimentCommand() - require.NoError(s.T(), err) - timestamp := s.host.LastJournaldTimestamp() _, err = s.startExperimentCommand(latestAgentImageVersion) require.NoError(s.T(), err) From 55b812442b4d7fa634ab1181475ebf836a7b6670 Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Fri, 28 Jun 2024 15:34:46 +0200 Subject: [PATCH 3/7] Fix linter --- test/new-e2e/tests/installer/host/host.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/new-e2e/tests/installer/host/host.go b/test/new-e2e/tests/installer/host/host.go index d3f0c3a46644c..becc6041041d8 100644 --- a/test/new-e2e/tests/installer/host/host.go +++ b/test/new-e2e/tests/installer/host/host.go @@ -171,6 +171,7 @@ func (h *Host) InstallerVersion() string { return strings.TrimSpace(h.remote.MustExecute("sudo datadog-installer version")) } +// AgentVersion returns the version of the agent on the host func (h *Host) AgentVersion() string { // Needs sudo to read the auth token authTokenRaw := h.remote.MustExecute("sudo cat /etc/datadog-agent/auth_token") From 353454f38b21d843582945e2d01447d2f5c7173b Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Mon, 1 Jul 2024 10:25:39 +0200 Subject: [PATCH 4/7] Stop using curl --- test/new-e2e/tests/installer/host/host.go | 24 +++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/test/new-e2e/tests/installer/host/host.go b/test/new-e2e/tests/installer/host/host.go index becc6041041d8..a6e9839d78206 100644 --- a/test/new-e2e/tests/installer/host/host.go +++ b/test/new-e2e/tests/installer/host/host.go @@ -7,9 +7,11 @@ package host import ( + "crypto/tls" "encoding/json" "fmt" "io/fs" + "net/http" "os/user" "path/filepath" "sort" @@ -177,18 +179,28 @@ func (h *Host) AgentVersion() string { authTokenRaw := h.remote.MustExecute("sudo cat /etc/datadog-agent/auth_token") authToken := strings.TrimSpace(string(authTokenRaw)) - requestHeader := fmt.Sprintf(" -H 'Content-Type: application/json' -H 'Authorization: Bearer %s' ", authToken) - response := h.remote.MustExecute(fmt.Sprintf( - "curl -s --insecure https://localhost:5001/agent/version %s", - requestHeader, - )) + request, err := http.NewRequest("GET", "https://localhost:5001/agent/version", nil) + require.NoError(h.t, err) + request.Header.Set("Content-Type", "application/json") + request.Header.Set("Authorization", "Bearer "+authToken) + client := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + }, + } + response, err := client.Do(request) + require.NoError(h.t, err) + defer response.Body.Close() + body := make([]byte, response.ContentLength) + _, err = response.Body.Read(body) + require.NoError(h.t, err) var versionParsed struct { Major int `json:"Major"` Minor int `json:"Minor"` Patch int `json:"Patch"` } - require.NoError(h.t, json.Unmarshal([]byte(response), &versionParsed)) + require.NoError(h.t, json.Unmarshal([]byte(body), &versionParsed)) ver := fmt.Sprintf("%d.%d.%d", versionParsed.Major, versionParsed.Minor, versionParsed.Patch) From e37d6c9cbd04b1563d62fd7bcaa741b0b81f1113 Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Mon, 1 Jul 2024 16:44:13 +0200 Subject: [PATCH 5/7] Wait for running --- test/new-e2e/tests/installer/upgrade_scenario_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/new-e2e/tests/installer/upgrade_scenario_test.go b/test/new-e2e/tests/installer/upgrade_scenario_test.go index d9cc23ad7fa1c..8c897538b255f 100644 --- a/test/new-e2e/tests/installer/upgrade_scenario_test.go +++ b/test/new-e2e/tests/installer/upgrade_scenario_test.go @@ -72,6 +72,8 @@ func (s *upgradeScenarioSuite) TestUpgradeSuccessful() { ) s.host.WaitForFileExists(true, "/var/run/datadog-installer/installer.sock") + state := s.host.State() + state.AssertUnitsRunning("datadog-installer.service") _, err := s.setCatalog(testCatalog) require.NoError(s.T(), err) From 233febd0b5608fd988cef944c0e6c8a3d0ef07c0 Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Tue, 2 Jul 2024 17:03:29 +0200 Subject: [PATCH 6/7] Remove flake mark --- test/new-e2e/tests/installer/all_packages_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/new-e2e/tests/installer/all_packages_test.go b/test/new-e2e/tests/installer/all_packages_test.go index c754543f11f9b..18fe2d51249bd 100644 --- a/test/new-e2e/tests/installer/all_packages_test.go +++ b/test/new-e2e/tests/installer/all_packages_test.go @@ -104,9 +104,6 @@ func TestPackages(t *testing.T) { continue } suite := test.t(flavor, flavor.Architecture) - if strings.Contains(suite.Name(), "scenario") { - continue - } t.Run(suite.Name(), func(t *testing.T) { t.Parallel() // FIXME: Fedora currently has DNS issues From d322ba7d7fd3c80bcfa8b26c50fd4d981349863e Mon Sep 17 00:00:00 2001 From: Paul Coignet Date: Wed, 3 Jul 2024 11:04:42 +0200 Subject: [PATCH 7/7] Stop asserting version running --- test/new-e2e/tests/installer/host/host.go | 37 ------------------- .../tests/installer/upgrade_scenario_test.go | 9 ----- 2 files changed, 46 deletions(-) diff --git a/test/new-e2e/tests/installer/host/host.go b/test/new-e2e/tests/installer/host/host.go index 33a527558b0ce..5b623e6d3aabd 100644 --- a/test/new-e2e/tests/installer/host/host.go +++ b/test/new-e2e/tests/installer/host/host.go @@ -7,11 +7,8 @@ package host import ( - "crypto/tls" - "encoding/json" "fmt" "io/fs" - "net/http" "os/user" "path/filepath" "sort" @@ -178,40 +175,6 @@ func (h *Host) InstallerVersion() string { return strings.TrimSpace(h.remote.MustExecute("sudo datadog-installer version")) } -// AgentVersion returns the version of the agent on the host -func (h *Host) AgentVersion() string { - // Needs sudo to read the auth token - authTokenRaw := h.remote.MustExecute("sudo cat /etc/datadog-agent/auth_token") - authToken := strings.TrimSpace(string(authTokenRaw)) - - request, err := http.NewRequest("GET", "https://localhost:5001/agent/version", nil) - require.NoError(h.t, err) - request.Header.Set("Content-Type", "application/json") - request.Header.Set("Authorization", "Bearer "+authToken) - client := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }, - } - response, err := client.Do(request) - require.NoError(h.t, err) - defer response.Body.Close() - body := make([]byte, response.ContentLength) - _, err = response.Body.Read(body) - require.NoError(h.t, err) - - var versionParsed struct { - Major int `json:"Major"` - Minor int `json:"Minor"` - Patch int `json:"Patch"` - } - require.NoError(h.t, json.Unmarshal([]byte(body), &versionParsed)) - - ver := fmt.Sprintf("%d.%d.%d", versionParsed.Major, versionParsed.Minor, versionParsed.Patch) - - return ver -} - // AssertPackageInstalledByInstaller checks if a package is installed by the installer on the host. func (h *Host) AssertPackageInstalledByInstaller(pkgs ...string) { for _, pkg := range pkgs { diff --git a/test/new-e2e/tests/installer/upgrade_scenario_test.go b/test/new-e2e/tests/installer/upgrade_scenario_test.go index 4111b4393fcfd..9a0b54ab4dd76 100644 --- a/test/new-e2e/tests/installer/upgrade_scenario_test.go +++ b/test/new-e2e/tests/installer/upgrade_scenario_test.go @@ -8,7 +8,6 @@ package installer import ( "encoding/json" "fmt" - "strings" "time" "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/host" @@ -185,10 +184,6 @@ func (s *upgradeScenarioSuite) assertSuccessfulStartExperiment(timestamp host.Jo installerStatus := s.getInstallerStatus() require.Equal(s.T(), version, installerStatus.Packages["datadog-agent"].ExperimentVersion) - - // Assert running version - v := s.host.AgentVersion() - require.Equal(s.T(), strings.TrimSuffix(version, "-1"), v) } func (s *upgradeScenarioSuite) assertSuccessfulPromoteExperiment(timestamp host.JournaldTimestamp, version string) { @@ -211,10 +206,6 @@ func (s *upgradeScenarioSuite) assertSuccessfulPromoteExperiment(timestamp host. installerStatus := s.getInstallerStatus() require.Equal(s.T(), version, installerStatus.Packages["datadog-agent"].StableVersion) require.Equal(s.T(), "", installerStatus.Packages["datadog-agent"].ExperimentVersion) - - // Assert running version - v := s.host.AgentVersion() - require.Equal(s.T(), strings.TrimSuffix(version, "-1"), v) } func (s *upgradeScenarioSuite) assertSuccessfulStopExperiment(timestamp host.JournaldTimestamp) {