seba-328 - better error handling
Change-Id: I42f28ea4b003ce4619516852d9ce74db3916179a
diff --git a/models/abstract/chassis.go b/models/abstract/chassis.go
index a86822d..2b3231b 100644
--- a/models/abstract/chassis.go
+++ b/models/abstract/chassis.go
@@ -18,6 +18,7 @@
import (
"errors"
+ "fmt"
)
const MAX_SLOTS int = 16
@@ -63,15 +64,52 @@
return nextPort, nil
}
func (chassis *Chassis) ActivateONTFull(slotNumber int, portNumber int, ontNumber int, serialNumber string, cTag uint32, sTag uint32, nasPortID string, circuitID string) error {
+ if slotNumber > len(chassis.Slots) {
+ errorMsg := fmt.Sprintf("Invalid slot Number %d ", slotNumber)
+ return errors.New(errorMsg)
+ }
+ if portNumber > 16 {
+ errorMsg := fmt.Sprintf("Invalid port Number %d ", portNumber)
+ return errors.New(errorMsg)
+ }
+ if ontNumber > 64 {
+ errorMsg := fmt.Sprintf("Invalid ont Number %d ", ontNumber)
+ return errors.New(errorMsg)
+ }
+
err := chassis.Slots[slotNumber-1].Ports[portNumber-1].provisionOntFull(ontNumber, serialNumber, cTag, sTag, nasPortID, circuitID)
return err
}
func (chassis *Chassis) ActivateONT(slotNumber int, portNumber int, ontNumber int, serialNumber string) error {
+ if slotNumber > len(chassis.Slots) {
+ errorMsg := fmt.Sprintf("Invalid slot Number %d ", slotNumber)
+ return errors.New(errorMsg)
+ }
+ if portNumber > 16 {
+ errorMsg := fmt.Sprintf("Invalid port Number %d ", portNumber)
+ return errors.New(errorMsg)
+ }
+ if ontNumber > 64 {
+ errorMsg := fmt.Sprintf("Invalid ont Number %d ", ontNumber)
+ return errors.New(errorMsg)
+ }
err := chassis.Slots[slotNumber-1].Ports[portNumber-1].provisionOnt(ontNumber, serialNumber)
return err
}
func (chassis *Chassis) DeleteONT(slotNumber int, portNumber int, ontNumber int, serialNumber string) error {
+ if slotNumber > len(chassis.Slots) {
+ errorMsg := fmt.Sprintf("Invalid slot Number %d ", slotNumber)
+ return errors.New(errorMsg)
+ }
+ if portNumber > 16 {
+ errorMsg := fmt.Sprintf("Invalid port Number %d ", portNumber)
+ return errors.New(errorMsg)
+ }
+ if ontNumber > 64 {
+ errorMsg := fmt.Sprintf("Invalid ont Number %d ", ontNumber)
+ return errors.New(errorMsg)
+ }
err := chassis.Slots[slotNumber-1].Ports[portNumber-1].deleteOnt(ontNumber, serialNumber)
return err
}