http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c91c9c5/test/integration/plugins/nuagevsp/test_nuage_non_public_sharednetwork_ip_range.py ---------------------------------------------------------------------- diff --git a/test/integration/plugins/nuagevsp/test_nuage_non_public_sharednetwork_ip_range.py b/test/integration/plugins/nuagevsp/test_nuage_non_public_sharednetwork_ip_range.py new file mode 100644 index 0000000..a3d550a --- /dev/null +++ b/test/integration/plugins/nuagevsp/test_nuage_non_public_sharednetwork_ip_range.py @@ -0,0 +1,654 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +""" Component tests for Shared Network functionality with Nuage VSP SDN plugin: +Non Public Shared Network IP Range +""" +# Import Local Modules +from nuageTestCase import nuageTestCase +from marvin.lib.utils import cleanup_resources +from marvin.lib.base import Account, Domain, User, Network, NetworkOffering +from marvin.lib.common import list_virtual_machines +from marvin.cloudstackAPI import (createVlanIpRange, + listVlanIpRanges, + deleteVlanIpRange, + updateVmNicIp) +# Import System Modules +from nose.plugins.attrib import attr + + +class TestNuageSharedNetworkNonPublicIPRange(nuageTestCase): + """Test Shared Network functionality with Nuage VSP SDN plugin: + Non Public Shared Network IP Range + """ + + @classmethod + def setUpClass(cls): + """ + Create the following domain tree and accounts that are required for + executing Nuage VSP SDN plugin test cases for shared networks: + Under ROOT - create domain D1 + Under domain D1 - Create two subdomains D11 and D12 + Under each of the domains - create one admin user and couple of + regular users. + Create shared network with the following scope: + 1. Network with scope="all" + 2. Network with scope="domain" with no subdomain access + 3. Network with scope="domain" with subdomain access + 4. Network with scope="account" + """ + + super(TestNuageSharedNetworkNonPublicIPRange, cls).setUpClass() + cls.sharednetworkdata = cls.test_data["acl"] + cls.nuagenetworkdata = cls.test_data["nuagevsp"] + + cls.domain_1 = None + cls.domain_2 = None + + try: + # backup default apikey and secretkey + cls.default_apikey = cls.api_client.connection.apiKey + cls.default_secretkey = cls.api_client.connection.securityKey + + # Create domains + cls.domain_1 = Domain.create( + cls.api_client, + cls.sharednetworkdata["domain1"] + ) + cls.domain_11 = Domain.create( + cls.api_client, + cls.sharednetworkdata["domain11"], + parentdomainid=cls.domain_1.id + ) + cls.domain_12 = Domain.create( + cls.api_client, + cls.sharednetworkdata["domain12"], + parentdomainid=cls.domain_1.id + ) + # Create 1 admin account and 2 user accounts for domain_1 + cls.account_d1 = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD1"], + admin=True, + domainid=cls.domain_1.id + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_d1) + cls.user_d1_apikey = user.apikey + cls.user_d1_secretkey = user.secretkey + + cls.account_d1a = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD1A"], + admin=False, + domainid=cls.domain_1.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d1a) + cls.user_d1a_apikey = user.apikey + cls.user_d1a_secretkey = user.secretkey + + cls.account_d1b = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD1B"], + admin=False, + domainid=cls.domain_1.id + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_d1b) + cls.user_d1b_apikey = user.apikey + cls.user_d1b_secretkey = user.secretkey + + # Create 1 admin and 2 user accounts for doamin_11 + cls.account_d11 = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD11"], + admin=True, + domainid=cls.domain_11.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d11) + cls.user_d11_apikey = user.apikey + cls.user_d11_secretkey = user.secretkey + + cls.account_d11a = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD11A"], + admin=False, + domainid=cls.domain_11.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d11a) + cls.user_d11a_apikey = user.apikey + cls.user_d11a_secretkey = user.secretkey + + cls.account_d11b = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD11B"], + admin=False, + domainid=cls.domain_11.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d11b) + cls.user_d11b_apikey = user.apikey + cls.user_d11b_secretkey = user.secretkey + + # Create 2 user accounts for doamin_12 + cls.account_d12a = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD12A"], + admin=False, + domainid=cls.domain_12.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d12a) + cls.user_d12a_apikey = user.apikey + cls.user_d12a_secretkey = user.secretkey + + cls.account_d12b = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD12B"], + admin=False, + domainid=cls.domain_12.id + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_d12b) + cls.user_d12b_apikey = user.apikey + cls.user_d12b_secretkey = user.secretkey + + # Create 1 user account and admin account in "ROOT" domain + + cls.account_roota = Account.create( + cls.api_client, + cls.sharednetworkdata["accountROOTA"], + admin=False, + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_roota) + cls.user_roota_apikey = user.apikey + cls.user_roota_secretkey = user.secretkey + + cls.account_root = Account.create( + cls.api_client, + cls.sharednetworkdata["accountROOTA"], + admin=True, + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_root) + cls.user_root_apikey = user.apikey + cls.user_root_secretkey = user.secretkey + + # service offering is already created in Nuagetestcase + cls.sharednetworkdata['mode'] = cls.zone.networktype + + # As admin user, create shared network with scope "all", "domain" + # with subdomain access, "domain" without subdomain access and + # "account" + + cls.api_client.connection.apiKey = cls.default_apikey + cls.api_client.connection.securityKey = cls.default_secretkey + + cls.shared_network_offering = NetworkOffering.create( + cls.api_client, + cls.nuagenetworkdata["shared_nuage_network_offering"], + conservemode=False + ) + # Enable Network offering + cls.shared_network_offering.update(cls.api_client, state='Enabled') + cls.shared_network_offering_id = cls.shared_network_offering.id + + cls.shared_network_all = Network.create( + cls.api_client, + cls.nuagenetworkdata["network_all"], + networkofferingid=cls.shared_network_offering_id, + zoneid=cls.zone.id + ) + + cls.shared_network_domain_d11 = Network.create( + cls.api_client, + cls.nuagenetworkdata["network_all"], + networkofferingid=cls.shared_network_offering_id, + zoneid=cls.zone.id, + domainid=cls.domain_11.id, + subdomainaccess=False + ) + + cls.shared_network_domain_with_subdomain_d11 = Network.create( + cls.api_client, + cls.nuagenetworkdata["network_all"], + networkofferingid=cls.shared_network_offering_id, + zoneid=cls.zone.id, + domainid=cls.domain_11.id, + subdomainaccess=True + ) + + cls.shared_network_account_d111a = Network.create( + cls.api_client, + cls.nuagenetworkdata["network_all"], + networkofferingid=cls.shared_network_offering_id, + zoneid=cls.zone.id, + domainid=cls.domain_11.id, + accountid=cls.account_d11a.user[0].username + ) + + cls._cleanup = [ + cls.account_root, + cls.account_roota, + cls.shared_network_all, + cls.shared_network_offering, + cls.service_offering, + ] + except Exception as e: + cls.domain_1.delete(cls.api_client, cleanup="true") + cleanup_resources(cls.api_client, cls._cleanup) + raise Exception("Failed to create the setup required to execute " + "the test cases: %s" % e) + + return + + @classmethod + def tearDownClass(cls): + cls.api_client.connection.apiKey = cls.default_apikey + cls.api_client.connection.securityKey = cls.default_secretkey + cls.domain_1.delete(cls.api_client, cleanup="true") + cleanup_resources(cls.api_client, cls._cleanup) + return + + def setUp(self): + self.api_client = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + + def tearDown(self): + # restore back default apikey and secretkey + self.api_client.connection.apiKey = self.default_apikey + self.api_client.connection.securityKey = self.default_secretkey + return + + def add_subnet_verify(self, network, services): + """verify required nic is present in the VM""" + + self.debug("Going to add new ip range in shared network %s" % + network.name) + cmd = createVlanIpRange.createVlanIpRangeCmd() + cmd.networkid = network.id + cmd.gateway = services["gateway"] + cmd.netmask = services["netmask"] + cmd.startip = services["startip"] + cmd.endip = services["endip"] + cmd.forVirtualNetwork = services["forvirtualnetwork"] + addedsubnet = self.api_client.createVlanIpRange(cmd) + + self.debug("verify above iprange is successfully added in shared " + "network %s or not" % network.name) + + cmd1 = listVlanIpRanges.listVlanIpRangesCmd() + cmd1.networkid = network.id + cmd1.id = addedsubnet.vlan.id + + allsubnets = self.api_client.listVlanIpRanges(cmd1) + self.assertEqual( + allsubnets[0].id, + addedsubnet.vlan.id, + "Check New subnet is successfully added to the shared Network" + ) + return addedsubnet + + def delete_subnet_verify(self, network, subnet): + """verify required nic is present in the VM""" + + self.debug("Going to delete ip range in shared network %s" % + network.name) + cmd = deleteVlanIpRange.deleteVlanIpRangeCmd() + cmd.id = subnet.vlan.id + self.api_client.deleteVlanIpRange(cmd) + + self.debug("verify above iprange is successfully deleted from shared " + "network %s or not" % network.name) + + cmd1 = listVlanIpRanges.listVlanIpRangesCmd() + cmd1.networkid = network.id + cmd1.id = subnet.vlan.id + + try: + allsubnets = self.api_client.listVlanIpRanges(cmd1) + self.assertEqual( + allsubnets[0].id, + subnet.vlan.id, + "Check Subnet is not present to the shared Network" + ) + self.fail("iprange is not successfully deleted from shared " + "network %s" % network.name) + except Exception as e: + self.debug("iprange is not successfully deleted from shared " + "network %s" % network.name) + self.debug("exception msg is %s" % e) + + def shared_subnet_not_present(self, network, subnetid): + shared_resources = self.vsd.get_shared_network_resource( + filter=self.get_externalID_filter(subnetid)) + try: + self.assertEqual(shared_resources.description, network.name, + "VSD shared resources description should match " + "network name in CloudStack" + ) + self.fail("still shared resource are present on VSD") + except Exception as e: + self.debug("sharedNetwork resources is successfully deleted from " + "VSD") + self.debug("exception msg is %s" % e) + + # Test cases relating to add/delete Shared Network IP ranges + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_01_add_delete_Subnet_in_sharednetwork_scope_all(self): + """Validate that subnet of same and different public gateway can be + added to shared network with scope=all + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope as all") + subnet1 = self.add_subnet_verify( + self.shared_network_all, self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_all, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_1, + sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network scope " + "as all") + subnet2 = self.add_subnet_verify( + self.shared_network_all, self.nuagenetworkdata["publiciprange2"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange2"]["startip"] + vm_2 = self.create_VM( + self.shared_network_all, account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_2, + sharedsubnetid=subnet_id) + # put ping here + self.delete_VM(vm_1) + self.delete_VM(vm_2) + self.delete_subnet_verify(self.shared_network_all, subnet1) + self.delete_subnet_verify(self.shared_network_all, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_02_add_delete_Subnet_in_sharednetwork_scope_domain(self): + """Validate subnet of same and different gateway can be added to public + shared network scope=domain with subdomain access + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope domain " + "with subdomain access") + subnet1 = self.add_subnet_verify( + self.shared_network_domain_with_subdomain_d11, + self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_domain_with_subdomain_d11, + account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_domain_with_subdomain_d11.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, vm_1, + sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network") + subnet2 = self.add_subnet_verify( + self.shared_network_domain_with_subdomain_d11, + self.nuagenetworkdata["publiciprange2"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange2"]["startip"] + vm_2 = self.create_VM( + self.shared_network_domain_with_subdomain_d11, + account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_domain_with_subdomain_d11.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, vm_2, + sharedsubnetid=subnet_id) + # put ping here + self.delete_VM(vm_1) + self.delete_VM(vm_2) + self.delete_subnet_verify( + self.shared_network_domain_with_subdomain_d11, subnet1) + self.delete_subnet_verify( + self.shared_network_domain_with_subdomain_d11, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_03_add_delete_Subnet_in_sharednetwork_scope_nosubdomain(self): + """Validate subnet of same and different gateway can added to public + shared network scope=domain without subdomain access + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope domain " + "without subdomain access") + subnet1 = self.add_subnet_verify( + self.shared_network_domain_d11, + self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_domain_d11, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_domain_d11, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_domain_d11.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_domain_d11, vm_1, + sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network") + subnet2 = self.add_subnet_verify( + self.shared_network_domain_d11, + self.nuagenetworkdata["publiciprange2"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange2"]["startip"] + vm_2 = self.create_VM( + self.shared_network_domain_d11, account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_domain_d11, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_domain_d11.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_domain_d11, vm_2, + sharedsubnetid=subnet_id) + # put ping here + self.delete_VM(vm_1) + self.delete_VM(vm_2) + self.delete_subnet_verify(self.shared_network_domain_d11, subnet1) + self.delete_subnet_verify(self.shared_network_domain_d11, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_04_add_delete_Subnet_in_sharednetwork_scope_account(self): + """Validate subnet of same and different gateway can be added to shared + network scope=Account + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope as " + "Account") + subnet1 = self.add_subnet_verify( + self.shared_network_account_d111a, + self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_account_d111a, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_account_d111a, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_account_d111a.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_account_d111a, + vm_1, sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network") + subnet2 = self.add_subnet_verify( + self.shared_network_account_d111a, + self.nuagenetworkdata["publiciprange2"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange2"]["startip"] + vm_2 = self.create_VM( + self.shared_network_account_d111a, account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_account_d111a, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_account_d111a.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_account_d111a, + vm_2, sharedsubnetid=subnet_id) + # put ping here + self.delete_VM(vm_1) + self.delete_VM(vm_2) + self.delete_subnet_verify(self.shared_network_account_d111a, subnet1) + self.delete_subnet_verify(self.shared_network_account_d111a, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_05_change_ip_from_different_Subnet_in_sharednetwork(self): + """Validate that ip of a vm can be changed to a different subnet ip for + shared_network_scope_all + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope as all") + subnet1 = self.add_subnet_verify( + self.shared_network_all, self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_all, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_1, + sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network scope " + "as all") + subnet2 = self.add_subnet_verify( + self.shared_network_all, self.nuagenetworkdata["publiciprange2"]) + + # stop VM to update the ipaddress + try: + vm_1.stop(self.api_client) + except Exception as e: + self.fail("Failed to stop the virtual instances, %s" % e) + vm_list = list_virtual_machines(self.api_client, id=vm_1.id) + nics = [x for x in vm_list[0].nic + if x.networkid == self.shared_network_all.id] + self.debug("Filtered nics list: %s:" % nics) + + cmd = updateVmNicIp.updateVmNicIpCmd() + for x in vm_list[0].nic: + cmd.nicid = x.id + cmd.ipaddress = self.nuagenetworkdata["publiciprange2"]["startip"] + self.api_client.updateVmNicIp(cmd) + + try: + vm_1.start(self.api_client) + except Exception as e: + self.fail("Failed to start the virtual instances, %s" % e) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_1, + sharedsubnetid=subnet_id) + + self.delete_VM(vm_1) + self.delete_subnet_verify(self.shared_network_all, subnet1) + self.delete_subnet_verify(self.shared_network_all, subnet2) + + @staticmethod + def generateKeysForUser(api_client, account): + user = User.list( + api_client, + account=account.name, + domainid=account.domainid)[0] + return (User.registerUserKeys( + api_client, + user.id))
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c91c9c5/test/integration/plugins/nuagevsp/test_nuage_password_reset.py ---------------------------------------------------------------------- diff --git a/test/integration/plugins/nuagevsp/test_nuage_password_reset.py b/test/integration/plugins/nuagevsp/test_nuage_password_reset.py index 1ab6d57..7973a3e 100644 --- a/test/integration/plugins/nuagevsp/test_nuage_password_reset.py +++ b/test/integration/plugins/nuagevsp/test_nuage_password_reset.py @@ -199,138 +199,148 @@ class TestNuagePasswordReset(nuageTestCase): # template. # 13. Delete all the created objects (cleanup). - self.debug("Testing user data & password reset functionality in an " - "Isolated network...") - - self.debug("Creating an Isolated network...") - net_off = self.create_NetworkOffering( - self.test_data["nuagevsp"]["isolated_network_offering"]) - self.network = self.create_Network(net_off) - self.validate_Network(self.network, state="Allocated") - - self.debug("Setting password enabled to false in the guest VM " - "template...") - self.defaultTemplateVal = self.template.passwordenabled - if self.template.passwordenabled: - self.updateTemplate(False) - - self.debug("Deploying a VM in the created Isolated network with user " - "data...") - expected_user_data = "hello world vm1" - user_data = base64.b64encode(expected_user_data) - self.test_data["virtual_machine_userdata"]["userdata"] = user_data - self.vm_1 = self.create_VM( - self.network, testdata=self.test_data["virtual_machine_userdata"]) - self.validate_Network(self.network, state="Implemented") - vr = self.get_Router(self.network) - self.check_Router_state(vr, state="Running") - self.check_VM_state(self.vm_1, state="Running") - - # VSD verification - self.verify_vsd_network(self.domain.id, self.network) - self.verify_vsd_router(vr) - self.verify_vsd_vm(self.vm_1) - - self.debug("verifying that the guest VM template is not password " - "enabled...") - self.debug("VM - %s password - %s !" % - (self.vm_1.name, self.vm_1.password)) - self.assertEqual( - self.vm_1.password, - self.test_data["virtual_machine_userdata"]["password"], - "Password is enabled for the VM (vm_1)" - ) - - self.debug("SSHing into the VM for verifying its user data...") - public_ip_1 = self.acquire_PublicIPAddress(self.network) - self.create_and_verify_fw(self.vm_1, public_ip_1, self.network) - ssh = self.ssh_into_VM(self.vm_1, public_ip_1) - user_data_cmd = self.get_userdata_url(self.vm_1) - self.debug("Getting user data with command: " + user_data_cmd) - actual_user_data = base64.b64decode(self.execute_cmd - (ssh, user_data_cmd)) - self.debug("Actual user data - " + actual_user_data + - ", Expected user data - " + expected_user_data) - self.assertEqual(actual_user_data, expected_user_data, - "Un-expected VM (VM_1) user data" - ) - - self.debug("Checking for cloud-set-guest-password script in the VM " - "for testing password reset functionality...") - ls_cmd = "ls /etc/init.d/cloud-set-guest-password" - ls_result = self.execute_cmd(ssh, ls_cmd) - ls_result = ls_result.lower() - self.debug("Response from ls_cmd: " + ls_result) - if "no such file" in ls_result: - self.debug("No cloud-set-guest-password script in the VM") - self.debug("Installing the cloud-set-guest-password script from " - "people.apache.org in the VM...") - self.install_cloud_set_guest_password_script(ssh) - self.debug("Stopping the VM, and creating a new password enabled " - "guest VM template with it...") - self.stop_vm(self.vm_1) - self.create_template(self.vm_1) - - self.debug("Deploying a new VM in the created Isolated network " - "with the newly created guest VM template...") - self.vm_2 = self.create_VM( + for zone in self.zones: + self.debug("Zone - %s" % zone.name) + # Get Zone details + self.getZoneDetails(zone=zone) + # Configure VSD sessions + self.configureVSDSessions() + + self.debug("Testing user data & password reset functionality in " + "an Isolated network...") + + self.debug("Creating an Isolated network...") + net_off = self.create_NetworkOffering( + self.test_data["nuagevsp"]["isolated_network_offering"]) + self.network = self.create_Network(net_off) + self.validate_Network(self.network, state="Allocated") + + self.debug("Setting password enabled to false in the guest VM " + "template...") + self.defaultTemplateVal = self.template.passwordenabled + if self.template.passwordenabled: + self.updateTemplate(False) + + self.debug("Deploying a VM in the created Isolated network with " + "user data...") + expected_user_data = "hello world vm1" + user_data = base64.b64encode(expected_user_data) + self.test_data["virtual_machine_userdata"]["userdata"] = user_data + self.vm_1 = self.create_VM( self.network, testdata=self.test_data["virtual_machine_userdata"]) - self.debug("Starting the VM...") - vm_2a = self.vm_2.start(self.api_client) - self.vm_2.password = vm_2a.password.strip() - self.vm_2.nic = vm_2a.nic + self.validate_Network(self.network, state="Implemented") + vr = self.get_Router(self.network) + self.check_Router_state(vr, state="Running") + self.check_VM_state(self.vm_1, state="Running") # VSD verification - self.verify_vsd_vm(self.vm_2) + self.verify_vsd_network(self.domain.id, self.network) + self.verify_vsd_router(vr) + self.verify_vsd_vm(self.vm_1) + + self.debug("verifying that the guest VM template is not password " + "enabled...") + self.debug("VM - %s password - %s !" % + (self.vm_1.name, self.vm_1.password)) + self.assertEqual( + self.vm_1.password, + self.test_data["virtual_machine_userdata"]["password"], + "Password is enabled for the VM (vm_1)" + ) + + self.debug("SSHing into the VM for verifying its user data...") + public_ip_1 = self.acquire_PublicIPAddress(self.network) + self.create_and_verify_fw(self.vm_1, public_ip_1, self.network) + ssh = self.ssh_into_VM(self.vm_1, public_ip_1) + user_data_cmd = self.get_userdata_url(self.vm_1) + self.debug("Getting user data with command: " + user_data_cmd) + actual_user_data = base64.b64decode(self.execute_cmd + (ssh, user_data_cmd)) + self.debug("Actual user data - " + actual_user_data + + ", Expected user data - " + expected_user_data) + self.assertEqual(actual_user_data, expected_user_data, + "Un-expected VM (VM_1) user data" + ) + + self.debug("Checking for cloud-set-guest-password script in the " + "VM for testing password reset functionality...") + ls_cmd = "ls /etc/init.d/cloud-set-guest-password" + ls_result = self.execute_cmd(ssh, ls_cmd) + ls_result = ls_result.lower() + self.debug("Response from ls_cmd: " + ls_result) + if "no such file" in ls_result: + self.debug("No cloud-set-guest-password script in the VM") + self.debug("Installing the cloud-set-guest-password script " + "from people.apache.org in the VM...") + self.install_cloud_set_guest_password_script(ssh) + self.debug("Stopping the VM, and creating a new password " + "enabled guest VM template with it...") + self.stop_vm(self.vm_1) + self.create_template(self.vm_1) + + self.debug("Deploying a new VM in the created Isolated " + "network with the newly created guest VM " + "template...") + self.vm_2 = self.create_VM( + self.network, + testdata=self.test_data["virtual_machine_userdata"]) + self.debug("Starting the VM...") + vm_2a = self.vm_2.start(self.api_client) + self.vm_2.password = vm_2a.password.strip() + self.vm_2.nic = vm_2a.nic + + # VSD verification + self.verify_vsd_vm(self.vm_2) + + self.debug("verifying that the guest VM template is password " + "enabled...") + self.debug("VM - %s password - %s !" % + (self.vm_2.name, self.vm_2.password)) + self.assertNotEqual( + self.vm_2.password, + self.test_data["virtual_machine_userdata"]["password"], + "Password is not enabled for the VM" + ) + + self.debug("SSHing into the VM for verifying its password...") + public_ip_2 = self.acquire_PublicIPAddress(self.network) + self.create_and_verify_fw(self.vm_2, public_ip_2, self.network) + self.ssh_into_VM(self.vm_2, public_ip_2) + + vm_test = self.vm_2 + vm_test_public_ip = public_ip_2 + else: + self.debug("Updating the guest VM template to password " + "enabled") + self.updateTemplate(True) + self.assertEqual(self.template.passwordenabled, True, + "Guest VM template is not password enabled" + ) + vm_test = self.vm_1 + vm_test_public_ip = public_ip_1 + + self.debug("Resetting password for VM - %s" % vm_test.name) + vm_test.password = vm_test.resetPassword(self.api_client) + self.debug("Password reset to - %s" % vm_test.password) + + self.debug("Starting the VM") + vm_test.start(self.api_client) self.debug("verifying that the guest VM template is password " "enabled...") self.debug("VM - %s password - %s !" % - (self.vm_2.name, self.vm_2.password)) + (vm_test.name, vm_test.password)) self.assertNotEqual( - self.vm_2.password, + vm_test.password, self.test_data["virtual_machine_userdata"]["password"], "Password is not enabled for the VM" ) - self.debug("SSHing into the VM for verifying its password...") - public_ip_2 = self.acquire_PublicIPAddress(self.network) - self.create_and_verify_fw(self.vm_2, public_ip_2, self.network) - self.ssh_into_VM(self.vm_2, public_ip_2) - - vm_test = self.vm_2 - vm_test_public_ip = public_ip_2 - else: - self.debug("Updating the guest VM template to password enabled") - self.updateTemplate(True) - self.assertEqual(self.template.passwordenabled, True, - "Guest VM template is not password enabled" - ) - vm_test = self.vm_1 - vm_test_public_ip = public_ip_1 - - self.debug("Resetting password for VM - %s" % vm_test.name) - vm_test.password = vm_test.resetPassword(self.api_client) - self.debug("Password reset to - %s" % vm_test.password) - - self.debug("Starting the VM") - vm_test.start(self.api_client) - - self.debug("verifying that the guest VM template is password " - "enabled...") - self.debug("VM - %s password - %s !" % - (vm_test.name, vm_test.password)) - self.assertNotEqual( - vm_test.password, - self.test_data["virtual_machine_userdata"]["password"], - "Password is not enabled for the VM" - ) - - self.debug("SSHing into the VM for verifying its new password after " - "its password reset...") - self.ssh_into_VM(vm_test, vm_test_public_ip) + self.debug("SSHing into the VM for verifying its new password " + "after its password reset...") + self.ssh_into_VM(vm_test, vm_test_public_ip) - self.debug("Setting password enabled to the default value in the " - "guest VM template...") - self.updateTemplate(self.defaultTemplateVal) + self.debug("Setting password enabled to the default value in the " + "guest VM template...") + self.updateTemplate(self.defaultTemplateVal) http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c91c9c5/test/integration/plugins/nuagevsp/test_nuage_public_sharednetwork_ip_range.py ---------------------------------------------------------------------- diff --git a/test/integration/plugins/nuagevsp/test_nuage_public_sharednetwork_ip_range.py b/test/integration/plugins/nuagevsp/test_nuage_public_sharednetwork_ip_range.py new file mode 100644 index 0000000..b0a5ae9 --- /dev/null +++ b/test/integration/plugins/nuagevsp/test_nuage_public_sharednetwork_ip_range.py @@ -0,0 +1,823 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +""" Component tests for Shared Network functionality with Nuage VSP SDN plugin: +Public Shared Network IP Range +""" +# Import Local Modules +from nuageTestCase import nuageTestCase +from marvin.lib.utils import cleanup_resources, validateList +from marvin.lib.base import (Account, + Domain, + User, + VirtualMachine, + Network, + NetworkOffering) +from marvin.lib.common import list_virtual_machines +from marvin.cloudstackAPI import (createVlanIpRange, + listVlanIpRanges, + deleteVlanIpRange, + updateVmNicIp) +from marvin.codes import PASS +# Import System Modules +from nose.plugins.attrib import attr + + +class TestNuageSharedNetworkPublicIPRange(nuageTestCase): + """Test Shared Network functionality with Nuage VSP SDN plugin: + Public Shared Network IP Range + """ + + @classmethod + def setUpClass(cls): + """ + Create the following domain tree and accounts that are required for + executing Nuage VSP SDN plugin test cases for shared networks: + Under ROOT - create domain D1 + Under domain D1 - Create two subdomains D11 and D12 + Under each of the domains - create one admin user and couple of + regular users. + Create shared network with the following scope: + 1. Network with scope="all" + 2. Network with scope="domain" with no subdomain access + 3. Network with scope="domain" with subdomain access + 4. Network with scope="account" + """ + + super(TestNuageSharedNetworkPublicIPRange, cls).setUpClass() + cls.sharednetworkdata = cls.test_data["acl"] + cls.nuagenetworkdata = cls.test_data["nuagevsp"] + + cls.domain_1 = None + cls.domain_2 = None + + try: + # backup default apikey and secretkey + cls.default_apikey = cls.api_client.connection.apiKey + cls.default_secretkey = cls.api_client.connection.securityKey + + # Create domains + cls.domain_1 = Domain.create( + cls.api_client, + cls.sharednetworkdata["domain1"] + ) + cls.domain_11 = Domain.create( + cls.api_client, + cls.sharednetworkdata["domain11"], + parentdomainid=cls.domain_1.id + ) + cls.domain_12 = Domain.create( + cls.api_client, + cls.sharednetworkdata["domain12"], + parentdomainid=cls.domain_1.id + ) + # Create 1 admin account and 2 user accounts for doamin_1 + cls.account_d1 = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD1"], + admin=True, + domainid=cls.domain_1.id + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_d1) + cls.user_d1_apikey = user.apikey + cls.user_d1_secretkey = user.secretkey + + cls.account_d1a = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD1A"], + admin=False, + domainid=cls.domain_1.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d1a) + cls.user_d1a_apikey = user.apikey + cls.user_d1a_secretkey = user.secretkey + + cls.account_d1b = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD1B"], + admin=False, + domainid=cls.domain_1.id + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_d1b) + cls.user_d1b_apikey = user.apikey + cls.user_d1b_secretkey = user.secretkey + + # Create 1 admin and 2 user accounts for doamin_11 + cls.account_d11 = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD11"], + admin=True, + domainid=cls.domain_11.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d11) + cls.user_d11_apikey = user.apikey + cls.user_d11_secretkey = user.secretkey + + cls.account_d11a = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD11A"], + admin=False, + domainid=cls.domain_11.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d11a) + cls.user_d11a_apikey = user.apikey + cls.user_d11a_secretkey = user.secretkey + + cls.account_d11b = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD11B"], + admin=False, + domainid=cls.domain_11.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d11b) + cls.user_d11b_apikey = user.apikey + cls.user_d11b_secretkey = user.secretkey + + # Create 2 user accounts for doamin_12 + cls.account_d12a = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD12A"], + admin=False, + domainid=cls.domain_12.id + ) + user = cls.generateKeysForUser(cls.api_client, cls.account_d12a) + cls.user_d12a_apikey = user.apikey + cls.user_d12a_secretkey = user.secretkey + + cls.account_d12b = Account.create( + cls.api_client, + cls.sharednetworkdata["accountD12B"], + admin=False, + domainid=cls.domain_12.id + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_d12b) + cls.user_d12b_apikey = user.apikey + cls.user_d12b_secretkey = user.secretkey + + # Create 1 user account and admin account in "ROOT" domain + + cls.account_roota = Account.create( + cls.api_client, + cls.sharednetworkdata["accountROOTA"], + admin=False, + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_roota) + cls.user_roota_apikey = user.apikey + cls.user_roota_secretkey = user.secretkey + + cls.account_root = Account.create( + cls.api_client, + cls.sharednetworkdata["accountROOTA"], + admin=True, + ) + + user = cls.generateKeysForUser(cls.api_client, cls.account_root) + cls.user_root_apikey = user.apikey + cls.user_root_secretkey = user.secretkey + + # service offering is already created in Nuagetestcase + cls.sharednetworkdata['mode'] = cls.zone.networktype + + # As admin user , create shared network with scope "all", "domain" + # with subdomain access ,"domain" without subdomain access and + # "account" + + cls.api_client.connection.apiKey = cls.default_apikey + cls.api_client.connection.securityKey = cls.default_secretkey + + cls.shared_network_offering = NetworkOffering.create( + cls.api_client, + cls.nuagenetworkdata["shared_nuage_public_network_offering"], + conservemode=False + ) + + # Enable Network offering + cls.shared_network_offering.update(cls.api_client, state='Enabled') + cls.shared_network_offering_id = cls.shared_network_offering.id + + cls.shared_network_all = Network.create( + cls.api_client, + cls.nuagenetworkdata["network_all"], + networkofferingid=cls.shared_network_offering_id, + zoneid=cls.zone.id + ) + + cls.shared_network_domain_d11 = Network.create( + cls.api_client, + cls.nuagenetworkdata["network_all"], + networkofferingid=cls.shared_network_offering_id, + zoneid=cls.zone.id, + domainid=cls.domain_11.id, + subdomainaccess=False + ) + + cls.shared_network_domain_with_subdomain_d11 = Network.create( + cls.api_client, + cls.nuagenetworkdata["network_all"], + networkofferingid=cls.shared_network_offering_id, + zoneid=cls.zone.id, + domainid=cls.domain_11.id, + subdomainaccess=True + ) + + cls.shared_network_account_d111a = Network.create( + cls.api_client, + cls.nuagenetworkdata["network_all"], + networkofferingid=cls.shared_network_offering_id, + zoneid=cls.zone.id, + domainid=cls.domain_11.id, + accountid=cls.account_d11a.user[0].username + ) + + cls._cleanup = [ + cls.account_root, + cls.account_roota, + cls.shared_network_all, + cls.shared_network_offering, + cls.service_offering, + ] + except Exception as e: + cls.domain_1.delete(cls.api_client, cleanup="true") + cleanup_resources(cls.api_client, cls._cleanup) + raise Exception("Failed to create the setup required to execute " + "the test cases: %s" % e) + + return + + @classmethod + def tearDownClass(cls): + cls.api_client.connection.apiKey = cls.default_apikey + cls.api_client.connection.securityKey = cls.default_secretkey + cleanup_resources(cls.api_client, cls._cleanup) + return + + def setUp(self): + self.api_client = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + + def tearDown(self): + # restore back default apikey and secretkey + self.api_client.connection.apiKey = self.default_apikey + self.api_client.connection.securityKey = self.default_secretkey + self.debug("Cleaning up the resources") + for obj in reversed(self.cleanup): + try: + if isinstance(obj, VirtualMachine): + obj.delete(self.api_client, expunge=True) + else: + obj.delete(self.api_client) + except Exception as e: + self.error("Failed to cleanup %s, got %s" % (obj, e)) + # cleanup_resources(self.api_client, self.cleanup) + self.cleanup = [] + self.debug("Cleanup complete!") + return + + def add_subnet_verify(self, network, services): + """verify required nic is present in the VM""" + + self.debug("Going to add new ip range in shared network %s" % + network.name) + cmd = createVlanIpRange.createVlanIpRangeCmd() + cmd.networkid = network.id + cmd.gateway = services["gateway"] + cmd.netmask = services["netmask"] + cmd.startip = services["startip"] + cmd.endip = services["endip"] + cmd.forVirtualNetwork = services["forvirtualnetwork"] + addedsubnet = self.api_client.createVlanIpRange(cmd) + + self.debug("verify above iprange is successfully added in shared " + "network %s or not" % network.name) + + cmd1 = listVlanIpRanges.listVlanIpRangesCmd() + cmd1.networkid = network.id + cmd1.id = addedsubnet.vlan.id + + allsubnets = self.api_client.listVlanIpRanges(cmd1) + self.assertEqual( + allsubnets[0].id, + addedsubnet.vlan.id, + "Check New subnet is successfully added to the shared Network" + ) + return addedsubnet + + def delete_subnet_verify(self, network, subnet): + """verify required nic is present in the VM""" + + self.debug("Going to delete ip range in shared network %s" % + network.name) + cmd = deleteVlanIpRange.deleteVlanIpRangeCmd() + cmd.id = subnet.vlan.id + self.api_client.deleteVlanIpRange(cmd) + + self.debug("verify above iprange is successfully deleted from shared " + "network %s or not" % network.name) + + cmd1 = listVlanIpRanges.listVlanIpRangesCmd() + cmd1.networkid = network.id + cmd1.id = subnet.vlan.id + + try: + allsubnets = self.api_client.listVlanIpRanges(cmd1) + self.assertEqual( + allsubnets[0].id, + subnet.vlan.id, + "Check Subnet is not present to the shared Network" + ) + self.fail("iprange is not successfully deleted from shared " + "network %s" % network.name) + except Exception as e: + self.debug("iprange is not successfully deleted from shared " + "network %s" % network.name) + self.debug("exception msg is %s" % e) + + def shared_subnet_not_present(self, network, subnetid): + shared_resources = self.vsd.get_shared_network_resource( + filter=self.get_externalID_filter(subnetid)) + try: + self.assertEqual(shared_resources.description, network.name, + "VSD shared resources description should match " + "network name in CloudStack" + ) + self.fail("still shared resource are present on VSD") + except Exception as e: + self.debug("sharedNetwork resources is successfully deleted from " + "VSD") + self.debug("exception msg is %s" % e) + + # Test cases relating to add/delete Shared Network IP ranges + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_01_add_delete_Subnet_in_public_sharednetwork_scope_all(self): + """Validate that subnet of same and different public gateway can be + added to shared network with scope=all + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope as all") + subnet1 = self.add_subnet_verify( + self.shared_network_all, self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_all, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_1, + sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network scope " + "as all") + subnet2 = self.add_subnet_verify( + self.shared_network_all, self.nuagenetworkdata["publiciprange2"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange2"]["startip"] + vm_2 = self.create_VM( + self.shared_network_all, account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_2, + sharedsubnetid=subnet_id) + # put ping here + self.delete_VM(vm_1) + self.delete_VM(vm_2) + self.delete_subnet_verify(self.shared_network_all, subnet1) + self.delete_subnet_verify(self.shared_network_all, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_02_add_delete_Subnet_in_public_sharednetwork_scope_domain(self): + """Validate subnet of same and different gateway can be added to public + shared network scope=domain with subdomain access + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope domain " + "with subdomain access") + subnet1 = self.add_subnet_verify( + self.shared_network_domain_with_subdomain_d11, + self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_domain_with_subdomain_d11, + account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_domain_with_subdomain_d11.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, vm_1, + sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network") + subnet2 = self.add_subnet_verify( + self.shared_network_domain_with_subdomain_d11, + self.nuagenetworkdata["publiciprange2"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange2"]["startip"] + vm_2 = self.create_VM( + self.shared_network_domain_with_subdomain_d11, + account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_domain_with_subdomain_d11.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, vm_2, + sharedsubnetid=subnet_id) + # put ping here + self.delete_VM(vm_1) + self.delete_VM(vm_2) + self.delete_subnet_verify( + self.shared_network_domain_with_subdomain_d11, subnet1) + self.delete_subnet_verify( + self.shared_network_domain_with_subdomain_d11, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_03_add_delete_Subnet_in_pub_sharednetwork_scope_nosubdomain(self): + """Validate subnet of same and different gateway can added to public + shared network scope=domain without subdomain access + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope domain " + "without subdomain access") + subnet1 = self.add_subnet_verify( + self.shared_network_domain_d11, + self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_domain_d11, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_domain_d11, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_domain_d11.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_domain_d11, vm_1, + sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network") + subnet2 = self.add_subnet_verify( + self.shared_network_domain_d11, + self.nuagenetworkdata["publiciprange2"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange2"]["startip"] + vm_2 = self.create_VM( + self.shared_network_domain_d11, account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_domain_d11, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_domain_d11.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_domain_d11, vm_2, + sharedsubnetid=subnet_id) + # put ping here + self.delete_VM(vm_1) + self.delete_VM(vm_2) + self.delete_subnet_verify(self.shared_network_domain_d11, subnet1) + self.delete_subnet_verify(self.shared_network_domain_d11, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_04_add_delete_Subnet_in_public_sharednetwork_scope_account(self): + """Validate subnet of same and different gateway can be added to shared + network scope=Account + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope as " + "Account") + subnet1 = self.add_subnet_verify( + self.shared_network_account_d111a, + self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_account_d111a, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_account_d111a, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_account_d111a.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_account_d111a, + vm_1, sharedsubnetid=subnet_id) + + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network") + subnet2 = self.add_subnet_verify( + self.shared_network_account_d111a, + self.nuagenetworkdata["publiciprange2"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange2"]["startip"] + vm_2 = self.create_VM( + self.shared_network_account_d111a, account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_account_d111a, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_account_d111a.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_account_d111a, + vm_2, sharedsubnetid=subnet_id) + # put ping here + self.delete_VM(vm_1) + self.delete_VM(vm_2) + self.delete_subnet_verify(self.shared_network_account_d111a, subnet1) + self.delete_subnet_verify(self.shared_network_account_d111a, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_05_change_ip_from_different_Subnet_public_shared(self): + """Validate that ip of a vm can be changed to a different subnet ip for + shared_network_scope_all + """ + + # Add subnet with same cidr + self.debug("Adding subnet of same cidr to shared Network scope as all") + subnet1 = self.add_subnet_verify( + self.shared_network_all, self.nuagenetworkdata["publiciprange1"]) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_all, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_1, + sharedsubnetid=subnet_id) + # Add subnet with different cidr + self.debug("Adding subnet of different cidr to shared Network scope " + "as all") + subnet2 = self.add_subnet_verify( + self.shared_network_all, self.nuagenetworkdata["publiciprange2"]) + + # stop VM to update the ipaddress + try: + vm_1.stop(self.api_client) + except Exception as e: + self.fail("Failed to stop the virtual instances, %s" % e) + vm_list = list_virtual_machines(self.api_client, id=vm_1.id) + nics = [x for x in vm_list[0].nic + if x.networkid == self.shared_network_all.id] + self.debug("Filtered nics list: %s:" % nics) + + cmd = updateVmNicIp.updateVmNicIpCmd() + for x in vm_list[0].nic: + cmd.nicid = x.id + cmd.ipaddress = self.nuagenetworkdata["publiciprange2"]["startip"] + self.api_client.updateVmNicIp(cmd) + + try: + vm_1.start(self.api_client) + except Exception as e: + self.fail("Failed to start the virtual instances, %s" % e) + + vm_list = list_virtual_machines(self.api_client, id=vm_1.id) + vm_list_validation_result = validateList(vm_list) + self.assertEqual(vm_list_validation_result[0], PASS, + "vm list validation failed due to %s" % + vm_list_validation_result[2]) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_list[0], + sharedsubnetid=subnet_id) + + self.delete_VM(vm_1) + self.delete_subnet_verify(self.shared_network_all, subnet1) + self.delete_subnet_verify(self.shared_network_all, subnet2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_06_restart_public_sharedNetwork_scope_all(self): + """Validate that restart Shared Network is done successfully without + any Error + """ + + self.debug("Adding subnet of same cidr to shared Network scope as all") + try: + self.add_subnet_verify( + self.shared_network_all, + self.nuagenetworkdata["publiciprange1"]) + except Exception as e: + self.debug("seems above test case is not able to clean the subnet") + self.debug("exception msg is %s" % e) + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["publiciprange1"]["startip"] + vm_1 = self.create_VM( + self.shared_network_all, account=self.account_d11a) + + # Verify shared Network and VM in VSD + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_1, + sharedsubnetid=subnet_id) + + # Restart network with cleanup + self.debug("Restarting shared Network with cleanup") + self.shared_network_all.restart(self.api_client, cleanup=True) + + self.debug("validating SharedNetwork on VSD") + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["publiciprange1"]["gateway"]) + self.delete_VM(vm_1) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_07_delete_first_subnet_public_sharednetwork_scope_all(self): + """Validate that when first subnet is removed then deletion of Network + works fine + """ + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["network_all"]["startip"] + vm_2 = self.create_VM( + self.shared_network_all, account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_all, + gateway=self.nuagenetworkdata["network_all"]["gateway"]) + subnet_id = self.get_subnet_id( + self.shared_network_all.id, + self.nuagenetworkdata["network_all"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_all, vm_2, + sharedsubnetid=subnet_id) + # Restart network with cleanup + cmd = listVlanIpRanges.listVlanIpRangesCmd() + cmd.networkid = self.shared_network_all.id + allsubnets = self.api_client.listVlanIpRanges(cmd) + self.delete_VM(vm_2) + firstsubnet = None + for subnet in allsubnets: + if subnet.endip == self.nuagenetworkdata["network_all"]["endip"]: + firstsubnet = subnet + + self.debug("cleanning first subnet") + try: + cmd = deleteVlanIpRange.deleteVlanIpRangeCmd() + cmd.id = firstsubnet.id + self.api_client.deleteVlanIpRange(cmd) + except Exception as e: + self.fail("Fail to delete the first subnet of shared Network") + self.debug("exception msg is %s" % e) + + self.shared_network_all.delete(self.api_client) + if self.shared_network_all in self._cleanup: + self._cleanup.remove(self.shared_network_all) + self.shared_subnet_not_present(self.shared_network_all, subnet_id) + + def test_08_public_sharednetwork_domain_cleanup(self): + """Validate that sharedNetwork Parent domain is cleaned up properly + """ + + try: + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["network_all"]["startip"] + vm_1 = self.create_VM( + self.shared_network_domain_with_subdomain_d11, + account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, + gateway=self.nuagenetworkdata["network_all"]["gateway"]) + subnet_id_subdomain = self.get_subnet_id( + self.shared_network_domain_with_subdomain_d11.id, + self.nuagenetworkdata["network_all"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, + self.shared_network_domain_with_subdomain_d11, + vm_1, sharedsubnetid=subnet_id_subdomain) + + self.test_data["virtual_machine"]["ipaddress"] = \ + self.nuagenetworkdata["network_all"]["endip"] + vm_2 = self.create_VM( + self.shared_network_domain_d11, account=self.account_d11a) + + self.verify_vsd_shared_network( + self.account_d11a.domainid, self.shared_network_domain_d11, + gateway=self.nuagenetworkdata["network_all"]["gateway"]) + subnet_id_nosubdomain = self.get_subnet_id( + self.shared_network_domain_d11.id, + self.nuagenetworkdata["network_all"]["gateway"]) + self.verify_vsd_enterprise_vm( + self.account_d11a.domainid, self.shared_network_domain_d11, + vm_2, sharedsubnetid=subnet_id_nosubdomain) + subnet_id_nosubdomain1 = self.get_subnet_id( + self.shared_network_domain_d11.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + subnet_id_subdomain1 = self.get_subnet_id( + self.shared_network_domain_with_subdomain_d11.id, + self.nuagenetworkdata["publiciprange2"]["gateway"]) + self.domain_1.delete(self.api_client, cleanup="true") + except Exception as e: + self.debug("test case Fail") + self.debug("exception msg is %s" % e) + self.domain_1.delete(self.api_client, cleanup="true") + self.fail("Fail to delete the Parent domain") + + self.shared_subnet_not_present( + self.shared_network_domain_with_subdomain_d11, + subnet_id_subdomain) + self.shared_subnet_not_present( + self.shared_network_domain_d11, subnet_id_nosubdomain) + self.shared_subnet_not_present( + self.shared_network_domain_with_subdomain_d11, + subnet_id_subdomain1) + self.shared_subnet_not_present( + self.shared_network_domain_d11, subnet_id_nosubdomain1) + + @staticmethod + def generateKeysForUser(api_client, account): + user = User.list( + api_client, + account=account.name, + domainid=account.domainid)[0] + + return (User.registerUserKeys( + api_client, + user.id))