@@ -4,8 +4,19 @@ import (
44 "fmt"
55 "net/http"
66 "os"
7+ "regexp"
8+ "strconv"
9+ "strings"
710 "testing"
811 "time"
12+
13+ "github.com/replicatedhq/embedded-cluster/e2e/cluster"
14+ )
15+
16+ const (
17+ AirgapInstallBundlePath = "/assets/ec-release.tgz"
18+ AirgapUpgradeBundlePath = "/assets/ec-release-upgrade.tgz"
19+ AirgapUpgrade2BundlePath = "/assets/ec-release-upgrade2.tgz"
920)
1021
1122// downloadAirgapBundle downloads the airgap bundle for the given version to the destination path.
@@ -30,7 +41,7 @@ func downloadAirgapBundle(t *testing.T, versionLabel string, destPath string, li
3041 }
3142 time .Sleep (1 * time .Minute )
3243 }
33- return fmt .Errorf ("failed to download airgap bundle for version %s after 5 attempts" , versionLabel )
44+ return fmt .Errorf ("failed to download airgap bundle for version %s after 20 attempts" , versionLabel )
3445}
3546
3647func maybeDownloadAirgapBundle (versionLabel string , destPath string , licenseID string ) (int64 , error ) {
@@ -68,3 +79,52 @@ func maybeDownloadAirgapBundle(versionLabel string, destPath string, licenseID s
6879
6980 return size , nil
7081}
82+
83+ func downloadAirgapBundleOnNode (t * testing.T , tc cluster.Cluster , node int , versionLabel string , destPath string , licenseID string ) error {
84+ for range 20 {
85+ size , err := maybeDownloadAirgapBundleOnNode (tc , node , versionLabel , destPath , licenseID )
86+ if err != nil {
87+ // when we deploy the api to staging it interrupts the download
88+ t .Logf ("failed to download airgap bundle for version %s on node %d with error %q, retrying" , versionLabel , node , err )
89+ } else {
90+ if size > 1 { // more than a GB
91+ t .Logf ("downloaded airgap bundle on node %d to %s (%.1f GB)" , node , destPath , size )
92+ return nil
93+ }
94+ t .Logf ("downloaded airgap bundle on node %d to %s (%.1f GB), retrying as it is less than 1GB" , node , destPath , size )
95+ }
96+ time .Sleep (1 * time .Minute )
97+ }
98+ return fmt .Errorf ("failed to download airgap bundle for version %s on node %d after 20 attempts" , versionLabel , node )
99+ }
100+
101+ func maybeDownloadAirgapBundleOnNode (tc cluster.Cluster , node int , versionLabel string , destPath string , licenseID string ) (float64 , error ) {
102+ // download airgap bundle
103+ airgapURL := fmt .Sprintf ("https://staging.replicated.app/embedded/embedded-cluster-smoke-test-staging-app/ci-airgap/%s?airgap=true" , versionLabel )
104+
105+ stdout , stderr , err := tc .RunCommandOnNode (node , []string {"curl" , "-f" , "-H" , fmt .Sprintf ("'Authorization: %s'" , licenseID ), "-L" , airgapURL , "-o" , destPath })
106+ if err != nil {
107+ return 0 , fmt .Errorf ("failed to download airgap bundle: %v: %s: %s" , err , stdout , stderr )
108+ }
109+
110+ // get the size of the file on the node
111+ stdout , stderr , err = tc .RunCommandOnNode (node , []string {"du" , "-h" , destPath , "|" , "awk" , "'{print $1}'" })
112+ if err != nil {
113+ return 0 , fmt .Errorf ("failed to check file size: %v: %s: %s" , err , stdout , stderr )
114+ }
115+
116+ sizeStr := strings .TrimSpace (stdout )
117+
118+ // match only if the size is in gigabytes
119+ re := regexp .MustCompile (`(?i)^([\d.]+)G$` )
120+ matches := re .FindStringSubmatch (sizeStr )
121+ if matches == nil {
122+ return 0 , fmt .Errorf ("file size is not in gigabytes: %s" , sizeStr )
123+ }
124+
125+ size , err := strconv .ParseFloat (matches [1 ], 64 )
126+ if err != nil {
127+ return 0 , fmt .Errorf ("failed to parse numeric value: %w" , err )
128+ }
129+ return size , nil
130+ }
0 commit comments