diff options
author | leonwang <wanghui71@huawei.com> | 2018-07-20 14:55:21 +0800 |
---|---|---|
committer | leonwang <wanghui71@huawei.com> | 2018-07-20 14:55:31 +0800 |
commit | 078bb837513f3b83fdd07f2e10f9abeb0bd485db (patch) | |
tree | 9a87c67bfe3ef12683f0c6d2f8b833d6d942b155 /ci/ansible/script | |
parent | 63ff6c6ec9ebbca90ac7304a27c0430dbcecb74f (diff) |
Update stor4nfv install scripts according to opensds aruba release
Since OpenSDS has published its aruba release and also supports
OpenStack scenario, this patch is designed for updating stor4nfv
code to prepare for integrating Compass4NFV and Apex installer on
OpenStack scenario.
Besides the large code changes, some tutorial docs are also added
or updated for better installing this project.
Change-Id: I1e4fec652c6c860028ef39448bc323839f3aa95c
Signed-off-by: leonwang <wanghui71@huawei.com>
Diffstat (limited to 'ci/ansible/script')
-rw-r--r-- | ci/ansible/script/check_ansible_version.sh | 26 | ||||
-rw-r--r-- | ci/ansible/script/keystone.sh | 178 | ||||
-rw-r--r-- | ci/ansible/script/sdsrc | 40 | ||||
-rw-r--r-- | ci/ansible/script/set_nginx_config.sh | 37 | ||||
-rw-r--r-- | ci/ansible/script/util.sh | 93 |
5 files changed, 374 insertions, 0 deletions
diff --git a/ci/ansible/script/check_ansible_version.sh b/ci/ansible/script/check_ansible_version.sh new file mode 100644 index 0000000..e9e1c9b --- /dev/null +++ b/ci/ansible/script/check_ansible_version.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Copyright (c) 2018 Huawei Technologies Co., Ltd. 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. + +ansiblever=$(ansible --version |grep -Eow '^ansible [^ ]+' |gawk '{ print $2 }') +echo "The actual version of ansible is $ansiblever" + +if [[ "$ansiblever" < '2.4.2' ]]; then + echo "Ansible version 2.4.2 or higher is required" + exit 1 +fi + +exit 0 + diff --git a/ci/ansible/script/keystone.sh b/ci/ansible/script/keystone.sh new file mode 100644 index 0000000..3de1e8b --- /dev/null +++ b/ci/ansible/script/keystone.sh @@ -0,0 +1,178 @@ +#!/usr/bin/env bash + +# Copyright (c) 2018 Huawei Technologies Co., Ltd. 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. + +# 'stack' user is just for install keystone through devstack + +create_user(){ + if id "${STACK_USER_NAME}" &> /dev/null; then + return + fi + sudo useradd -s /bin/bash -d "${STACK_HOME}" -m "${STACK_USER_NAME}" + echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack +} + + +remove_user(){ + userdel "${STACK_USER_NAME}" -f -r + rm /etc/sudoers.d/stack +} + +devstack_local_conf(){ +DEV_STACK_LOCAL_CONF=${DEV_STACK_DIR}/local.conf +cat > "$DEV_STACK_LOCAL_CONF" << DEV_STACK_LOCAL_CONF_DOCK +[[local|localrc]] +# use TryStack git mirror +GIT_BASE=$STACK_GIT_BASE + +# If the "*_PASSWORD" variables are not set here you will be prompted to enter +# values for them by "stack.sh" and they will be added to "local.conf". +ADMIN_PASSWORD=$STACK_PASSWORD +DATABASE_PASSWORD=$STACK_PASSWORD +RABBIT_PASSWORD=$STACK_PASSWORD +SERVICE_PASSWORD=$STACK_PASSWORD + +# Neither is set by default. +HOST_IP=$HOST_IP + +# path of the destination log file. A timestamp will be appended to the given name. +LOGFILE=\$DEST/logs/stack.sh.log + +# Old log files are automatically removed after 7 days to keep things neat. Change +# the number of days by setting "LOGDAYS". +LOGDAYS=2 + +ENABLED_SERVICES=mysql,key +# Using stable/queens branches +# --------------------------------- +KEYSTONE_BRANCH=$STACK_BRANCH +KEYSTONECLIENT_BRANCH=$STACK_BRANCH +DEV_STACK_LOCAL_CONF_DOCK +chown stack:stack "$DEV_STACK_LOCAL_CONF" +} + +opensds_conf() { +cat >> "$OPENSDS_CONFIG_DIR/opensds.conf" << OPENSDS_GLOBAL_CONFIG_DOC + + +[keystone_authtoken] +memcached_servers = $HOST_IP:11211 +signing_dir = /var/cache/opensds +cafile = /opt/stack/data/ca-bundle.pem +auth_uri = http://$HOST_IP/identity +project_domain_name = Default +project_name = service +user_domain_name = Default +password = $STACK_PASSWORD +username = $OPENSDS_SERVER_NAME +auth_url = http://$HOST_IP/identity +auth_type = password + +OPENSDS_GLOBAL_CONFIG_DOC + +cp "$OPENSDS_DIR/examples/policy.json" "$OPENSDS_CONFIG_DIR" +} + +create_user_and_endpoint(){ + . "$DEV_STACK_DIR/openrc" admin admin + openstack user create --domain default --password "$STACK_PASSWORD" "$OPENSDS_SERVER_NAME" + openstack role add --project service --user opensds admin + openstack group create service + openstack group add user service opensds + openstack role add service --project service --group service + openstack group add user admins admin + openstack service create --name "opensds$OPENSDS_VERSION" --description "OpenSDS Block Storage" "opensds$OPENSDS_VERSION" + openstack endpoint create --region RegionOne "opensds$OPENSDS_VERSION" public "http://$HOST_IP:50040/$OPENSDS_VERSION/%\(tenant_id\)s" + openstack endpoint create --region RegionOne "opensds$OPENSDS_VERSION" internal "http://$HOST_IP:50040/$OPENSDS_VERSION/%\(tenant_id\)s" + openstack endpoint create --region RegionOne "opensds$OPENSDS_VERSION" admin "http://$HOST_IP:50040/$OPENSDS_VERSION/%\(tenant_id\)s" +} + +delete_redundancy_data() { + . "$DEV_STACK_DIR/openrc" admin admin + openstack project delete demo + openstack project delete alt_demo + openstack project delete invisible_to_admin + openstack user delete demo + openstack user delete alt_demo +} + +download_code(){ + if [ ! -d "${DEV_STACK_DIR}" ];then + git clone "${STACK_GIT_BASE}/openstack-dev/devstack.git" -b "${STACK_BRANCH}" "${DEV_STACK_DIR}" + chown stack:stack -R "${DEV_STACK_DIR}" + fi +} + +install(){ + create_user + download_code + opensds_conf + + # If keystone is ready to start, there is no need continue next step. + if wait_for_url "http://$HOST_IP/identity" "keystone" 0.25 4; then + return + fi + devstack_local_conf + cd "${DEV_STACK_DIR}" + su "$STACK_USER_NAME" -c "${DEV_STACK_DIR}/stack.sh" >/dev/null + create_user_and_endpoint + delete_redundancy_data +} + +cleanup() { + su "$STACK_USER_NAME" -c "${DEV_STACK_DIR}/clean.sh" >/dev/null +} + +uninstall(){ + su "$STACK_USER_NAME" -c "${DEV_STACK_DIR}/unstack.sh" >/dev/null +} + +uninstall_purge(){ + rm "${STACK_HOME:?'STACK_HOME must be defined and cannot be empty'}/*" -rf + remove_user +} + +# *************************** +TOP_DIR=$(cd $(dirname "$0") && pwd) + +# OpenSDS configuration directory +OPENSDS_CONFIG_DIR=${OPENSDS_CONFIG_DIR:-/etc/opensds} + +source "$TOP_DIR/util.sh" +source "$TOP_DIR/sdsrc" + +case "$# $1" in + "1 install") + echo "Starting install keystone..." + install + ;; + "1 uninstall") + echo "Starting uninstall keystone..." + uninstall + ;; + "1 cleanup") + echo "Starting cleanup keystone..." + cleanup + ;; + "1 uninstall_purge") + echo "Starting uninstall purge keystone..." + uninstall_purge + ;; + *) + echo "The value of the parameter can only be one of the following: install/uninstall/cleanup/uninstall_purge" + exit 1 + ;; +esac + diff --git a/ci/ansible/script/sdsrc b/ci/ansible/script/sdsrc new file mode 100644 index 0000000..d26083d --- /dev/null +++ b/ci/ansible/script/sdsrc @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Copyright (c) 2018 Huawei Technologies Co., Ltd. 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. + +# Global +HOST_IP=${HOST_IP:-} +HOST_IP=$(get_default_host_ip "$HOST_IP" "inet") +if [ "$HOST_IP" == "" ]; then + die $LINENO "Could not determine host ip address. See local.conf for suggestions on setting HOST_IP." +fi + +# OpenSDS configuration. +OPENSDS_VERSION=${OPENSDS_VERSION:-v1beta} + +# OpenSDS service name in keystone. +OPENSDS_SERVER_NAME=${OPENSDS_SERVER_NAME:-opensds} + +# devstack keystone configuration +STACK_GIT_BASE=${STACK_GIT_BASE:-https://git.openstack.org} +STACK_USER_NAME=${STACK_USER_NAME:-stack} +STACK_PASSWORD=${STACK_PASSWORD:-opensds@123} +STACK_HOME=${STACK_HOME:-/opt/stack} +STACK_BRANCH=${STACK_BRANCH:-stable/queens} +DEV_STACK_DIR=$STACK_HOME/devstack + +GOPATH=${GOPATH:-$HOME/gopath} +OPENSDS_DIR=${GOPATH}/src/github.com/opensds/opensds + diff --git a/ci/ansible/script/set_nginx_config.sh b/ci/ansible/script/set_nginx_config.sh new file mode 100644 index 0000000..3abbfcd --- /dev/null +++ b/ci/ansible/script/set_nginx_config.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Copyright (c) 2018 Huawei Technologies Co., Ltd. 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. + +TOP_DIR=$(cd $(dirname "$0") && pwd) +source "$TOP_DIR/util.sh" +source "$TOP_DIR/sdsrc" + +cat > /etc/nginx/sites-available/default <<EOF + server { + listen 8088 default_server; + listen [::]:8088 default_server; + root /var/www/html; + index index.html index.htm index.nginx-debian.html; + server_name _; + location /v3/ { + proxy_pass http://$HOST_IP/identity/v3/; + } + location /v1beta/ { + proxy_pass http://$HOST_IP:50040/$OPENSDS_VERSION/; + } + } +EOF + + diff --git a/ci/ansible/script/util.sh b/ci/ansible/script/util.sh new file mode 100644 index 0000000..b0e30eb --- /dev/null +++ b/ci/ansible/script/util.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +# Copyright (c) 2017 Huawei Technologies Co., Ltd. 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. + +# Echo text to the log file, summary log file and stdout +# echo_summary "something to say" +function echo_summary { + echo -e "$@" +} + +wait_for_url() { + local url=$1 + local prefix=${2:-} + local wait=${3:-1} + local times=${4:-30} + + which curl >/dev/null || { + echo_summary "curl must be installed" + exit 1 + } + + local i + for i in $(seq 1 "$times"); do + local out + if out=$(curl --max-time 1 -gkfs "$url" 2>/dev/null); then + echo_summary "On try ${i}, ${prefix}: ${out}" + return 0 + fi + sleep "${wait}" + done + echo_summary "Timed out waiting for ${prefix} to answer at ${url}; tried ${times} waiting ${wait} between each" + return 1 +} + +# Prints line number and "message" in error format +# err $LINENO "message" +err() { + local exitcode=$? + local xtrace + xtrace=$(set +o | grep xtrace) + set +o xtrace + local msg="[ERROR] ${BASH_SOURCE[2]}:$1 $2" + echo "$msg" + $xtrace + return $exitcode +} + +# Prints line number and "message" then exits +# die $LINENO "message" +die() { + local exitcode=$? + set +o xtrace + local line=$1; shift + if [ $exitcode == 0 ]; then + exitcode=1 + fi + err "$line" "$*" + # Give buffers a second to flush + sleep 1 + exit $exitcode +} + +get_default_host_ip() { + local host_ip=$1 + local af=$2 + # Search for an IP unless an explicit is set by ``HOST_IP`` environment variable + if [ -z "$host_ip" ]; then + host_ip="" + # Find the interface used for the default route + host_ip_iface=${host_ip_iface:-$(ip -f "$af" route | awk '/default/ {print $5}' | head -1)} + local host_ips + host_ips=$(LC_ALL=C ip -f "$af" addr show "${host_ip_iface}" | sed /temporary/d |awk /$af'/ {split($2,parts,"/"); print parts[1]}') + local ip + for ip in $host_ips; do + host_ip=$ip + break; + done + fi + echo "$host_ip" +} + |