Skip to content

Commit ef43fbc

Browse files
committed
Fix cleanup of spec-files post e2e tests
1 parent e859893 commit ef43fbc

File tree

6 files changed

+150
-20
lines changed

6 files changed

+150
-20
lines changed

cmd/get/events/events.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ package events
1616

1717
import (
1818
"fmt"
19+
"time"
20+
21+
"github.com/spf13/cobra"
22+
"k8s.io/klog/v2"
23+
1924
"github.com/ppc64le-cloud/pvsadm/pkg"
2025
"github.com/ppc64le-cloud/pvsadm/pkg/client"
2126
"github.com/ppc64le-cloud/pvsadm/pkg/utils"
22-
"github.com/spf13/cobra"
23-
"k8s.io/klog/v2"
24-
"time"
2527
)
2628

2729
var (
@@ -34,7 +36,7 @@ var Cmd = &cobra.Command{
3436
Long: `Get the PowerVS events`,
3537
PreRunE: func(cmd *cobra.Command, args []string) error {
3638
if pkg.Options.InstanceID == "" && pkg.Options.InstanceName == "" {
37-
return fmt.Errorf("--instance-name or --instance-name required")
39+
return fmt.Errorf("--instance-id or --instance-name required")
3840
}
3941
return nil
4042
},

cmd/get/get.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/spf13/cobra"
1919

2020
"github.com/ppc64le-cloud/pvsadm/cmd/get/events"
21+
"github.com/ppc64le-cloud/pvsadm/cmd/get/peravailability"
2122
"github.com/ppc64le-cloud/pvsadm/cmd/get/ports"
2223
"github.com/ppc64le-cloud/pvsadm/pkg"
2324
)
@@ -31,6 +32,7 @@ var Cmd = &cobra.Command{
3132

3233
func init() {
3334
Cmd.AddCommand(events.Cmd)
35+
Cmd.AddCommand(peravailability.Cmd)
3436
Cmd.AddCommand(ports.Cmd)
3537
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceID, "instance-id", "i", "", "Instance ID of the PowerVS instance")
3638
Cmd.PersistentFlags().StringVarP(&pkg.Options.InstanceName, "instance-name", "n", "", "Instance name of the PowerVS")
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2021 IBM Corp
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package peravailability
16+
17+
import (
18+
"fmt"
19+
"sort"
20+
21+
"github.com/spf13/cobra"
22+
"k8s.io/klog/v2"
23+
24+
"github.com/ppc64le-cloud/pvsadm/pkg"
25+
"github.com/ppc64le-cloud/pvsadm/pkg/client"
26+
)
27+
28+
const powerEdgeRouter = "power-edge-router"
29+
30+
var Cmd = &cobra.Command{
31+
Use: "per-availability",
32+
Short: "List regions that support PER",
33+
Long: "List regions that support Power Edge Router (PER)",
34+
PreRunE: func(cmd *cobra.Command, args []string) error {
35+
if pkg.Options.InstanceID == "" && pkg.Options.InstanceName == "" {
36+
return fmt.Errorf("--instance-id or --instance-name required")
37+
}
38+
return nil
39+
},
40+
RunE: func(cmd *cobra.Command, args []string) error {
41+
var perEnabledRegions = []string{}
42+
opt := pkg.Options
43+
c, err := client.NewClientWithEnv(opt.APIKey, opt.Environment, opt.Debug)
44+
if err != nil {
45+
klog.Errorf("failed to create a session with IBM cloud: %v", err)
46+
return err
47+
}
48+
49+
pvmclient, err := client.NewPVMClientWithEnv(c, opt.InstanceID, opt.InstanceName, opt.Environment)
50+
if err != nil {
51+
return err
52+
}
53+
ret, err := pvmclient.DatacenterClient.GetAll()
54+
if err != nil {
55+
return err
56+
}
57+
supportsPER := false
58+
for _, datacenter := range ret.Datacenters {
59+
if datacenter.Capabilities[powerEdgeRouter] {
60+
perEnabledRegions = append(perEnabledRegions, *datacenter.Location.Region)
61+
if pvmclient.Zone == *datacenter.Location.Region {
62+
supportsPER = true
63+
}
64+
}
65+
}
66+
if !supportsPER {
67+
klog.Infof("%s, where the current instance is present does not support PER.", pvmclient.Zone)
68+
} else {
69+
klog.Infof("%s, where the current instance is present supports PER.", pvmclient.Zone)
70+
}
71+
sort.Strings(perEnabledRegions)
72+
klog.Infoln("The following zones/datacenters have support for PER:", perEnabledRegions)
73+
klog.Infoln("More information at https://cloud.ibm.com/docs/overview?topic=overview-locations")
74+
return nil
75+
},
76+
}

pkg/client/datacenter/datacenter.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2021 IBM Corp
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package datacenter
16+
17+
import (
18+
"context"
19+
20+
"github.com/IBM-Cloud/power-go-client/clients/instance"
21+
"github.com/IBM-Cloud/power-go-client/ibmpisession"
22+
"github.com/IBM-Cloud/power-go-client/power/models"
23+
)
24+
25+
type Client struct {
26+
client *instance.IBMPIDatacentersClient
27+
instanceID string
28+
}
29+
30+
func NewClient(sess *ibmpisession.IBMPISession, powerinstanceid string) *Client {
31+
c := &Client{
32+
instanceID: powerinstanceid,
33+
}
34+
c.client = instance.NewIBMPIDatacenterClient(context.Background(), sess, powerinstanceid)
35+
return c
36+
}
37+
38+
func (c *Client) Get(id string) (*models.Datacenter, error) {
39+
return c.client.Get(id)
40+
}
41+
42+
func (c *Client) GetAll() (*models.Datacenters, error) {
43+
return c.client.GetAll()
44+
}

pkg/client/pvmclient.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/IBM/go-sdk-core/v5/core"
2626

2727
"github.com/ppc64le-cloud/pvsadm/pkg"
28+
"github.com/ppc64le-cloud/pvsadm/pkg/client/datacenter"
2829
"github.com/ppc64le-cloud/pvsadm/pkg/client/dhcp"
2930
"github.com/ppc64le-cloud/pvsadm/pkg/client/events"
3031
"github.com/ppc64le-cloud/pvsadm/pkg/client/image"
@@ -41,15 +42,17 @@ type PVMClient struct {
4142
Region string
4243
Zone string
4344

44-
PISession *ibmpisession.IBMPISession
45-
InstanceClient *instance.Client
46-
ImgClient *image.Client
47-
JobClient *job.Client
48-
VolumeClient *volume.Client
49-
NetworkClient *network.Client
50-
EventsClient *events.Client
51-
KeyClient *key.Client
52-
DHCPClient *dhcp.Client
45+
PISession *ibmpisession.IBMPISession
46+
47+
DatacenterClient *datacenter.Client
48+
DHCPClient *dhcp.Client
49+
EventsClient *events.Client
50+
ImgClient *image.Client
51+
InstanceClient *instance.Client
52+
JobClient *job.Client
53+
KeyClient *key.Client
54+
NetworkClient *network.Client
55+
VolumeClient *volume.Client
5356
}
5457

5558
func NewPVMClient(c *Client, instanceID, instanceName, ep string) (*PVMClient, error) {
@@ -97,13 +100,14 @@ func NewPVMClient(c *Client, instanceID, instanceName, ep string) (*PVMClient, e
97100
return nil, err
98101
}
99102

103+
pvmclient.DatacenterClient = datacenter.NewClient(pvmclient.PISession, instanceID)
104+
pvmclient.DHCPClient = dhcp.NewClient(pvmclient.PISession, instanceID)
105+
pvmclient.EventsClient = events.NewClient(pvmclient.PISession, instanceID)
100106
pvmclient.ImgClient = image.NewClient(pvmclient.PISession, instanceID)
101-
pvmclient.JobClient = job.NewClient(pvmclient.PISession, instanceID)
102-
pvmclient.VolumeClient = volume.NewClient(pvmclient.PISession, instanceID)
103107
pvmclient.InstanceClient = instance.NewClient(pvmclient.PISession, instanceID)
104-
pvmclient.NetworkClient = network.NewClient(pvmclient.PISession, instanceID)
105-
pvmclient.EventsClient = events.NewClient(pvmclient.PISession, instanceID)
108+
pvmclient.JobClient = job.NewClient(pvmclient.PISession, instanceID)
106109
pvmclient.KeyClient = key.NewClient(pvmclient.PISession, instanceID)
107-
pvmclient.DHCPClient = dhcp.NewClient(pvmclient.PISession, instanceID)
110+
pvmclient.NetworkClient = network.NewClient(pvmclient.PISession, instanceID)
111+
pvmclient.VolumeClient = volume.NewClient(pvmclient.PISession, instanceID)
108112
return pvmclient, nil
109113
}

test/e2e/sync/sync.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"errors"
1919
"io/fs"
2020
"os"
21+
"path/filepath"
2122
"strings"
2223

2324
"github.com/IBM-Cloud/bluemix-go/api/resource/resourcev1/management"
@@ -231,14 +232,15 @@ func createObjects() error {
231232
// Delete Temporarily created local object files and spec file
232233
func deleteTempFiles() error {
233234
klog.Infoln("STEP: Delete created Files")
234-
specFolder := strings.Split(SpecFileName, "/")[0]
235-
klog.Infoln("Spec folder : ", specFolder)
235+
specFolder := filepath.Dir(SpecFileName)
236+
klog.Infoln("deleting spec folder:", specFolder)
236237

237238
err := os.RemoveAll(specFolder)
238239
if err != nil {
239240
klog.Errorf("ERROR: %v", err)
240241
}
241242

243+
klog.Infoln("deleting object folder:", ObjectsFolderName)
242244
err = os.RemoveAll(ObjectsFolderName)
243245
if err != nil {
244246
klog.Errorf("ERROR: %v", err)

0 commit comments

Comments
 (0)