From 57a8bf659ed3c81f9e6d089b572945eb406554d9 Mon Sep 17 00:00:00 2001 From: DennyZhang Date: Wed, 30 Oct 2013 17:37:44 -0500 Subject: [PATCH] remove code duplication in run-*.sh These shell scripts have code duplication for defensive checking variables of ORG and PROJECT Change-Id: I72a900d5c8ee105cf91d27a3cdf7068f91dec329 --- .../jenkins/files/slave_scripts/functions.sh | 49 +++++++++++++++++++ .../jenkins/files/slave_scripts/run-bash8.sh | 10 +--- .../jenkins/files/slave_scripts/run-cover.sh | 10 +--- .../jenkins/files/slave_scripts/run-docs.sh | 10 +--- .../jenkins/files/slave_scripts/run-pep8.sh | 10 +--- .../jenkins/files/slave_scripts/run-pylint.sh | 10 +--- .../files/slave_scripts/run-selenium.sh | 10 +--- .../files/slave_scripts/run-tarball.sh | 10 +--- .../files/slave_scripts/run-unittests.sh | 11 +---- .../files/slave_scripts/select-mirror.sh | 10 +--- 10 files changed, 67 insertions(+), 73 deletions(-) create mode 100755 modules/jenkins/files/slave_scripts/functions.sh mode change 100644 => 100755 modules/jenkins/files/slave_scripts/run-pep8.sh mode change 100644 => 100755 modules/jenkins/files/slave_scripts/run-pylint.sh mode change 100644 => 100755 modules/jenkins/files/slave_scripts/run-tarball.sh diff --git a/modules/jenkins/files/slave_scripts/functions.sh b/modules/jenkins/files/slave_scripts/functions.sh new file mode 100755 index 0000000000..ef013eb2ce --- /dev/null +++ b/modules/jenkins/files/slave_scripts/functions.sh @@ -0,0 +1,49 @@ +# +# Copyright 2013 OpenStack Foundation +# +# 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. +# +# helper functions + +function check_variable_org_project() +{ + org=$1 + project=$2 + filename=$3 + + if [[ -z "$org" || -z "$project" ]] + then + echo "Usage: $filename ORG PROJECT" + echo + echo "ORG: The project organization (eg 'openstack')" + echo "PROJECT: The project name (eg 'nova')" + exit 1 + fi +} + +function check_variable_version_org_project() +{ + version=$1 + org=$2 + project=$3 + filename=$4 + if [[ -z "$version" || -z "$org" || -z "$project" ]] + then + echo "Usage: $filename VERSION ORG PROJECT" + echo + echo "VERSION: The tox environment python version (eg '27')" + echo "ORG: The project organization (eg 'openstack')" + echo "PROJECT: The project name (eg 'nova')" + exit 1 + fi +} diff --git a/modules/jenkins/files/slave_scripts/run-bash8.sh b/modules/jenkins/files/slave_scripts/run-bash8.sh index fd137577fb..62dae77f08 100755 --- a/modules/jenkins/files/slave_scripts/run-bash8.sh +++ b/modules/jenkins/files/slave_scripts/run-bash8.sh @@ -17,14 +17,8 @@ org=$1 project=$2 -if [[ -z "$org" || -z "$project" ]] -then - echo "Usage: $0 ORG PROJECT" - echo - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_org_project "$org" "$project" "$0" source /usr/local/jenkins/slave_scripts/select-mirror.sh $org $project diff --git a/modules/jenkins/files/slave_scripts/run-cover.sh b/modules/jenkins/files/slave_scripts/run-cover.sh index d9e16cdea0..95248cae64 100755 --- a/modules/jenkins/files/slave_scripts/run-cover.sh +++ b/modules/jenkins/files/slave_scripts/run-cover.sh @@ -7,14 +7,8 @@ org=$1 project=$2 -if [[ -z "$org" || -z "$project" ]] -then - echo "Usage: $0 ORG PROJECT" - echo - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_org_project "$org" "$project" "$0" source /usr/local/jenkins/slave_scripts/select-mirror.sh $org $project diff --git a/modules/jenkins/files/slave_scripts/run-docs.sh b/modules/jenkins/files/slave_scripts/run-docs.sh index 4150374ac5..5efa6bbbf3 100755 --- a/modules/jenkins/files/slave_scripts/run-docs.sh +++ b/modules/jenkins/files/slave_scripts/run-docs.sh @@ -10,14 +10,8 @@ org=$1 project=$2 -if [[ -z "$org" || -z "$project" ]] -then - echo "Usage: $0 ORG PROJECT" - echo - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_org_project "$org" "$project" "$0" source /usr/local/jenkins/slave_scripts/select-mirror.sh $org $project diff --git a/modules/jenkins/files/slave_scripts/run-pep8.sh b/modules/jenkins/files/slave_scripts/run-pep8.sh old mode 100644 new mode 100755 index 4a3ad327a5..fda4aa3909 --- a/modules/jenkins/files/slave_scripts/run-pep8.sh +++ b/modules/jenkins/files/slave_scripts/run-pep8.sh @@ -17,14 +17,8 @@ org=$1 project=$2 -if [[ -z "$org" || -z "$project" ]] -then - echo "Usage: $0 ORG PROJECT" - echo - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_org_project "$org" "$project" "$0" source /usr/local/jenkins/slave_scripts/select-mirror.sh $org $project diff --git a/modules/jenkins/files/slave_scripts/run-pylint.sh b/modules/jenkins/files/slave_scripts/run-pylint.sh old mode 100644 new mode 100755 index a0dd2e3b6d..cd6e5a698f --- a/modules/jenkins/files/slave_scripts/run-pylint.sh +++ b/modules/jenkins/files/slave_scripts/run-pylint.sh @@ -17,14 +17,8 @@ org=$1 project=$2 -if [[ -z "$org" || -z "$project" ]] -then - echo "Usage: $0 ORG PROJECT" - echo - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_org_project "$org" "$project" "$0" source /usr/local/jenkins/slave_scripts/select-mirror.sh $org $project diff --git a/modules/jenkins/files/slave_scripts/run-selenium.sh b/modules/jenkins/files/slave_scripts/run-selenium.sh index a5991222e0..73541c7c2d 100755 --- a/modules/jenkins/files/slave_scripts/run-selenium.sh +++ b/modules/jenkins/files/slave_scripts/run-selenium.sh @@ -10,14 +10,8 @@ org=$1 project=$2 -if [[ -z "$org" || -z "$project" ]] -then - echo "Usage: $0 ORG PROJECT" - echo - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_org_project "$org" "$project" "$0" source /usr/local/jenkins/slave_scripts/select-mirror.sh $org $project diff --git a/modules/jenkins/files/slave_scripts/run-tarball.sh b/modules/jenkins/files/slave_scripts/run-tarball.sh old mode 100644 new mode 100755 index 3d60781d31..80eb6aba38 --- a/modules/jenkins/files/slave_scripts/run-tarball.sh +++ b/modules/jenkins/files/slave_scripts/run-tarball.sh @@ -17,14 +17,8 @@ org=$1 project=$2 -if [[ -z "$org" || -z "$project" ]] -then - echo "Usage: $0 ORG PROJECT" - echo - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_org_project "$org" "$project" "$0" source /usr/local/jenkins/slave_scripts/select-mirror.sh $org $project diff --git a/modules/jenkins/files/slave_scripts/run-unittests.sh b/modules/jenkins/files/slave_scripts/run-unittests.sh index 66b2791032..31f5e6ef7d 100755 --- a/modules/jenkins/files/slave_scripts/run-unittests.sh +++ b/modules/jenkins/files/slave_scripts/run-unittests.sh @@ -14,15 +14,8 @@ version=$1 org=$2 project=$3 -if [[ -z "$version" || -z "$org" || -z "$project" ]] -then - echo "Usage: $? VERSION ORG PROJECT" - echo - echo "VERSION: The tox environment python version (eg '27')" - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_version_org_project "$version" "$org" "$project" "$0" venv=py$version diff --git a/modules/jenkins/files/slave_scripts/select-mirror.sh b/modules/jenkins/files/slave_scripts/select-mirror.sh index 7825490b09..6aea1cbf95 100755 --- a/modules/jenkins/files/slave_scripts/select-mirror.sh +++ b/modules/jenkins/files/slave_scripts/select-mirror.sh @@ -17,14 +17,8 @@ org=$1 project=$2 -if [[ -z "$org" || -z "$project" ]] -then - echo "Usage: $0 ORG PROJECT" - echo - echo "ORG: The project organization (eg 'openstack')" - echo "PROJECT: The project name (eg 'nova')" - exit 1 -fi +source /usr/local/jenkins/slave_scripts/functions.sh +check_variable_org_project "$org" "$project" "$0" rm -f ~/.pydistutils.cfg mkdir -p ~/.pip