Skip to content

Commit

Permalink
Merge pull request #845 from SoftLayer/issues844
Browse files Browse the repository at this point in the history
Handling missing Datacenter name for 'vlan list'
  • Loading branch information
CHRISTOPHER GALLO authored and GitHub Enterprise committed Mar 22, 2024
2 parents 6ddec1b + 3028efb commit f9ca444
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
6 changes: 5 additions & 1 deletion plugin/commands/vlan/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ func (cmd *ListCommand) Run(args []string) error {
} else {
premium = T("No")
}
datacenterName := ""
if vlan.PrimaryRouter != nil && vlan.PrimaryRouter.Datacenter != nil && vlan.PrimaryRouter.Datacenter.Name != nil {
datacenterName = utils.FormatStringPointer(vlan.PrimaryRouter.Datacenter.Name)
}
table.Add(
utils.FormatIntPointer(vlan.Id),
utils.FormatIntPointer(vlan.VlanNumber),
utils.FormatStringPointer(vlan.FullyQualifiedName),
utils.FormatStringPointer(vlan.Name),
cases.Title(language.Und).String(utils.FormatStringPointer(vlan.NetworkSpace)),
utils.FormatStringPointer(vlan.PrimaryRouter.Datacenter.Name),
datacenterName,
getPodWithClosedAnnouncement(vlan, pods),
getFirewallGateway(vlan),
utils.FormatUIntPointer(vlan.HardwareCount),
Expand Down
16 changes: 15 additions & 1 deletion plugin/commands/vlan/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/softlayer/softlayer-go/sl"
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/vlan"
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
)

Expand All @@ -23,10 +24,11 @@ var _ = Describe("VLAN List", func() {
fakeSession *session.Session
slCommand *metadata.SoftlayerCommand
fakeNetworkManager *testhelpers.FakeNetworkManager

)
BeforeEach(func() {
fakeUI = terminal.NewFakeUI()
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{""})
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
cliCommand = vlan.NewListCommand(slCommand)
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
Expand Down Expand Up @@ -241,5 +243,17 @@ var _ = Describe("VLAN List", func() {
Expect(fakeUI.Outputs()).To(ContainSubstring(`]`))
})
})
Context("Issues844", func() {
BeforeEach(func() {
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{"getNetworkVlans_844"})
cliCommand.NetworkManager = managers.NewNetworkManager(fakeSession)
})
It("Handle empty Datacenter Name for some routers", func() {
err := testhelpers.RunCobraCommand(cliCommand.Command)
Expect(err).NotTo(HaveOccurred())
Expect(fakeUI.Outputs()).To(ContainSubstring("dal13.fcr01.1362"))
Expect(fakeUI.Outputs()).To(ContainSubstring("3087"))
})
})
})
})
48 changes: 48 additions & 0 deletions plugin/testfixtures/SoftLayer_Account/getNetworkVlans_844.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[
{
"accountId": 1013059,
"firewallInterfaces": [],
"fullyQualifiedName": "dal13.fcr01.1362",
"hardwareCount": 0,
"id": 2206583,
"modifyDate": "2024-03-19T00:18:53-06:00",
"networkSpace": "PUBLIC",
"primaryRouter": {
"datacenter": {
"id": 1854895,
"locationStatus": {
"id": 2,
"status": "Active"
},
"longName": "Dallas 13",
"name": "dal13",
"statusId": 2
},
"fullyQualifiedDomainName": "fcr01a.dal13.softlayer.com",
"id": 1076163
},
"primarySubnetId": 1602653,
"subnetCount": 6,
"tagReferences": [],
"totalPrimaryIpAddressCount": 13,
"virtualGuestCount": 10,
"vlanNumber": 1362
},
{
"accountId": 1013059,
"firewallInterfaces": [],
"hardwareCount": 0,
"id": 2934960,
"modifyDate": "2020-08-21T13:10:43-06:00",
"primaryRouter": {
"fullyQualifiedDomainName": "xcr04.dal03.softlayer.com",
"id": 1475295
},
"primarySubnetId": null,
"subnetCount": 0,
"tagReferences": [],
"totalPrimaryIpAddressCount": 0,
"virtualGuestCount": 0,
"vlanNumber": 3087
}
]
14 changes: 10 additions & 4 deletions plugin/testhelpers/fake_softlayer_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ func (h *FakeTransportHandler) ClearErrors() {
h.ErrorMap = make(map[string]sl.Error)
}

func (h *FakeTransportHandler) SetFileNames(files []string) {
h.FileNames = files
// fmt.Printf("SetFileNames: %v\n", h.FileNames)
}

func NewFakeSoftlayerSession(fileNames []string) *session.Session {

sess := &session.Session{}
Expand Down Expand Up @@ -174,24 +179,25 @@ func readJsonTestFixtures(service string, method string, fileNames []string, ide
}
// fmt.Printf("WD: %v, Scope: %v", wd, scope)
baseFixture := filepath.Join(wd, scope, "testfixtures", service+"/"+method+".json")
// fmt.Printf("BASE FIXTURE: %v\n", baseFixture)

// If we specified a file name, check there first
if len(fileNames) > 0 {
//find the file name that matches the service and method name
for _, filename := range fileNames {
//fmt.Println("check file:" + filename)
// fmt.Println("check file:" + filename)
// If the file exists as is, just load and return it.
// actual path should be of the format testfixtures/SoftLayer_Service/method-string.json
workingPath = service + "/" + filename + ".json"
// Make sure the filepath starts with the service/method combo
if !strings.HasPrefix(workingPath, service + "/" + method) {
fmt.Printf("OK %v doesn't start with %v\n", workingPath, service + "/" + method)
// fmt.Printf("OK %v doesn't start with %v\n", workingPath, service + "/" + method)
continue
}
fmt.Printf("OK %v DOES INFACT start with %v\n", workingPath, service + "/" + method)
// fmt.Printf("OK %v DOES INFACT start with %v\n", workingPath, service + "/" + method)
if _, err := os.Stat(filepath.Join(wd, scope, "testfixtures", workingPath)); err == nil {
fixture = filepath.Join(wd, scope, "testfixtures", workingPath)
fmt.Printf("LOADED %v OK!\n", fixture)
// fmt.Printf("LOADED %v OK!\n", fixture)
return ioutil.ReadFile(fixture) // #nosec
}
}
Expand Down

0 comments on commit f9ca444

Please sign in to comment.