Skip to content

Commit f9ca444

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #845 from SoftLayer/issues844
Handling missing Datacenter name for 'vlan list'
2 parents 6ddec1b + 3028efb commit f9ca444

File tree

4 files changed

+78
-6
lines changed

4 files changed

+78
-6
lines changed

plugin/commands/vlan/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,17 @@ func (cmd *ListCommand) Run(args []string) error {
106106
} else {
107107
premium = T("No")
108108
}
109+
datacenterName := ""
110+
if vlan.PrimaryRouter != nil && vlan.PrimaryRouter.Datacenter != nil && vlan.PrimaryRouter.Datacenter.Name != nil {
111+
datacenterName = utils.FormatStringPointer(vlan.PrimaryRouter.Datacenter.Name)
112+
}
109113
table.Add(
110114
utils.FormatIntPointer(vlan.Id),
111115
utils.FormatIntPointer(vlan.VlanNumber),
112116
utils.FormatStringPointer(vlan.FullyQualifiedName),
113117
utils.FormatStringPointer(vlan.Name),
114118
cases.Title(language.Und).String(utils.FormatStringPointer(vlan.NetworkSpace)),
115-
utils.FormatStringPointer(vlan.PrimaryRouter.Datacenter.Name),
119+
datacenterName,
116120
getPodWithClosedAnnouncement(vlan, pods),
117121
getFirewallGateway(vlan),
118122
utils.FormatUIntPointer(vlan.HardwareCount),

plugin/commands/vlan/list_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/softlayer/softlayer-go/sl"
1414
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/vlan"
1515
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
16+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
1617
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
1718
)
1819

@@ -23,10 +24,11 @@ var _ = Describe("VLAN List", func() {
2324
fakeSession *session.Session
2425
slCommand *metadata.SoftlayerCommand
2526
fakeNetworkManager *testhelpers.FakeNetworkManager
27+
2628
)
2729
BeforeEach(func() {
2830
fakeUI = terminal.NewFakeUI()
29-
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
31+
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{""})
3032
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
3133
cliCommand = vlan.NewListCommand(slCommand)
3234
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
@@ -241,5 +243,17 @@ var _ = Describe("VLAN List", func() {
241243
Expect(fakeUI.Outputs()).To(ContainSubstring(`]`))
242244
})
243245
})
246+
Context("Issues844", func() {
247+
BeforeEach(func() {
248+
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{"getNetworkVlans_844"})
249+
cliCommand.NetworkManager = managers.NewNetworkManager(fakeSession)
250+
})
251+
It("Handle empty Datacenter Name for some routers", func() {
252+
err := testhelpers.RunCobraCommand(cliCommand.Command)
253+
Expect(err).NotTo(HaveOccurred())
254+
Expect(fakeUI.Outputs()).To(ContainSubstring("dal13.fcr01.1362"))
255+
Expect(fakeUI.Outputs()).To(ContainSubstring("3087"))
256+
})
257+
})
244258
})
245259
})
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[
2+
{
3+
"accountId": 1013059,
4+
"firewallInterfaces": [],
5+
"fullyQualifiedName": "dal13.fcr01.1362",
6+
"hardwareCount": 0,
7+
"id": 2206583,
8+
"modifyDate": "2024-03-19T00:18:53-06:00",
9+
"networkSpace": "PUBLIC",
10+
"primaryRouter": {
11+
"datacenter": {
12+
"id": 1854895,
13+
"locationStatus": {
14+
"id": 2,
15+
"status": "Active"
16+
},
17+
"longName": "Dallas 13",
18+
"name": "dal13",
19+
"statusId": 2
20+
},
21+
"fullyQualifiedDomainName": "fcr01a.dal13.softlayer.com",
22+
"id": 1076163
23+
},
24+
"primarySubnetId": 1602653,
25+
"subnetCount": 6,
26+
"tagReferences": [],
27+
"totalPrimaryIpAddressCount": 13,
28+
"virtualGuestCount": 10,
29+
"vlanNumber": 1362
30+
},
31+
{
32+
"accountId": 1013059,
33+
"firewallInterfaces": [],
34+
"hardwareCount": 0,
35+
"id": 2934960,
36+
"modifyDate": "2020-08-21T13:10:43-06:00",
37+
"primaryRouter": {
38+
"fullyQualifiedDomainName": "xcr04.dal03.softlayer.com",
39+
"id": 1475295
40+
},
41+
"primarySubnetId": null,
42+
"subnetCount": 0,
43+
"tagReferences": [],
44+
"totalPrimaryIpAddressCount": 0,
45+
"virtualGuestCount": 0,
46+
"vlanNumber": 3087
47+
}
48+
]

plugin/testhelpers/fake_softlayer_session.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func (h *FakeTransportHandler) ClearErrors() {
131131
h.ErrorMap = make(map[string]sl.Error)
132132
}
133133

134+
func (h *FakeTransportHandler) SetFileNames(files []string) {
135+
h.FileNames = files
136+
// fmt.Printf("SetFileNames: %v\n", h.FileNames)
137+
}
138+
134139
func NewFakeSoftlayerSession(fileNames []string) *session.Session {
135140

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

178184
// If we specified a file name, check there first
179185
if len(fileNames) > 0 {
180186
//find the file name that matches the service and method name
181187
for _, filename := range fileNames {
182-
//fmt.Println("check file:" + filename)
188+
// fmt.Println("check file:" + filename)
183189
// If the file exists as is, just load and return it.
184190
// actual path should be of the format testfixtures/SoftLayer_Service/method-string.json
185191
workingPath = service + "/" + filename + ".json"
186192
// Make sure the filepath starts with the service/method combo
187193
if !strings.HasPrefix(workingPath, service + "/" + method) {
188-
fmt.Printf("OK %v doesn't start with %v\n", workingPath, service + "/" + method)
194+
// fmt.Printf("OK %v doesn't start with %v\n", workingPath, service + "/" + method)
189195
continue
190196
}
191-
fmt.Printf("OK %v DOES INFACT start with %v\n", workingPath, service + "/" + method)
197+
// fmt.Printf("OK %v DOES INFACT start with %v\n", workingPath, service + "/" + method)
192198
if _, err := os.Stat(filepath.Join(wd, scope, "testfixtures", workingPath)); err == nil {
193199
fixture = filepath.Join(wd, scope, "testfixtures", workingPath)
194-
fmt.Printf("LOADED %v OK!\n", fixture)
200+
// fmt.Printf("LOADED %v OK!\n", fixture)
195201
return ioutil.ReadFile(fixture) // #nosec
196202
}
197203
}

0 commit comments

Comments
 (0)