orchestrationapi_test.go : enchanement test 22/204422/1
authorjaehoon.hyun <jaehoon.hyun@samsung.com>
Wed, 24 Apr 2019 01:00:54 +0000 (10:00 +0900)
committerjaehoon.hyun <jaehoon.hyun@samsung.com>
Wed, 24 Apr 2019 01:00:54 +0000 (10:00 +0900)
Add wifi turn on/off function
Add TestTurnOffWifiErrorAtRequestServiceApi test

Change-Id: I04ef686074fa631b571b4e05351698ca1744955f

src/orchestrationapi/orchestration_api_test.go

index e8fbbb8..4705ec3 100755 (executable)
@@ -19,6 +19,7 @@ package orchestrationapi
 import (
        "fmt"
        "log"
+       "net"
        "os/exec"
        "testing"
        "time"
@@ -77,6 +78,8 @@ func TestConfigureMgrScoringMgrAlreadyScoring2Library(t *testing.T) {
        //start configuremgr
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
        time.Sleep(time.Duration(300) * time.Millisecond)
@@ -133,6 +136,8 @@ func TestConfigureMgrServiceMgrScoringMgr(t *testing.T) {
        //configuremgr init
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
        RequestService("ls", []string{"-al"})
@@ -187,6 +192,8 @@ func TestConfigureMgrScoringMgr(t *testing.T) {
        //start configuremgr
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
        time.Sleep(time.Duration(3) * time.Second)
@@ -242,6 +249,8 @@ func TestConfigureMgrScoringMgrMyscoring2(t *testing.T) {
        //start configuremgr
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring2/", listeningDir))
        time.Sleep(time.Duration(3) * time.Second)
@@ -298,6 +307,8 @@ func TestConfigureMgrScoringMgrMyScoringLib(t *testing.T) {
        //start configuremgr
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
        time.Sleep(time.Duration(3) * time.Second)
@@ -350,6 +361,8 @@ func TestConfigureMgrDiscoveryMgr(t *testing.T) {
        //configuremgr init
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
        time.Sleep(time.Duration(3) * time.Second)
@@ -409,6 +422,8 @@ func TestRequestServiceFunctionServiceMgr(t *testing.T) {
        //servicemgr init
        servicemgr.Init()
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
        time.Sleep(time.Duration(3) * time.Second)
@@ -470,6 +485,8 @@ func TestConfigureMgrDiscoveryMgrScoringMgr(t *testing.T) {
        //configuremgr init
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "../scoringmgr/mock/myscoring/", listeningDir))
        time.Sleep(time.Duration(300) * time.Millisecond)
@@ -532,6 +549,8 @@ func TestConfigureMgrDiscoveryMgrServiceMgr(t *testing.T) {
        //configuremgr init
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
        time.Sleep(time.Duration(3) * time.Second)
@@ -598,6 +617,8 @@ func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T) {
        //configuremgr init
        go orcheMock.IConfiguremgr.Watch(listeningDir)
 
+       orcheMock.Ready = true
+
        //user scenario
        execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -626,12 +647,13 @@ func TestOrchestrationInitThreadAndRequestServiceThread(t *testing.T) {
        orcheMock := Init("")
        ExitTestChan := make(chan int, 2)
 
+       //init scenario
+       listeningDir := "/tmp/foo"
+       execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
+       execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
+       time.Sleep(time.Duration(100) * time.Millisecond)
+
        go func() {
-               //init scenario
-               listeningDir := "/tmp/foo"
-               execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
-               execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
-               time.Sleep(time.Duration(100) * time.Millisecond)
 
                orcheMock.IScoringmgr = scoringmgr.Init()
                orcheMock.IConfiguremgr = configuremgr.Init()
@@ -709,6 +731,82 @@ func TestOrchestrationInitThreadAndRequestServiceThread(t *testing.T) {
        time.Sleep(time.Duration(100) * time.Millisecond)
 }
 
+func TestTurnOffWifiErrorAtRequestServiceApi(t *testing.T) {
+       //init scenario
+       //TODO : Need wifi off logic.
+       turnOffWifi()
+       listeningDir := "/tmp/foo"
+       execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
+       execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
+       time.Sleep(time.Duration(100) * time.Millisecond)
+
+       orcheMock := Init("")
+
+       orcheMock.IScoringmgr = scoringmgr.Init()
+       orcheMock.IConfiguremgr = configuremgr.Init()
+
+       orcheMock.IScoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
+       orcheMock.IScoringmgr.IStartResourceService = scoringmgr.StartResourceService
+       orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService
+       orcheMock.IScoringmgr.IGetScore = scoringmgr.GetScore
+       orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
+
+       orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = discoverymgr.AddNewServiceName
+       orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
+       orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
+
+       orcheMock.IDiscoverymgr.GetEndpointDevices = discoverymgr.GetDeviceListWithService
+       orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp
+
+       //discoverymgr init
+       discoverymgr.InitDiscovery()
+
+       //servicemgr init
+       servicemgr.Init()
+
+       //scoringmgr init
+       orcheMock.IScoringmgr.Listening()
+       orcheMock.IScoringmgr.IStartResourceService()
+
+       //securemgr init
+       securemgr.Init("../securemgr/test/key.txt")
+
+       //configuremgr init
+       go orcheMock.IConfiguremgr.Watch(listeningDir)
+
+       orcheMock.Ready = true
+
+       //user scenario
+       execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
+       time.Sleep(time.Duration(100) * time.Millisecond)
+       ret := RequestService("ls", []string{"-al"})
+       if ret != -2 {
+               t.Fatal("is it wifi on????? plz off and retry test ", ret)
+       } else {
+               log.Println(logPrefixTest, "REEEEEEEEETTTTTTTTT == ", ret)
+       }
+
+       time.Sleep(time.Duration(100) * time.Millisecond)
+
+       //release scoringmgr
+       orcheMock.IScoringmgr.IStopResourceService()
+       orcheMock.IScoringmgr.RemoveAll()
+
+       //release configuremgr
+       orcheMock.IConfiguremgr.Done <- true
+
+       //release discoverymgr
+       discoverymgr.ExitChan <- 1
+       if discoverymgr.IsNilServer() == true {
+               discoverymgr.ExitPollingOutBoundCh <- 1
+       }
+
+       //turnOn wifi
+       turnOnWifi()
+
+       time.Sleep(time.Duration(100) * time.Millisecond)
+}
+
 func PushConfPathDiscoveryDeviceMock(doc *confdescription.Doc) (err error) {
        log.Println("[orchestrationapi] pushConfPathDiscoveryDeviceMock")
        log.Println(*doc)
@@ -743,3 +841,44 @@ func execCommand(command string) {
                log.Fatal(err)
        }
 }
+
+//=============== NETWORK INTERFACE CARD CONTROL =======================
+func turnOffWifi() {
+       log.Println("turn off wifi")
+       wlIfaces := findWifiIface()
+       log.Println(wlIfaces)
+
+       for _, wlIface := range wlIfaces {
+               execCommand(fmt.Sprintf("sudo ifconfig %s down", wlIface))
+       }
+
+}
+
+func turnOnWifi() {
+       log.Println("turn on wifi")
+
+       wlIfaces := findWifiIface()
+       log.Println(wlIfaces)
+
+       for _, wlIface := range wlIfaces {
+               execCommand(fmt.Sprintf("sudo ifconfig %s up", wlIface))
+       }
+
+}
+
+func findWifiIface() (wlIfaces []string) {
+       ifaces, _ := net.Interfaces()
+       for _, iface := range ifaces {
+               if iface.Name[0:2] == "wl" {
+                       wlIfaces = append(wlIfaces, iface.Name)
+               }
+       }
+
+       return
+}
+
+func getNetworkInterfaceCard() {
+       execCommand(fmt.Sprintf("ifconfig"))
+}
+
+//=============== NETWORK INTERFACE CARD CONTROL =======================