mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-8720: Handle corner case in remove nic from vm Please see the bug for more details
Incorporating comments from pavanb018 This closes #671
This commit is contained in:
parent
8b0266d12e
commit
b1fa378612
@ -37,7 +37,10 @@ from marvin.lib.base import (
|
||||
NetworkOffering,
|
||||
Network,
|
||||
VpcOffering,
|
||||
VPC
|
||||
VPC,
|
||||
PublicIPAddress,
|
||||
FireWallRule,
|
||||
NATRule
|
||||
)
|
||||
from marvin.lib.common import (get_domain,
|
||||
get_zone,
|
||||
@ -46,7 +49,8 @@ from marvin.lib.common import (get_domain,
|
||||
list_events,
|
||||
list_zones,
|
||||
get_free_vlan,
|
||||
update_resource_limit
|
||||
update_resource_limit,
|
||||
list_nat_rules
|
||||
)
|
||||
|
||||
from marvin.lib.utils import (validateList,
|
||||
@ -167,6 +171,11 @@ class Services:
|
||||
"displaytext": "TestVPC add remove network",
|
||||
"cidr": '10.0.0.1/24'
|
||||
},
|
||||
"natrule": {
|
||||
"privateport": 22,
|
||||
"publicport": 22,
|
||||
"protocol": "TCP"
|
||||
},
|
||||
}
|
||||
|
||||
@ddt
|
||||
@ -811,7 +820,7 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
|
||||
self.assertTrue(len(self.nics) == 1, "nics list should contain the nic of added isolated network,\
|
||||
the number of nics for the network should be 1, instead they are %s" %
|
||||
len(self.nics))
|
||||
return
|
||||
return self.nics
|
||||
|
||||
@attr(tags = ["advanced", "dvs"])
|
||||
def test_07_remove_nic_running_vm(self):
|
||||
@ -909,6 +918,109 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
|
||||
self.debug("Operation failed with exception: %s" % e.exception)
|
||||
return
|
||||
|
||||
@attr(tags = ["advanced"], required_hardware="true")
|
||||
def test_29_remove_nic_CS22503(self):
|
||||
"""Test to verify remove nic from vm if the nic ip is same as another vm ip in another network"""
|
||||
|
||||
# 1. Deploy vm v1 with networks n1 and n2
|
||||
# 2. Check the ip address of nic in n2 say ip1
|
||||
# 3. Deployed vm v2 in another network say n3 with same IP address as ip1 using
|
||||
# 'deployVirtualMachine' api with 'ipaddress' as one of the parameters.
|
||||
# 4. Acquire public IP in n3 network.
|
||||
# 5. Configure PF on the acquired IP and assign it to vm v2
|
||||
# 6. Try to remove nic n2 from v1. Should be successfull
|
||||
# There was a bug due to both vms has same ip address, so not allowing to remove nic
|
||||
|
||||
vm1 = self.virtual_machine
|
||||
nic2 = self.addNetworkToVm(self.isolated_network, vm1)
|
||||
#get the ip address of the nic added in 2nd network
|
||||
vm1_ip = nic2[0].ipaddress
|
||||
self.assertIsNotNone(vm1_ip, "New nic did not get the ip address")
|
||||
#Create network n3
|
||||
self.network3 = Network.create(
|
||||
self.api_client,
|
||||
self.services["isolated_network"],
|
||||
self.account.name,
|
||||
self.account.domainid,
|
||||
networkofferingid=self.isolated_network_offering.id
|
||||
)
|
||||
self.cleanup.append(self.network3)
|
||||
self.vm2 = VirtualMachine.create(
|
||||
self.api_client,
|
||||
self.services["virtual_machine"],
|
||||
accountid=self.account.name,
|
||||
domainid=self.account.domainid,
|
||||
serviceofferingid=self.service_offering.id,
|
||||
networkids=[self.network3.id],
|
||||
ipaddress=vm1_ip,
|
||||
mode=self.zone.networktype
|
||||
)
|
||||
self.cleanup.append(self.vm2)
|
||||
vm2 = VirtualMachine.list(
|
||||
self.api_client,
|
||||
id=self.vm2.id
|
||||
)
|
||||
self.assertEqual(validateList(vm2)[0], PASS, "list vms returned invalid response")
|
||||
self.assertIsNotNone(vm2[0].nic[0].ipaddress, "vm2 didn't get the ip address")
|
||||
self.assertEqual(
|
||||
vm1_ip,
|
||||
vm2[0].nic[0].ipaddress,
|
||||
"vm2 did not get the ip address passed while deploying vm"
|
||||
)
|
||||
ip_address = PublicIPAddress.create(
|
||||
self.apiclient,
|
||||
self.account.name,
|
||||
self.zone.id,
|
||||
self.account.domainid,
|
||||
self.services["virtual_machine"],
|
||||
self.network3.id
|
||||
)
|
||||
self.cleanup.append(ip_address)
|
||||
self.cleanup = self.cleanup[::-1]
|
||||
# Open up firewall port for SSH
|
||||
FireWallRule.create(
|
||||
self.apiclient,
|
||||
ipaddressid=ip_address.ipaddress.id,
|
||||
protocol=self.services["natrule"]["protocol"],
|
||||
cidrlist=['0.0.0.0/0'],
|
||||
startport=self.services["natrule"]["publicport"],
|
||||
endport=self.services["natrule"]["publicport"]
|
||||
)
|
||||
# Create NAT rule
|
||||
nat_rule = NATRule.create(
|
||||
self.apiclient,
|
||||
self.vm2,
|
||||
self.services["natrule"],
|
||||
ip_address.ipaddress.id
|
||||
)
|
||||
list_nat_rule_response = list_nat_rules(
|
||||
self.apiclient,
|
||||
id=nat_rule.id
|
||||
)
|
||||
self.assertEqual(
|
||||
validateList(list_nat_rule_response)[0],
|
||||
PASS,
|
||||
"Check list response returns a valid list"
|
||||
)
|
||||
self.assertEqual(
|
||||
list_nat_rule_response[0].id,
|
||||
nat_rule.id,
|
||||
"Check Correct Port forwarding Rule is returned"
|
||||
)
|
||||
#Try to remove nic 2 from vm1
|
||||
try:
|
||||
vm1.remove_nic(self.apiclient, self.nics[0].id)
|
||||
vm1_res = VirtualMachine.list(self.apiclient, id=vm1.id)
|
||||
self.assertEqual(validateList(vm1_res)[0], PASS, "invalid listvm response")
|
||||
self.assertEqual(
|
||||
len(vm1_res[0].nic),
|
||||
1,
|
||||
"VM has more than one nic even after removing the 2nd nic"
|
||||
)
|
||||
except Exception as e:
|
||||
self.fail("Failed to delete the nic from vm")
|
||||
return
|
||||
|
||||
class TestUpdateVirtualMachineNIC(cloudstackTestCase):
|
||||
|
||||
@classmethod
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user