Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is based on Jacek Izykowski's work: #21 Initial patchset is a merge of his work to master. Following patchsets are fixes and improvements. Changes: * Remove loading keystone variables from environment. * Introduce an ini-format config file. * Command line params take precedence over config params. * Move flags to configuration/ package. * Refactors. * Introduce dryRun flag that parses config but doesn't do anything. * Bake sample test config file into test binary using go generate. This is done so that we don't have to complicate integration test setup on CI-side and needlessly couple it. It will be easier to add test cases this way as well. Co-authored-by: Jacek Izykowski <jacek.izykowski@codilime.com> Co-authored-by: Michal Kostrzewa <michal.kostrzewa@codilime.com> Change-Id: I92f0df4f84f519836a0af183cc4580f72189feb0 Closes-Bug: #1787565
- Loading branch information
Michal Kostrzewa
committed
Sep 11, 2018
1 parent
adf6312
commit 33bf8bd
Showing
18 changed files
with
518 additions
and
140 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# build output dir | ||
build/* | ||
|
||
# files generated with go generate | ||
baked* | ||
|
||
# test reports | ||
*.xml | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,20 @@ | ||
# | ||
# Copyright (c) 2018 Juniper Networks, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the `"License`"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an `"AS IS`" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
Write-Host "Baking test case data..." | ||
go generate -tags "unit, integration" ./... | ||
if ($LastExitCode -ne 0) { | ||
throw "Code generation failed." | ||
} |
This file contains 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 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 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 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 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,41 @@ | ||
[DRIVER] | ||
# Net adapter for HNS switch, must be physical | ||
Adapter = Ethernet0 | ||
|
||
# IP address of Contrail Controller API | ||
ControllerIP = 10.0.0.10 | ||
|
||
# Port of Contrail Controller API | ||
ControllerPort = 8082 | ||
|
||
# URL of Agent API | ||
AgentURL = http://127.0.0.1:9091 | ||
|
||
# Name of Transparent virtual switch. | ||
# Special wildcard "<adapter>" will be interpretted as value of netAdapter | ||
# parameter. For example, if netAdapter is "Ethernet0", then vswitchName will | ||
# be equal to "Layered Ethernet0". | ||
# You can use Get-VMSwitch PowerShell command to check how the switch is called | ||
# on your version of OS. | ||
VSwitchName = Layered?<adapter> | ||
|
||
|
||
[AUTH] | ||
# Auth method. Available values: (keystone|noauth). If keystone. [KEYSTONE] section must be filled. | ||
AuthMethod = keystone | ||
|
||
[KEYSTONE] | ||
# Keystone auth url. If empty, will read from environment variable. | ||
Os_auth_url = http://10.0.0.10:5000/v2.0/ | ||
|
||
# Contrail username. If empty, will read from environment variable. | ||
Os_username = admin | ||
|
||
# Tenant name. If empty, will read environment variable. | ||
Os_tenant_name = admin | ||
|
||
# Contrail password. If empty, will read environment variable. | ||
Os_password = hunter2 | ||
|
||
# Keystone token. If empty, will read environment variable. | ||
Os_token = |
This file contains 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,33 @@ | ||
# | ||
# Copyright (c) 2018 Juniper Networks, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the `"License`"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an `"AS IS`" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# This script is invoked by go generate. | ||
# We bake sample configuration file into the compiled test binary, so that we don't have to | ||
# transfer the file separately to remote machine to invoke integration tests that use it. | ||
|
||
$CfgFile = Get-Content -Raw ../cnm-driver.conf.sample | ||
|
||
" | ||
package configuration_test | ||
const ( | ||
sampleCfgFile = `` | ||
$CfgFile | ||
`` | ||
) | ||
" | Out-File baked_data_test.go -Encoding ASCII | ||
# We set encoding to ASCII, because without it, we get 'unexpected NUL in input' error while | ||
# compiling the generated file. |
This file contains 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,6 @@ | ||
These tests require, that sample config file in the root of this repository is baked | ||
into the binary itself. Supplied `Invoke-Build.ps1` and `Invoke-Tests.ps1` scripts already | ||
generate the required code. To do this by hand, however, invoke | ||
``` | ||
go generate -tags unit,integration ./... | ||
``` |
This file contains 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,65 @@ | ||
// | ||
// Copyright (c) 2018 Juniper Networks, Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package configuration | ||
|
||
import ( | ||
"github.com/Juniper/contrail-windows-docker-driver/adapters/secondary/controller_rest/auth" | ||
) | ||
|
||
type DriverConf struct { | ||
Adapter string | ||
ControllerIP string | ||
ControllerPort int | ||
AgentURL string | ||
VSwitchName string | ||
} | ||
|
||
type AuthConf struct { | ||
AuthMethod string | ||
Keystone auth.KeystoneParams | ||
} | ||
|
||
type Configuration struct { | ||
Driver DriverConf | ||
Auth AuthConf | ||
} | ||
|
||
func NewDefaultConfiguration() (conf Configuration) { | ||
conf.Driver.Adapter = "Ethernet0" | ||
conf.Driver.ControllerIP = "192.168.0.10" | ||
conf.Driver.ControllerPort = 8082 | ||
conf.Driver.AgentURL = "http://127.0.0.1:9091" | ||
conf.Driver.VSwitchName = "Layered <adapter>" | ||
|
||
conf.Auth.AuthMethod = "noauth" | ||
|
||
conf.Auth.Keystone.Os_auth_url = "" | ||
conf.Auth.Keystone.Os_username = "" | ||
conf.Auth.Keystone.Os_tenant_name = "" | ||
conf.Auth.Keystone.Os_password = "" | ||
conf.Auth.Keystone.Os_token = "" | ||
|
||
return | ||
} | ||
|
||
func DefaultConfigFilepath() string { | ||
return "" | ||
// TODO: uncomment the following lines once templating logic is implemented in ansible. | ||
// For now, return empty string, so that docker driver defaults to reading only command | ||
// line parameters. | ||
// return string(filepath.Join(os.Getenv("ProgramData"), | ||
// "Contrail", "etc", "contrail", "cnm-driver.conf")) | ||
} |
Oops, something went wrong.