move isAlmostEqual to utils

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
Prasanna Santhanam 2013-07-04 20:14:03 +05:30
parent 048cf5aae8
commit da9552b7f3
2 changed files with 56 additions and 56 deletions

View File

@ -20,7 +20,7 @@
import marvin import marvin
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import *
from marvin.integration.lib.utils import * from marvin.integration.lib.utils import isAlmostEqual
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 nose.plugins.attrib import attr from nose.plugins.attrib import attr
@ -273,21 +273,6 @@ class TestServiceOfferings(cloudstackTestCase):
raise Exception("Warning: Exception during cleanup : %s" % e) raise Exception("Warning: Exception during cleanup : %s" % e)
return return
def isAlmostEqual(self, first_digit, second_digit, range=0):
digits_equal_within_range = False
try:
if ((first_digit - range) < second_digit < (first_digit + range)):
digits_equal_within_range = True
except Exception as e:
self.fail(
"%s: Failed while comparing the numbers %s & %s" %
(e, first_digit, second_digit))
return digits_equal_within_range
@attr(tags=["advanced", "advancedns", "smoke", "basic", "eip", "sg"]) @attr(tags=["advanced", "advancedns", "smoke", "basic", "eip", "sg"])
def test_02_edit_service_offering(self): def test_02_edit_service_offering(self):
"""Test to update existing service offering""" """Test to update existing service offering"""
@ -447,10 +432,10 @@ class TestServiceOfferings(cloudstackTestCase):
"Check CPU Speed for small offering" "Check CPU Speed for small offering"
) )
self.assertTrue( self.assertTrue(
self.isAlmostEqual(int(int(total_mem)/1024), isAlmostEqual(int(int(total_mem) / 1024),
int(self.small_offering.memory), int(self.small_offering.memory),
range=20 range=20
), ),
"Check Memory(kb) for small offering" "Check Memory(kb) for small offering"
) )
return return

View File

@ -35,11 +35,11 @@ def restart_mgmt_server(server):
try: try:
# Get the SSH client # Get the SSH client
ssh = is_server_ssh_ready( ssh = is_server_ssh_ready(
server["ipaddress"], server["ipaddress"],
server["port"], server["port"],
server["username"], server["username"],
server["password"], server["password"],
) )
result = ssh.execute("/etc/init.d/cloud-management restart") result = ssh.execute("/etc/init.d/cloud-management restart")
res = str(result) res = str(result)
# Server Stop - OK # Server Stop - OK
@ -57,21 +57,21 @@ def fetch_latest_mail(services, from_mail):
# Login to mail server to verify email # Login to mail server to verify email
mail = imaplib.IMAP4_SSL(services["server"]) mail = imaplib.IMAP4_SSL(services["server"])
mail.login( mail.login(
services["email"], services["email"],
services["password"] services["password"]
) )
mail.list() mail.list()
mail.select(services["folder"]) mail.select(services["folder"])
date = (datetime.date.today() - datetime.timedelta(1)).strftime("%d-%b-%Y") date = (datetime.date.today() - datetime.timedelta(1)).strftime("%d-%b-%Y")
result, data = mail.uid( result, data = mail.uid(
'search', 'search',
None, None,
'(SENTSINCE {date} HEADER FROM "{mail}")'.format( '(SENTSINCE {date} HEADER FROM "{mail}")'.format(
date=date, date=date,
mail=from_mail mail=from_mail
) )
) )
# Return False if email is not present # Return False if email is not present
if data == []: if data == []:
return False return False
@ -112,11 +112,11 @@ def is_server_ssh_ready(ipaddress, port, username, password, retries=50, keyPair
while True: while True:
try: try:
ssh = remoteSSHClient( ssh = remoteSSHClient(
host=ipaddress, host=ipaddress,
port=port, port=port,
user=username, user=username,
passwd=password, passwd=password,
keyPairFileLocation=keyPairFileLocation) keyPairFileLocation=keyPairFileLocation)
except Exception as e: except Exception as e:
if loop_cnt == 0: if loop_cnt == 0:
raise e raise e
@ -129,9 +129,9 @@ def is_server_ssh_ready(ipaddress, port, username, password, retries=50, keyPair
def format_volume_to_ext3(ssh_client, device="/dev/sda"): def format_volume_to_ext3(ssh_client, device="/dev/sda"):
"""Format attached storage to ext3 fs""" """Format attached storage to ext3 fs"""
cmds = [ cmds = [
"echo -e 'n\np\n1\n\n\nw' | fdisk %s" % device, "echo -e 'n\np\n1\n\n\nw' | fdisk %s" % device,
"mkfs.ext3 %s1" % device, "mkfs.ext3 %s1" % device,
] ]
for c in cmds: for c in cmds:
ssh_client.execute(c) ssh_client.execute(c)
@ -143,15 +143,15 @@ def fetch_api_client(config_file='datacenterCfg'):
testClientLogger = logging.getLogger("testClient") testClientLogger = logging.getLogger("testClient")
asyncTimeout = 3600 asyncTimeout = 3600
return cloudstackAPIClient.CloudStackAPIClient( return cloudstackAPIClient.CloudStackAPIClient(
marvin.cloudstackConnection.cloudConnection( marvin.cloudstackConnection.cloudConnection(
mgt.mgtSvrIp, mgt.mgtSvrIp,
mgt.port, mgt.port,
mgt.apiKey, mgt.apiKey,
mgt.securityKey, mgt.securityKey,
asyncTimeout, asyncTimeout,
testClientLogger testClientLogger
) )
) )
def get_process_status(hostip, port, username, password, linklocalip, process, hypervisor=None): def get_process_status(hostip, port, username, password, linklocalip, process, hypervisor=None):
@ -164,10 +164,10 @@ def get_process_status(hostip, port, username, password, linklocalip, process, h
else: else:
ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -ostricthostkeychecking=no " ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -ostricthostkeychecking=no "
ssh_command = ssh_command + \ ssh_command = ssh_command +\
"-oUserKnownHostsFile=/dev/null -p 3922 %s %s" % ( "-oUserKnownHostsFile=/dev/null -p 3922 %s %s" % (
linklocalip, linklocalip,
process) process)
# Double hop into router # Double hop into router
timeout = 5 timeout = 5
@ -183,3 +183,18 @@ def get_process_status(hostip, port, username, password, linklocalip, process, h
time.sleep(5) time.sleep(5)
timeout = timeout - 1 timeout = timeout - 1
return res return res
def isAlmostEqual(self, first_digit, second_digit, range=0):
digits_equal_within_range = False
try:
if ((first_digit - range) < second_digit < (first_digit + range)):
digits_equal_within_range = True
except Exception as e:
self.fail(
"%s: Failed while comparing the numbers %s & %s" %
(e, first_digit, second_digit))
return digits_equal_within_range