Skip to content

Commit

Permalink
Merge pull request #3847 from LiilyZhang/zhangl/Issue3845
Browse files Browse the repository at this point in the history
Issue #3845 - Update the download worker to allow download…
  • Loading branch information
LiilyZhang authored Jul 21, 2023
2 parents ea438bd + 3cc359e commit 71ad5b5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
31 changes: 26 additions & 5 deletions container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
docker "github.com/fsouza/go-dockerclient"
"github.com/open-horizon/anax/containermessage"
"os"
"testing"
)

Expand Down Expand Up @@ -210,11 +211,14 @@ func Test_RemoveEnvVar_nothing3(t *testing.T) {
}

func Test_CheckPermissions_0(t *testing.T) {
if err := createTmpDir(); err != nil {
t.Errorf("Failed to create ./tmp directory with 0777 permission, err: %v", err)
}

binds := []string{"/tmp"}
binds := []string{"./tmp"}

if err := hasValidBindPermissions(binds); err != nil {
t.Errorf("Bind is supported, should not have returned an error.")
t.Errorf("Bind is supported, should not have returned an error")
}

binds = []string{"/root"}
Expand All @@ -229,7 +233,7 @@ func Test_CheckPermissions_0(t *testing.T) {
t.Errorf("Bind is not supported, should have returned an error.")
}

binds = []string{"/tmp:/hosttmp:ro"}
binds = []string{"./tmp:/hosttmp:ro"}

if err := hasValidBindPermissions(binds); err != nil {
t.Errorf("Bind is supported, should not have returned an error.")
Expand All @@ -241,7 +245,7 @@ func Test_CheckPermissions_0(t *testing.T) {
t.Errorf("Bind is not supported, should have returned an error.")
}

binds = []string{"/tmp:/hosttmp"}
binds = []string{"./tmp:/hosttmp"}

if err := hasValidBindPermissions(binds); err != nil {
t.Errorf("Bind is supported, should not have returned an error.")
Expand All @@ -253,7 +257,7 @@ func Test_CheckPermissions_0(t *testing.T) {
t.Errorf("Bind is not supported, should have returned an error.")
}

binds = []string{"/tmp:/hosttmp:rw"}
binds = []string{"./tmp:/hosttmp:rw"}

if err := hasValidBindPermissions(binds); err != nil {
t.Errorf("Bind is supported, should not have returned an error.")
Expand All @@ -271,4 +275,21 @@ func Test_CheckPermissions_0(t *testing.T) {
t.Errorf("Bind is supported, should not have returned an error.")
}

os.RemoveAll("./tmp")

}

func createTmpDir () error {
if err := os.MkdirAll("./tmp", 0777); err != nil {
return err
}

if info, err := os.Stat("./tmp"); err != nil {
return err
} else if info.Mode()&4 == 0 || info.Mode()&2 == 0 {
if err := os.Chmod("./tmp", 0777); err != nil {
return err
}
}
return nil
}
15 changes: 8 additions & 7 deletions download/download_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
MACPACKAGETYPE = "pkg"

HZN_CLUSTER_FILE = "horizon-agent-edge-cluster-files.tar.gz"
HZN_CLUSTER_IMAGE = "amd64_anax_k8s.tar.gz"
HZN_CLUSTER_IMAGE = "%v_anax_k8s.tar.gz"
HZN_CONTAINER_FILE = "%v_anax.tar.gz"
HZN_EDGE_FILE = "horizon-agent-%v-%v-%v.tar.gz"
HZN_CONFIG_FILE = "agent-install.cfg"
Expand Down Expand Up @@ -486,20 +486,21 @@ func (w *DownloadWorker) formAgentUpgradePackageNames(dev *persistence.ExchangeD
return nil, "", fmt.Errorf("No node policy found in the local db.")
}

archProp, err := pol.Properties.GetProperty(externalpolicy.PROP_NODE_ARCH)
if err != nil {
return nil, "", err
}

if dev.GetNodeType() == persistence.DEVICE_TYPE_CLUSTER {
return &[]string{HZN_CLUSTER_FILE, HZN_CLUSTER_IMAGE}, "", nil
cluster_image := fmt.Sprintf(HZN_CLUSTER_IMAGE, archProp.Value)
return &[]string{HZN_CLUSTER_FILE, cluster_image}, "", nil
}

installTypeProp, err := pol.Properties.GetProperty(externalpolicy.PROP_NODE_OS)
if err != nil {
return nil, "", fmt.Errorf("Failed to find node os property: %v", err)
}

archProp, err := pol.Properties.GetProperty(externalpolicy.PROP_NODE_ARCH)
if err != nil {
return nil, "", err
}

allFiles := []string{}

containerizedProp, err := pol.Properties.GetProperty(externalpolicy.PROP_NODE_CONTAINERIZED)
Expand Down
3 changes: 2 additions & 1 deletion download/download_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package download

import (
"fmt"
"github.com/boltdb/bolt"
"github.com/open-horizon/anax/config"
"github.com/open-horizon/anax/cutil"
Expand Down Expand Up @@ -208,7 +209,7 @@ func Test_formAgentUpgradePackageNames(t *testing.T) {
t.Errorf("Expected 2 files for download. Got %v.", downloadFiles)
} else if !cutil.SliceContains(*downloadFiles, HZN_CLUSTER_FILE) {
t.Errorf("Did not find expected file %s for download. Got %v.", HZN_CLUSTER_FILE, downloadFiles)
} else if !cutil.SliceContains(*downloadFiles, HZN_CLUSTER_IMAGE) {
} else if !cutil.SliceContains(*downloadFiles, fmt.Sprintf(HZN_CLUSTER_IMAGE, "amd64")) {
t.Errorf("Did not find expected file %s for download. Got %v.", HZN_CLUSTER_IMAGE, downloadFiles)
}

Expand Down
4 changes: 2 additions & 2 deletions kube_operator/api_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func sortAPIObjects(allObjects []APIObjects, customResources map[string][]*unstr
if typedCRD, ok := obj.Object.(*crdv1beta1.CustomResourceDefinition); ok {
kind := typedCRD.Spec.Names.Kind
if kind == "" {
return objMap, namespace, fmt.Errorf(kwlog(fmt.Sprintf("Error: custom resource definition object missing kind field.", obj.Object)))
return objMap, namespace, fmt.Errorf(kwlog(fmt.Sprintf("Error: custom resource definition object missing kind field: %v", obj.Object)))
}
customResourceList, ok := customResources[kind]
if !ok {
Expand All @@ -138,7 +138,7 @@ func sortAPIObjects(allObjects []APIObjects, customResources map[string][]*unstr
} else if typedCRD, ok := obj.Object.(*crdv1.CustomResourceDefinition); ok {
kind := typedCRD.Spec.Names.Kind
if kind == "" {
return objMap, namespace, fmt.Errorf(kwlog(fmt.Sprintf("Error: custom resource definition object missing kind field.", obj.Object)))
return objMap, namespace, fmt.Errorf(kwlog(fmt.Sprintf("Error: custom resource definition object missing kind field: %v", obj.Object)))
}
customResourceList, ok := customResources[kind]
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion persistence/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c EstablishedAgreement) String() string {
"RunningWorkload: %v, "+
"AgreementTimeout: %v, "+
"ServiceDefId: %v, "+
"FailedVerAttempts: %v",
"FailedVerAttempts: %v, "+
"LastVerAttemptUpdateTime: %v",
c.Name, c.DependentServices, c.Archived, c.CurrentAgreementId, c.ConsumerId, c.CounterPartyAddress, ServiceConfigNames(&c.CurrentDeployment),
"********", c.ProposalSig,
Expand Down

0 comments on commit 71ad5b5

Please sign in to comment.