Replace old CLI calls in grenade
This patch replaces old CLI calls (sahara) with new ones (openstack dataprocessing) in grenade. Also some code refactoring is done. Change-Id: If818032b3d438cf28f2d939140039db6280409fb
This commit is contained in:
parent
7749f50ede
commit
e3c25efef0
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "cluster-grenade",
|
|
||||||
"plugin_name": "fake",
|
|
||||||
"hadoop_version": "0.1",
|
|
||||||
"cluster_template_id" : "CLUSTER_TEMPLATE_ID",
|
|
||||||
"user_keypair_id": "KEYPAIR",
|
|
||||||
"default_image_id": "IMAGE_ID"
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "cluster-template-grenade",
|
|
||||||
"plugin_name": "fake",
|
|
||||||
"hadoop_version": "0.1",
|
|
||||||
"node_groups": [
|
|
||||||
{
|
|
||||||
"name": "allinone",
|
|
||||||
"node_group_template_id": "NG_ID",
|
|
||||||
"count": 1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "ng-template-grenade",
|
|
||||||
"flavor_id": "FLAVOR_ID",
|
|
||||||
"plugin_name": "fake",
|
|
||||||
"hadoop_version": "0.1",
|
|
||||||
"node_processes": ["jobtracker", "namenode", "tasktracker", "datanode"],
|
|
||||||
"auto_security_group": true,
|
|
||||||
"security_groups": ["SEC_GROUP"],
|
|
||||||
"floating_ip_pool": "FLOATING_IP_POOL"
|
|
||||||
}
|
|
@ -12,99 +12,42 @@ set -o xtrace
|
|||||||
SAHARA_USER=sahara_grenade
|
SAHARA_USER=sahara_grenade
|
||||||
SAHARA_PROJECT=sahara_grenade
|
SAHARA_PROJECT=sahara_grenade
|
||||||
SAHARA_PASS=pass
|
SAHARA_PASS=pass
|
||||||
SAHARA_SERVER=sahara_server1
|
|
||||||
SAHARA_KEY=sahara_key
|
SAHARA_KEY=sahara_key
|
||||||
SAHARA_KEY_FILE=$SAVE_DIR/sahara_key.pem
|
SAHARA_KEY_FILE=$SAVE_DIR/sahara_key.pem
|
||||||
|
|
||||||
JSON_PATH=`dirname $BASH_SOURCE`
|
|
||||||
PUBLIC_NETWORK_NAME=${PUBLIC_NETWORK_NAME:-public}
|
PUBLIC_NETWORK_NAME=${PUBLIC_NETWORK_NAME:-public}
|
||||||
PRIVATE_NETWORK_NAME=${PRIVATE_NETWORK_NAME:-private}
|
|
||||||
# cirros image is not appropriate for cluster creation
|
# cirros image is not appropriate for cluster creation
|
||||||
SAHARA_IMAGE_NAME=${SAHARA_IMAGE_NAME:-fedora-heat-test-image}
|
SAHARA_IMAGE_NAME=${SAHARA_IMAGE_NAME:-fedora-heat-test-image}
|
||||||
SAHARA_IMAGE_USER=${SAHARA_IMAGE_USER:-fedora}
|
SAHARA_IMAGE_USER=${SAHARA_IMAGE_USER:-fedora}
|
||||||
|
|
||||||
# custom flavor parameters
|
# custom flavor parameters
|
||||||
SAHARA_FLAVOR_NAME=${SAHARA_FLAVOR_NAME:-sahara_flavor}
|
SAHARA_FLAVOR_NAME=${SAHARA_FLAVOR_NAME:-sahara_flavor}
|
||||||
SAHARA_FLAVOR_RAM=${SAHARA_FLAVOR_RAM:-1024}
|
SAHARA_FLAVOR_RAM=${SAHARA_FLAVOR_RAM:-1024}
|
||||||
SAHARA_FLAVOR_DISK=${SAHARA_FLAVOR_DISK:-10}
|
SAHARA_FLAVOR_DISK=${SAHARA_FLAVOR_DISK:-10}
|
||||||
|
|
||||||
function _sahara_set_user {
|
NG_TEMPLATE_NAME=ng-template-grenade
|
||||||
|
CLUSTER_TEMPLATE_NAME=cluster-template-grenade
|
||||||
|
CLUSTER_NAME=cluster-grenade
|
||||||
|
|
||||||
|
function sahara_set_user {
|
||||||
|
# set ourselves to the created sahara user
|
||||||
OS_TENANT_NAME=$SAHARA_PROJECT
|
OS_TENANT_NAME=$SAHARA_PROJECT
|
||||||
OS_PROJECT_NAME=$SAHARA_PROJECT
|
OS_PROJECT_NAME=$SAHARA_PROJECT
|
||||||
OS_USERNAME=$SAHARA_USER
|
OS_USERNAME=$SAHARA_USER
|
||||||
OS_PASSWORD=$SAHARA_PASS
|
OS_PASSWORD=$SAHARA_PASS
|
||||||
}
|
}
|
||||||
|
|
||||||
function register_image {
|
function create_tenant {
|
||||||
eval $(openstack --os-image-api-version 1 image show -f \
|
|
||||||
shell -c id $SAHARA_IMAGE_NAME)
|
|
||||||
resource_save sahara image_id $id
|
|
||||||
sahara image-register --id $id --username $SAHARA_IMAGE_USER
|
|
||||||
sahara image-add-tag --id $id --tag fake
|
|
||||||
sahara image-add-tag --id $id --tag 0.1
|
|
||||||
echo $id
|
|
||||||
}
|
|
||||||
|
|
||||||
# args: <template> <floating_ip_pool> <security_group> <flavor_id>
|
|
||||||
function create_node_group_template {
|
|
||||||
local tmp_file
|
|
||||||
tmp_file=$(mktemp)
|
|
||||||
local floating_pool=$2
|
|
||||||
if is_service_enabled neutron; then
|
|
||||||
eval $(openstack network show $2 -f shell -c id)
|
|
||||||
local floating_pool=$id
|
|
||||||
fi
|
|
||||||
|
|
||||||
sed -e "s/FLAVOR_ID/$4/g" \
|
|
||||||
-e "s/FLOATING_IP_POOL/$floating_pool/g" \
|
|
||||||
-e "s/SEC_GROUP/$3/g" $1 > $tmp_file
|
|
||||||
local template_id
|
|
||||||
template_id=$(sahara node-group-template-create --json "$tmp_file" \
|
|
||||||
| awk '$2 ~ /^id/ { print $4 }')
|
|
||||||
echo $template_id
|
|
||||||
}
|
|
||||||
|
|
||||||
# args: <template> <node_group_id>
|
|
||||||
function create_cluster_template {
|
|
||||||
local tmp_file
|
|
||||||
tmp_file=$(mktemp)
|
|
||||||
sed -e "s/NG_ID/$2/g" $1 > $tmp_file
|
|
||||||
local cluster_template_id
|
|
||||||
cluster_template_id=$(sahara cluster-template-create --json $tmp_file \
|
|
||||||
| awk '$2 ~ /^id/ { print $4 }')
|
|
||||||
echo $cluster_template_id
|
|
||||||
}
|
|
||||||
|
|
||||||
# args: <template> <cluster_template_id> <keypair> <image_id>
|
|
||||||
function create_cluster {
|
|
||||||
local tmp_file
|
|
||||||
tmp_file=$(mktemp)
|
|
||||||
sed -e "s/CLUSTER_TEMPLATE_ID/$2/g" \
|
|
||||||
-e "s/KEYPAIR/$3/g" \
|
|
||||||
-e "s/IMAGE_ID/$4/g" $1 > $tmp_file
|
|
||||||
|
|
||||||
# adding neutron management network id if neutron is enabled
|
|
||||||
local net_id
|
|
||||||
net_id=$(resource_get network net_id)
|
|
||||||
if [[ -n "$net_id" ]]; then
|
|
||||||
sed -i '8i ,"neutron_management_network": "NET_ID"' $tmp_file
|
|
||||||
sed -i -e "s/NET_ID/$net_id/g" $tmp_file
|
|
||||||
fi
|
|
||||||
|
|
||||||
local cluster_id
|
|
||||||
cluster_id=$(sahara cluster-create --json $tmp_file \
|
|
||||||
| awk '$2 ~ /^id/ { print $4 }')
|
|
||||||
echo $cluster_id
|
|
||||||
}
|
|
||||||
|
|
||||||
function create {
|
|
||||||
# create a tenant for the server
|
# create a tenant for the server
|
||||||
eval $(openstack project create -f shell -c id $SAHARA_PROJECT)
|
eval $(openstack project create -f shell -c id $SAHARA_PROJECT)
|
||||||
if [[ -z "$id" ]]; then
|
if [[ -z "$id" ]]; then
|
||||||
die $LINENO "Didn't create $SAHARA_PROJECT project"
|
die $LINENO "Didn't create $SAHARA_PROJECT project"
|
||||||
fi
|
fi
|
||||||
resource_save sahara project_id $id
|
resource_save sahara project_id $id
|
||||||
|
}
|
||||||
|
|
||||||
# create the user, and set $id locally
|
function create_user {
|
||||||
eval $(openstack user create $SAHARA_USER \
|
eval $(openstack user create $SAHARA_USER \
|
||||||
--project $id \
|
--project $id \
|
||||||
--password $SAHARA_PASS \
|
--password $SAHARA_PASS \
|
||||||
@ -113,51 +56,80 @@ function create {
|
|||||||
die $LINENO "Didn't create $SAHARA_USER user"
|
die $LINENO "Didn't create $SAHARA_USER user"
|
||||||
fi
|
fi
|
||||||
resource_save sahara user_id $id
|
resource_save sahara user_id $id
|
||||||
|
}
|
||||||
|
|
||||||
# create flavor
|
function create_keypair {
|
||||||
|
|
||||||
eval $(openstack flavor create -f shell -c id --ram $SAHARA_FLAVOR_RAM \
|
|
||||||
--disk $SAHARA_FLAVOR_DISK $SAHARA_FLAVOR_NAME)
|
|
||||||
flavor_id=$id
|
|
||||||
|
|
||||||
# register image
|
|
||||||
image_id=$(register_image)
|
|
||||||
|
|
||||||
# set ourselves to the created sahara user
|
|
||||||
_sahara_set_user
|
|
||||||
|
|
||||||
# create security group
|
|
||||||
nova secgroup-create $SAHARA_USER "Sahara security group"
|
|
||||||
nova secgroup-add-rule $SAHARA_USER tcp 22 22 0.0.0.0/0
|
|
||||||
|
|
||||||
# create key pair for access
|
# create key pair for access
|
||||||
openstack keypair create $SAHARA_KEY > $SAHARA_KEY_FILE
|
openstack keypair create $SAHARA_KEY > $SAHARA_KEY_FILE
|
||||||
chmod 600 $SAHARA_KEY_FILE
|
chmod 600 $SAHARA_KEY_FILE
|
||||||
|
}
|
||||||
|
|
||||||
# create node group template
|
function create_flavor {
|
||||||
ng_id=$(create_node_group_template $JSON_PATH/ng-template.json \
|
eval $(openstack flavor create -f shell -c id \
|
||||||
$PUBLIC_NETWORK_NAME $SAHARA_USER $flavor_id)
|
--ram $SAHARA_FLAVOR_RAM \
|
||||||
|
--disk $SAHARA_FLAVOR_DISK \
|
||||||
|
$SAHARA_FLAVOR_NAME)
|
||||||
|
resource_save sahara flavor_id $id
|
||||||
|
}
|
||||||
|
|
||||||
resource_save sahara ng_id $ng_id
|
function register_image {
|
||||||
|
eval $(openstack --os-image-api-version 1 image show \
|
||||||
|
-f shell -c id $SAHARA_IMAGE_NAME)
|
||||||
|
resource_save sahara image_id $id
|
||||||
|
openstack dataprocessing image register $id --username $SAHARA_IMAGE_USER
|
||||||
|
openstack dataprocessing image tags set $id --tags fake 0.1
|
||||||
|
}
|
||||||
|
|
||||||
# create cluster template
|
function create_node_group_template {
|
||||||
cluster_template_id=$(create_cluster_template \
|
eval $(openstack network show -f shell -c id $PUBLIC_NETWORK_NAME)
|
||||||
$JSON_PATH/cluster-template.json $ng_id)
|
local public_net_id=$id
|
||||||
resource_save sahara cluster_template_id $cluster_template_id
|
local flavor_id=$(resource_get sahara flavor_id)
|
||||||
|
openstack dataprocessing node group template create \
|
||||||
|
--name $NG_TEMPLATE_NAME \
|
||||||
|
--flavor $flavor_id \
|
||||||
|
--plugin fake \
|
||||||
|
--plugin-version 0.1 \
|
||||||
|
--processes jobtracker namenode tasktracker datanode \
|
||||||
|
--floating-ip-pool $public_net_id \
|
||||||
|
--auto-security-group
|
||||||
|
}
|
||||||
|
|
||||||
# create cluster
|
function create_cluster_template {
|
||||||
cluster_id=$(create_cluster $JSON_PATH/cluster-create.json \
|
openstack dataprocessing cluster template create \
|
||||||
$cluster_template_id $SAHARA_KEY $image_id)
|
--name $CLUSTER_TEMPLATE_NAME \
|
||||||
resource_save sahara cluster_id $cluster_id
|
--node-groups $NG_TEMPLATE_NAME:1
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_cluster {
|
||||||
|
local net_id=$(resource_get network net_id)
|
||||||
|
local image_id=$(resource_get sahara image_id)
|
||||||
|
if [[ -n "$net_id" ]]; then
|
||||||
|
eval $(openstack dataprocessing cluster create \
|
||||||
|
--name $CLUSTER_NAME \
|
||||||
|
--cluster-template $CLUSTER_TEMPLATE_NAME \
|
||||||
|
--image $image_id \
|
||||||
|
--user-keypair $SAHARA_KEY \
|
||||||
|
--neutron-network $net_id \
|
||||||
|
-f shell -c id)
|
||||||
|
else
|
||||||
|
eval $(openstack dataprocessing cluster create \
|
||||||
|
--name $CLUSTER_NAME \
|
||||||
|
--cluster-template $CLUSTER_TEMPLATE_NAME \
|
||||||
|
--image $image_id \
|
||||||
|
--user-keypair $SAHARA_KEY \
|
||||||
|
-f shell -c id)
|
||||||
|
fi
|
||||||
|
resource_save sahara cluster_id $id
|
||||||
|
}
|
||||||
|
|
||||||
|
function wait_active_state {
|
||||||
# wait until cluster moves to active state
|
# wait until cluster moves to active state
|
||||||
local timeleft=1000
|
local timeleft=1000
|
||||||
while [[ $timeleft -gt 0 ]]; do
|
while [[ $timeleft -gt 0 ]]; do
|
||||||
local cluster_state
|
eval $(openstack dataprocessing cluster show -f shell \
|
||||||
cluster_state=$(sahara cluster-show --id $cluster_id \
|
-c Status $CLUSTER_NAME)
|
||||||
| awk '$2 ~ /^status/ { print $4;exit }')
|
if [[ "$status" != "Active" ]]; then
|
||||||
if [[ "$cluster_state" != "Active" ]]; then
|
if [[ "$status" == "Error" ]]; then
|
||||||
if [[ "$cluster_state" == "Error" ]]; then
|
|
||||||
die $LINENO "Cluster is in Error state"
|
die $LINENO "Cluster is in Error state"
|
||||||
fi
|
fi
|
||||||
echo "Cluster is still not in Active state"
|
echo "Cluster is still not in Active state"
|
||||||
@ -171,19 +143,38 @@ function create {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function create {
|
||||||
|
create_tenant
|
||||||
|
|
||||||
|
create_user
|
||||||
|
|
||||||
|
create_flavor
|
||||||
|
|
||||||
|
register_image
|
||||||
|
|
||||||
|
sahara_set_user
|
||||||
|
|
||||||
|
create_keypair
|
||||||
|
|
||||||
|
create_node_group_template
|
||||||
|
|
||||||
|
create_cluster_template
|
||||||
|
|
||||||
|
create_cluster
|
||||||
|
|
||||||
|
wait_active_state
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function verify {
|
function verify {
|
||||||
_sahara_set_user
|
sahara_set_user
|
||||||
# check that cluster is in Active state
|
# check that cluster is in Active state
|
||||||
local cluster_id
|
local cluster_id=$(resource_get sahara cluster_id)
|
||||||
cluster_id=$(resource_get sahara cluster_id)
|
eval $(openstack dataprocessing cluster show -f shell \
|
||||||
local cluster_state
|
-c Status $CLUSTER_NAME)
|
||||||
cluster_state=$(sahara cluster-show --id $cluster_id \
|
if [[ "$status" != "Active" ]]; then
|
||||||
| awk '$2 ~ /^status/ { print $4;exit }')
|
|
||||||
echo -n $cluster_state
|
|
||||||
if [[ "$cluster_state" != "Active" ]]; then
|
|
||||||
die $LINENO "Cluster is not in Active state anymore"
|
die $LINENO "Cluster is not in Active state anymore"
|
||||||
fi
|
fi
|
||||||
echo "Sahara verification: SUCCESS"
|
echo "Sahara verification: SUCCESS"
|
||||||
@ -194,62 +185,32 @@ function verify_noapi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function destroy {
|
function destroy {
|
||||||
_sahara_set_user
|
sahara_set_user
|
||||||
set +o errexit
|
set +o errexit
|
||||||
|
|
||||||
# delete cluster
|
# delete cluster
|
||||||
local cluster_id
|
openstack dataprocessing cluster delete $CLUSTER_NAME --wait
|
||||||
cluster_id=$(resource_get sahara cluster_id)
|
|
||||||
sahara cluster-delete --id $cluster_id > /dev/null
|
|
||||||
# wait for cluster deletion
|
|
||||||
local timeleft=500
|
|
||||||
while [[ $timeleft -gt 0 ]]; do
|
|
||||||
sahara cluster-show --id $cluster_id > /dev/null
|
|
||||||
local rc=$?
|
|
||||||
|
|
||||||
if [[ "$rc" != 1 ]]; then
|
|
||||||
echo "Cluster still exists"
|
|
||||||
sleep 5
|
|
||||||
timeleft=$((timeleft - 5))
|
|
||||||
if [[ $timeleft == 0 ]]; then
|
|
||||||
die $LINENO "Cluster hasn't been deleted during 500 seconds"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
set -o errexit
|
set -o errexit
|
||||||
|
|
||||||
# delete cluster template
|
# delete cluster template
|
||||||
local cluster_template_id
|
openstack dataprocessing cluster template delete $CLUSTER_TEMPLATE_NAME
|
||||||
cluster_template_id=$(resource_get sahara cluster_template_id)
|
|
||||||
sahara cluster-template-delete --id $cluster_template_id
|
|
||||||
|
|
||||||
# delete node group template
|
# delete node group template
|
||||||
local ng_id
|
openstack dataprocessing node group template delete $NG_TEMPLATE_NAME
|
||||||
ng_id=$(resource_get sahara ng_id)
|
|
||||||
|
|
||||||
sahara node-group-template-delete --id $ng_id
|
|
||||||
|
|
||||||
# delete security group
|
|
||||||
nova secgroup-delete $SAHARA_USER
|
|
||||||
|
|
||||||
source_quiet $TOP_DIR/openrc admin admin
|
source_quiet $TOP_DIR/openrc admin admin
|
||||||
|
|
||||||
# unregister image
|
# unregister image
|
||||||
local image_id
|
local image_id=$(resource_get sahara image_id)
|
||||||
image_id=$(resource_get sahara image_id)
|
openstack dataprocessing image unregister $image_id
|
||||||
sahara image-unregister --id $image_id
|
|
||||||
|
|
||||||
# delete flavor
|
# delete flavor
|
||||||
openstack flavor delete $SAHARA_FLAVOR_NAME
|
openstack flavor delete $SAHARA_FLAVOR_NAME
|
||||||
|
|
||||||
# delete user and project
|
# delete user and project
|
||||||
local user_id
|
local user_id=$(resource_get sahara user_id)
|
||||||
user_id=$(resource_get sahara user_id)
|
local project_id=$(resource_get sahara project_id)
|
||||||
local project_id
|
|
||||||
project_id=$(resource_get sahara project_id)
|
|
||||||
openstack user delete $user_id
|
openstack user delete $user_id
|
||||||
openstack project delete $project_id
|
openstack project delete $project_id
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user