Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FA] Use the api to parse versions #27107

Merged
merged 9 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions test/new-e2e/tests/installer/all_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 32 additions & 40 deletions test/new-e2e/tests/installer/upgrade_scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ package installer
import (
"encoding/json"
"fmt"
"regexp"
"strings"
"time"

"github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/host"
Expand All @@ -33,9 +31,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{
Expand All @@ -48,14 +51,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"
Expand Down Expand Up @@ -126,13 +121,13 @@ func (s *upgradeScenarioSuite) TestStopWithoutExperiment() {

s.setCatalog(testCatalog)

beforeStatus := s.getInstallerStatus()["datadog-agent"]
beforeStatus := s.getInstallerStatus()

_, err := s.stopExperimentCommand()
require.NoError(s.T(), err)

afterStatus := s.getInstallerStatus()["datadog-agent"]
require.Equal(s.T(), beforeStatus, afterStatus)
afterStatus := s.getInstallerStatus()
require.Equal(s.T(), beforeStatus.Packages["datadog-agent"], afterStatus.Packages["datadog-agent"])
}

func (s *upgradeScenarioSuite) startExperimentCommand(version string) (string, error) {
Expand Down Expand Up @@ -188,7 +183,7 @@ 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)
}

func (s *upgradeScenarioSuite) assertSuccessfulPromoteExperiment(timestamp host.JournaldTimestamp, version string) {
Expand All @@ -209,8 +204,8 @@ 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)
}

func (s *upgradeScenarioSuite) assertSuccessfulStopExperiment(timestamp host.JournaldTimestamp) {
Expand All @@ -229,29 +224,26 @@ func (s *upgradeScenarioSuite) assertSuccessfulStopExperiment(timestamp host.Jou
)

installerStatus := s.getInstallerStatus()
require.Equal(s.T(), "none", installerStatus["datadog-agent"].ExperimentVersion)
require.Equal(s.T(), "", installerStatus.Packages["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"),
}
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
Expand Down
Loading