diff --git a/cmd/image/qcow2ova/password-generator.go b/cmd/image/qcow2ova/password-generator.go index 200ab084..d9a9e67f 100644 --- a/cmd/image/qcow2ova/password-generator.go +++ b/cmd/image/qcow2ova/password-generator.go @@ -20,12 +20,10 @@ import ( ) // GeneratePassword generates the password of length n -func GeneratePassword(n int) (b64Password string, err error) { +func GeneratePassword(n int) (string, error) { b := make([]byte, n) - _, err = rand.Read(b) - if err != nil { - return + if _, err := rand.Read(b); err != nil { + return "", err } - b64Password = base64.URLEncoding.EncodeToString(b) - return + return base64.URLEncoding.EncodeToString(b), nil } diff --git a/cmd/image/qcow2ova/validate/tools/tools.go b/cmd/image/qcow2ova/validate/tools/tools.go index d78ba93a..9d3c5816 100644 --- a/cmd/image/qcow2ova/validate/tools/tools.go +++ b/cmd/image/qcow2ova/validate/tools/tools.go @@ -15,18 +15,20 @@ package tools import ( + "fmt" "os/exec" + "strings" "k8s.io/klog/v2" ) -var commands = map[string]string{ +var imageBinaries = map[string]string{ "qemu-img": "yum install qemu-img -y", "growpart": "yum install cloud-utils-growpart -y", } type Rule struct { - failedCommand string + missingBins []string } func (p *Rule) String() string { @@ -34,20 +36,27 @@ func (p *Rule) String() string { } func (p *Rule) Verify() error { - for command := range commands { - path, err := exec.LookPath(command) + for binary := range imageBinaries { + path, err := exec.LookPath(binary) if err != nil { - p.failedCommand = command - return err + p.missingBins = append(p.missingBins, binary) + } else { + klog.Infof("%s found at %s", binary, path) } - klog.Infof("%s found at %s", command, path) + } + if len(p.missingBins) > 0 { + return fmt.Errorf("executable file(s) not found in $PATH: %s", strings.Join(p.missingBins, ", ")) } return nil } func (p *Rule) Hint() string { - if p.failedCommand != "" { - return commands[p.failedCommand] + if len(p.missingBins) > 0 { + var hints []string + for _, binary := range p.missingBins { + hints = append(hints, imageBinaries[binary]) + } + return strings.Join(hints, "\n") } return "" } diff --git a/pkg/client/events/events.go b/pkg/client/events/events.go index f7c3bac9..5d127a03 100644 --- a/pkg/client/events/events.go +++ b/pkg/client/events/events.go @@ -20,7 +20,6 @@ import ( "github.com/IBM-Cloud/power-go-client/ibmpisession" "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_events" "github.com/IBM/go-sdk-core/v5/core" - "github.com/ppc64le-cloud/pvsadm/pkg" ) type Client struct { @@ -38,6 +37,6 @@ func NewClient(sess *ibmpisession.IBMPISession, powerinstanceid string) *Client } func (c *Client) GetPcloudEventsGetsince(since time.Duration) (*p_cloud_events.PcloudEventsGetqueryOK, error) { - params := p_cloud_events.NewPcloudEventsGetqueryParamsWithTimeout(pkg.TIMEOUT).WithCloudInstanceID(c.instanceID).WithFromTime(core.StringPtr(time.Now().UTC().Add(-since).Format(time.RFC3339))) + params := p_cloud_events.NewPcloudEventsGetqueryParams().WithCloudInstanceID(c.instanceID).WithFromTime(core.StringPtr(time.Now().UTC().Add(-since).Format(time.RFC3339))) return c.client.PcloudEventsGetquery(params, c.session.AuthInfo(c.instanceID)) } diff --git a/pkg/types.go b/pkg/types.go deleted file mode 100644 index ff4498bb..00000000 --- a/pkg/types.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2021 IBM Corp -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package pkg - -import "time" - -const ( - TIMEOUT = 60 * time.Minute -)