diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index 81e8f02e730..2d6b2ab520f 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -25,6 +25,8 @@ from marvin.sshClient import SshClient from marvin.integration.lib.utils import * from marvin.integration.lib.base 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 #Import System modules import os @@ -178,7 +180,6 @@ class TestCreateVolume(cloudstackTestCase): ) if isinstance(list_vm_response, list): - vm = list_vm_response[0] if vm.state == 'Running': self.debug("VM state: %s" % vm.state) @@ -187,31 +188,17 @@ class TestCreateVolume(cloudstackTestCase): if timeout == 0: raise Exception( "Failed to start VM (ID: %s) " % vm.id) - timeout = timeout - 1 - try: - ssh = self.virtual_machine.get_ssh_client( + vol_sz = str(list_volume_response[0].size) + ssh = self.virtual_machine.get_ssh_client( reconnect=True ) - c = "/sbin/fdisk -l" - res = ssh.execute(c) - - 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" - ) + ret = checkVolumeSize(ssh_handle=ssh,size_to_verify=vol_sz) + self.debug(" Volume Size Expected %s Actual :%s" %(vol_sz,ret[1])) 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): #Clean up, terminate the created volumes diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py index e870158cfb5..957807d84b1 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/integration/lib/utils.py @@ -28,13 +28,18 @@ import email import socket import urlparse import datetime +from platform import system from marvin.cloudstackAPI import cloudstackAPIClient, listHosts +from cloudstackException import GetDetailExceptionInfo from marvin.sshClient import SshClient -from marvin.codes import (FAIL, +from marvin.codes import ( + SUCCESS, + FAIL, PASS, MATCH_NOT_FOUND, INVALID_INPUT, - EMPTY_LIST) + EMPTY_LIST, + FAILED) def restart_mgmt_server(server): """Restarts the management server""" @@ -428,3 +433,40 @@ def verifyElementInList(inp, toverify, responsevar=None, pos=0): else: 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)] diff --git a/tools/marvin/marvin/marvinInit.py b/tools/marvin/marvin/marvinInit.py index 36d907ecbec..5218d235da4 100644 --- a/tools/marvin/marvin/marvinInit.py +++ b/tools/marvin/marvin/marvinInit.py @@ -94,7 +94,7 @@ class MarvinInit: return self.__tcRunLogger def getDebugFile(self): - if self.__logFolderPath is None: + if self.__logFolderPath is not None: self.__tcResultFile = open(self.__logFolderPath + "/results.txt", "w") return self.__tcResultFile diff --git a/tools/marvin/marvin/sshClient.py b/tools/marvin/marvin/sshClient.py index fd8726cee37..588c9787293 100644 --- a/tools/marvin/marvin/sshClient.py +++ b/tools/marvin/marvin/sshClient.py @@ -17,7 +17,10 @@ import paramiko import time -import cloudstackException +from cloudstackException import ( + internalError, + GetDetailExceptionInfo + ) import contextlib import logging from marvin.codes import ( @@ -60,8 +63,7 @@ class SshClient(object): if port is not None or port >= 0: self.port = port if self.createConnection() == FAIL: - raise cloudstackException.\ - internalError("Connection Failed") + raise internalError("Connection Failed") def execute(self, 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 2: stdin,stdout,stderr values of command output ''' - excep_msg = '' - ret = {"status": None, "stdin": None, "stdout": None, "stderr": None} + ret = {"status": FAIL, "stdin": None, "stdout": None, "stderr": ''} if command is None or command == '': ret["status"] = INVALID_INPUT return ret @@ -152,14 +153,12 @@ class SshClient(object): status_check = stdout.channel.recv_exit_status() if status_check == 0: ret["status"] = SUCCESS - else: - ret["status"] = FAIL except Exception as e: - excep_msg = str(e) ret["status"] = EXCEPTION_OCCURRED + ret["stderr"] = GetDetailExceptionInfo(e) finally: 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 def scp(self, srcFile, destPath):