summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xrun_tests.sh2
-rwxr-xr-xtestsuites/rubbos/run_rubbos.py159
2 files changed, 160 insertions, 1 deletions
diff --git a/run_tests.sh b/run_tests.sh
index b87d2fcb..e6e90846 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -79,7 +79,7 @@ function run_test(){
#adjust config parameters, different test suite has different methods, take rubbos as an example
#run test case, different test suite has different methods
file={$BASEDIR}/testsuites/rubbos/testcase_cfg/{$i}.yaml
- python ${BOTTLENECK_TOP_DIR}/testsuites/rubbos/run_rubbos.py $file
+ python ${BOTTLENECK_TOP_DIR}/testsuites/rubbos/run_rubbos.py -c $file
done
;;
"vstf")
diff --git a/testsuites/rubbos/run_rubbos.py b/testsuites/rubbos/run_rubbos.py
index e69de29b..d487313a 100755
--- a/testsuites/rubbos/run_rubbos.py
+++ b/testsuites/rubbos/run_rubbos.py
@@ -0,0 +1,159 @@
+#!/usr/bin/env python
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import os
+import argparse
+import time
+import heatclient
+import keystoneclient
+import glanceclient
+import novaclient
+
+#------------------------------------------------------
+# parser for configuration files in each test case
+# ------------------------------------------------------
+parser = argparse.ArgumentParser()
+parser.add_argument("-c", "--conf",
+ help="configuration files for the testcase, in yaml format",
+ default="rubbos_1-1-1.yaml")
+args = parser.parse_args()
+
+#--------------------------------------------------
+# logging configuration
+#--------------------------------------------------
+logger = logging.getLogger('run_rubbos')
+logger.setLevel(logging.DEBUG)
+
+def _get_keystone_client():
+ keystone_client = keystoneclient.v2_0.client.Client(
+ auth_url=os.environ.get('OS_AUTH_URL'),
+ username=os.environ.get('OS_USERNAME'),
+ password=os.environ.get('OS_PASSWORD'),
+ tenant_name=os.environ.get('OS_TENANT_NAME'),
+ cacert=os.environ.get('OS_CACERT'))
+ return keystone_client
+
+def _get_heat_client():
+ keystone = _get_keystone_client()
+ heat_endpoint = keystone.service_catalog.url_for(service_type='orchestration')
+ heat_client = heatclient.client.Client('1', endpoint=heat_endpoint, token=keystone.auth_token)
+
+ return heat_client
+
+def _get_glance_client():
+ keystone = _get_keystone_client()
+ glance_endpoint = keystone.service_catalog.url_for(service_type='image',
+ endpoint_type='publicURL')
+ return glanceclient.v2.client.Client(glance_endpoint, token=keystone.auth_token)
+
+def _get_nova_client():
+ nova_client = novaclient.client.Client("2", auth_url=os.environ.get('OS_AUTH_URL'),
+ username=os.environ.get('OS_USERNAME'),
+ password=os.environ.get('OS_PASSWORD'),
+ tenant_name=os.environ.get('OS_TENANT_NAME'),
+ region_name=os.environ.get('OS_REGION_NAME'),
+ cacert=os.environ.get('OS_CACERT'))
+ return nova_client
+
+def download_url(url, dest_path):
+ """
+ Download a file to a destination path given a URL
+ """
+ name = url.rsplit('/')[-1]
+ dest = dest_path + "/" + name
+ try:
+ response = urllib2.urlopen(url)
+ except (urllib2.HTTPError, urllib2.URLError):
+ return False
+
+ with open(dest, 'wb') as f:
+ shutil.copyfileobj(response, f)
+ return True
+
+def rubbos_env_prepare(template=None):
+ """ Prepare for rubbos running env
+ """
+ #logger.info("generate heat template for the testcase based on template '%s'." % template)
+ pass
+
+def rubbos_env_cleanup():
+ glance = _get_glance_client()
+ heat = _get_heat_client()
+ nova = _get_nova_client()
+
+ for stack in self.heat.stacks.list():
+ heat.stacks.delete(stack.id)
+
+ for image in self.glance.images.list():
+ glance.images.delete(image.id)
+
+ for keypair in self.nova.keypairs.list():
+ nova.keypairs.delete(keypair.id)
+
+ for flavor in self.nova.flavors.list():
+ nova.flavors.delete(flavor.id)
+
+ logger.info("openstack env cleanup")
+
+def rubbos_load_image(name=None):
+ file_url = '/tmp'
+ download_url(image_url,file_url)
+
+ glance = _get_glance_client()
+ image_args = {'name': name,
+ 'disk-format': 'qcow2',
+ 'container_format': 'bare',
+ 'file': '/tmp/bottlenecks-trusty-server.img'}
+ image = glance.images.create(**image_args)
+ if not (image.id):
+ logger.error("failed to upload rubbos image to openstack")
+ exit(-1)
+
+def rubbos_create_instance(template_file=None, rubbos_parameters=None):
+ heat = _get_heat_client()
+ template = open(template_file, 'r')
+ rubbos_stack = heat.stacks.create(stack_name='rubbos', template=template.read(), parameters=rubbos_parameters)
+ uid = rubbos_stack['stack']['id']
+
+def rubbos_stack_check(stack_name=None):
+ for stack in heat.stacks.list():
+ if stack.stack_name == stack_name:
+ return stack.stack_status
+ return 'NOT_FOUND'
+
+def rubbos_run():
+ pass
+
+def main():
+ global Heat_template
+ global image_url
+
+ image_url = 'http://artifacts.opnfv.org/bottlenecks/rubbos/bottlenecks-trusty-server.img'
+
+ if not (args.conf):
+ logger.error("configuration files are not set for testcase")
+ exit(-1)
+ else:
+ Heat_template = args.conf
+
+ parameters={'image': 'rubbos',
+ 'key_name': 'rubbos-key',
+ 'public_net': 'net04_ext'}
+
+ rubbos_env_prepare(Heat_template)
+ rubbos_env_cleanup()
+ rubbos_load_image(name='rubbos')
+ rubbos_create_instance(template_file=Heat_template, rubbos_paramters=parameters)
+ time.sleep(400)
+ rubbos_stack_check(stack_name='rubbos')
+ rubbos_run()
+ rubbos_env_cleanup()
+
+if __name__=='__main__':
+ main()
/* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/bin/bash
##############################################################################
# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
compass_vm_dir=$WORK_DIR/vm/compass
rsa_file=$compass_vm_dir/boot.rsa
ssh_args="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $rsa_file"
function tear_down_compass() {
    sudo virsh destroy compass > /dev/null 2>&1
    sudo virsh undefine compass > /dev/null 2>&1

    sudo umount $compass_vm_dir/old > /dev/null 2>&1
    sudo umount $compass_vm_dir/new > /dev/null 2>&1

    sudo rm -rf $compass_vm_dir

    log_info "tear_down_compass success!!!"
}

function install_compass_core() {
    install_compass "compass_nodocker.yml"
}

function set_compass_machine() {
    local config_file=$WORK_DIR/installer/compass-install/install/group_vars/all

    sed -i -e '/test: true/d' -e '/pxe_boot_macs/d' $config_file
    echo "test: true" >> $config_file
    echo "pxe_boot_macs: [${machines}]" >> $config_file

    install_compass "compass_machine.yml"
}

function install_compass() {
    local inventory_file=$compass_vm_dir/inventory.file
    sed -i "s/mgmt_next_ip:.*/mgmt_next_ip: ${COMPASS_SERVER}/g" $WORK_DIR/installer/compass-install/install/group_vars/all
    echo "compass_nodocker ansible_ssh_host=$MGMT_IP ansible_ssh_port=22" > $inventory_file
    PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook -e pipeline=true --private-key=$rsa_file --user=root --connection=ssh --inventory-file=$inventory_file $WORK_DIR/installer/compass-install/install/$1
    exit_status=$?
    rm $inventory_file
    if [[ $exit_status != 0 ]];then
        /bin/false
    fi
}

function wait_ok() {
    set +x
    log_info "wait_compass_ok enter"
    ssh-keygen -f "/root/.ssh/known_hosts" -R $MGMT_IP >/dev/null 2>&1
    retry=0
    until timeout 1s ssh $ssh_args root@$MGMT_IP "exit" >/dev/null 2>&1
    do
        log_progress "os install time used: $((retry*100/$1))%"
        sleep 1
        let retry+=1
        if [[ $retry -ge $1 ]];then
            timeout 1s ssh $ssh_args root@$MGMT_IP "exit"
            log_error "os install time out"
            exit 1
        fi
    done
    set -x
    log_warn "os install time used: 100%"
    log_info "wait_compass_ok exit"
}

function launch_compass() {
    local old_mnt=$compass_vm_dir/old
    local new_mnt=$compass_vm_dir/new
    local old_iso=$WORK_DIR/iso/centos.iso
    local new_iso=$compass_vm_dir/centos.iso

    log_info "launch_compass enter"
    tear_down_compass

    set -e
    mkdir -p $compass_vm_dir $old_mnt
    sudo mount -o loop $old_iso $old_mnt
    cd $old_mnt;find .|cpio -pd $new_mnt;cd -

    sudo umount $old_mnt

    chmod 755 -R $new_mnt

    cp $COMPASS_DIR/util/isolinux.cfg $new_mnt/isolinux/ -f
    cp $COMPASS_DIR/util/ks.cfg $new_mnt/isolinux/ -f

    sed -i -e "s/REPLACE_MGMT_IP/$MGMT_IP/g" \
           -e "s/REPLACE_MGMT_NETMASK/$MGMT_MASK/g" \
           -e "s/REPLACE_GW/$MGMT_GW/g" \
           -e "s/REPLACE_INSTALL_IP/$COMPASS_SERVER/g" \
           -e "s/REPLACE_INSTALL_NETMASK/$INSTALL_MASK/g" \
           -e "s/REPLACE_COMPASS_EXTERNAL_NETMASK/$COMPASS_EXTERNAL_MASK/g" \
           -e "s/REPLACE_COMPASS_EXTERNAL_IP/$COMPASS_EXTERNAL_IP/g" \
           -e "s/REPLACE_COMPASS_EXTERNAL_GW/$COMPASS_EXTERNAL_GW/g" \
           $new_mnt/isolinux/isolinux.cfg

    if [[ -n $COMPASS_DNS1 ]]; then
        sed -i -e "s/REPLACE_COMPASS_DNS1/$COMPASS_DNS1/g" $new_mnt/isolinux/isolinux.cfg
    fi

    if [[ -n $COMPASS_DNS2 ]]; then
        sed -i -e "s/REPLACE_COMPASS_DNS2/$COMPASS_DNS2/g" $new_mnt/isolinux/isolinux.cfg
    fi

    ssh-keygen -f $new_mnt/bootstrap/boot.rsa -t rsa -N ''
    cp $new_mnt/bootstrap/boot.rsa $rsa_file

    rm -rf $new_mnt/.rr_moved $new_mnt/rr_moved
    sudo mkisofs -quiet -r -J -R -b isolinux/isolinux.bin  -no-emul-boot -boot-load-size 4 -boot-info-table -hide-rr-moved -x "lost+found:" -o $new_iso $new_mnt

    rm -rf $old_mnt $new_mnt

    qemu-img create -f qcow2 $compass_vm_dir/disk.img 100G

    # create vm xml
    sed -e "s/REPLACE_MEM/$COMPASS_VIRT_MEM/g" \
        -e "s/REPLACE_CPU/$COMPASS_VIRT_CPUS/g" \
        -e "s#REPLACE_IMAGE#$compass_vm_dir/disk.img#g" \
        -e "s#REPLACE_ISO#$compass_vm_dir/centos.iso#g" \
        -e "s/REPLACE_NET_MGMT/mgmt/g" \
        -e "s/REPLACE_NET_INSTALL/install/g" \
        -e "s/REPLACE_NET_EXTERNAL/external/g" \
        $COMPASS_DIR/deploy/template/vm/compass.xml \
        > $WORK_DIR/vm/compass/libvirt.xml

    sudo virsh define $compass_vm_dir/libvirt.xml
    sudo virsh start compass

    exit_status=$?
    if [ $exit_status != 0 ];then
        log_error "virsh start compass failed"
        exit 1
    fi

    if ! wait_ok 500;then
        log_error "install os timeout"
        exit 1
    fi

    if ! install_compass_core;then
        log_error "install compass core failed"
        exit 1
    fi

    set +e
    log_info "launch_compass exit"
}