diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..1f96a03 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,34 @@ + + +**Snap version** (use `snapctl -v`): + +**Environment**: +- **Cloud provider or hardware configuration**: +- **OS** (e.g. from /etc/os-release): +- **Kernel** (e.g. `uname -a`): +- **Relevant tools** (e.g. plugins used with Snap): +- **Others** (e.g. deploying with Ansible): + + +**What happened**: + + +**What you expected to happen**: + + +**Steps to reproduce it** (as minimally and precisely as possible): + +1. +2. +3. + + +**Anything else do we need to know** (e.g. issue happens only occasionally): diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..f7d30d0 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,21 @@ + +Fixes # + +Summary of changes: +- +- +- + +How to verify it: +- + +Testing done: +- + +A picture of a snapping turtle (not required but encouraged): +- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..acc50ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# File managed by pluginsync +# +# NOTE: please commit OS/Editor specific settings in your .gitignore_global +# .idea +# .DS_Store +# +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof + +# Output of the go coverage tool +*.out +profile.cov + +# we don't vendor godep _workspace +**/Godeps/_workspace/** +vendor/ + +# ignore build artifacts +build/ diff --git a/.pluginsync.yml b/.pluginsync.yml new file mode 100644 index 0000000..edbf030 --- /dev/null +++ b/.pluginsync.yml @@ -0,0 +1,18 @@ +# File managed by pluginsync +pluginsync_config: '0.1.7' +managed_files: +- .github +- .github/ISSUE_TEMPLATE.md +- .github/PULL_REQUEST_TEMPLATE.md +- .gitignore +- .pluginsync.yml +- .travis.yml +- CONTRIBUTING.md +- LICENSE +- Makefile +- scripts +- scripts/build.sh +- scripts/common.sh +- scripts/deps.sh +- scripts/pre_deploy.sh +- scripts/test.sh diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..570c630 --- /dev/null +++ b/.sync.yml @@ -0,0 +1,21 @@ +:global: + maintainer: core +.travis.yml: + env: + global: + - ORG_PATH=/home/travis/gopath/src/github.com/intelsdi-x + - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/${TRAVIS_REPO_SLUG} + matrix: + - TEST_TYPE=small + - TEST_TYPE=medium + deploy: + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: YyBdd22h/0hl6YtA25GzLsija8Yg8uvF8RjDVwNheqcAEpmroLCq4LMMFo+AubUv+6oGmttLXRPfHk0uP3040Vp44TSTMC/mmRNQl8sxO+h/9UOWTCIFsFFxj0uN6S2oFDutLbqwRlt3pK2kxxGwJwL3PgBqUQ0c4HKNRpqRSSyeCi3+omq9r5C1H+b+XCYPz7kyQHKYRFqAm3441SJV+mInZTQHYz01rMuinN/P/rUEl988w9YxLoaR2keqAY5NVaOh35/Cnih/wVL8wdwcajSv939WblZ6tU/+ZL65d7Zv79zx4JCbeelzCxLBy+ftOaEtsm5F73Q3FGbXNBjmmMC24tDjo6kPVKLQBKRaJ3976LaYYyRw8Y83EytkZ5zntQprB6JtRY2zy0Y5LqUUImGw5A2O403gEZfvuNjROPU38Wd9rwkL0qP1w5dzd8qW2tn4KMARmF04dx8frSc8MXPxrIrEN/NOoH/wBSQFr70iDFrfxpsmjwBZ10HNQUhhLIWRxckpaeFYmxA4cq9OH1XOP/Yvaf9l0HtOouZEdrMOyHTuGr0WiGT7zslosKU0kjSwLStg1K6qyyiIpARNs2mpwNUaReKs8acqIMlPQkJIFfgOPkr819TZ8O6Q4rjsfmglOCWfIIa2UTdSFkwkS2R33vtmdirJWaiK3Pazrus= + api_key: + secure: SE4c+5pw4lt+aij6uN6CRuTxnDc2wjSOiU18ZJj1TmZxhGEBq02MZivacziA6WlmEOhsG4giaR06/MFtZBr4EJH53mn4nbF+K5f6sdG5VIx8ibt3+Vw7A1stNDYBgupWMO0s7kxUSsQUAjCb+u+udEUz6vLjQkFEaASVA+cFXgP9YS3uevIfNOwJ8ipB7cHAA/48+0nS8UfTm0oXD2DbBNiavUSYQbor9Zylfxj/dRcykVANCy2VfTv9j8b86J7BTlnoTMaNGsaUMCYC+gRxapOhh6fj5Dn6XXFRPPpy/zLiUvW3itW8EsyKUgZFOr76nGQ1ptKbmSvfQIw19uNem45ufg2+2Lbwkt+SMinepn8PaVlYtgrxxFpWEQZAkZVrQbudwUdQDlKVTFKvBMtvYJ9frh0AwDwuLRkvyYdOZwPEA3zb6LOhoaeh76cb/EXtdg4HOhJjUmvvdBJ9vmzzh6kKcvKhY/ihKxoBlXOSDvwXIMUVs66jiPR5nDfY2bWYCL5wnve4o+Uj5YJdyAdC5HCsSAuXURCkVSk2JtLP/mVAQZs0P/pnmyurEUZ55c3M2DVWjNE2ksB/KNMLCt7d9uBczaOkLvuvuMNx1xyigwLcuK4/DZAjxgtLi9oqDfVbPRGuEcxvZp06pe1TZJO51ft2gR1lT0R7pNouIdWXVNQ= +scripts/deps.sh: + packages: + - github.com/smartystreets/goconvey # NOTE: this should be moved to godep/glide + - github.com/stretchr/testify/mock + - github.com/gorilla/mux diff --git a/.travis.yml b/.travis.yml index d2c774d..195f933 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,70 @@ -sudo: required +# File managed by pluginsync +sudo: false language: go go: -- 1.6 -- 1.5.3 +- 1.6.3 +- 1.7.1 env: global: - - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap-plugin-collector-snmp + - ORG_PATH=/home/travis/gopath/src/github.com/intelsdi-x + - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/${TRAVIS_REPO_SLUG} matrix: - - TEST=small - - TEST=legacy + - TEST_TYPE=small + - TEST_TYPE=medium + - TEST_TYPE=build +matrix: + exclude: + - go: 1.6.3 + env: TEST_TYPE=build before_install: -- go get github.com/tools/godep -- if [ ! -d $SNAP_PLUGIN_SOURCE ]; then mkdir -p $HOME/gopath/src/github.com/intelsdi-x; ln -s $TRAVIS_BUILD_DIR $SNAP_PLUGIN_SOURCE; fi # CI for forks not from intelsdi-x +- "[[ -d $SNAP_PLUGIN_SOURCE ]] || mkdir -p $ORG_PATH && ln -s $TRAVIS_BUILD_DIR $SNAP_PLUGIN_SOURCE" install: -- export TMPDIR=$HOME/tmp -- mkdir -p $TMPDIR -- cd $SNAP_PLUGIN_SOURCE # change dir into source +- cd $SNAP_PLUGIN_SOURCE - make deps script: -- make check TEST=$TEST 2>&1 # Run test suite +- make check 2>&1 notifications: + email: false slack: secure: VkbZLIc2RH8yf3PtIAxUNPdAu3rQQ7yQx0GcK124JhbEnZGaHyK615V0rbG7HcVmYKGPdB0cXqZiLBDKGqGKb2zR1NepOe1nF03jxGSpPq8jIFeEXSJGEYGL34ScDzZZGuG6qwbjFcXiW5lqn6t8igzp7v2+URYBaZo5ktCS2xY= +before_deploy: +- "./scripts/pre_deploy.sh" +deploy: +- provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: YyBdd22h/0hl6YtA25GzLsija8Yg8uvF8RjDVwNheqcAEpmroLCq4LMMFo+AubUv+6oGmttLXRPfHk0uP3040Vp44TSTMC/mmRNQl8sxO+h/9UOWTCIFsFFxj0uN6S2oFDutLbqwRlt3pK2kxxGwJwL3PgBqUQ0c4HKNRpqRSSyeCi3+omq9r5C1H+b+XCYPz7kyQHKYRFqAm3441SJV+mInZTQHYz01rMuinN/P/rUEl988w9YxLoaR2keqAY5NVaOh35/Cnih/wVL8wdwcajSv939WblZ6tU/+ZL65d7Zv79zx4JCbeelzCxLBy+ftOaEtsm5F73Q3FGbXNBjmmMC24tDjo6kPVKLQBKRaJ3976LaYYyRw8Y83EytkZ5zntQprB6JtRY2zy0Y5LqUUImGw5A2O403gEZfvuNjROPU38Wd9rwkL0qP1w5dzd8qW2tn4KMARmF04dx8frSc8MXPxrIrEN/NOoH/wBSQFr70iDFrfxpsmjwBZ10HNQUhhLIWRxckpaeFYmxA4cq9OH1XOP/Yvaf9l0HtOouZEdrMOyHTuGr0WiGT7zslosKU0kjSwLStg1K6qyyiIpARNs2mpwNUaReKs8acqIMlPQkJIFfgOPkr819TZ8O6Q4rjsfmglOCWfIIa2UTdSFkwkS2R33vtmdirJWaiK3Pazrus= + bucket: snap.ci.snap-telemetry.io + region: us-west-2 + skip_cleanup: true + local-dir: s3 + upload-dir: plugins + acl: public_read + on: + repo: intelsdi-x/snap-plugin-collector-snmp + branch: master + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" +- provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: YyBdd22h/0hl6YtA25GzLsija8Yg8uvF8RjDVwNheqcAEpmroLCq4LMMFo+AubUv+6oGmttLXRPfHk0uP3040Vp44TSTMC/mmRNQl8sxO+h/9UOWTCIFsFFxj0uN6S2oFDutLbqwRlt3pK2kxxGwJwL3PgBqUQ0c4HKNRpqRSSyeCi3+omq9r5C1H+b+XCYPz7kyQHKYRFqAm3441SJV+mInZTQHYz01rMuinN/P/rUEl988w9YxLoaR2keqAY5NVaOh35/Cnih/wVL8wdwcajSv939WblZ6tU/+ZL65d7Zv79zx4JCbeelzCxLBy+ftOaEtsm5F73Q3FGbXNBjmmMC24tDjo6kPVKLQBKRaJ3976LaYYyRw8Y83EytkZ5zntQprB6JtRY2zy0Y5LqUUImGw5A2O403gEZfvuNjROPU38Wd9rwkL0qP1w5dzd8qW2tn4KMARmF04dx8frSc8MXPxrIrEN/NOoH/wBSQFr70iDFrfxpsmjwBZ10HNQUhhLIWRxckpaeFYmxA4cq9OH1XOP/Yvaf9l0HtOouZEdrMOyHTuGr0WiGT7zslosKU0kjSwLStg1K6qyyiIpARNs2mpwNUaReKs8acqIMlPQkJIFfgOPkr819TZ8O6Q4rjsfmglOCWfIIa2UTdSFkwkS2R33vtmdirJWaiK3Pazrus= + bucket: snap.ci.snap-telemetry.io + region: us-west-2 + skip_cleanup: true + local-dir: s3 + upload-dir: plugins + acl: public_read + on: + repo: intelsdi-x/snap-plugin-collector-snmp + tags: true + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" +- provider: releases + api_key: + secure: SE4c+5pw4lt+aij6uN6CRuTxnDc2wjSOiU18ZJj1TmZxhGEBq02MZivacziA6WlmEOhsG4giaR06/MFtZBr4EJH53mn4nbF+K5f6sdG5VIx8ibt3+Vw7A1stNDYBgupWMO0s7kxUSsQUAjCb+u+udEUz6vLjQkFEaASVA+cFXgP9YS3uevIfNOwJ8ipB7cHAA/48+0nS8UfTm0oXD2DbBNiavUSYQbor9Zylfxj/dRcykVANCy2VfTv9j8b86J7BTlnoTMaNGsaUMCYC+gRxapOhh6fj5Dn6XXFRPPpy/zLiUvW3itW8EsyKUgZFOr76nGQ1ptKbmSvfQIw19uNem45ufg2+2Lbwkt+SMinepn8PaVlYtgrxxFpWEQZAkZVrQbudwUdQDlKVTFKvBMtvYJ9frh0AwDwuLRkvyYdOZwPEA3zb6LOhoaeh76cb/EXtdg4HOhJjUmvvdBJ9vmzzh6kKcvKhY/ihKxoBlXOSDvwXIMUVs66jiPR5nDfY2bWYCL5wnve4o+Uj5YJdyAdC5HCsSAuXURCkVSk2JtLP/mVAQZs0P/pnmyurEUZ55c3M2DVWjNE2ksB/KNMLCt7d9uBczaOkLvuvuMNx1xyigwLcuK4/DZAjxgtLi9oqDfVbPRGuEcxvZp06pe1TZJO51ft2gR1lT0R7pNouIdWXVNQ= + file: + - release/snap-plugin-collector-snmp_linux_x86_64 + skip_cleanup: true + on: + repo: intelsdi-x/snap-plugin-collector-snmp + tags: true + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b6469d..b975063 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# snap collector plugin - snmp +# snap plugin collector snmp 1. [Contributing Code](#contributing-code) 2. [Contributing Examples](#contributing-examples) @@ -11,37 +11,37 @@ This repository has dedicated developers from Intel working on updates. The most **_IMPORTANT_**: We encourage contributions to the project from the community. We ask that you keep the following guidelines in mind when planning your contribution. * Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/intelsdi-x/snap-plugin-collector-snmp/issues)** and let us know what you are thinking. -* **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created. -* **For feature requests**, we want to improve upon the library incrementally which means small changes at a time. In order ensure your PR can be reviewed in a timely manner, please keep PRs small, e.g. <10 files and <500 lines changed. If you think this is unrealistic, then mention that within the issue and we can discuss it. +* **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created. Include the `Fixes #` syntax to link it to the issue you're addressing. +* **For feature requests**, we want to improve upon the library incrementally which means small changes at a time. In order to ensure your PR can be reviewed in a timely manner, please keep PRs small, e.g. <10 files and <500 lines changed. If you think this is unrealistic, then mention that within the issue and we can discuss it. Once you're ready to contribute code back to this repo, start with these steps: * Fork the appropriate sub-projects that are affected by your change. * Clone the fork to `$GOPATH/src/github.com/intelsdi-x/`: - ``` - $ git clone https://github.com//.git - ``` + ``` +$ cd "${GOPATH}/src/github.com/intelsdi-x/" +$ git clone https://github.com/intelsdi-x/snap-plugin-collector-snmp.git + ``` * Create a topic branch for your change and checkout that branch: ``` - $ git checkout -b some-topic-branch +$ git checkout -b some-topic-branch ``` * Make your changes and run the test suite if one is provided. * Commit your changes and push them to your fork. * Open a pull request for the appropriate project. * Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback. -* To report a bug or issue, please open a new issue against this repository. -If you have questions feel free to contact the [maintainers](https://github.com/intelsdi-x/snap/blob/master/README.md#maintainers) by tagging them: @intelsdi-x/plugin-maintainers. +If you have questions feel free to contact the [maintainers](https://github.com/intelsdi-x/snap/blob/master/README.md#maintainers). ## Contributing Examples The most immediately helpful way you can benefit this project is by cloning the repository, adding some further examples and submitting a pull request. -Have you written a blog post about how you use [snap](http://github.com/intelsdi-x/snap) and/or this plugin? Share it with us! +Have you written a blog post about how you use [Snap](http://github.com/intelsdi-x/snap) and/or this plugin? Send it to us [on Slack](http://slack.snap-telemetry.io)! ## Contribute Elsewhere -This repository is one of **many** plugins in **Snap**, the open telemetry framework. See the full project at http://github.com/intelsdi-x/snap. +This repository is one of **many** plugins in **Snap**, a powerful telemetry framework. See the full project at http://snap-telemetry.io ## Thank You And **thank you!** Your contribution, through code and participation, is incredibly important to us. diff --git a/LICENSE b/LICENSE index d645695..f433b1a 100644 --- a/LICENSE +++ b/LICENSE @@ -175,28 +175,3 @@ of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/Makefile b/Makefile index f70b452..e9ea9a7 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,36 @@ +# File managed by pluginsync +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2015 Intel Corporation +# +# 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. + default: $(MAKE) deps $(MAKE) all deps: - bash -c "godep restore" + bash -c "./scripts/deps.sh" test: - bash -c "./scripts/test.sh $(TEST)" + bash -c "./scripts/test.sh $(TEST_TYPE)" +test-legacy: + bash -c "./scripts/test.sh legacy" +test-small: + bash -c "./scripts/test.sh small" +test-medium: + bash -c "./scripts/test.sh medium" +test-large: + bash -c "./scripts/test.sh large" check: $(MAKE) test all: diff --git a/collector/collector_test.go b/collector/collector_test.go index 188c0e0..917dd92 100644 --- a/collector/collector_test.go +++ b/collector/collector_test.go @@ -1,4 +1,4 @@ -// +build legacy +// +build medium /* http://www.apache.org/licenses/LICENSE-2.0.txt diff --git a/scripts/build.sh b/scripts/build.sh index 49b9bef..58b6d41 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,26 +1,48 @@ -#!/bin/bash -e +#!/bin/bash +# File managed by pluginsync -GITVERSION=`git describe --always` -SOURCEDIR=$1 -BUILDDIR=$SOURCEDIR/build -PLUGIN=`echo $SOURCEDIR | grep -oh "snap-.*"` -ROOTFS=$BUILDDIR/rootfs -BUILDCMD='go build -a -ldflags "-w"' +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# 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. -echo -echo "**** Snap Plugin Build ****" -echo +set -e +set -u +set -o pipefail -# Disable CGO for builds -export CGO_ENABLED=0 +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +plugin_name=${__proj_dir##*/} +build_dir="${__proj_dir}/build" +go_build=(go build -ldflags "-w") -# Clean build bin dir -rm -rf $ROOTFS/* +_info "project path: ${__proj_dir}" +_info "plugin name: ${plugin_name}" + +export CGO_ENABLED=0 -# Make dir -mkdir -p $ROOTFS +# rebuild binaries: +_debug "removing: ${build_dir:?}/*" +rm -rf "${build_dir:?}/"* -# Build plugin -echo "Source Dir = $SOURCEDIR" -echo "Building Snap Plugin: $PLUGIN" -$BUILDCMD -o $ROOTFS/$PLUGIN +_info "building plugin: ${plugin_name}" +export GOOS=linux +export GOARCH=amd64 +mkdir -p "${build_dir}/${GOOS}/x86_64" +"${go_build[@]}" -o "${build_dir}/${GOOS}/x86_64/${plugin_name}" . || exit 1 diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 0000000..b8e7413 --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,111 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# 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. + +set -e +set -u +set -o pipefail + +LOG_LEVEL="${LOG_LEVEL:-6}" +NO_COLOR="${NO_COLOR:-}" + +trap_exitcode() { + exit $? +} + +trap trap_exitcode SIGINT + +_fmt () { + local color_debug="\x1b[35m" + local color_info="\x1b[32m" + local color_notice="\x1b[34m" + local color_warning="\x1b[33m" + local color_error="\x1b[31m" + local colorvar=color_$1 + + local color="${!colorvar:-$color_error}" + local color_reset="\x1b[0m" + if [ "${NO_COLOR}" = "true" ] || [[ "${TERM:-}" != "xterm"* ]] || [ -t 1 ]; then + # Don't use colors on pipes or non-recognized terminals + color=""; color_reset="" + fi + echo -e "$(date -u +"%Y-%m-%d %H:%M:%S UTC") ${color}$(printf "[%9s]" "${1}")${color_reset}"; +} + +_debug () { [ "${LOG_LEVEL}" -ge 7 ] && echo "$(_fmt debug) ${*}" 1>&2 || true; } +_info () { [ "${LOG_LEVEL}" -ge 6 ] && echo "$(_fmt info) ${*}" 1>&2 || true; } +_notice () { [ "${LOG_LEVEL}" -ge 5 ] && echo "$(_fmt notice) ${*}" 1>&2 || true; } +_warning () { [ "${LOG_LEVEL}" -ge 4 ] && echo "$(_fmt warning) ${*}" 1>&2 || true; } +_error () { [ "${LOG_LEVEL}" -ge 3 ] && echo "$(_fmt error) ${*}" 1>&2 || true; exit 1; } + +_test_dirs() { + local test_dirs=$(find . -type f -name '*.go' -not -path "./.*" -not -path "*/_*" -not -path "./Godeps/*" -not -path "./vendor/*" -print0 | xargs -0 -n1 dirname| sort -u) + _debug "go code directories ${test_dirs}" + echo "${test_dirs}" +} + +_go_get() { + local _url=$1 + local _util + + _util=$(basename "${_url}") + + type -p "${_util}" > /dev/null || go get "${_url}" && _debug "go get ${_util} ${_url}" +} + +_goimports() { + _go_get golang.org/x/tools/cmd/goimports + test -z "$(goimports -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)" +} + +_golint() { + _go_get github.com/golang/lint/golint + golint ./... +} + +_go_vet() { + go vet $(_test_dirs) +} + +_go_race() { + go test -race ./... +} + +_go_test() { + _info "running test type: ${TEST_TYPE}" + # Standard go tooling behavior is to ignore dirs with leading underscors + for dir in $(_test_dirs); + do + if [[ -z ${go_cover+x} ]]; then + _debug "running go test with cover in ${dir}" + go test -v --tags="${TEST_TYPE}" -covermode=count -coverprofile="${dir}/profile.tmp" "${dir}" + if [ -f "${dir}/profile.tmp" ]; then + tail -n +2 "${dir}/profile.tmp" >> profile.cov + rm "${dir}/profile.tmp" + fi + else + _debug "running go test without cover in ${dir}" + go test -v --tags="${TEST_TYPE}" "${dir}" + fi + done +} + +_go_cover() { + go tool cover -func profile.cov +} diff --git a/scripts/deps.sh b/scripts/deps.sh new file mode 100755 index 0000000..7829708 --- /dev/null +++ b/scripts/deps.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# 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. + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +detect_go_dep() { + [[ -f "${__proj_dir}/Godeps/Godeps.json" ]] && _dep='godep' + [[ -f "${__proj_dir}/glide.yaml" ]] && _dep='glide' + [[ -f "${__proj_dir}/vendor/vendor.json" ]] && _dep='govendor' + _info "golang dependency tool: ${_dep}" + echo "${_dep}" +} + +install_go_dep() { + local _dep=${_dep:=$(_detect_dep)} + _info "ensuring ${_dep} is available" + case $_dep in + godep) + _go_get github.com/tools/godep + ;; + glide) + _go_get github.com/Masterminds/glide + ;; + govendor) + _go_get github.com/kardianos/govendor + ;; + esac +} + +restore_go_dep() { + local _dep=${_dep:=$(_detect_dep)} + _info "restoring dependency with ${_dep}" + case $_dep in + godep) + (cd "${__proj_dir}" && godep restore) + ;; + glide) + (cd "${__proj_dir}" && glide install) + ;; + govendor) + (cd "${__proj_dir}" && govendor sync) + ;; + esac +} + +_dep=$(detect_go_dep) +install_go_dep +restore_go_dep +_go_get github.com/smartystreets/goconvey +_go_get github.com/stretchr/testify/mock +_go_get github.com/gorilla/mux diff --git a/scripts/pre_deploy.sh b/scripts/pre_deploy.sh new file mode 100755 index 0000000..9a57824 --- /dev/null +++ b/scripts/pre_deploy.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# 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. + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +build_path="${__proj_dir}/build" +_info "build_path: ${build_path}" +_debug "$(find "${build_path}")" + +plugin_name="${__proj_dir##*/}" +git_sha=$(git log --pretty=format:"%H" -1) +s3_path="${__proj_dir}/s3/${plugin_name}" + +set +u +if [ -z "$TRAVIS_TAG" ]; then + set -u + git_path="${s3_path}/${git_sha}" + latest_path="${s3_path}/latest_build" + mkdir -p "${git_path}" + mkdir -p "${latest_path}" + + _info "copying plugin binaries to ${git_path}" + cp -rp "${build_path}/"* "${git_path}" + _info "copying plugin binaries to ${latest_path}" + cp -rp "${build_path}/"* "${latest_path}" +else + set -u + tag_path="${s3_path}/${TRAVIS_TAG}" + latest_path="${s3_path}/latest" + mkdir -p "${tag_path}" + mkdir -p "${latest_path}" + + _info "copying plugin binaries to ${tag_path}" + cp -rp "${build_path}/"* "${tag_path}" + _info "copying plugin binaries to ${latest_path}" + cp -rp "${build_path}/"* "${latest_path}" +fi + +release_path="${SNAP_PATH:-"${__proj_dir}/release"}" +mkdir -p "${release_path}" + +_info "moving plugin binaries to ${release_path}" + +for file in "${build_path}"/**/*/snap-plugin-* ; do + filename="${file##*/}" + parent="${file%/*}" + arch="${parent##*/}" + parent="${parent%/*}" + os="${parent##*/}" + cp "${file}" "${release_path}/${filename}_${os}_${arch}" +done + +_debug "$(find "${build_path}")" +_debug "$(find "${s3_path}")" +_debug "$(find "${release_path}")" diff --git a/scripts/test.sh b/scripts/test.sh index b3408bd..a63d7f0 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,87 +1,100 @@ -#!/bin/bash -e -# The script does automatic checking on a Go package and its sub-packages, including: -# 1. gofmt (http://golang.org/cmd/gofmt/) -# 2. goimports (https://github.com/bradfitz/goimports) -# 3. golint (https://github.com/golang/lint) -# 4. go vet (http://golang.org/cmd/vet) -# 5. race detector (http://blog.golang.org/race-detector) -# 6. test coverage (http://blog.golang.org/cover) +#!/bin/bash +# File managed by pluginsync +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# 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. -# Capture what test we should run -TEST_SUITE=$1 +# Support travis.ci environment matrix: +TEST_TYPE="${TEST_TYPE:-$1}" +UNIT_TEST="${UNIT_TEST:-"gofmt goimports go_vet go_test go_cover"}" +TEST_K8S="${TEST_K8S:-0}" -if [[ ( $TEST_SUITE == "small" ) || ( $TEST_SUITE == "legacy" ) ]]; then - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls - go get -u github.com/golang/lint/golint - go get golang.org/x/tools/cmd/goimports - go get github.com/smartystreets/goconvey/convey - go get golang.org/x/tools/cmd/cover - go get github.com/stretchr/testify - go get github.com/gorilla/mux +set -e +set -u +set -o pipefail +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" - COVERALLS_TOKEN=t47LG6BQsfLwb9WxB56hXUezvwpED6D11 - TEST_DIRS="main.go collector/" - VET_DIRS=". ./collector/..." +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" - set -e +_debug "script directory ${__dir}" +_debug "project directory ${__proj_dir}" - # Automatic checks - echo "gofmt" - test -z "$(gofmt -l -d $TEST_DIRS | tee /dev/stderr)" +[[ "$TEST_TYPE" =~ ^(small|medium|large|legacy|build)$ ]] || _error "invalid TEST_TYPE (value must be 'small', 'medium', 'large', 'legacy', or 'build' recieved:${TEST_TYPE}" - echo "goimports" - test -z "$(goimports -l -d $TEST_DIRS | tee /dev/stderr)" +_gofmt() { + test -z "$(gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)" +} - # Useful but should not fail on link per: https://github.com/golang/lint - # "The suggestions made by golint are exactly that: suggestions. Golint is not perfect, - # and has both false positives and false negatives. Do not treat its output as a gold standard. - # We will not be adding pragmas or other knobs to suppress specific warnings, so do not expect - # or require code to be completely "lint-free". In short, this tool is not, and will never be, - # trustworthy enough for its suggestions to be enforced automatically, for example as part of - # a build process" - # echo "golint" - # golint ./... +test_unit() { + # The script does automatic checking on a Go package and its sub-packages, including: + # 1. gofmt (http://golang.org/cmd/gofmt/) + # 2. goimports (https://github.com/bradfitz/goimports) + # 3. golint (https://github.com/golang/lint) + # 4. go vet (http://golang.org/cmd/vet) + # 5. race detector (http://blog.golang.org/race-detector) + # 6. go test + # 7. test coverage (http://blog.golang.org/cover) + local go_tests + go_tests=(gofmt goimports golint go_vet go_race go_test go_cover) - echo "go vet" - go vet $VET_DIRS - # go test -race ./... - Lets disable for now + _debug "available unit tests: ${go_tests[*]}" + _debug "user specified tests: ${UNIT_TEST}" - # Run test coverage on each subdirectories and merge the coverage profile. - echo "mode: count" > profile.cov + ((n_elements=${#go_tests[@]}, max=n_elements - 1)) - # Standard go tooling behavior is to ignore dirs with leading underscors - for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path './examples/*' -not -path './scripts/*' -not -path './build/*' -not -path './Godeps/*' -type d); - do - if ls $dir/*.go &> /dev/null; then - go test --tags=$TEST_SUITE -covermode=count -coverprofile=$dir/profile.tmp $dir - if [ -f $dir/profile.tmp ] - then - cat $dir/profile.tmp | tail -n +2 >> profile.cov - rm $dir/profile.tmp - fi - fi - done + for ((i = 0; i <= max; i++)); do + if [[ "${UNIT_TEST}" =~ (^| )"${go_tests[i]}"( |$) ]]; then + _info "running ${go_tests[i]}" + _"${go_tests[i]}" + else + _debug "skipping ${go_tests[i]}" + fi + done +} - go tool cover -func profile.cov - - # Disabled Coveralls.io for now - # To submit the test coverage result to coveralls.io, - # use goveralls (https://github.com/mattn/goveralls) - # goveralls -coverprofile=profile.cov -service=travis-ci -repotoken t47LG6BQsfLwb9WxB56hXUezvwpED6D11 - # - # If running inside Travis we update coveralls. We don't want his happening on Macs - # if [ "$TRAVIS" == "true" ] - # then - # n=1 - # until [ $n -ge 6 ] - # do - # echo "posting to coveralls attempt $n of 5" - # goveralls -v -coverprofile=profile.cov -service travis.ci -repotoken $COVERALLS_TOKEN && break - # n=$[$n+1] - # sleep 30 - # done - # fi +if [[ $TEST_TYPE == "legacy" ]]; then + echo "mode: count" > profile.cov + export TEST_TYPE="unit" + test_unit +elif [[ $TEST_TYPE == "small" ]]; then + if [[ -f "${__dir}/small.sh" ]]; then + . "${__dir}/small.sh" + else + echo "mode: count" > profile.cov + test_unit + fi +elif [[ $TEST_TYPE == "medium" ]]; then + if [[ -f "${__dir}/medium.sh" ]]; then + . "${__dir}/medium.sh" + else + UNIT_TEST="go_test" + test_unit + fi +elif [[ $TEST_TYPE == "large" ]]; then + if [[ "${TEST_K8S}" != "0" && -f "$__dir/large_k8s.sh" ]]; then + . "${__dir}/large_k8s.sh" + elif [[ -f "${__dir}/large_compose.sh" ]]; then + . "${__dir}/large_compose.sh" + else + _info "No large tests." + fi +elif [[ $TEST_TYPE == "build" ]]; then + "${__dir}/build.sh" fi