diff options
author | wu.zhihui <wu.zhihui1@zte.com.cn> | 2016-09-23 16:53:55 +0800 |
---|---|---|
committer | wu.zhihui <wu.zhihui1@zte.com.cn> | 2016-09-27 11:20:11 +0800 |
commit | 1a2b55736da4d18758f81444933181e380202f60 (patch) | |
tree | b6c0dec37b7989456feb82485aed629333e9af36 | |
parent | 58ac79cd54821bf8c3891d136be4254aa79bfa08 (diff) |
code refactor: run_qtip.sh
1. Add prepare_qtip_image.sh to prepare qtip image before qtip test.
2. Add cleanup_qtip_image.sh to clean up qtip image after finishing
qtip test.
Both of them are invoked in run_qtip.sh
Change-Id: Iba892a2e02e31820ed0525f80a4e2885899557e0
Signed-off-by: wu.zhihui <wu.zhihui1@zte.com.cn>
-rw-r--r-- | docker/cleanup_qtip_image.sh | 24 | ||||
-rw-r--r-- | docker/prepare_qtip_image.sh | 49 | ||||
-rwxr-xr-x | docker/run_qtip.sh | 66 | ||||
-rw-r--r-- | func/fetchimg.py | 35 | ||||
-rw-r--r-- | func/spawn_vm.py | 32 | ||||
-rw-r--r-- | tests/fetchimg_test.py | 34 | ||||
-rw-r--r-- | tests/spawn_vm_test.py | 13 |
7 files changed, 101 insertions, 152 deletions
diff --git a/docker/cleanup_qtip_image.sh b/docker/cleanup_qtip_image.sh new file mode 100644 index 00000000..9c2b59db --- /dev/null +++ b/docker/cleanup_qtip_image.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [[ ! -f ${QTIP_DIR}/openrc ]];then + source ${REPOS_DIR}/releng/utils/fetch_os_creds.sh \ + -d ${QTIP_DIR}/openrc \ + -i ${INSTALLER_TYPE} \ + -a ${INSTALLER_IP} +fi + +source ${QTIP_DIR}/openrc + +cleanup_image() +{ + echo + if ! glance image-list; then + return + fi + + echo "Deleting image QTIP_CentOS..." + glance image-delete $(glance image-list | grep -e QTIP_CentOS | awk '{print $2}') + +} + +cleanup_image diff --git a/docker/prepare_qtip_image.sh b/docker/prepare_qtip_image.sh new file mode 100644 index 00000000..4095c806 --- /dev/null +++ b/docker/prepare_qtip_image.sh @@ -0,0 +1,49 @@ +#!/bin/bash +IMGNAME='QTIP_CentOS.qcow2' +IMGPATH='/home/opnfv/imgstore' +IMGURL='http://build.opnfv.org/artifacts.opnfv.org/qtip/QTIP_CentOS.qcow2' + +load_image() +{ + if [[ -n $( glance image-list | grep -e QTIP_CentOS) ]]; then + return + fi + + test -d $IMGPATH || mkdir -p $IMGPATH + if [[ ! -f "$IMGPATH/$IMGNAME" ]];then + echo + echo "========== Downloading QTIP_CentOS image ==========" + cd $IMGPATH + wget -c --progress=dot:giga $IMGURL + fi + + echo + echo "========== Loading QTIP_CentOS image ==========" + output=$(glance image-create \ + --name QTIP_CentOS \ + --visibility public \ + --disk-format qcow2 \ + --container-format bare \ + --file $IMGPATH/$IMGNAME ) + echo "$output" + + IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}') + + if [ -z "$IMAGE_ID" ]; then + echo 'Failed uploading QTIP_CentOS image to cloud'. + exit 1 + fi + + echo "QTIP_CentOS image id: $IMAGE_ID" +} + +rm -rf ${QTIP_DIR}/openrc + +${REPOS_DIR}/releng/utils/fetch_os_creds.sh \ +-d ${QTIP_DIR}/openrc \ +-i ${INSTALLER_TYPE} \ +-a ${INSTALLER_IP} + +source ${QTIP_DIR}/openrc + +load_image diff --git a/docker/run_qtip.sh b/docker/run_qtip.sh index 37eb0ea7..79529e54 100755 --- a/docker/run_qtip.sh +++ b/docker/run_qtip.sh @@ -1,40 +1,28 @@ #! /bin/bash - - - -cp ${REPOS_DIR}/releng/utils/fetch_os_creds.sh ${QTIP_DIR}/data/ -cd ${QTIP_DIR} && source get_env_info.sh \ --n ${INSTALLER_TYPE} \ --i ${INSTALLER_IP} - -source ${QTIP_DIR}/opnfv-creds.sh - -if [ "$TEST_CASE" == "compute" ]; then - cd ${QTIP_DIR} && python qtip.py -l default -f compute - cd ${QTIP_DIR}/data/ref_results/ && python compute_suite.py -fi - -if [ "$TEST_CASE" == "storage" ]; then - cd ${QTIP_DIR} && python qtip.py -l default -f storage - cd ${QTIP_DIR}/data/ref_results/ && python storage_suite.py -fi - -if [ "$TEST_CASE" == "network" ]; then - cd ${QTIP_DIR} && python qtip.py -l default -f network - cd ${QTIP_DIR}/data/ref_results/ && python network_suite.py -fi - - -if [ "$TEST_CASE" == "all" ]; then - cd ${QTIP_DIR} && python qtip.py -l default -f compute - cd ${QTIP_DIR} && python qtip.py -l default -f storage - cd ${QTIP_DIR} && python qtip.py -l default -f network - - cd ${QTIP_DIR}/data/ref_results/ && python compute_suite.py - cd ${QTIP_DIR}/data/ref_results/ && python storage_suite.py - cd ${QTIP_DIR}/data/ref_results/ && python network_suite.py -fi - - - - +run_test_suite() +{ + if [ "$TEST_CASE" == "compute" ]; then + cd ${QTIP_DIR} && python qtip.py -l default -f compute + cd ${QTIP_DIR}/data/ref_results/ && python compute_suite.py + elif [ "$TEST_CASE" == "storage" ]; then + cd ${QTIP_DIR} && python qtip.py -l default -f storage + cd ${QTIP_DIR}/data/ref_results/ && python storage_suite.py + elif [ "$TEST_CASE" == "network" ]; then + cd ${QTIP_DIR} && python qtip.py -l default -f network + cd ${QTIP_DIR}/data/ref_results/ && python network_suite.py + elif [ "$TEST_CASE" == "all" ]; then + cd ${QTIP_DIR} && python qtip.py -l default -f compute + cd ${QTIP_DIR} && python qtip.py -l default -f storage + cd ${QTIP_DIR} && python qtip.py -l default -f network + + cd ${QTIP_DIR}/data/ref_results/ && python compute_suite.py + cd ${QTIP_DIR}/data/ref_results/ && python storage_suite.py + cd ${QTIP_DIR}/data/ref_results/ && python network_suite.py + fi +} + +source ${QTIP_DIR}/docker/prepare_qtip_image.sh + +run_test_suite + +source ${QTIP_DIR}/docker/cleanup_qtip_image.sh diff --git a/func/fetchimg.py b/func/fetchimg.py deleted file mode 100644 index 1ed3def6..00000000 --- a/func/fetchimg.py +++ /dev/null @@ -1,35 +0,0 @@ -##############################################################################
-# Copyright (c) 2015 Dell Inc 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 time
-
-IMGSTORE = "/home/opnfv/imgstore"
-
-
-class FetchImg:
-
- def __init__(self):
- print 'Fetching Image!'
-
- @staticmethod
- def download():
- time.sleep(2)
- os.system('mkdir -p Temp_Img')
- filepath = './Temp_Img/QTIP_CentOS.qcow2'
- imgstorepath = IMGSTORE + "/QTIP_CentOS.qcow2"
- if os.path.isfile(imgstorepath):
- os.system("ln -s %s %s" % (imgstorepath, filepath))
- print "QTIP_CentOS.qcow2 exists locally. Skipping the download and using the file from IMG store"
- else:
- print 'Fetching QTIP_CentOS.qcow2'
- os.system('wget http://artifacts.opnfv.org/qtip/QTIP_CentOS.qcow2 -P Temp_Img')
-
- while not os.path.isfile(filepath):
- time.sleep(10)
- print 'Download Completed!'
diff --git a/func/spawn_vm.py b/func/spawn_vm.py index 5710308b..7ac4340e 100644 --- a/func/spawn_vm.py +++ b/func/spawn_vm.py @@ -11,11 +11,9 @@ import os import sys
from collections import defaultdict
from func.env_setup import Env_setup
-from func.fetchimg import FetchImg
import yaml
import heatclient.client
import keystoneclient
-import glanceclient
from novaclient import client
import time
from func.create_zones import create_zones
@@ -191,41 +189,12 @@ class SpawnVM(Env_setup): '1', endpoint=heat_endpoint, token=keystone.auth_token)
return self._heat_client
- def _get_glance_client(self):
- if self._glance_client is None:
- keystone = self._get_keystone_client()
- glance_endpoint = keystone.service_catalog.url_for(
- service_type='image')
- self._glance_client = glanceclient.Client(
- '2', glance_endpoint, token=keystone.auth_token)
- return self._glance_client
-
def create_stack(self, vm_role_ip_dict, heat_template):
global sshkey
stackname = 'QTIP'
heat = self._get_heat_client()
- glance = self._get_glance_client()
-
- available_images = []
- for image_list in glance.images.list():
- available_images.append(image_list.name)
-
- if 'QTIP_CentOS' in available_images:
- print 'Image Present'
-
- elif 'QTIP_CentOS' not in available_images:
- fetchImage = FetchImg()
- fetchImage.download()
- print 'Uploading Image to Glance. Please wait'
- qtip_image = glance.images.create(
- name='QTIP_CentOS',
- visibility='public',
- disk_format='qcow2',
- container_format='bare')
- glance.images.upload(
- qtip_image.id, open('./Temp_Img/QTIP_CentOS.qcow2'))
for checks in range(3):
print "Try to delete heats %s" % checks
for prev_stacks in heat.stacks.list():
@@ -233,7 +202,6 @@ class SpawnVM(Env_setup): print 'QTIP Stacks exists.\nDeleting Existing Stack'
heat.stacks.delete('QTIP')
time.sleep(10)
-
print '\nStack Creating Started\n'
try:
diff --git a/tests/fetchimg_test.py b/tests/fetchimg_test.py deleted file mode 100644 index 5d482567..00000000 --- a/tests/fetchimg_test.py +++ /dev/null @@ -1,34 +0,0 @@ -import mock -from func.fetchimg import FetchImg - - -class TestClass: - @mock.patch('func.fetchimg.os') - @mock.patch('func.fetchimg.os.path') - def test_fetch_img_success(self, mock_path, mock_os): - mock_os.system.return_value = True - mock_path.isfile.return_value = True - img = FetchImg() - img.download() - - @mock.patch('func.fetchimg.time') - @mock.patch('func.fetchimg.os.system') - @mock.patch('func.fetchimg.os.path') - def test_fetch_img_fail(self, mock_path, mock_system, mock_time): - img = FetchImg() - mock_system.return_value = True - mock_path.isfile.side_effect = [False, False, True] - img.download() - assert mock_time.sleep.call_count == 2 - - @mock.patch('func.fetchimg.time') - @mock.patch('func.fetchimg.os.system') - @mock.patch('func.fetchimg.os.path') - def test_fetch_temp_success(self, mock_path, mock_system, mock_time): - img = FetchImg() - mock_system.return_value = True - mock_path.isfile.side_effect = [True] - img.download() - filepath = './Temp_Img/QTIP_CentOS.qcow2' - imgstorepath = "/home/opnfv/imgstore/QTIP_CentOS.qcow2" - mock_system.assert_called_with("ln -s %s %s" % (imgstorepath, filepath)) diff --git a/tests/spawn_vm_test.py b/tests/spawn_vm_test.py index eb843ad9..b22745d7 100644 --- a/tests/spawn_vm_test.py +++ b/tests/spawn_vm_test.py @@ -10,15 +10,6 @@ class KeystoneMock(MagicMock): v2_0 = Mock() -class ImageMock(MagicMock): - name = 'QTIP_CentOS' - - -class ImagesMock(MagicMock): - def list(self): - return [ImageMock()] - - class StackMock(MagicMock): status = 'COMPLETE' outputs = [{'output_key': 'availability_instance_1', @@ -55,13 +46,11 @@ class TestClass: @mock.patch('func.spawn_vm.FetchImg') @mock.patch('func.spawn_vm.create_zones') @mock.patch('func.spawn_vm.client', autospec=True) - @mock.patch('func.spawn_vm.glanceclient', autospec=True) @mock.patch('func.spawn_vm.keystoneclient.v2_0', autospec=True) @mock.patch('func.spawn_vm.heatclient.client', autospec=True) - def test_create_zones_success(self, mock_heat, mock_keystone, mock_glance, + def test_create_zones_success(self, mock_heat, mock_keystone, mock_nova_client, mock_zone, mock_fetch, mock_setup, test_input, expected): - mock_glance.Client.return_value = Mock(images=ImagesMock()) mock_nova_client.Client.return_value = Mock() mock_heat.Client.return_value = Mock(stacks=HeatMock()) k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel'}) |