openmano first code upload

Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
diff --git a/test/test-multivim.sh b/test/test-multivim.sh
new file mode 100755
index 0000000..d08ceb9
--- /dev/null
+++ b/test/test-multivim.sh
@@ -0,0 +1,195 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#This script is a basic test for openmano, that deals with two openvim
+#stopping on an error
+#WARNING: It destroy the database content
+
+
+function usage(){
+    echo -e "usage: ${BASH_SOURCE[0]} [-f]\n  Deletes openvim/openmano content and make automatically the wiki steps"
+    echo -e "  at 'https://github.com/nfvlabs/openmano/wiki/Getting-started#how-to-use-it'"
+    echo -e "  OPTIONS:"
+    echo -e "    -f --force : does not prompt for confirmation"
+    echo -e "    -h --help  : shows this help"
+}
+
+function is_valid_uuid(){
+    echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
+    return 1
+}
+
+
+#detect if is called with a source to use the 'exit'/'return' command for exiting
+[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
+
+#check correct arguments
+[[ -n $1 ]] && [[ $1 != -h ]] && [[ $1 != --help ]] && [[ $1 != -f ]] && [[ $1 != --force ]] && \
+   echo "invalid argument '$1'?" &&  usage >&2 && $_exit 1
+[[ $1 == -h ]] || [[ $1 == --help ]]  && usage && $_exit 0
+
+#ask for confirmation if argument is not -f --force
+force=""
+[[ $1 == -f ]] || [[ $1 == --force ]] && force=y
+[[ $force != y ]] && read -e -p "WARNING: openmano and openvim database content will be lost!!!  Continue(y/N)" force
+[[ $force != y ]] && [[ $force != yes ]] && echo "aborted!" && $_exit
+
+DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+DIR_BASE=$(dirname $DIRNAME)
+DIR_BASE=$(dirname $DIR_BASE)
+DIRvim=$DIR_BASE/openvim
+DIRmano=$DIR_BASE/openmano
+DIRscripts=$DIR_BASE/scripts
+
+echo "deleting deployed vm"
+openvim vm-delete -f | grep -q deleted && sleep 10 #give some time to get virtual machines deleted
+
+echo "Stopping openmano"
+$DIRscripts/service-openmano.sh stop
+
+echo "Initializing databases"
+$DIRvim/database_utils/init_vim_db.sh -u vim -p vimpw
+$DIRmano/database_utils/init_mano_db.sh -u mano -p manopw
+
+echo "Starting openmano"
+$DIRscripts/service-openmano.sh start
+
+echo "Creating openmano tenant 'mytenant'"
+nfvotenant=`openmano tenant-create mytenant --description=mytenant |gawk '{print $1}'`
+#check a valid uuid is obtained
+is_valid_uuid $nfvotenant || ! echo "fail" >&2 || $_exit 1 
+export OPENMANO_TENANT=$nfvotenant
+echo "  $nfvotenant"
+
+echo "Adding example hosts"
+openvim host-add $DIRvim/test/hosts/host-example0.json || ! echo "fail" >&2 || $_exit 1
+openvim host-add $DIRvim/test/hosts/host-example1.json || ! echo "fail" >&2 || $_exit 1
+openvim host-add $DIRvim/test/hosts/host-example2.json || ! echo "fail" >&2 || $_exit 1
+openvim host-add $DIRvim/test/hosts/host-example3.json || ! echo "fail" >&2 || $_exit 1
+echo "Adding example nets"
+openvim net-create $DIRvim/test/networks/net-example0.yaml || ! echo "fail" >&2 || $_exit 1
+openvim net-create $DIRvim/test/networks/net-example1.yaml || ! echo "fail" >&2 || $_exit 1
+openvim net-create $DIRvim/test/networks/net-example2.yaml || ! echo "fail" >&2 || $_exit 1
+openvim net-create $DIRvim/test/networks/net-example3.yaml || ! echo "fail" >&2 || $_exit 1
+
+echo "Creating openvim tenant 'admin'"
+vimtenant=`openvim tenant-create '{"tenant": {"name":"admin", "description":"admin"}}' |gawk '{print $1}'`
+#check a valid uuid is obtained
+is_valid_uuid $vimtenant || ! echo "fail" >&2 || $_exit 1
+echo "  $vimtenant"
+OPENVIM_TENANT_1=$vimtenant && export OPENVIM_TENANT=$vimtenant
+
+echo "Creating datacenter 'mydc1' in openmano"
+datacenter=`openmano datacenter-create mydc1 http://localhost:9080/openvim |gawk '{print $1}'`
+#check a valid uuid is obtained
+is_valid_uuid $datacenter || ! echo "fail" >&2 || $_exit 1 
+echo "  $datacenter"
+OPENMANO_DATACENTER_1=$datacenter && export OPENMANO_DATACENTER=$datacenter
+
+echo "Attaching openmano tenant to the datacenter and the openvim tenant"
+openmano datacenter-attach mydc1 --vim-tenant-id $vimtenant || ! echo "fail" >&2 || $_exit 1 
+
+echo "Updating external nets in openmano"
+openmano datacenter-net-update -f mydc1 || ! echo "fail" >&2 || $_exit 1
+
+echo "Creating a second fake datacenter 'mydc2' in openmano"
+datacenter2=`openmano datacenter-create mydc2 http://localhost:9082/openvim |gawk '{print $1}'`
+#check a valid uuid is obtained
+is_valid_uuid $datacenter || ! echo "fail" >&2 || $_exit 1 
+echo "  $datacenter2"
+OPENMANO_DATACENTER_2=$datacenter2
+echo "Attaching a second fake openvim 'mydc2'"
+openmano datacenter-attach mydc2 --vim-tenant-id $vimtenant || ! echo "fail" >&2 || $_exit 1
+
+echo "Creating VNFs, must fail in second openvim"
+openmano vnf-create $DIRmano/vnfs/examples/linux.yaml         || ! echo "fail" >&2 || $_exit 1
+openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF1.yaml || ! echo "fail" >&2 || $_exit 1
+openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF2.yaml || ! echo "fail" >&2 || $_exit 1
+
+echo "Checking images and flavors created at openvim"
+nb=`openvim image-list | wc -l`
+echo -n " $nb images "
+[[ $nb -eq 3 ]] || ! echo "fail" >&2 || $_exit 1
+echo " $nb flavors "
+[[ $nb -eq 3 ]] || ! echo "fail" >&2 || $_exit 1
+
+echo "Creating Scenarios"
+openmano scenario-create $DIRmano/scenarios/examples/simple.yaml  || ! echo "fail" >&2 || $_exit 1
+openmano scenario-create $DIRmano/scenarios/examples/complex.yaml || ! echo "fail" >&2 || $_exit 1
+
+echo "Deleting openvim images and flavors to force reload again"
+openvim image-delete -f
+openvim flavor-delete -f
+
+echo "Launching scenarios"
+openmano scenario-deploy simple simple-instance   || ! echo "fail" >&2 || $_exit 1
+openmano scenario-deploy complex complex-instance || ! echo "fail" >&2 || $_exit 1
+
+echo "Checking that openvim has 5 VM running"
+nb=`openvim vm-list | wc -l`
+[[ $nb -eq 5 ]] || ! echo "fail" >&2 || $_exit 1
+while openvim vm-list | grep -q CREATING ; do sleep 1; done
+openvim vm-list | grep -v -q ERROR || ! echo "fail: VM with error" >&2 || $_exit 1
+
+echo "Removing scenarios"
+for scenario in `openmano instance-scenario-list  | awk '{print $2}'`
+do
+  openmano instance-scenario-delete -f $scenario
+done
+
+echo "Editing datacenters so that Changing openvim Working with the second openvim"
+openmano datacenter-edit -f mydc1 'vim_url: http://localhost:9083/openvim'
+openmano datacenter-edit -f mydc2 'vim_url: http://localhost:9080/openvim'
+export OPENMANO_DATACENTER=$OPENMANO_DATACENTER_2
+
+echo "Updating external nets in openmano for second datacenter"
+openmano datacenter-net-update -f mydc2 || ! echo "fail" >&2 || $_exit 1
+
+echo "Launching Scenario instances"
+openmano scenario-deploy simple simple-instance   || ! echo "fail" >&2 || $_exit 1
+openmano scenario-deploy complex complex-instance || ! echo "fail" >&2 || $_exit 1
+
+echo "Checking images and flavors created at openvim"
+nb=`openvim image-list | wc -l`
+echo -n " $nb images "
+[[ $nb -eq 3 ]] || ! echo "fail" >&2 || $_exit 1
+echo " $nb flavors "
+[[ $nb -eq 3 ]] || ! echo "fail" >&2 || $_exit 1
+
+echo "Checking that openvim has 5 VM running"
+nb=`openvim vm-list | wc -l`
+[[ $nb -eq 5 ]] || ! echo "fail" >&2 || $_exit 1
+while openvim vm-list | grep -q CREATING ; do sleep 1; done
+openvim vm-list | grep -v -q ERROR || ! echo "fail: VM with error" >&2 || $_exit 1
+
+
+echo
+echo DONE
+#echo "Listing VNFs"
+#openmano vnf-list
+#echo "Listing scenarios"
+#openmano scenario-list
+#echo "Listing scenario instances"
+#openmano instance-scenario-list
+
+
diff --git a/test/test_os.sh b/test/test_os.sh
new file mode 100755
index 0000000..ae092c2
--- /dev/null
+++ b/test/test_os.sh
@@ -0,0 +1,253 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#This script can be used as a basic test of openmano deployment over openstack.
+#in order to use you need to set the OS_XXXX bash variables with openstack values
+#    OS_USERNAME     e.g.: admin
+#    OS_PASSWORD     
+#    OS_AUTH_URL     url to access openstack VIM e.g. http:/openstack:35357/v2.0
+#    OS_TENANT_NAME  e.g.: admin
+#    OS_CONFIG       e.g.: "'network_vlan_ranges: sriov_net'"
+#    OS_TEST_IMAGE_PATH_LINUX  image path(location) to use by the VNF linux
+#    OS_TEST_IMAGE_PATH_LINUXDATA image path(location) to use by the VNF dataplaneVNF_2VMs and dataplaneVNF3
+
+#it should be used with source. It can modifies /home/$USER/.bashrc appending the variables
+#you need to delete them manually if desired
+
+function usage(){
+    echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] <action>\n  test openmano using a openstack VIM"
+    echo -e "  <action> is a list of the following items (by default 'reset create')"
+    echo -e "    reset     reset the openmano database content"
+    echo -e "    create    creates items at openstack VIM"
+    echo -e "    delete    delete created items"
+    echo -e "  OPTIONS:"
+    echo -e "    -f --force       does not prompt for confirmation"
+    echo -e "    -h --help        shows this help"
+    echo -e "    --insert-bashrc  insert the created tenant,datacenter variables at"
+    echo -e "                     ~/.bashrc to be available by openmano config"
+}
+
+function is_valid_uuid(){
+    echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
+    return 1
+}
+
+#detect if is called with a source to use the 'exit'/'return' command for exiting
+[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
+
+#detect if environment variables are set
+fail=""
+[[ -z $OS_USERNAME ]] && echo "OS_USERNAME variable not defined" >&2 && fail=1
+[[ -z $OS_PASSWORD ]] && echo "OS_PASSWORD variable not defined" >&2 && fail=1
+[[ -z $OS_AUTH_URL ]] && echo "OS_AUTH_URL variable not defined" >&2 && fail=1
+[[ -z $OS_TENANT_NAME ]] && echo "OS_TENANT_NAME variable not defined" >&2 && fail=1
+[[ -z $OS_CONFIG ]] && echo "OS_CONFIG variable not defined" >&2 && fail=1
+[[ -z $OS_TEST_IMAGE_PATH_LINUX ]] && echo "OS_TEST_IMAGE_PATH_LINUX variable not defined" >&2 && fail=1
+[[ -z $OS_TEST_IMAGE_PATH_LINUXDATA ]] && echo "OS_TEST_IMAGE_PATH_LINUXDATA variable not defined" >&2 && fail=1
+[[ -n $fail ]] && $_exit 1
+
+#check correct arguments
+action_list=""
+for param in $*
+do
+   if [[ $param == reset ]] || [[ $param == create ]] || [[ $param == delete ]]
+   then 
+       action_list="$action_list $param"
+   elif [[ $param == -h ]] || [[ $param == --help ]]
+   then
+       usage
+       $_exit 0
+   elif [[ $param == -f ]] || [[ $param == --force ]]
+   then
+       force=y
+   elif [[ $param == --insert-bashrc ]]
+   then
+       insert_bashrc=y
+   else
+       echo "invalid argument '$param'?" &&  usage >&2 && $_exit 1
+   fi
+done
+
+DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+DIRmano=$(dirname $DIRNAME)
+DIRscript=$(dirname $DIRmano)/scripts
+#by default action should be reset create
+[[ -z $action_list ]] && action_list="reset create"
+
+for action in $action_list
+do
+if [[ $action == "reset" ]] 
+then 
+
+    #ask for confirmation if argument is not -f --force
+    [[ $force != y ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N)" force
+    [[ $force != y ]] && [[ $force != yes ]] && echo "aborted!" && $_exit
+
+    echo "Stopping openmano"
+    $DIRscript/service-openmano.sh mano stop
+    echo "Initializing openmano database"
+    $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw
+    echo "Starting openmano"
+    $DIRscript/service-openmano.sh mano start
+
+elif [[ $action == "delete" ]]
+then
+    result=`openmano tenant-list TOS-tenant`
+    nfvotenant=`echo $result |gawk '{print $1}'`
+    #check a valid uuid is obtained
+    is_valid_uuid $nfvotenant || ! echo "Tenant TOS-tenant not found. Already delete?" >&2 || $_exit 1
+    export OPENMANO_TENANT=$nfvotenant
+    openmano instance-scenario-delete -f simple-instance     || echo "fail"
+    openmano instance-scenario-delete -f complex2-instance   || echo "fail"
+    openmano scenario-delete -f simple       || echo "fail"
+    openmano scenario-delete -f complex2     || echo "fail"
+    openmano vnf-delete -f linux             || echo "fail"
+    openmano vnf-delete -f dataplaneVNF_2VMs || echo "fail"
+    openmano vnf-delete -f dataplaneVNF3     || echo "fail"
+    openmano vnf-delete -f TOS-VNF1          || echo "fail"
+    openmano datacenter-detach TOS-dc        || echo "fail"
+    openmano datacenter-delete -f TOS-dc     || echo "fail"
+    openmano tenant-delete -f TOS-tenant     || echo "fail"
+
+elif [[ $action == "create" ]]
+then 
+
+    printf "%-50s" "Creating openmano tenant 'TOS-tenant': "
+    result=`openmano tenant-create TOS-tenant --description="created by test_os.sh"`
+    nfvotenant=`echo $result |gawk '{print $1}'`
+    #check a valid uuid is obtained
+    ! is_valid_uuid $nfvotenant && echo "FAIL" && echo "    $result" && $_exit 1 
+    export OPENMANO_TENANT=$nfvotenant
+    [[ $insert_bashrc == y ]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant"  >> ~/.bashrc
+    echo $nfvotenant
+
+    printf "%-50s" "Creating datacenter 'TOS-dc' in openmano:"
+    result=`openmano datacenter-create TOS-dc "${OS_AUTH_URL}" "--type=openstack" "--config=${OS_CONFIG}"`
+    datacenter=`echo $result |gawk '{print $1}'`
+    #check a valid uuid is obtained
+    ! is_valid_uuid $datacenter && echo "FAIL" && echo "    $result" && $_exit 1 
+    echo $datacenter
+    export OPENMANO_DATACENTER=$datacenter
+    [[ $insert_bashrc == y ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter"  >> ~/.bashrc
+
+    printf "%-50s" "Attaching openmano tenant to the datacenter:"
+    result=`openmano datacenter-attach TOS-dc "--user=$OS_USERNAME" "--password=$OS_PASSWORD" "--vim-tenant-name=$OS_TENANT_NAME"`
+    [[ $? != 0 ]] && echo  "FAIL" && echo "    $result" && $_exit 1
+    echo OK
+
+    printf "%-50s" "Updating external nets in openmano: "
+    result=`openmano datacenter-net-update -f TOS-dc`
+    [[ $? != 0 ]] && echo  "FAIL" && echo "    $result"  && $_exit 1
+    echo OK
+
+    printf "%-50s" "Creating VNF 'linux': "
+    #glance image-create --file=./US1404dpdk.qcow2 --name=US1404dpdk --disk-format=qcow2 --min-disk=2 --is-public=True --container-format=bare
+    #nova image-meta US1404dpdk set location=/mnt/powervault/virtualization/vnfs/os/US1404dpdk.qcow2
+    #glance image-create --file=./US1404user.qcow2 --min-disk=2 --is-public=True --container-format=bare --name=US1404user --disk-format=qcow2
+    #nova image-meta US1404user  set location=/mnt/powervault/virtualization/vnfs/os/US1404user.qcow2
+    result=`openmano vnf-create $DIRmano/vnfs/examples/linux.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUX"`
+    vnf=`echo $result |gawk '{print $1}'`
+    #check a valid uuid is obtained
+    ! is_valid_uuid $vnf && echo FAIL && echo "    $result" &&  $_exit 1
+    echo $vnf
+    
+    printf "%-50s" "Creating VNF 1PF,1VF,2GHP,4PThreads: "
+    result=`openmano vnf-create "vnf:
+        name: TOS-VNF1
+        external-connections:
+        - name: eth0
+          type: mgmt
+          VNFC: TOS-VNF1-VM
+          local_iface_name: eth0
+        - name: PF0
+          type: data
+          VNFC: TOS-VNF1-VM
+          local_iface_name: PF0
+        - name: VF0
+          type: data
+          VNFC: TOS-VNF1-VM
+          local_iface_name: VF0
+        VNFC: 
+        - name: TOS-VNF1-VM
+          VNFC image: $OS_TEST_IMAGE_PATH_LINUXDATA
+          numas:
+          - paired-threads: 2
+            paired-threads-id: [ [0,2], [1,3] ]
+            memory: 2
+            interfaces:
+            - name:  PF0
+              vpci: '0000:00:11.0'
+              dedicated: 'yes'
+              bandwidth: 10 Gbps
+              mac_address: '20:33:45:56:77:44'
+            - name:  VF0
+              vpci:  '0000:00:12.0'
+              dedicated: 'no'
+              bandwidth: 1 Gbps
+              mac_address: '20:33:45:56:77:45'
+          bridge-ifaces:
+          - name: eth0
+            vpci: '0000:00:09.0'
+            bandwidth: 1 Mbps
+            mac_address: '20:33:45:56:77:46'
+            model: e1000
+       "`
+    vnf=`echo $result |gawk '{print $1}'`
+    ! is_valid_uuid $vnf && echo FAIL && echo "    $result" && $_exit 1
+    echo $vnf
+ 
+    printf "%-50s" "Creating VNF 'dataplaneVNF_2VMs': "
+    result=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF_2VMs.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUXDATA,$OS_TEST_IMAGE_PATH_LINUXDATA"`
+    vnf=`echo $result |gawk '{print $1}'`
+    ! is_valid_uuid $vnf && echo FAIL && echo "    $result" && $_exit 1
+    echo $vnf
+ 
+    printf "%-50s" "Creating VNF 'dataplaneVNF3.yaml': "
+    result=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF3.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUXDATA"`
+    vnf=`echo $result |gawk '{print $1}'`
+    ! is_valid_uuid $vnf && echo FAIL && echo "    $result" && $_exit 1
+    echo $vnf
+
+    for sce in simple complex2
+    do
+      printf "%-50s" "Creating scenario '$sce':"
+      result=`openmano scenario-create $DIRmano/scenarios/examples/${sce}.yaml`
+      scenario=`echo $result |gawk '{print $1}'`
+      ! is_valid_uuid $scenario && echo FAIL && echo "    $result" &&  $_exit 1
+      echo $scenario
+    done
+
+    for sce in simple complex2
+    do 
+      printf "%-50s" "Deploying scenario '$sce':"
+      result=`openmano scenario-deploy $sce ${sce}-instance`
+      instance=`echo $result |gawk '{print $1}'`
+      ! is_valid_uuid $instance && echo FAIL && echo "    $result" && $_exit 1
+      echo $instance
+    done
+
+    echo
+    echo DONE
+fi
+done
+
diff --git a/test/test_osconnector.py b/test/test_osconnector.py
new file mode 100755
index 0000000..152155b
--- /dev/null
+++ b/test/test_osconnector.py
@@ -0,0 +1,274 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+'''
+test_osconnector.py makes a test over osconnector.py (openstack connector)
+credentiasl must be provided with environment bash variables or arguments
+'''
+__author__="Alfonso Tierno, Gerardo Garcia"
+__date__ ="$22-jun-2014 11:19:29$"
+
+
+import os
+import sys
+import getopt
+#import yaml
+#from jsonschema import validate as js_v, exceptions as js_e
+
+#load osconnector, insert openmano directory in the path
+r=sys.argv[0].rfind('/')
+if r<0:
+    osconnector_path=".."
+else:
+    osconnector_path=sys.argv[0][:r+1]+".."
+sys.path.insert(0, osconnector_path)
+#sys.path.insert(0, '/home/atierno/workspace/openmano/openmano')
+import osconnector
+
+version="0.1"
+
+def usage():
+    print "Usage: ", sys.argv[0], "[options]"
+    print "  -v|--version            openstack version (by default 2)"
+    print "  -u|--username USER      user to authenticate (by default bash:OS_USERNAME)"
+    print "  -p|--password PASSWD    password to authenticate (by default bash:OS_PASSWORD)"
+    print "  -U|--auth_url URL       url of authentication over keystone (by default bash:OS_AUTH_URL)"
+    print "  -t|--tenant_name TENANT password to authenticate (by default bash:OS_TENANT_NAME)"
+    print "  -i|--image IMAGE        use this local path or url for loading image (by default cirros)"
+    print "  --skip-admin-tests      skip tests that requires administrative permissions, like create tenants"
+    print "  -h|--help               shows this help"
+    return
+
+def delete_items():
+    global myvim
+    global rollback_list
+    print "Making rollback, deleting items"
+    for i in range(len(rollback_list)-1, -1, -1):
+        item,name,id_ = rollback_list[i]
+        if item=="creds":
+            print ("changing credentials %s='%s'" % (name, id_)).ljust(50),
+        else:
+            print ("deleting %s '%s'" % (item, name)).ljust(50),
+        sys.stdout.flush()
+        if item=="flavor":
+            result,message=myvim.delete_tenant_flavor(id_)
+        elif item=="image":
+            result,message=myvim.delete_tenant_image(id_)
+        elif item=="tenant":
+            result,message=myvim.delete_tenant(id_)
+        elif item=="user":
+            result,message=myvim.delete_user(id_)
+        elif item=="network":
+            result,message=myvim.delete_tenant_network(id_)
+        elif item=="vm":
+            result,message=myvim.delete_tenant_vminstance(id_)
+        elif item=="creds":
+            try:
+                myvim[name]=id_
+                result=1
+            except Exception, e:
+                result=-1
+                message= "  " + str(type(e))[6:-1] + ": "+  str(e)
+        else:
+            print "Internal error unknown item rollback %s,%s,%s" % (item,name,id_)
+            continue
+        if result<0:
+            print " Fail"
+            print "  VIM response:", message
+            continue
+        else:
+            print " Ok"
+
+if __name__=="__main__":
+    global myvim
+    global rollback_list
+    #print "(c) Copyright Telefonica"
+    rollback_list=[]
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hv:u:U:p:t:i:",
+                 ["username=", "help", "version=", "password=", "tenant=", "url=","skip-admin-tests",'image='])
+    except getopt.GetoptError, err:
+        # print help information and exit:
+        print "Error:", err # will print something like "option -a not recognized"
+        usage()
+        sys.exit(2)
+        
+    creds = {}
+    creds['version'] = os.environ.get('OS_VERSION', '2')
+    creds['username'] = os.environ.get('OS_USERNAME')
+    creds['password'] = os.environ.get('OS_PASSWORD')
+    creds['auth_url'] = os.environ.get('OS_AUTH_URL')
+    creds['tenant_name'] = os.environ.get('OS_TENANT_NAME')
+    skip_admin_tests=False
+    image_path="http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img"
+    for o, a in opts:
+        if o in ("-h", "--help"):
+            usage()
+            sys.exit()
+        elif o in ("-v", "--version"):
+            creds['version']=a
+        elif o in ("-u", "--username"):
+            creds['username']=a
+        elif o in ("-p", "--password"):
+            creds['password']=a
+        elif o in ("-U", "--auth_url"):
+            creds['auth_url']=a
+        elif o in ("-t", "--tenant_name"):
+            creds['tenant_name']=a
+        elif o in ("-i", "--image"):
+            image_path=a
+        elif o=="--skip-admin-tests":
+            skip_admin_tests=True
+        else:
+            assert False, "Unhandled option"
+ 
+    if creds['auth_url']==None:
+        print "you must provide openstack url with -U or bash OS_AUTH_URL"
+        sys.exit()
+    print "creds:", creds
+    
+
+    try:
+        print 'load osconnector class'.ljust(50),
+        sys.stdout.flush()
+        try:
+            myvim=osconnector.osconnector(uuid=None, name='test-openstack', tenant=creds['tenant_name'], 
+                url=creds['auth_url'], url_admin=None,
+                user=creds['username'], passwd=creds['password'],
+                debug = False, config={'network_vlan_ranges':'physnet_sriov'} )
+            print " Ok"
+        except Exception, e:
+            print " Fail"
+            print str(type(e))[6:-1] + ": "+  str(e) 
+            exit(-1)
+        
+        if not skip_admin_tests:
+            tenant_name="tos-tenant"
+            print ("creating new tenant '%s'" % tenant_name).ljust(50),
+            sys.stdout.flush()
+            result,new_tenant=myvim.new_tenant(tenant_name, "test tenant_description, trying a long description to get the limit. 2 trying a long description to get the limit. 3. trying a long description to get the limit.")
+            if result<0:
+                print " Fail"
+                print "  you can skip tenant creation with param'--skip-admin-tests'"
+                print "  VIM response:", new_tenant
+                exit(-1)
+            else:
+                print " Ok", new_tenant
+                rollback_list.append(("tenant",tenant_name,new_tenant))
+
+            user_name="tos-user"
+            print ("creating new user '%s'" % user_name).ljust(50),
+            sys.stdout.flush()
+            result,new_user=myvim.new_user(user_name, user_name, tenant_id=new_tenant)
+            if result<0:
+                print " Fail"
+                print "  VIM response:", new_user
+                exit(-1)
+            else:
+                print " Ok", new_user
+                rollback_list.append(("user",user_name,new_user))
+                    
+        name="tos-fl1"
+        print ("creating new flavor '%s'"%name).ljust(50),
+        sys.stdout.flush()
+        flavor={}
+        flavor['name']=name
+        result,new_flavor1=myvim.new_tenant_flavor(flavor, True)
+        if result<0:
+            print " Fail"
+            print "  VIM response:", new_flavor1
+            exit(-1)
+        else:
+            print " Ok", new_flavor1
+            rollback_list.append(("flavor",name,new_flavor1))
+            
+        name="tos-cirros"
+        print ("creating new image '%s'"%name).ljust(50),
+        sys.stdout.flush()
+        image={}
+        image['name']=name
+        image['location']=image_path #"/home/atierno/cirros-0.3.3-x86_64-disk.img"
+        result,new_image1=myvim.new_tenant_image(image)
+        if result<0:
+            print " Fail"
+            print "  VIM response:", new_image1
+            exit(-1)
+        else:
+            print " Ok", new_image1
+            rollback_list.append(("image",name, new_image1))
+
+        if not skip_admin_tests:
+            try:
+                print 'changing credentials to new tenant'.ljust(50),
+                sys.stdout.flush()
+                myvim['tenant']  =tenant_name
+                myvim['user']=user_name
+                myvim['passwd']=user_name
+                print " Ok"
+                rollback_list.append(("creds", "tenant", creds["tenant_name"]))
+                rollback_list.append(("creds", "user",   creds["username"]))
+                rollback_list.append(("creds", "passwd", creds["password"]))
+            except Exception, e:
+                print " Fail"
+                print " Error setting osconnector to new tenant:", str(type(e))[6:-1] + ": "+  str(e)
+                exit(-1)
+
+        name="tos-net-bridge"
+        print ("creating new net '%s'"%name).ljust(50),
+        sys.stdout.flush()
+        result,new_net1=myvim.new_tenant_network(name, "bridge")
+        if result<0:
+            print " Fail"
+            print "  VIM response:", new_net1
+            exit(-1)
+        else:
+            print " Ok", new_net1
+            rollback_list.append(("network",name, new_net1))
+
+        name="tos-vm-cloud"
+        print ("creating new VM '%s'"%name).ljust(50),
+        sys.stdout.flush()
+        result,new_vm1=myvim.new_tenant_vminstance(name, "vm-cloud-description", False,new_image1,new_flavor1,
+                                    [{"net_id":new_net1, "type":"virtio"}] )
+        if result<0:
+            print " Fail"
+            print "  VIM response:", new_vm1
+            exit(-1)
+        else:
+            print " Ok", new_vm1
+            rollback_list.append(("vm",name, new_vm1))
+
+            
+        print 'DONE  Ok'
+        print "Type ENTER to delete items"
+        raw_input('> ')  
+        exit()      
+              
+    except KeyboardInterrupt:
+        print " Canceled!"
+    except SystemExit:
+        pass
+    if len(rollback_list):
+        delete_items()
+