Skip to content

Commit

Permalink
added test from prod clone project
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapil Arora authored and Kapil Arora committed Dec 27, 2015
1 parent 898bb0f commit ec04007
Show file tree
Hide file tree
Showing 13 changed files with 2,857 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# continuous-delivery-pipeline
Simple DevOps Continous Delivery Pipleine for a Ruby and MySQL app using Docker, docker-compose, Jenkins, GitLab, Docker Registry and Snap Creator.

Change docker registry from 10.65.57.126:5000 in all files to your registry
2 changes: 2 additions & 0 deletions ruby-mysql-web-test-with-prod-clone-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Download NetApp NMSDK from https://mysupport.netapp.com/documentation/productlibrary/index.html?productID=60427
Copy the contents under /lib/ruby/NetApp to netapp_sdk/lib/NetApp
3 changes: 3 additions & 0 deletions ruby-mysql-web-test-with-prod-clone-data/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash
docker-compose stop
yes | docker-compose rm
20 changes: 20 additions & 0 deletions ruby-mysql-web-test-with-prod-clone-data/clone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
echo "Reading config...."
source database.config
echo "HOST: $HOST"
echo "VOLUME_PROD: $VOLUME_PROD"
echo "VOLUME_CLONE_NAME: $VOLUME_CLONE_NAME"
echo "MOUNT_AT: $MOUNT_AT"
echo "MYSQL_PASSWORD: $MYSQL_PASSWORD"
echo "STORGAE_HOST: $STORGAE_HOST"
echo "STORGAE_USER: $STORGAE_USER"
echo "STORAGE_PASSWORD: $STORAGE_PASSWORD"
cd netapp_sdk
echo "deleting existing clone"
if ruby flexClone.rb $STORGAE_HOST $STORGAE_USER $STORAGE_PASSWORD delete $VOLUME_CLONE_NAME;then
echo "deleted"
else
echo "delete failed"
fi
echo "creating new clone"
ruby flexClone.rb $STORGAE_HOST $STORGAE_USER $STORAGE_PASSWORD create $VOLUME_CLONE_NAME $VOLUME_PROD
9 changes: 9 additions & 0 deletions ruby-mysql-web-test-with-prod-clone-data/database.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HOST=<nfs export IP or host>
VOLUME_PROD=mysql_data_prod
VOLUME_CLONE_NAME=mysql_data_prod_clone
MOUNT_AT=/mnt/mysql_data_prod_clone
MYSQL_PASSWORD=<mysql password>
STORGAE_HOST=<cDot SVM IP or host>
STORGAE_USER=vsadmin
STORAGE_PASSWORD=<svm password>

14 changes: 14 additions & 0 deletions ruby-mysql-web-test-with-prod-clone-data/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ruby_web:
image: 10.65.57.126:5000/ruby-mysql-web:0.0.1-SNAPSHOT
environment:
PORT: 9595
ports:
- "9595:9595"
links:
- mysql_db:mysql_host
mysql_db:
image: mysql:latest
volumes:
- /mnt/mysql_data_prod_clone:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: netapp01
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /bin/bash

TEST_PORT=9595

echo "Staring application with docker compose"
docker-compose up -d
echo "Sleeping for 10 seconds for web service to start"
sleep 10s
echo "calling the webservice to see if it is active and returns http code 200"
#curl -s --head --request GET http://localhost:9292/locandtweet/netapp | grep "200 OK" > /dev/null
httpCode=`curl -sL -w "%{http_code}\\n" "http://10.65.57.126:$TEST_PORT/table/employees" -o /dev/null`
echo "Http code returned: $httpCode"
if [ $httpCode == 200 ]
then
echo "test passed!"
exit 0
else
echo "test failed"
exit 1
fi

17 changes: 17 additions & 0 deletions ruby-mysql-web-test-with-prod-clone-data/mountTestData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
echo "Reading config...."
source database.config
echo "HOST: $HOST"
echo "VOLUME_PROD: $VOLUME_PROD"
echo "VOLUME_CLONE_NAME: $VOLUME_CLONE_NAME"
echo "MOUNT_AT: $MOUNT_AT"
echo "creating $MOUNT_AT dir if not exist already"
mkdir -p $MOUNT_AT
echo "trying Umount volume"
umount $MOUNT_AT
echo "Mounting volume $HOST:/$VOLUME_CLONE_NAME at location $MOUNT_AT"
mount -t nfs $HOST:/$VOLUME_CLONE_NAME $MOUNT_AT
121 changes: 121 additions & 0 deletions ruby-mysql-web-test-with-prod-clone-data/netapp_sdk/flexClone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
$:.unshift 'lib/NetApp'
require 'NaServer'


def print_usage
print("Usage:flexClone.rb <storage> <user> <password> <command> <clone-volname>")
print(" [<volume>]\n")
print("<storage> -- Storage system name\n")
print("<user> -- User name\n")
print("<password> -- Password\n")
print("<command> -- Possible commands are:\n")
print(" create - to create a new clone\n")
print(" delete - to destroy a clone\n")
print("<clone-volname> -- clone volume name \n")
print("[<parent-volname] -- name of the parent volume to create the clone. \n")
exit
end


args = ARGV.length
if(args < 5)
print_usage()
end
$storage = ARGV[0]
$user = ARGV[1]
$pw = ARGV[2]
$command = ARGV[3]
$clone_name = ARGV[4]
$parent_vol = nil
if(args > 5)
$parent_vol = ARGV[5]
end



def create_flexclone()
clone_in = NaElement.new("volume-clone-create")
clone_in.child_add_string("parent-volume", $parent_vol)
clone_in.child_add_string("volume", $clone_name)
# Invoke volume-clone-create API
out = $s.invoke_elem(clone_in)
if(out.results_status() == "failed")
print(out.results_reason() + "\n")
exit
end
end

def delete_flexclone()
clone_destroy_in = NaElement.new("volume-destroy")
clone_destroy_in.child_add_string("name", $clone_name)
# Invoke volume-destroy API
out = $s.invoke_elem(clone_destroy_in)
if(out.results_status() == "failed")
print(out.results_reason() + "\n")
exit
end
end

def mount_flexclone()
clone_mount_in = NaElement.new("volume-mount")
clone_mount_in.child_add_string("volume-name", $clone_name)
clone_mount_in.child_add_string("export-policy-override", "true")
clone_mount_in.child_add_string("junction-path", "/"+$clone_name)
# Invoke volume-destroy API
out = $s.invoke_elem(clone_mount_in)
if(out.results_status() == "failed")
print(out.results_reason() + "\n")
exit
end
end

def unmount_flexclone()
clone_unmount_in = NaElement.new("volume-unmount")
clone_unmount_in.child_add_string("volume-name", $clone_name)
out = $s.invoke_elem(clone_unmount_in)
if(out.results_status() == "failed")
print(out.results_reason() + "\n")
exit
end
end

def volume_offline()
clone_offline_in = NaElement.new("volume-offline")
clone_offline_in.child_add_string("name", $clone_name)
# Invoke volume-destroy API
out = $s.invoke_elem(clone_offline_in)
if(out.results_status() == "failed")
print(out.results_reason() + "\n")
exit
end
end


def main
if(not (($command == "create") or ($command == "delete")))
print($command+" is not a valid command\n")
print_usage()
end
if (($command == "create") and ($parent_vol == nil))
print($command+" operation requires <parent-volname>\n")
print("Usage: flexclone.py <storage> <user> <password>"+$command+" <clone-volname> <parent-volname>\n")
exit
end
$s = NaServer.new($storage, 1, 3)
$s.set_admin_user($user, $pw)
if($command == "create")
create_flexclone()
mount_flexclone()
elsif($command == "delete")
unmount_flexclone()
volume_offline()
delete_flexclone()
else
print("Invalid operation\n")
print_usage()
end
end


main()

Loading

0 comments on commit ec04007

Please sign in to comment.