Skip to content

Commit a908b8d

Browse files
Santhosh EdukullaGirish Shilamkar
authored andcommitted
CLOUDSTACK-5793: Fixed few issues related CLOUDSTACK-5973
1 parent df58f51 commit a908b8d

2 files changed

Lines changed: 55 additions & 31 deletions

File tree

test/integration/component/test_add_remove_network.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Services:
6767

6868
def __init__(self):
6969
self.services = {
70-
70+
"sleep": 60,
7171
"ostype": "CentOS 5.3 (64-bit)",
7272
# Cent OS 5.3 (64 bit)
7373

@@ -392,8 +392,7 @@ def test_03_add_nw_multiple_times(self, value):
392392
# Trying to add same network to vm for the second time
393393
with self.assertRaises(Exception) as e:
394394
self.addNetworkToVm(network, self.virtual_machine)
395-
396-
self.debug("Adding same network again failed with exception: %s" % e.exception)
395+
self.debug("Adding same network again failed with exception: %s" % e.exception)
397396

398397
return
399398

@@ -515,7 +514,7 @@ def test_10_add_nw_invalid_ipaddress_running_vm(self):
515514
with self.assertRaises(Exception) as e:
516515
self.addNetworkToVm(self.shared_network, self.virtual_machine,
517516
ipaddress = ipaddress)
518-
self.debug("API failed with exception: %s" % e.exception)
517+
self.debug("API failed with exception: %s" % e.exception)
519518

520519
return
521520

@@ -552,9 +551,7 @@ def test_14_add_nw_different_account(self, value):
552551

553552
with self.assertRaises(Exception) as e:
554553
self.virtual_machine.add_nic(self.apiclient, network.id)
555-
network.delete(self.apiclient)
556-
557-
self.debug("Operation failed with exception %s" % e.exception)
554+
self.debug("Operation failed with exception %s" % e.exception)
558555

559556
return
560557

@@ -606,15 +603,13 @@ def test_24_add_nw_different_domain(self):
606603
domainid=self.child_do_admin_2.domainid, serviceofferingid=self.service_offering.id,
607604
mode=self.zone.networktype)
608605

606+
time.sleep(self.services["sleep"])
609607
self.debug("Trying to %s network in domain %s to a vm in domain %s, This should fail" %
610608
(network.type, self.child_domain_1.name, self.child_domain_2.name))
611609

612610
with self.assertRaises(Exception) as e:
613611
virtual_machine.add_nic(self.apiclient, network.id)
614-
self.debug("Operation failed with exception %s" % e.exception)
615-
616-
network.delete(self.apiclient)
617-
612+
self.debug("Operation failed with exception %s" % e.exception)
618613
return
619614

620615
@attr(tags = ["advanced"])
@@ -686,7 +681,7 @@ def test_25_add_nw_above_account_limit(self):
686681

687682
with self.assertRaises(Exception) as e:
688683
virtual_machine.add_nic(self.apiclient, network_2.id)
689-
self.debug("Operation failed with exception %s" % e.exception)
684+
self.debug("Operation failed with exception %s" % e.exception)
690685

691686
return
692687

@@ -836,7 +831,7 @@ def test_08_remove_default_nic(self):
836831
self.virtual_machine.id)
837832
with self.assertRaises(Exception):
838833
self.virtual_machine.remove_nic(self.apiclient, vm_list[0].nic[0].id)
839-
self.debug("Removing default nic of vm failed")
834+
self.debug("Removing default nic of vm failed")
840835
return
841836

842837
@attr(tags = ["advanced"])
@@ -867,7 +862,7 @@ def test_09_remove_foreign_nic(self):
867862
operation should fail")
868863
with self.assertRaises(Exception) as e:
869864
self.virtual_machine.remove_nic(self.apiclient, virtual_machine.nic[0].id)
870-
self.debug("Operation failed with exception: %s" % e.exception)
865+
self.debug("Operation failed with exception: %s" % e.exception)
871866
return
872867

873868
class TestUpdateVirtualMachineNIC(cloudstackTestCase):
@@ -1045,7 +1040,7 @@ def test_12_make_default_nic_as_default(self):
10451040
self.debug("Trying to set default nic again as default nic, This should fail")
10461041
with self.assertRaises(Exception) as e:
10471042
self.virtual_machine.update_default_nic(self.apiclient, nicId = defaultNicId)
1048-
self.debug("updateDefaultNic operation failed as expected with exception: %s" %
1043+
self.debug("updateDefaultNic operation failed as expected with exception: %s" %
10491044
e.exception)
10501045

10511046
return
@@ -1070,15 +1065,16 @@ def test_13_set_foreign_nic_as_default(self):
10701065
virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
10711066
accountid=account.name,domainid=account.domainid,
10721067
serviceofferingid=self.service_offering.id,mode=self.zone.networktype)
1068+
time.sleep(self.services["sleep"])
10731069
self.debug("Deployed virtual machine: %s" % virtual_machine.id)
1074-
1070+
10751071
foreignNicId = virtual_machine.nic[0].id
10761072

10771073
self.debug("Trying to set nic of new virtual machine as default nic of existing virtual machine, This \
10781074
operation should fail")
10791075
with self.assertRaises(Exception) as e:
10801076
self.virtual_machine.update_default_nic(self.apiclient, nicId = foreignNicId)
1081-
self.debug("updateDefaultNic operation failed as expected with exception: %s" %
1077+
self.debug("updateDefaultNic operation failed as expected with exception: %s" %
10821078
e.exception)
10831079

10841080
return
@@ -1224,6 +1220,7 @@ def test_17_add_nic_different_zone(self):
12241220
cmd.networkid = isolated_network.id
12251221

12261222
with self.assertRaises(Exception) as e:
1223+
time.sleep(5)
12271224
self.apiclient.addNicToVirtualMachine(cmd)
12281225
self.debug("addNicToVirtualMachine API failed with exception: %s" % e.exception)
12291226

@@ -1265,6 +1262,7 @@ def test_18_add_nic_basic_zone(self):
12651262
virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
12661263
serviceofferingid=self.service_offering.id,
12671264
mode=basicZone.networktype)
1265+
time.sleep(self.services["sleep"])
12681266
self.debug("Deployed virtual machine %s: " % virtual_machine.id)
12691267

12701268
cmd = addNicToVirtualMachine.addNicToVirtualMachineCmd()
@@ -1274,6 +1272,7 @@ def test_18_add_nic_basic_zone(self):
12741272
self.dedbug("Trying to add isolated network to VM (both in basic zone,\
12751273
this operation should fail")
12761274
with self.assertRaises(Exception) as e:
1275+
time.sleep(5)
12771276
self.apiclient.addNicToVirtualMachine(cmd)
12781277
self.debug("addNicToVirtualMachine API failed with exception: %s" % e.exception)
12791278

@@ -1306,6 +1305,7 @@ def test_26_add_nic_insufficient_permission(self):
13061305
insufficient permission")
13071306

13081307
with self.assertRaises(Exception) as e:
1308+
time.sleep(5)
13091309
api_client.addNicToVirtualMachine(cmd)
13101310
self.debug("addNicToVirtualMachine API failed with exception: %s" % e.exception)
13111311

@@ -1372,7 +1372,7 @@ def tearDown(self):
13721372
def tearDownClass(cls):
13731373
try:
13741374
# Disable Network Offerings
1375-
#cls.isolated_network_offering.update(cls.api_client, state='Disabled')
1375+
cls.isolated_network_offering.update(cls.api_client, state='Disabled')
13761376
# Cleanup resources used
13771377
cleanup_resources(cls.api_client, cls._cleanup)
13781378

@@ -1601,7 +1601,7 @@ def test_21_update_nic_wrong_vm_id(self):
16011601

16021602
with self.assertRaises(Exception) as e:
16031603
self.apiclient.updateDefaultNicForVirtualMachine(cmd)
1604-
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
1604+
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
16051605
e.exception)
16061606

16071607
return
@@ -1647,7 +1647,7 @@ def test_22_update_nic_wrong_nic_id(self):
16471647

16481648
with self.assertRaises(Exception) as e:
16491649
self.apiclient.updateDefaultNicForVirtualMachine(cmd)
1650-
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
1650+
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
16511651
e.exception)
16521652

16531653
return
@@ -1676,7 +1676,7 @@ def test_23_update_nic_incorrect_vm_state(self):
16761676
accountid=account.name,domainid=account.domainid,
16771677
serviceofferingid=self.service_offering.id,
16781678
mode=self.zone.networktype)
1679-
1679+
time.sleep(self.services["sleep"])
16801680
self.debug("Created virtual machine %s" % virtual_machine.id)
16811681

16821682
self.debug("Creating isolated network in account %s" % account.name)
@@ -1729,7 +1729,7 @@ def test_23_update_nic_incorrect_vm_state(self):
17291729

17301730
with self.assertRaises(Exception) as e:
17311731
self.apiclient.updateDefaultNicForVirtualMachine(cmd)
1732-
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
1732+
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
17331733
e.exception)
17341734

17351735
return
@@ -1779,7 +1779,7 @@ def test_28_update_nic_insufficient_permission(self):
17791779

17801780
with self.assertRaises(Exception) as e:
17811781
api_client.updateDefaultNicForVirtualMachine(cmd)
1782-
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
1782+
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
17831783
e.exception)
17841784

17851785
return

tools/marvin/marvin/sshClient.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
# under the License.
1717

1818
import paramiko
19+
from paramiko import (BadHostKeyException,
20+
AuthenticationException,
21+
SSHException,
22+
SSHClient,
23+
AutoAddPolicy,
24+
Transport,
25+
SFTPClient)
26+
import socket
1927
import time
2028
from cloudstackException import (
2129
internalError,
@@ -40,8 +48,8 @@ def __init__(self, host, port, user, passwd, retries=20, delay=30,
4048
self.user = user
4149
self.passwd = passwd
4250
self.keyPairFiles = keyPairFiles
43-
self.ssh = paramiko.SSHClient()
44-
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
51+
self.ssh = SSHClient()
52+
self.ssh.set_missing_host_key_policy(AutoAddPolicy())
4553
self.logger = logging.getLogger('sshClient')
4654
self.retryCnt = 0
4755
self.delay = 0
@@ -60,7 +68,7 @@ def __init__(self, host, port, user, passwd, retries=20, delay=30,
6068
self.delay = delay
6169
if timeout is not None and timeout > 0:
6270
self.timeout = timeout
63-
if port is not None or port >= 0:
71+
if port is not None and port >= 0:
6472
self.port = port
6573
if self.createConnection() == FAIL:
6674
raise internalError("Connection Failed")
@@ -91,6 +99,7 @@ def createConnection(self):
9199
FAIL If connection through ssh failed
92100
'''
93101
ret = FAIL
102+
except_msg = ''
94103
while self.retryCnt >= 0:
95104
try:
96105
self.logger.debug("SSH Connection: Host:%s User:%s\
@@ -114,7 +123,20 @@ def createConnection(self):
114123
)
115124
ret = SUCCESS
116125
break
117-
except Exception as se:
126+
except BadHostKeyException, e:
127+
except_msg = GetDetailExceptionInfo(e)
128+
except AuthenticationException, e:
129+
except_msg = GetDetailExceptionInfo(e)
130+
except SSHException, e:
131+
except_msg = GetDetailExceptionInfo(e)
132+
except socket.error, e:
133+
except_msg = GetDetailExceptionInfo(e)
134+
except Exception, e:
135+
except_msg = GetDetailExceptionInfo(e)
136+
finally:
137+
self.logger.exception("SshClient: "
138+
"Exception under createConnection: %s"
139+
% except_msg)
118140
self.retryCnt = self.retryCnt - 1
119141
if self.retryCnt == 0:
120142
break
@@ -156,15 +178,17 @@ def runCommand(self, command):
156178
except Exception as e:
157179
ret["status"] = EXCEPTION_OCCURRED
158180
ret["stderr"] = GetDetailExceptionInfo(e)
181+
self.logger.exception("SshClient: Exception under runCommand :%s" %
182+
GetDetailExceptionInfo(e))
159183
finally:
160-
self.logger.debug(" Host: %s Cmd: %s Output:%s Exception: %s" %
161-
(self.host, command, str(ret), ret["stderr"]))
184+
self.logger.debug(" Host: %s Cmd: %s Output:%s" %
185+
(self.host, command, str(ret)))
162186
return ret
163187

164188
def scp(self, srcFile, destPath):
165-
transport = paramiko.Transport((self.host, int(self.port)))
189+
transport = Transport((self.host, int(self.port)))
166190
transport.connect(username=self.user, password=self.passwd)
167-
sftp = paramiko.SFTPClient.from_transport(transport)
191+
sftp = SFTPClient.from_transport(transport)
168192
try:
169193
sftp.put(srcFile, destPath)
170194
except IOError, e:

0 commit comments

Comments
 (0)