mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #51809 from davidz627/gci_api_test
Automatic merge from submit-queue (batch tested with PRs 52109, 52235, 51809, 52161, 50080). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.. Updated pd.go tests to use GCE API instead of GCloud Commands Fixes #49796
This commit is contained in:
commit
37780d1c67
@ -294,6 +294,24 @@ func (gce *GCECloud) GetAllZones() (sets.String, error) {
|
|||||||
return zones, nil
|
return zones, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListInstanceNames returns a string of instance names seperated by spaces.
|
||||||
|
func (gce *GCECloud) ListInstanceNames(project, zone string) (string, error) {
|
||||||
|
res, err := gce.service.Instances.List(project, zone).Fields("items(name)").Do()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
var output string
|
||||||
|
for _, item := range res.Items {
|
||||||
|
output += item.Name + " "
|
||||||
|
}
|
||||||
|
return output, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteInstance deletes an instance specified by project, zone, and name
|
||||||
|
func (gce *GCECloud) DeleteInstance(project, zone, name string) (*compute.Operation, error) {
|
||||||
|
return gce.service.Instances.Delete(project, zone, name).Do()
|
||||||
|
}
|
||||||
|
|
||||||
// Implementation of Instances.CurrentNodeName
|
// Implementation of Instances.CurrentNodeName
|
||||||
func (gce *GCECloud) CurrentNodeName(hostname string) (types.NodeName, error) {
|
func (gce *GCECloud) CurrentNodeName(hostname string) (types.NodeName, error) {
|
||||||
return types.NodeName(hostname), nil
|
return types.NodeName(hostname), nil
|
||||||
|
@ -19,7 +19,6 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
mathrand "math/rand"
|
mathrand "math/rand"
|
||||||
"os/exec"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -450,16 +449,18 @@ var _ = SIGDescribe("Pod Disks", func() {
|
|||||||
// Verify that disk shows up in node 0's volumeInUse list
|
// Verify that disk shows up in node 0's volumeInUse list
|
||||||
framework.ExpectNoError(waitForPDInVolumesInUse(nodeClient, diskName, host0Name, nodeStatusTimeout, true /* should exist*/))
|
framework.ExpectNoError(waitForPDInVolumesInUse(nodeClient, diskName, host0Name, nodeStatusTimeout, true /* should exist*/))
|
||||||
|
|
||||||
output, err := exec.Command("gcloud", "compute", "instances", "list", "--project="+framework.TestContext.CloudConfig.ProjectID).CombinedOutput()
|
gceCloud, err := framework.GetGCECloud()
|
||||||
|
framework.ExpectNoError(err, fmt.Sprintf("Unable to create gcloud client err=%v", err))
|
||||||
|
|
||||||
|
output, err := gceCloud.ListInstanceNames(framework.TestContext.CloudConfig.ProjectID, framework.TestContext.CloudConfig.Zone)
|
||||||
framework.ExpectNoError(err, fmt.Sprintf("Unable to get list of node instances err=%v output=%s", err, output))
|
framework.ExpectNoError(err, fmt.Sprintf("Unable to get list of node instances err=%v output=%s", err, output))
|
||||||
Expect(true, strings.Contains(string(output), string(host0Name)))
|
Expect(true, strings.Contains(string(output), string(host0Name)))
|
||||||
|
|
||||||
By("deleting host0")
|
By("deleting host0")
|
||||||
|
resp, err := gceCloud.DeleteInstance(framework.TestContext.CloudConfig.ProjectID, framework.TestContext.CloudConfig.Zone, string(host0Name))
|
||||||
|
framework.ExpectNoError(err, fmt.Sprintf("Failed to delete host0pod: err=%v response=%#v", err, resp))
|
||||||
|
|
||||||
output, err = exec.Command("gcloud", "compute", "instances", "delete", string(host0Name), "--project="+framework.TestContext.CloudConfig.ProjectID, "--zone="+framework.TestContext.CloudConfig.Zone).CombinedOutput()
|
output, err = gceCloud.ListInstanceNames(framework.TestContext.CloudConfig.ProjectID, framework.TestContext.CloudConfig.Zone)
|
||||||
framework.ExpectNoError(err, fmt.Sprintf("Failed to delete host0pod: err=%v output=%s", err, output))
|
|
||||||
|
|
||||||
output, err = exec.Command("gcloud", "compute", "instances", "list", "--project="+framework.TestContext.CloudConfig.ProjectID).CombinedOutput()
|
|
||||||
framework.ExpectNoError(err, fmt.Sprintf("Unable to get list of node instances err=%v output=%s", err, output))
|
framework.ExpectNoError(err, fmt.Sprintf("Unable to get list of node instances err=%v output=%s", err, output))
|
||||||
Expect(false, strings.Contains(string(output), string(host0Name)))
|
Expect(false, strings.Contains(string(output), string(host0Name)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user