-
Notifications
You must be signed in to change notification settings - Fork 260
Circleci #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Circleci #220
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3bea777
Initial circle ci commit.
912a1cf
Fixing ipam errorf along with setting image with golang version 1.10
11225c8
Fixing logger_test so that it will work on linux as well.
6cb4c3c
Fixing network_test.
6d16b83
Rebased on master.
8a0c4ac
Added some changes in attempt to test cns restserver in mock
4a10e80
Reverting some changes that aren't required for working unit tests.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| version: 2 | ||
| jobs: | ||
| setup-and-test: | ||
| # docker: | ||
| # - image: golang:1.10 | ||
| machine: | ||
| image: circleci/classic:latest | ||
| steps: | ||
| - checkout | ||
| - run: | ||
| name: Setup-and-test | ||
| command: | | ||
| sudo -E env "PATH=$PATH" apt-get update | ||
| sudo -E env "PATH=$PATH" apt-get install -y ebtables | ||
| sudo -E env "PATH=$PATH" apt-get install -y ipset | ||
| mkdir -p /home/circleci/go1-10 | ||
| mkdir --parents /home/circleci/.goproject/src/github.com/Azure/azure-container-networking | ||
| wget https://storage.googleapis.com/golang/go1.10.2.linux-amd64.tar.gz | ||
| tar -C /home/circleci/go1-10 -xvf go1.10.2.linux-amd64.tar.gz | ||
| rm go1.10.2.linux-amd64.tar.gz | ||
| mv * /home/circleci/.goproject/src/github.com/Azure/azure-container-networking | ||
| cd /home/circleci/.goproject/src/github.com/Azure/azure-container-networking | ||
| export GOROOT='/home/circleci/go1-10/go' | ||
| export GOPATH='/home/circleci/.goproject' | ||
| export PATH=$GOROOT/bin:$PATH | ||
| go get ./... | ||
| go get github.com/docker/libnetwork/driverapi | ||
| go get github.com/gorilla/mux | ||
| sudo -E env "PATH=$PATH" go test ./ipam/ | ||
| sudo -E env "PATH=$PATH" go test ./log/ | ||
| sudo -E env "PATH=$PATH" go test ./netlink/ | ||
| sudo -E env "PATH=$PATH" go test ./store/ | ||
| sudo -E env "PATH=$PATH" go test ./telemetry/ | ||
| sudo -E env "PATH=$PATH" go test ./cni/ipam/ | ||
| sudo -E env "PATH=$PATH" go test ./cnm/network/ | ||
| sudo -E env "PATH=$PATH" go test ./cns/ipamclient/ | ||
| #sudo -E env "PATH=$PATH" go test ./cns/restserver/ | ||
| workflows: | ||
| version: 2 | ||
| run-tests: | ||
| jobs: | ||
| - setup-and-test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,18 +6,78 @@ package restserver | |
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "encoding/xml" | ||
| "fmt" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "net/url" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns" | ||
| "github.com/Azure/azure-container-networking/cns/common" | ||
| "github.com/Azure/azure-container-networking/cns/imdsclient" | ||
| acncommon "github.com/Azure/azure-container-networking/common" | ||
| ) | ||
|
|
||
| var service HTTPService | ||
| var mux *http.ServeMux | ||
| type IPAddress struct { | ||
| XMLName xml.Name `xml:"IPAddress"` | ||
| Address string `xml:"Address,attr"` | ||
| IsPrimary bool `xml:"IsPrimary,attr"` | ||
| } | ||
| type IPSubnet struct { | ||
| XMLName xml.Name `xml:"IPSubnet"` | ||
| Prefix string `xml:"Prefix,attr"` | ||
| IPAddress []IPAddress | ||
| } | ||
|
|
||
| type Interface struct { | ||
| XMLName xml.Name `xml:"Interface"` | ||
| MacAddress string `xml:"MacAddress,attr"` | ||
| IsPrimary bool `xml:"IsPrimary,attr"` | ||
| IPSubnet []IPSubnet | ||
| } | ||
|
|
||
| type xmlDocument struct { | ||
| XMLName xml.Name `xml:"Interfaces"` | ||
| Interface []Interface | ||
| } | ||
|
|
||
| var ( | ||
| service HTTPService | ||
| mux *http.ServeMux | ||
| hostQueryForProgrammedVersionResponse = `{"httpStatusCode":"200","networkContainerId":"eab2470f-test-test-test-b3cd316979d5","version":"1"}` | ||
| hostQueryResponse = xmlDocument{ | ||
| XMLName: xml.Name{Local: "Interfaces"}, | ||
| Interface: []Interface{Interface{ | ||
| XMLName: xml.Name{Local: "Interface"}, | ||
| MacAddress: "*", | ||
| IsPrimary: true, | ||
| IPSubnet: []IPSubnet{ | ||
| IPSubnet{XMLName: xml.Name{Local: "IPSubnet"}, | ||
| Prefix: "10.0.0.0/16", | ||
| IPAddress: []IPAddress{ | ||
| IPAddress{ | ||
| XMLName: xml.Name{Local: "IPAddress"}, | ||
| Address: "10.0.0.4", | ||
| IsPrimary: true}, | ||
| }}, | ||
| }, | ||
| }}, | ||
| } | ||
| ) | ||
|
|
||
| func getInterfaceInfo(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/xml") | ||
| output, _ := xml.Marshal(hostQueryResponse) | ||
| w.Write(output) | ||
| } | ||
|
|
||
| func getContainerInfo(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/json; charset=UTF-8") | ||
| w.WriteHeader(http.StatusOK) | ||
| w.Write([]byte(hostQueryForProgrammedVersionResponse)) | ||
| } | ||
|
|
||
| // Wraps the test run with service setup and teardown. | ||
| func TestMain(m *testing.M) { | ||
|
|
@@ -33,6 +93,11 @@ func TestMain(m *testing.M) { | |
|
|
||
| // Configure test mode. | ||
| service.(*httpRestService).Name = "cns-test-server" | ||
| service.(*httpRestService).imdsClient.HostQueryURL = imdsclient.HostQueryURL | ||
| service.(*httpRestService).imdsClient.HostQueryURLForProgrammedVersion = imdsclient.HostQueryURLForProgrammedVersion | ||
| // Following HostQueryURL and HostQueryURLForProgrammedVersion are only for mock environment. | ||
| // service.(*httpRestService).imdsClient.HostQueryURL = "http://localhost:9000/getInterface" | ||
| // service.(*httpRestService).imdsClient.HostQueryURLForProgrammedVersion = "http://localhost:9000/machine/plugins/?comp=nmagent&type=NetworkManagement/interfaces/%s/networkContainers/%s/authenticationToken/%s/api-version/%s" | ||
|
|
||
| // Start the service. | ||
| err = service.Start(&config) | ||
|
|
@@ -44,6 +109,26 @@ func TestMain(m *testing.M) { | |
| // Get the internal http mux as test hook. | ||
| mux = service.(*httpRestService).Listener.GetMux() | ||
|
|
||
| // Setup mock nmagent server | ||
| u, err := url.Parse("tcp://localhost:9000") | ||
| if err != nil { | ||
| fmt.Println(err.Error()) | ||
| } | ||
|
|
||
| nmAgentServer, err := acncommon.NewListener(u) | ||
| if err != nil { | ||
| fmt.Println(err.Error()) | ||
| } | ||
|
|
||
| nmAgentServer.AddHandler("/getInterface", getInterfaceInfo) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create flag for const string |
||
| nmAgentServer.AddHandler("machine/plugins/?comp=nmagent&type=NetworkManagement/interfaces/{interface}/networkContainers/{networkContainer}/authenticationToken/{authToken}/api-version/{version}", getContainerInfo) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create flag for const string |
||
|
|
||
| err = nmAgentServer.Start(make(chan error, 1)) | ||
| if err != nil { | ||
| fmt.Printf("Failed to start agent, err:%v.\n", err) | ||
| return | ||
| } | ||
|
|
||
| // Run tests. | ||
| exitCode := m.Run() | ||
|
|
||
|
|
@@ -71,7 +156,7 @@ func setEnv(t *testing.T) *httptest.ResponseRecorder { | |
| envRequestJSON := new(bytes.Buffer) | ||
| json.NewEncoder(envRequestJSON).Encode(envRequest) | ||
|
|
||
| req, err := http.NewRequest(http.MethodPost, cns.V1Prefix+cns.SetEnvironmentPath, envRequestJSON) | ||
| req, err := http.NewRequest(http.MethodPost, cns.V2Prefix+cns.SetEnvironmentPath, envRequestJSON) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create some variables to avoid deep nesting for readability.