CLOUDSTACK-5948: Fixes to BVT test_volumes.py

1. Added a generic way of verifying isk volumes.
2. Now, detach volume is called post the assert.
3. Added a sleep post detach volume to facilitate list volumes to have some time for detach operation.
4. Added a fix for a log check.
This commit is contained in:
Santhosh Edukulla 2014-01-29 10:36:23 +05:30 committed by Girish Shilamkar
parent 226df296d0
commit d057585128
4 changed files with 61 additions and 33 deletions

View File

@ -25,6 +25,8 @@ from marvin.sshClient import SshClient
from marvin.integration.lib.utils import * from marvin.integration.lib.utils import *
from marvin.integration.lib.base import * from marvin.integration.lib.base import *
from marvin.integration.lib.common import * from marvin.integration.lib.common import *
from marvin.integration.lib.utils import checkVolumeSize
from marvin.codes import SUCCESS
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
#Import System modules #Import System modules
import os import os
@ -178,7 +180,6 @@ class TestCreateVolume(cloudstackTestCase):
) )
if isinstance(list_vm_response, list): if isinstance(list_vm_response, list):
vm = list_vm_response[0] vm = list_vm_response[0]
if vm.state == 'Running': if vm.state == 'Running':
self.debug("VM state: %s" % vm.state) self.debug("VM state: %s" % vm.state)
@ -187,31 +188,17 @@ class TestCreateVolume(cloudstackTestCase):
if timeout == 0: if timeout == 0:
raise Exception( raise Exception(
"Failed to start VM (ID: %s) " % vm.id) "Failed to start VM (ID: %s) " % vm.id)
timeout = timeout - 1 timeout = timeout - 1
try: vol_sz = str(list_volume_response[0].size)
ssh = self.virtual_machine.get_ssh_client( ssh = self.virtual_machine.get_ssh_client(
reconnect=True reconnect=True
) )
c = "/sbin/fdisk -l" ret = checkVolumeSize(ssh_handle=ssh,size_to_verify=vol_sz)
res = ssh.execute(c) self.debug(" Volume Size Expected %s Actual :%s" %(vol_sz,ret[1]))
except Exception as e:
self.fail("SSH access failed for VM: %s - %s" %
(self.virtual_machine.ipaddress, e))
# Disk /dev/sda doesn't contain a valid partition table
# Disk /dev/sda: 21.5 GB, 21474836480 bytes
result = str(res)
self.debug("fdisk result: %s" % result)
self.assertEqual(
str(list_volume_response[0].size) in result,
True,
"Check if promised disk size actually available"
)
self.virtual_machine.detach_volume(self.apiClient, volume) self.virtual_machine.detach_volume(self.apiClient, volume)
self.assertEqual(ret[0],SUCCESS,"Check if promised disk size actually available")
time.sleep(self.services["sleep"])
def tearDown(self): def tearDown(self):
#Clean up, terminate the created volumes #Clean up, terminate the created volumes

View File

@ -28,13 +28,18 @@ import email
import socket import socket
import urlparse import urlparse
import datetime import datetime
from platform import system
from marvin.cloudstackAPI import cloudstackAPIClient, listHosts from marvin.cloudstackAPI import cloudstackAPIClient, listHosts
from cloudstackException import GetDetailExceptionInfo
from marvin.sshClient import SshClient from marvin.sshClient import SshClient
from marvin.codes import (FAIL, from marvin.codes import (
SUCCESS,
FAIL,
PASS, PASS,
MATCH_NOT_FOUND, MATCH_NOT_FOUND,
INVALID_INPUT, INVALID_INPUT,
EMPTY_LIST) EMPTY_LIST,
FAILED)
def restart_mgmt_server(server): def restart_mgmt_server(server):
"""Restarts the management server""" """Restarts the management server"""
@ -428,3 +433,40 @@ def verifyElementInList(inp, toverify, responsevar=None, pos=0):
else: else:
return [FAIL, MATCH_NOT_FOUND] return [FAIL, MATCH_NOT_FOUND]
def checkVolumeSize(ssh_handle=None,
volume_name="/dev/sda",
cmd_inp="/sbin/fdisk -l | grep Disk",
size_to_verify=0):
'''
@Name : getDiskUsage
@Desc : provides facility to verify the volume size against the size to verify
@Input: 1. ssh_handle : machine against which to execute the disk size cmd
2. volume_name : The name of the volume against which to verify the size
3. cmd_inp : Input command used to veify the size
4. size_to_verify: size against which to compare.
@Output: Returns FAILED in case of an issue, else SUCCESS
'''
try:
if ssh_handle is None or cmd_inp is None or volume_name is None:
return INVALID_INPUT
cmd = cmd_inp
'''
Retrieve the cmd output
'''
if system().lower() != "windows":
fdisk_output = ssh_handle.runCommand(cmd_inp)
if fdisk_output["status"] != SUCCESS:
return FAILED
temp_out = fdisk_output["stdout"]
for line in temp_out.split("\n"):
if volume_name in line:
parts = line.split()
if str(parts[-2]) == str(size_to_verify):
return [SUCCESS,str(parts[-2])]
return [FAILED,"Volume Not Found"]
except Exception, e:
print "\n Exception Occurred under getDiskUsage: " \
"%s" %GetDetailExceptionInfo(e)
return [FAILED,GetDetailExceptionInfo(e)]

View File

@ -94,7 +94,7 @@ class MarvinInit:
return self.__tcRunLogger return self.__tcRunLogger
def getDebugFile(self): def getDebugFile(self):
if self.__logFolderPath is None: if self.__logFolderPath is not None:
self.__tcResultFile = open(self.__logFolderPath + self.__tcResultFile = open(self.__logFolderPath +
"/results.txt", "w") "/results.txt", "w")
return self.__tcResultFile return self.__tcResultFile

View File

@ -17,7 +17,10 @@
import paramiko import paramiko
import time import time
import cloudstackException from cloudstackException import (
internalError,
GetDetailExceptionInfo
)
import contextlib import contextlib
import logging import logging
from marvin.codes import ( from marvin.codes import (
@ -60,8 +63,7 @@ class SshClient(object):
if port is not None or port >= 0: if port is not None or port >= 0:
self.port = port self.port = port
if self.createConnection() == FAIL: if self.createConnection() == FAIL:
raise cloudstackException.\ raise internalError("Connection Failed")
internalError("Connection Failed")
def execute(self, command): def execute(self, command):
stdin, stdout, stderr = self.ssh.exec_command(command) stdin, stdout, stderr = self.ssh.exec_command(command)
@ -134,8 +136,7 @@ class SshClient(object):
INVALID_INPUT : If invalid value for command is passed INVALID_INPUT : If invalid value for command is passed
2: stdin,stdout,stderr values of command output 2: stdin,stdout,stderr values of command output
''' '''
excep_msg = '' ret = {"status": FAIL, "stdin": None, "stdout": None, "stderr": ''}
ret = {"status": None, "stdin": None, "stdout": None, "stderr": None}
if command is None or command == '': if command is None or command == '':
ret["status"] = INVALID_INPUT ret["status"] = INVALID_INPUT
return ret return ret
@ -152,14 +153,12 @@ class SshClient(object):
status_check = stdout.channel.recv_exit_status() status_check = stdout.channel.recv_exit_status()
if status_check == 0: if status_check == 0:
ret["status"] = SUCCESS ret["status"] = SUCCESS
else:
ret["status"] = FAIL
except Exception as e: except Exception as e:
excep_msg = str(e)
ret["status"] = EXCEPTION_OCCURRED ret["status"] = EXCEPTION_OCCURRED
ret["stderr"] = GetDetailExceptionInfo(e)
finally: finally:
self.logger.debug(" Host: %s Cmd: %s Output:%s Exception: %s" % self.logger.debug(" Host: %s Cmd: %s Output:%s Exception: %s" %
(self.host, command, str(ret), excep_msg)) (self.host, command, str(ret), ret["stderr"]))
return ret return ret
def scp(self, srcFile, destPath): def scp(self, srcFile, destPath):