def test_01_isolated_persistent_network(self):
        network = Network.create(
            self.apiclient,
            self.services["isolated_network"],
            networkofferingid=self.isolated_persistent_network_offering.id,
            zoneid=self.zone.id)
        self.cleanup.append(network)
        networkVlan = network.vlan
        response = verifyNetworkState(self.apiclient, network.id,
                                      "implemented")
        exceptionOccurred = response[0]
        isNetworkInDesiredState = response[1]
        exceptionMessage = response[2]

        if (exceptionOccurred or (not isNetworkInDesiredState)):
            self.fail(exceptionMessage)
        self.assertIsNotNone(networkVlan,
                             "vlan must not be null for persistent network")

        router = Router.list(self.apiclient, networkid=network.id)[0]
        router_host_id = router.hostid
        host = Host.list(self.apiclient, id=router_host_id)[0]
        if host.hypervisor.lower() in "kvm":
            result = self.verify_bridge_creation(host, networkVlan)
            self.assertEqual(
                int(result), 0,
                "Failed to find bridge on the breth1$-{networkVlan}")
        elif host.hypervisor.lower() in ["xenserver", "vmware"]:
            self.verify_network_setup_on_host_per_cluster(
                host.hypervisor.lower(), networkVlan)
    def test_02_L2_persistent_network(self):
        network_vlan = 90
        network = Network.create(
            self.apiclient,
            self.services["l2_network"],
            networkofferingid=self.l2_persistent_network_offering.id,
            zoneid=self.zone.id,
            vlan=network_vlan)
        self.cleanup.append(network)
        response = verifyNetworkState(self.apiclient, network.id,
                                      "implemented")
        exceptionOccurred = response[0]
        isNetworkInDesiredState = response[1]
        exceptionMessage = response[2]

        if (exceptionOccurred or (not isNetworkInDesiredState)):
            self.fail(exceptionMessage)
        self.assertIsNotNone(network_vlan,
                             "vlan must not be null for persistent network")

        self.validate_persistent_network_resources_created_on_host(
            network_vlan)
    def test_03_deploy_and_destroy_VM_and_verify_network_resources_persist(
            self):
        network_vlan = 99
        network = Network.create(
            self.apiclient,
            self.services["l2_network"],
            networkofferingid=self.l2_persistent_network_offering.id,
            zoneid=self.zone.id,
            vlan=network_vlan)
        self.cleanup.append(network)
        response = verifyNetworkState(self.apiclient, network.id,
                                      "implemented")
        logger.debug(response)
        exceptionOccurred = response[0]
        isNetworkInDesiredState = response[1]
        exceptionMessage = response[2]

        if (exceptionOccurred or (not isNetworkInDesiredState)):
            self.fail(exceptionMessage)
        self.assertIsNotNone(network_vlan,
                             "vlan must not be null for persistent network")
        try:
            virtual_machine = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                networkids=[network.id],
                serviceofferingid=self.service_offering.id)

            VirtualMachine.delete(virtual_machine,
                                  self.apiclient,
                                  expunge=True)

            self.validate_persistent_network_resources_created_on_host(
                network_vlan)
        except Exception as e:
            self.fail("Exception occurred: %s" % e)
        return