Skip to content

Commit cf29a08

Browse files
cloud-iaas-fabric-automation cloud-iaas-fabric-automationGitHub Enterprise
authored andcommitted
Merge pull request #925 from SoftLayer/issues924
Added support for nvme dual raid ordering.
2 parents fbfc8f6 + 2ae5548 commit cf29a08

4 files changed

Lines changed: 629 additions & 12 deletions

File tree

plugin/i18n/v2Resources/active.en-US.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,6 +3944,9 @@
39443944
"Item {{.Item}} does not exist for package {{.Package}}": {
39453945
"other": "Item {{.Item}} does not exist for package {{.Package}}"
39463946
},
3947+
"Item {{.Item}} does not exist for package {{.Package}} with category {{.Category}}": {
3948+
"other": "Item {{.Item}} does not exist for package {{.Package}} with category {{.Category}}"
3949+
},
39473950
"Item: {{.itemID}} was cancelled.": {
39483951
"other": "Item: {{.itemID}} was cancelled."
39493952
},

plugin/managers/order.go

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ func (i orderManager) GetPriceIdList(packageKeyname string, itemKeynames []strin
332332
return nil, err
333333
}
334334
var prices []int
335-
categoryDict := map[string]int{"gpu0": -1, "pcie_slot0": -1}
335+
// start at -1 so we can increment before we use it. 0 is a valid value here
336+
categoryDict := map[string]int{"gpu0": -1, "pcie_slot0": -1, "disk_controller": -1}
336337

337338
for _, itemKeyname := range itemKeynames {
338339
var newItems []datatypes.Product_Item
@@ -355,10 +356,10 @@ func (i orderManager) GetPriceIdList(packageKeyname string, itemKeynames []strin
355356
itemCategory = *matchingItem.ItemCategory.CategoryCode
356357
}
357358

359+
// Normal items
358360
if _, ok := categoryDict[itemCategory]; !ok {
359361
for _, p := range matchingItem.Prices {
360-
if ((p.LocationGroupId != nil && *p.LocationGroupId == 0) ||
361-
p.LocationGroupId == nil) && p.Id != nil {
362+
if isDefaultPrice(p) {
362363

363364
capacityMin := -1
364365
capacityMax := -1
@@ -386,19 +387,23 @@ func (i orderManager) GetPriceIdList(packageKeyname string, itemKeynames []strin
386387
}
387388
}
388389
}
390+
// Items in categoryDict need special handling if there are more than 1
389391
} else {
390-
var PriceIdList []int
392+
391393
categoryDict[itemCategory] += 1
392-
categoryCode := itemCategory[:len(itemCategory)-1] + strconv.Itoa(categoryDict[itemCategory])
394+
categoryCode := getSpecialCategory(categoryDict[itemCategory], itemCategory)
393395
for _, p := range matchingItem.Prices {
394-
if p.LocationGroupId != nil && *p.LocationGroupId == 0 &&
395-
len(p.Categories) > 0 && p.Categories[0].CategoryCode != nil &&
396+
if isDefaultPrice(p) && len(p.Categories) > 0 && p.Categories[0].CategoryCode != nil &&
396397
*p.Categories[0].CategoryCode == categoryCode {
397-
398-
PriceIdList = append(PriceIdList, *p.Id)
398+
priceId = *p.Id
399399
}
400400
}
401-
priceId = PriceIdList[0]
401+
if priceId == 0 {
402+
subs := map[string]interface{}{"Item": itemKeyname, "Package": packageKeyname, "Category": categoryCode}
403+
return nil, errors.New(
404+
T("Item {{.Item}} does not exist for package {{.Package}} with category {{.Category}}", subs))
405+
}
406+
402407
}
403408
prices = append(prices, priceId)
404409
}
@@ -491,3 +496,28 @@ func (i orderManager) GetAllCancelation(mask string) ([]datatypes.Billing_Item_C
491496
func (i orderManager) DeleteQuote(quoteId int) (datatypes.Billing_Order_Quote, error) {
492497
return i.BillingOrderQuoteService.Id(quoteId).DeleteQuote()
493498
}
499+
500+
func getSpecialCategory(index int, base string) string {
501+
// Special case because its disk_controller and disk_controller1
502+
// unlike gpu0/pci0 -> gpu1/pci1
503+
if base == "disk_controller" {
504+
if index == 0 {
505+
return base
506+
} else {
507+
return fmt.Sprintf("%s1", base)
508+
}
509+
}
510+
categoryCode := base[:len(base)-1] + strconv.Itoa(index)
511+
return categoryCode
512+
}
513+
514+
func isDefaultPrice(price datatypes.Product_Item_Price) bool {
515+
if price.LocationGroupId != nil && *price.LocationGroupId > 0 {
516+
return false
517+
} else {
518+
if price.Id != nil {
519+
return true
520+
}
521+
}
522+
return false
523+
}

plugin/managers/order_test.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ var _ = Describe("Order", func() {
222222
})
223223
Describe("GetPriceIdList", func() {
224224
Items := []string{
225-
"PRIVATE_NETWORK_VLAN",
226-
"DOMAIN_INFO_1_YEAR",
225+
"PRIVATE_NETWORK_VLAN", "DOMAIN_INFO_1_YEAR",
227226
}
228227
BeforeEach(func() {
229228
fakeSLSession = testhelpers.NewFakeSoftlayerSession(nil)
@@ -250,5 +249,36 @@ var _ = Describe("Order", func() {
250249
Expect(err).To(HaveOccurred())
251250
})
252251
})
252+
Context("NVMe Selection", func() {
253+
BeforeEach(func() {
254+
handler := testhelpers.GetSessionHandler(fakeSLSession)
255+
handler.SetFileNames([]string{"getItems-3137"})
256+
})
257+
It("Select NVMe Prices", func() {
258+
Items := []string{
259+
"DISK_CONTROLLER_RAID", "DISK_CONTROLLER_RAID_1_MIRRORED_NMVE_M_2",
260+
}
261+
prices, err := OrderManager.GetPriceIdList("Test", Items, 0)
262+
Expect(err).ToNot(HaveOccurred())
263+
Expect(len(prices)).To(Equal(2))
264+
Expect(prices[0]).To(Equal(22484)) // DISK_CONTROLLER_RAID
265+
Expect(prices[1]).To(Equal(306531)) // DISK_CONTROLLER_RAID_1_MIRRORED_NMVE_M_2
266+
})
267+
It("Select nonraid Prices", func() {
268+
Items := []string{"DISK_CONTROLLER_NONRAID"}
269+
prices, err := OrderManager.GetPriceIdList("Test", Items, 0)
270+
Expect(err).ToNot(HaveOccurred())
271+
Expect(len(prices)).To(Equal(1))
272+
Expect(prices[0]).To(Equal(876)) // DISK_CONTROLLER_NONRAID
273+
})
274+
It("Select NVMe Prices Failure", func() {
275+
Items := []string{
276+
"DISK_CONTROLLER_RAID_1_MIRRORED_NMVE_M_2", "DISK_CONTROLLER_RAID",
277+
}
278+
_, err := OrderManager.GetPriceIdList("Test", Items, 0)
279+
Expect(err).To(HaveOccurred())
280+
Expect(err.Error()).To(ContainSubstring("Item DISK_CONTROLLER_RAID does not exist for package Test with category disk_controller1"))
281+
})
282+
})
253283
})
254284
})

0 commit comments

Comments
 (0)