diff --git a/container/container_test.go b/container/container_test.go index 80bea75aa..4c2c3fd07 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" docker "github.com/fsouza/go-dockerclient" "github.com/open-horizon/anax/containermessage" + "os" "testing" ) @@ -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"} @@ -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.") @@ -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.") @@ -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.") @@ -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 } diff --git a/download/download_worker.go b/download/download_worker.go index 49925d480..d1bb65bf8 100644 --- a/download/download_worker.go +++ b/download/download_worker.go @@ -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" @@ -486,8 +486,14 @@ 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) @@ -495,11 +501,6 @@ func (w *DownloadWorker) formAgentUpgradePackageNames(dev *persistence.ExchangeD 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) diff --git a/download/download_worker_test.go b/download/download_worker_test.go index 64ae6e831..28eb6d8d1 100644 --- a/download/download_worker_test.go +++ b/download/download_worker_test.go @@ -4,6 +4,7 @@ package download import ( + "fmt" "github.com/boltdb/bolt" "github.com/open-horizon/anax/config" "github.com/open-horizon/anax/cutil" @@ -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) } diff --git a/kube_operator/api_objects.go b/kube_operator/api_objects.go index 35dd3f6ba..2867b9d27 100644 --- a/kube_operator/api_objects.go +++ b/kube_operator/api_objects.go @@ -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 { @@ -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 { diff --git a/persistence/persistence.go b/persistence/persistence.go index c3b0a4470..42876c49a 100644 --- a/persistence/persistence.go +++ b/persistence/persistence.go @@ -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,