Fix config drive test for Shared Network

This commit is contained in:
Frank Maximus 2018-07-13 14:21:51 +02:00
parent b0490c5195
commit 41fcf43057
3 changed files with 110 additions and 163 deletions

View File

@ -309,6 +309,9 @@ class ConfigDriveUtils:
def validate_network_networking(self, network, vpc): def validate_network_networking(self, network, vpc):
pass pass
def validate_shared_networking(self, network, vm):
pass
def validate_StaticNat_rule_For_VM(self, public_ip, network, vm): def validate_StaticNat_rule_For_VM(self, public_ip, network, vm):
self.validate_PublicIPAddress( self.validate_PublicIPAddress(
public_ip, network, static_nat=True, vm=vm) public_ip, network, static_nat=True, vm=vm)
@ -699,7 +702,10 @@ class ConfigDriveUtils:
for network in network_list: for network in network_list:
self.validate_Network(network, state="Implemented") self.validate_Network(network, state="Implemented")
self.validate_network_networking(network, self.vpc) if network.type == "Shared":
self.validate_shared_networking(network, self.vpc)
else:
self.validate_network_networking(network, self.vpc)
if self.vpc_acl_rule is not None: if self.vpc_acl_rule is not None:
self.validate_acl_rule(self.vpc_acl_rule) self.validate_acl_rule(self.vpc_acl_rule)
@ -907,6 +913,10 @@ class ConfigDriveUtils:
vm = VirtualMachine.list(self.api_client, id=vm.id)[0] vm = VirtualMachine.list(self.api_client, id=vm.id)[0]
return next(nic for nic in vm.nic if nic.networkid == network.id) return next(nic for nic in vm.nic if nic.networkid == network.id)
def get_public_shared_ip(self, vm, network):
nic = self._find_nic(vm, network)
return PublicIPAddress({"ipaddress": nic})
def plug_nic(self, vm, network): def plug_nic(self, vm, network):
vm.add_nic(self.api_client, network.id) vm.add_nic(self.api_client, network.id)
self.debug("Added NIC in VM with ID - %s and network with ID - %s" self.debug("Added NIC in VM with ID - %s and network with ID - %s"

View File

@ -1302,6 +1302,8 @@ class nuageTestCase(cloudstackTestCase):
) )
vm_info = VirtualMachine.list(self.api_client, id=vm.id)[0] vm_info = VirtualMachine.list(self.api_client, id=vm.id)[0]
for nic in vm_info.nic: for nic in vm_info.nic:
if nic.type == "Shared":
continue
vsd_subnet = self.vsd.get_subnet( vsd_subnet = self.vsd.get_subnet(
filter=self.get_externalID_filter(nic.networkid)) filter=self.get_externalID_filter(nic.networkid))
vsd_vport = self.vsd.get_vport( vsd_vport = self.vsd.get_vport(

View File

@ -205,6 +205,15 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
def validate_network_networking(self, network, vpc): def validate_network_networking(self, network, vpc):
self.verify_vsd_network(self.domain.id, network, vpc=vpc) self.verify_vsd_network(self.domain.id, network, vpc=vpc)
def validate_shared_networking(self, network, vm):
# Verify shared Network and VM in VSD
subnet_id = self.get_subnet_id(network.id, network.gateway)
self.verify_vsd_shared_network(self.domain.id, network,
gateway=network.gateway)
self.verify_vsd_enterprise_vm(self.domain.id, network, vm,
sharedsubnetid=subnet_id)
def _get_test_data(self, key): def _get_test_data(self, key):
return self.test_data["nuagevsp"][key] return self.test_data["nuagevsp"][key]
@ -987,7 +996,9 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
'Network found success = %s, expected success = %s' 'Network found success = %s, expected success = %s'
% (str(shared_network.success), 'True')) % (str(shared_network.success), 'True'))
self.validate_Network(shared_network.network, state="Allocated") shared_nw_1 = shared_network.network
self.validate_Network(shared_nw_1, state="Allocated")
shared_test_data2 = self.test_data["nuagevsp"]["network_all2"] shared_test_data2 = self.test_data["nuagevsp"]["network_all2"]
shared_network2 = self.verify_network_creation( shared_network2 = self.verify_network_creation(
@ -997,7 +1008,10 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
'Network found success = %s, expected success = %s' 'Network found success = %s, expected success = %s'
% (str(shared_network2.success), 'True')) % (str(shared_network2.success), 'True'))
self.validate_Network(shared_network2.network, state="Allocated") shared_nw_1 = shared_network.network
shared_nw_2 = shared_network2.network
shared_nw_ids = [shared_nw_1.id, shared_nw_2.id]
self.validate_Network(shared_nw_2, state="Allocated")
self.debug("+++Test user data & password reset functionality " self.debug("+++Test user data & password reset functionality "
"using configdrive in an Isolated network without VR") "using configdrive in an Isolated network without VR")
@ -1005,13 +1019,9 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
self.given_template_password_enabled_is(True) self.given_template_password_enabled_is(True)
public_ip_ranges = PublicIpRange.list(self.api_client) public_ip_ranges = PublicIpRange.list(self.api_client)
for ip_range in public_ip_ranges: for ip_range in public_ip_ranges:
if shared_network.network.id == ip_range.networkid \ if ip_range.networkid in shared_nw_ids:
or shared_network2.network.id == ip_range.networkid:
self.enable_NuageUnderlayPublicIpRange(ip_range.id) self.enable_NuageUnderlayPublicIpRange(ip_range.id)
self.generate_ssh_keys()
self.debug("keypair name %s " % self.keypair.name)
self.debug("+++Deploy of a VM on a shared network with multiple " self.debug("+++Deploy of a VM on a shared network with multiple "
"ip ranges, all should have the same value for the " "ip ranges, all should have the same value for the "
"underlay flag.") "underlay flag.")
@ -1019,7 +1029,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
self.debug("+++ Adding subnet of different gateway") self.debug("+++ Adding subnet of different gateway")
subnet = self.add_subnet_to_shared_network_and_verify( subnet = self.add_subnet_to_shared_network_and_verify(
shared_network.network, shared_nw_1,
self.test_data["nuagevsp"]["publiciprange2"]) self.test_data["nuagevsp"]["publiciprange2"])
tmp_test_data = copy.deepcopy( tmp_test_data = copy.deepcopy(
self.test_data["virtual_machine"]) self.test_data["virtual_machine"])
@ -1028,213 +1038,138 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
self.test_data["nuagevsp"]["network_all"]["endip"] self.test_data["nuagevsp"]["network_all"]["endip"]
with self.assertRaises(Exception): with self.assertRaises(Exception):
self.create_VM( self.create_VM([shared_nw_1], testdata=tmp_test_data)
[shared_network.network],
testdata=tmp_test_data)
self.debug("+++ In a shared network with multiple ip ranges, " self.debug("+++ In a shared network with multiple ip ranges, "
"userdata with config drive must be allowed.") "userdata with config drive must be allowed.")
self.enable_NuageUnderlayPublicIpRange(subnet.vlan.id) self.enable_NuageUnderlayPublicIpRange(subnet.vlan.id)
vm1 = self.create_VM( vm1 = self.when_I_deploy_a_vm_with_keypair_in([shared_nw_1])
[shared_network.network],
testdata=self.test_data["virtual_machine_userdata"],
keypair=self.keypair.name)
# Check VM
self.check_VM_state(vm1, state="Running")
# Verify shared Network and VM in VSD
self.verify_vsd_shared_network(
self.domain.id,
shared_network.network,
gateway=self.test_data["nuagevsp"]["network_all"]["gateway"])
subnet_id = self.get_subnet_id(
shared_network.network.id,
self.test_data["nuagevsp"]["network_all"]["gateway"])
self.verify_vsd_enterprise_vm(
self.domain.id,
shared_network.network, vm1,
sharedsubnetid=subnet_id)
with self.assertRaises(Exception): self.then_vr_is_as_expected(shared_nw_1)
self.get_Router(shared_network)
self.debug("+++ Verified no VR is spawned for this network ") public_ip = self.get_public_shared_ip(vm1, shared_nw_1)
# We need to have the vm password self.then_config_drive_is_as_expected(vm1, public_ip, metadata=True)
self.when_I_reset_the_password(vm1)
self.debug("Password reset to - %s" % vm1.password) self.update_and_validate_userdata(vm1, "helloworld vm1", public_ip)
self.debug("VM - %s password - %s !" % self.then_config_drive_is_as_expected(vm1, public_ip)
(vm1.name, vm1.password))
public_ip = PublicIPAddress({"ipaddress": vm1}) # =====================================================================
self.then_config_drive_is_as_expected( # Test using network2 as default network
vm1, public_ip, # =====================================================================
metadata=True)
expected_user_data = self.update_and_validate_userdata(vm1,
"helloworldvm1",
public_ip)
self.then_config_drive_is_as_expected(
vm1, public_ip)
self.debug("+++ Adding a non-default nic to the VM " self.debug("+++ Adding a non-default nic to the VM "
"making it a multi-nic VM...") "making it a multi-nic VM...")
self.nic_operation_VM(vm1, shared_network2.network, self.plug_nic(vm1, shared_nw_2)
operation="add") self.then_config_drive_is_as_expected(vm1, public_ip, metadata=True)
self.then_config_drive_is_as_expected(vm1, public_ip,
metadata=True)
self.when_I_reset_the_password(vm1)
self.debug("Password reset to - %s" % vm1.password)
self.debug("VM - %s password - %s !" %
(vm1.name, vm1.password))
expected_user_data1 = self.update_and_validate_userdata(vm1, self.when_I_reset_the_password(vm1)
"himultinicvm", self.update_and_validate_userdata(vm1, "hellomultinicvm1", public_ip)
public_ip)
self.then_config_drive_is_as_expected(vm1, public_ip)
self.debug("+++ Updating non-default nic as the default nic " self.debug("+++ Updating non-default nic as the default nic "
"of the multi-nic VM...") "of the multi-nic VM...")
self.nic_operation_VM(vm1, self.update_default_nic(vm1, shared_nw_2)
shared_network2.network, operation="update") self.stop_and_start_vm(vm1)
vm1.stop(self.api_client)
vm1.start(self.api_client) public_ip_2 = self.get_public_shared_ip(vm1, shared_nw_2)
self.then_config_drive_is_as_expected(vm1, public_ip_2, metadata=True)
public_ip_2 = PublicIPAddress(
{"ipaddress": VirtualMachine.list(self.api_client,
id=vm1.id)[0].nic[1]})
self.then_config_drive_is_as_expected(vm1, public_ip_2,
metadata=True)
self.when_I_reset_the_password(vm1) self.when_I_reset_the_password(vm1)
self.debug("Password reset to - %s" % vm1.password)
self.debug("VM - %s password - %s !" %
(vm1.name, vm1.password))
self.then_config_drive_is_as_expected(vm1, public_ip_2)
expected_user_data1 = self.update_and_validate_userdata(vm1,
"himultinicvm",
public_ip)
self.then_config_drive_is_as_expected(vm1, public_ip_2) self.then_config_drive_is_as_expected(vm1, public_ip_2)
self.update_and_validate_userdata(vm1, "hellomultinicvm1again",
public_ip_2)
self.debug("+++ Updating the default nic of the multi-nic VM, " self.debug("+++ Updating the default nic of the multi-nic VM, "
"deleting the non-default nic...") "deleting the non-default nic...")
self.nic_operation_VM(vm1, self.update_default_nic(vm1, shared_nw_1)
shared_network.network, operation="update") self.stop_and_start_vm(vm1)
vm1.stop(self.api_client) self.then_config_drive_is_as_expected(vm1, public_ip, metadata=True)
vm1.start(self.api_client)
public_ip = PublicIPAddress({"ipaddress": vm1})
self.then_config_drive_is_as_expected(vm1, public_ip,
metadata=True)
self.nic_operation_VM(vm1, self.unplug_nic(vm1, shared_nw_2)
shared_network2.network, operation="remove")
multinicvm1 = self.create_VM([shared_network2.network, # =====================================================================
shared_network.network]) # Another Multinic VM
multinicvm1.password = multinicvm1.resetPassword(self.api_client) # =====================================================================
self.debug("+++ MultiNICVM Password reset to - %s"
% multinicvm1.password) multinicvm1 = self.when_I_deploy_a_vm([shared_nw_2, shared_nw_1])
self.debug("MultiNICVM - %s password - %s !" public_ip_3 = self.get_public_shared_ip(multinicvm1, shared_nw_2)
% (multinicvm1.name, multinicvm1.password))
public_ip_3 = \
PublicIPAddress(
{"ipaddress": VirtualMachine.list(
self.api_client, id=multinicvm1.id)[0].nic[0]})
self.then_config_drive_is_as_expected( self.then_config_drive_is_as_expected(
multinicvm1, public_ip_3, multinicvm1, public_ip_3,
metadata=True) metadata=True)
expected_user_data2 = self.update_and_validate_userdata( self.update_and_validate_userdata(multinicvm1, "hello multinicvm1",
multinicvm1, "hello multinicvm1", public_ip) public_ip)
self.then_config_drive_is_as_expected(multinicvm1, public_ip_3) self.then_config_drive_is_as_expected(multinicvm1, public_ip_3)
multinicvm1.delete(self.api_client, expunge=True) multinicvm1.delete(self.api_client, expunge=True)
shared_nw_2.delete(self.api_client)
shared_network2.network.delete(self.api_client) # =====================================================================
# We need to have the vm password
self.when_I_reset_the_password(vm1)
self.debug("Password reset to - %s" % vm1.password)
self.debug("VM - %s password - %s !" %
(vm1.name, vm1.password))
public_ip = PublicIPAddress({"ipaddress": vm1})
self.debug("+++ Verifying userdata after rebootVM - %s" % vm1.name) self.debug("+++ Scenario: "
"update userdata and reset password after reboot")
vm1.reboot(self.api_client) vm1.reboot(self.api_client)
self.then_config_drive_is_as_expected(vm1, public_ip, self.then_config_drive_is_as_expected(vm1, public_ip, metadata=True)
metadata=True) self.update_and_validate_userdata(vm1, "hello afterboot", public_ip)
self.debug("Updating userdata for VM - %s" % vm1.name)
expected_user_data1 = self.update_and_validate_userdata(vm1,
"hiafterboot",
public_ip)
self.then_config_drive_is_as_expected(vm1, public_ip)
self.debug("Resetting password for VM - %s" % vm1.name)
self.when_I_reset_the_password(vm1) self.when_I_reset_the_password(vm1)
self.debug("SSHing into the VM for verifying its new password "
"after its password reset...")
self.then_config_drive_is_as_expected(vm1, public_ip) self.then_config_drive_is_as_expected(vm1, public_ip)
self.debug("+++ Migrating one of the VMs in the created Isolated " # =====================================================================
"network to another host, if available...") self.debug("+++ Scenario: "
"update userdata and reset password after migrate")
self.migrate_VM(vm1) self.migrate_VM(vm1)
self.then_config_drive_is_as_expected(vm1, public_ip, self.then_config_drive_is_as_expected(vm1, public_ip, metadata=True)
metadata=True) self.update_and_validate_userdata(vm1, "hello after migrate",
public_ip)
self.debug("Updating userdata after migrating VM - %s" % vm1.name)
expected_user_data1 = self.update_and_validate_userdata(vm1,
"aftermigrate",
public_ip)
self.then_config_drive_is_as_expected(vm1, public_ip)
self.debug("Resetting password for VM - %s" % vm1.name)
self.when_I_reset_the_password(vm1) self.when_I_reset_the_password(vm1)
self.debug("SSHing into the VM for verifying its new password "
"after its password reset...")
self.then_config_drive_is_as_expected(vm1, public_ip) self.then_config_drive_is_as_expected(vm1, public_ip)
self.debug("+++ Verify userdata after stopstartVM - %s" % vm1.name) # =====================================================================
vm1.stop(self.api_client) self.debug("+++ Scenario: "
vm1.start(self.api_client) "update userdata and reset password after stop/start")
self.then_config_drive_is_as_expected(vm1, public_ip, self.stop_and_start_vm(vm1)
metadata=True) self.then_config_drive_is_as_expected(vm1, public_ip, metadata=True)
self.debug("Updating userdata for VM - %s" % vm1.name) self.update_and_validate_userdata(vm1, "hello afterstopstart",
expected_user_data1 = self.update_and_validate_userdata(vm1,
"stopstart",
public_ip) public_ip)
self.then_config_drive_is_as_expected(vm1, public_ip)
self.debug("Resetting password for VM - %s" % vm1.name)
self.when_I_reset_the_password(vm1) self.when_I_reset_the_password(vm1)
self.debug("SSHing into the VM for verifying its new password "
"after its password reset...")
self.then_config_drive_is_as_expected(vm1, public_ip) self.then_config_drive_is_as_expected(vm1, public_ip)
self.debug("+++ Verify userdata after VM recover- %s" % vm1.name) # =====================================================================
vm1.delete(self.api_client, expunge=False) self.debug("+++ Scenario: "
self.debug("Recover VM - %s" % vm1.name) "verify config drive after delete/recover")
vm1.recover(self.api_client) self.delete_and_recover_vm(vm1)
vm1.start(self.api_client)
self.then_config_drive_is_as_expected(vm1, public_ip, self.then_config_drive_is_as_expected(vm1, public_ip,
metadata=True) metadata=True)
# =====================================================================
self.debug("+++ Scenario: "
"Start VM fails when ConfigDrive provider is disabled")
self.given_config_drive_provider_is("Disabled") self.given_config_drive_provider_is("Disabled")
expected_user_data1 = self.update_and_validate_userdata(vm1, with self.assertRaises(Exception):
"afterrecover", self.when_I_update_userdata(vm1, "hi with provider state Disabled")
public_ip)
self.then_config_drive_is_as_expected(vm1, public_ip,
metadata=True)
self.debug("+++ When template is not password enabled, "
"verify configdrive of VM - %s" % vm1.name)
vm1.delete(self.api_client, expunge=True)
self.given_config_drive_provider_is("Enabled") self.given_config_drive_provider_is("Enabled")
self.delete(vm1, expunge=True)
# =====================================================================
self.debug("+++ Scenario: "
"Update Userdata on a VM that is not password enabled")
self.update_template(passwordenabled=False) self.update_template(passwordenabled=False)
self.generate_ssh_keys()
self.debug("keypair name %s " % self.keypair.name)
vm1 = self.create_VM( vm1 = self.create_VM(
[shared_network.network], [shared_nw_1],
testdata=self.test_data["virtual_machine_userdata"], testdata=self.test_data["virtual_machine_userdata"],
keypair=self.keypair.name) keypair=self.keypair.name)
expected_user_data1 = self.update_and_validate_userdata(vm1,
"sample data", self.update_and_validate_userdata(vm1, "This is sample data",
public_ip) public_ip)
public_ip = PublicIPAddress({"ipaddress": vm1}) public_ip = PublicIPAddress({"ipaddress": vm1})
self.then_config_drive_is_as_expected(vm1, public_ip, self.then_config_drive_is_as_expected(vm1, public_ip,
metadata=True) metadata=True)
vm1.delete(self.api_client, expunge=True)
shared_network.network.delete(self.api_client) self.delete(vm1, expunge=True)
self.delete(shared_nw_1)
@attr(tags=["advanced", "nuagevsp", "endurance"], required_hardware="true") @attr(tags=["advanced", "nuagevsp", "endurance"], required_hardware="true")
def test_nuage_configdrive_endurance(self): def test_nuage_configdrive_endurance(self):