SEBA-173
Change-Id: I3480e254784d4af68316d482990d664c50544cff
diff --git a/api/abstract_olt_api.proto b/api/abstract_olt_api.proto
index 12c8941..72dad9b 100644
--- a/api/abstract_olt_api.proto
+++ b/api/abstract_olt_api.proto
@@ -50,13 +50,7 @@
string DeviceID =1;
string ChassisDeviceID =2;
}
-message ActivateSlotMessage{
- string CLLI =1;
- int32 SlotNumber = 2;
-}
-message ActivateSlotReturn{
- bool Success = 1;
-}
+
message AddOntMessage{
string CLLI=1;
int32 SlotNumber=2;
@@ -68,6 +62,16 @@
bool Success=1;
}
+message DeleteOntMessage{
+ string CLLI=1;
+ int32 SlotNumber=2;
+ int32 PortNumber=3;
+ int32 OntNumber=4;
+ string SerialNumber=5;
+}
+message DeleteOntReturn{
+ bool Success=1;
+}
service AbstractOLT{
rpc CreateChassis(AddChassisMessage) returns (AddChassisReturn) {
option(google.api.http) = {
@@ -75,24 +79,23 @@
body:"*"
};
}
-
rpc CreateOLTChassis(AddOLTChassisMessage) returns (AddOLTChassisReturn) {
option(google.api.http) = {
post: "/v1/CreateOLTChassis"
body:"*"
};
}
- rpc EnableSlot(ActivateSlotMessage) returns (ActivateSlotReturn){
- option(google.api.http) = {
- post: "/v1/EnableSlot"
- body:"*"
- };
- }
rpc ProvisionOnt(AddOntMessage) returns (AddOntReturn) {
option(google.api.http) = {
post:"/v1/ProvsionOnt"
body:"*"
};
}
+ rpc DeleteOnt(DeleteOntMessage) returns (DeleteOntReturn){
+ option(google.api.http)={
+ post:"/v1/DeleteOnt"
+ body:"*"
+ };
+ }
}
diff --git a/api/handler.go b/api/handler.go
index 4aeae13..6beba76 100644
--- a/api/handler.go
+++ b/api/handler.go
@@ -17,7 +17,6 @@
package api
import (
- "errors"
"fmt"
"log"
"net"
@@ -111,23 +110,30 @@
}
/*
-EnableSlot - activates an OLT Chassis
-*/
-func (s *Server) EnableSlot(ctx context.Context, in *ActivateSlotMessage) (*ActivateSlotReturn, error) {
- return nil, errors.New("garbage error")
-}
-
-/*
ProvisionOnt provisions an ONT on a specific Chassis/LineCard/Port
*/
func (s *Server) ProvisionOnt(ctx context.Context, in *AddOntMessage) (*AddOntReturn, error) {
absChassisMap := models.GetAbstractChassisMap()
clli := in.GetCLLI()
chassis := (*absChassisMap)[clli]
- err := chassis.ActivateONT(int(in.GetSlotNumber()), int(in.GetPortNumber()), int(in.GetPortNumber()), in.GetSerialNumber())
+ err := chassis.ActivateONT(int(in.GetSlotNumber()), int(in.GetPortNumber()), int(in.GetOntNumber()), in.GetSerialNumber())
if err != nil {
return nil, err
}
return &AddOntReturn{Success: true}, nil
}
+
+/*
+DeleteOnt - deletes a previously provision ont
+*/
+func (s *Server) DeleteOnt(ctx context.Context, in *DeleteOntMessage) (*DeleteOntReturn, error) {
+ absChassisMap := models.GetAbstractChassisMap()
+ clli := in.GetCLLI()
+ chassis := (*absChassisMap)[clli]
+ err := chassis.DeleteONT(int(in.GetSlotNumber()), int(in.GetPortNumber()), int(in.GetOntNumber()), in.GetSerialNumber())
+ if err != nil {
+ return nil, err
+ }
+ return &DeleteOntReturn{Success: true}, nil
+}
diff --git a/api/handler_test.go b/api/handler_test.go
index c319e6d..59aad10 100644
--- a/api/handler_test.go
+++ b/api/handler_test.go
@@ -43,7 +43,7 @@
clli = ret.DeviceID
}
func TestHandler_CreateOLTChassis(t *testing.T) {
- fmt.Println("in handlerTest_CreateChassis")
+ fmt.Println("in handlerTest_CreateOltChassis")
message := &api.AddOLTChassisMessage{CLLI: clli, SlotIP: "12.2.2.0", SlotPort: 9191,
Hostname: slotHostname, Type: api.AddOLTChassisMessage_edgecore}
ret, err := server.CreateOLTChassis(ctx, message)
@@ -52,43 +52,31 @@
}
fmt.Printf("CreateOLTChassis success %v\n", ret)
}
-func TestHandler_EnableSlot(t *testing.T) {
- ctx = context.Background()
- server = api.Server{}
- fmt.Println("in handler_test_EnableSlot")
- // slot number 1 should be provisioned above
- message := &api.ActivateSlotMessage{CLLI: clli, SlotNumber: 1}
- ret, err := server.EnableSlot(ctx, message)
- if err != nil {
- t.Fatalf("EnableSlot failed with %v\n", err)
- }
- fmt.Printf("EnableSlot succeeded with %v\n", ret)
- // Slot 2 isn't provisioned and should fail
- message = &api.ActivateSlotMessage{CLLI: clli, SlotNumber: 2}
- ret, err = server.EnableSlot(ctx, message)
- if err != nil {
- switch err.(type) {
- case *physical.UnprovisionedSlotError:
- fmt.Printf("EnableSlot failed as it should with %v\n", err)
- default:
- t.Fatalf("EnableSlot failed with %v\n", err)
- }
- t.Fatalf("EnableSlot should have failed but didn't")
- }
-
-}
func TestHandler_ProvisionOnt(t *testing.T) {
ctx = context.Background()
server = api.Server{}
- fmt.Println("in handlerTest_CreateChassis")
+ fmt.Println("in handlerTest_ProvisonOnt")
// this one should succeed
message := &api.AddOntMessage{CLLI: clli, SlotNumber: 1, PortNumber: 3, OntNumber: 2, SerialNumber: "2033029402"}
ret, err := server.ProvisionOnt(ctx, message)
if err != nil {
t.Fatalf("ProvisionOnt failed %v\n", err)
}
+ // do it again on same ont/port should fail with AllReadyActiveError
+ ret, err = server.ProvisionOnt(ctx, message)
+ if err != nil {
+ switch err.(type) {
+ case *physical.AllReadyActiveError:
+ fmt.Printf("ProvisionOnt failed as it should with %v\n", err)
+ default:
+ t.Fatalf("ProvsionOnt test failed with %v\n", err)
+ }
+
+ } else {
+ t.Fatalf("ProvsionOnt should have failed with AllReadyActiveError but didn't")
+ }
+
// this one should fail
- fmt.Println("here")
//SlotNumber 1 hasn't been provisioned
message = &api.AddOntMessage{CLLI: clli, SlotNumber: 2, PortNumber: 3, OntNumber: 2, SerialNumber: "2033029402"}
ret, err = server.ProvisionOnt(ctx, message)
@@ -104,3 +92,43 @@
}
fmt.Printf("ProvisionOnt success %v\n", ret)
}
+func TestHandler_DeleteOnt(t *testing.T) {
+ ctx = context.Background()
+ server = api.Server{}
+ fmt.Println("in handlerTest_DeleteOnt")
+ // this one should succeed
+ //De-Activate ONT 3 on PONPort 0 Slot 0 on my cilli but not active
+ message := &api.DeleteOntMessage{CLLI: clli, SlotNumber: 1, PortNumber: 3, OntNumber: 2, SerialNumber: "2033029402"}
+ ret, err := server.DeleteOnt(ctx, message)
+ if err != nil {
+ t.Fatalf("DeleteOnt failed %v\n", err)
+ }
+ // This should fail with AllReadyDeactivatedError
+ ret, err = server.DeleteOnt(ctx, message)
+ if err != nil {
+ switch err.(type) {
+ case *physical.AllReadyDeactivatedError:
+ fmt.Printf("DeleteOnt failed as expected with %v\n", err)
+ default:
+ t.Fatalf("DeleteOnt failed with %v\n", err)
+ }
+ } else {
+ t.Fatal("DeleteOnt should have failed with AllReadyDeactivatedError")
+ }
+
+ // this one should fail
+ //SlotNumber 1 hasn't been provisioned
+ message = &api.DeleteOntMessage{CLLI: clli, SlotNumber: 2, PortNumber: 3, OntNumber: 2, SerialNumber: "2033029402"}
+ ret, err = server.DeleteOnt(ctx, message)
+ if err != nil {
+ switch err.(type) {
+ case *abstract.UnprovisonedPortError:
+ fmt.Printf("DeleteOnt failed as it should with %v\n", err)
+ default:
+ t.Fatalf("DeleteOnt test failed with %v\n", err)
+ }
+ } else {
+ t.Fatalf("DeleteOnt should have failed but didn't")
+ }
+ fmt.Printf("DeletenOnt success %v\n", ret)
+}