def test_04_remove_unused_range(self):
        """
        Test removing unused vlan range
        """
        # 1. Add new non contiguous range to existing vlan range
        # 2. Remove unused vlan range
        # 3. Unused vlan range should gte removed successfully

        vlan1 = self.existingvlan+","+self.vlan["partial_range"][0]
        self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = vlan1)

        self.debug("Removing vlan : %s" % self.vlan["partial_range"][0])

        self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.existingvlan)

        physicalnetworks = PhysicalNetwork.list(self.apiclient, id=self.physicalnetworkid)

        self.assertTrue(isinstance(physicalnetworks, list), "PhysicalNetwork.list should return a \
                        valid list object")

        self.assertTrue(len(physicalnetworks) > 0, "physical networks list should not be empty")

        vlanranges= physicalnetworks[0].vlan

        self.assert_(vlanranges.find(self.vlan["partial_range"][0]) == -1, "vlan range is not removed")

        return
    def test_extendPhysicalNetworkVlan(self):
        """
        Test to update a physical network and extend its vlan
        """
        phy_networks = PhysicalNetwork.list(self.apiClient)
        self.assertNotEqual(len(phy_networks), 0,
            msg="There are no physical networks in the zone")

        phy_network = None
        for network in phy_networks:
            if hasattr(network, 'vlan'):
                phy_network = network
                break

        self.assert_(phy_network is not None, msg="No network with vlan found")

        self.network = phy_network
        self.networkid = phy_network.id
        self.existing_vlan = phy_network.vlan
        vlan1 = self.existing_vlan+","+self.vlan["partial_range"][0]
        updatePhysicalNetworkResponse = self.network.update(self.apiClient, id = self.networkid, vlan = vlan1)
        self.assert_(updatePhysicalNetworkResponse is not None,
            msg="couldn't extend the physical network with vlan %s"%vlan1)
        self.assert_(isinstance(self.network, PhysicalNetwork))

        vlan2 = vlan1+","+self.vlan["partial_range"][1]
        updatePhysicalNetworkResponse2 = self.network.update(self.apiClient, id = self.networkid, vlan = vlan2)
        self.assert_(updatePhysicalNetworkResponse2 is not None,
            msg="couldn't extend the physical network with vlan %s"%vlan2)
        self.assert_(isinstance(self.network, PhysicalNetwork))

        vlanranges= updatePhysicalNetworkResponse2.vlan
        self.assert_(vlanranges is not None,
            "No VLAN ranges found on the deployment")
    def validatePhysicalNetworkVlan(self, physicalNetworkId, vlan):
        """Validate whether the physical network has the updated vlan

        params:

        @physicalNetworkId: The id of physical network which needs to be validated
        @vlan: vlan with which physical network was updated. This should match with the vlan of listed
               physical network

        Raise Exception if not matched
        """

        self.debug("Listing physical networks with id: %s" % physicalNetworkId)

        physicalnetworks = PhysicalNetwork.list(self.apiclient, id=physicalNetworkId)

        self.assertTrue(isinstance(physicalnetworks, list), "PhysicalNetwork.list should return a \
                        valid list object")

        self.assertTrue(len(physicalnetworks) > 0, "physical networks list should not be empty")

        self.debug("Checking if physical network vlan matches with the passed vlan")

        vlans = xsplit(vlan,[','])

        for virtualLan in vlans:
            self.assert_(physicalnetworks[0].vlan.find(virtualLan) != -1, "vlan range %s \
                        is not present in physical network: %s" % (virtualLan, physicalNetworkId))

        return
예제 #4
0
    def test_extendPhysicalNetworkVlan(self):
        """
        Test to update a physical network and extend its vlan
        """
        phy_networks = PhysicalNetwork.list(self.apiClient)
        self.assertNotEqual(len(phy_networks),
                            0,
                            msg="There are no physical networks in the zone")

        self.network = phy_networks[0]
        self.networkid = phy_networks[0].id
        self.existing_vlan = phy_networks[0].vlan
        vlan1 = self.existing_vlan + "," + self.vlan["partial_range"][0]
        updatePhysicalNetworkResponse = self.network.update(self.apiClient,
                                                            id=self.networkid,
                                                            vlan=vlan1)
        self.assert_(updatePhysicalNetworkResponse is not None,
                     msg="couldn't extend the physical network with vlan %s" %
                     vlan1)
        self.assert_(isinstance(self.network, PhysicalNetwork))

        vlan2 = vlan1 + "," + self.vlan["partial_range"][1]
        updatePhysicalNetworkResponse2 = self.network.update(self.apiClient,
                                                             id=self.networkid,
                                                             vlan=vlan2)
        self.assert_(updatePhysicalNetworkResponse2 is not None,
                     msg="couldn't extend the physical network with vlan %s" %
                     vlan2)
        self.assert_(isinstance(self.network, PhysicalNetwork))

        vlanranges = updatePhysicalNetworkResponse2.vlan
        self.assert_(vlanranges is not None,
                     "No VLAN ranges found on the deployment")
        self.assert_(str(vlanranges) == vlan2, "vlan ranges are not extended")
    def test_extendPhysicalNetworkVlan(self):
        """
        Test to update a physical network and extend its vlan
        """
        phy_networks = PhysicalNetwork.list(self.apiClient)
        self.assertNotEqual(len(phy_networks), 0,
            msg="There are no physical networks in the zone")

        self.network = phy_networks[0]
        self.networkid = phy_networks[0].id
        self.existing_vlan = phy_networks[0].vlan
        vlan1 = self.existing_vlan+","+self.vlan["part"][0]
        updatePhysicalNetworkResponse = self.network.update(self.apiClient, id = self.networkid, vlan = vlan1)
        self.assert_(updatePhysicalNetworkResponse is not None,
            msg="couldn't extend the physical network with vlan %s"%vlan1)
        self.assert_(isinstance(self.network, PhysicalNetwork))

        vlan2 = vlan1+","+self.vlan["part"][1]
        updatePhysicalNetworkResponse2 = self.network.update(self.apiClient, id = self.networkid, vlan = vlan2)
        self.assert_(updatePhysicalNetworkResponse2 is not None,
            msg="couldn't extend the physical network with vlan %s"%vlan2)
        self.assert_(isinstance(self.network, PhysicalNetwork))

        vlanranges= updatePhysicalNetworkResponse2.vlan
        self.assert_(vlanranges is not None,
            "No VLAN ranges found on the deployment")
        self.assert_(vlanranges.find(self.vlan["full"]) > 0, "vlan ranges are not extended")
예제 #6
0
 def get_nicira_enabled_physical_network_id(cls, physical_networks):
     nicira_physical_network_name = None
     for physical_network in physical_networks:
         for provider in physical_network.providers:
             if provider.name == 'NiciraNvp':
                 nicira_physical_network_name = physical_network.name
     if nicira_physical_network_name is None:
         raise Exception('Did not find a Nicira enabled physical network in configuration')
     return PhysicalNetwork.list(cls.api_client, name=nicira_physical_network_name)[0].id
예제 #7
0
def get_free_vlan(apiclient, zoneid):
    """
    Find an unallocated VLAN outside the range allocated to the physical network.

    @note: This does not guarantee that the VLAN is available for use in
    the deployment's network gear
    @return: physical_network, shared_vlan_tag
    """
    list_physical_networks_response = PhysicalNetwork.list(apiclient, zoneid=zoneid)
    assert isinstance(list_physical_networks_response, list)
    assert len(list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid

    physical_network = list_physical_networks_response[0]

    networks = list_networks(apiclient, zoneid=zoneid, type="Shared")
    usedVlanIds = []

    if isinstance(networks, list) and len(networks) > 0:
        usedVlanIds = [int(nw.vlan) for nw in networks if nw.vlan != "untagged"]

    if hasattr(physical_network, "vlan") is False:
        while True:
            shared_ntwk_vlan = random.randrange(1, 4095)
            if shared_ntwk_vlan in usedVlanIds:
                continue
            else:
                break
    else:
        vlans = xsplit(physical_network.vlan, ["-", ","])

        assert len(vlans) > 0
        assert int(vlans[0]) < int(vlans[-1]), "VLAN range  %s was improperly split" % physical_network.vlan

        # Assuming random function will give different integer each time
        retriesCount = 20

        shared_ntwk_vlan = None

        while True:

            if retriesCount == 0:
                break

            free_vlan = int(vlans[-1]) + random.randrange(1, 20)

            if free_vlan > 4095:
                free_vlan = int(vlans[0]) - random.randrange(1, 20)
            if free_vlan < 0 or (free_vlan in usedVlanIds):
                retriesCount -= 1
                continue
            else:
                shared_ntwk_vlan = free_vlan
                break

    return physical_network, shared_ntwk_vlan
예제 #8
0
    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()

        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        self.physicalnetworks = PhysicalNetwork.list(self.apiclient, zoneid=self.zone.id)
        self.assertNotEqual(len(self.physicalnetworks), 0, "Check if the list physical network API returns a non-empty response")
        self.clusters = Cluster.list(self.apiclient, hypervisor='VMware')
        self.assertNotEqual(len(self.clusters), 0, "Check if the list cluster API returns a non-empty response")

        self.cleanup = []
        return
예제 #9
0
    def setUpClass(cls):
        testClient = super(TestRegionVpcOffering, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = Services().services

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype


        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"]
        )
        if cls.template == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]


        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
                                            cls.apiclient,
                                            cls.services["service_offering"]
                                            )
        cls._cleanup = [cls.service_offering, ]

        try:
            list_physical_networks = PhysicalNetwork.list(
                                                     cls.apiclient,
                                                     zoneid=cls.zone.id
                                                     )
            assert validateList(list_physical_networks)[0] == PASS,\
                "physical networks list validation failed"

            cls.isOvsPluginEnabled = False
            for i in range(0, len(list_physical_networks)):
                list_network_serviceprovider = NetworkServiceProvider.list(
                                                                       cls.apiclient,
                                                                       physicalnetworkid=list_physical_networks[i].id
                                                                       )
                for j in range(0, len(list_network_serviceprovider)):
                    if((str(list_network_serviceprovider[j].name).lower() == 'ovs') and
                        (str(list_network_serviceprovider[j].state).lower() == 'enabled')):
                        cls.isOvsPluginEnabled = True
                        break
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest(e)
        return
예제 #10
0
    def getZoneDetails(cls, zone=None):
        # Get Zone, Domain and templates
        cls.zone = zone if zone else get_zone(
            cls.api_client,
            zone_name=cls.test_client.getZoneForTests()
        )
        cls.domain = get_domain(cls.api_client)
        cls.template = get_template(cls.api_client,
                                    cls.zone.id,
                                    cls.test_data["ostype"]
                                    )
        cls.test_data["virtual_machine"]["zoneid"] = cls.zone.id
        cls.test_data["virtual_machine"]["template"] = cls.template.id

        # Check if the host hypervisor type is simulator
        hypervisors = Hypervisor.list(cls.api_client, zoneid=cls.zone.id)
        assert hypervisors is not None and len(hypervisors) > 0, \
            "Expected at least one hypervisor"
        cls.isSimulator = any(map(lambda h: h.name == "Simulator",
                                  hypervisors))

        # Get configured Nuage VSP device details
        try:
            physical_networks = PhysicalNetwork.list(
                cls.api_client,
                zoneid=cls.zone.id
            )

            cls.vsp_physical_network = next(pn for pn in physical_networks
                                            if pn.isolationmethods == "VSP")
            cls.nuage_vsp_device = Nuage.list(
                cls.api_client,
                physicalnetworkid=cls.vsp_physical_network.id)[0]

            # Take username and password from the datacenter config file,
            # as they are not returned by the API.
            config_nuage_device = next(device for zone in cls.config.zones
                                       if zone.name == cls.zone.name
                                       for physnet in zone.physical_networks
                                       if "VSP" in physnet.isolationmethods
                                       for provider in physnet.providers
                                       if provider.name == "NuageVsp"
                                       for device in provider.devices)

            cls.nuage_vsp_device.username = config_nuage_device.username
            cls.nuage_vsp_device.password = config_nuage_device.password
            cls.cms_id = cls.nuage_vsp_device.cmsid
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Warning: Could not get configured "
                                    "Nuage VSP device details - %s" % e)
        return
 def tearDown(self):
     """
     Teardown to update a physical network and shrink its vlan
     @return:
     """
     phy_networks = PhysicalNetwork.list(self.apiClient)
     self.assertNotEqual(len(phy_networks), 0,
         msg="There are no physical networks in the zone")
     self.network = phy_networks[0]
     self.networkid = phy_networks[0].id
     updateResponse = self.network.update(self.apiClient, id = self.networkid, vlan=self.existing_vlan)
     self.assert_(updateResponse.vlan.find(self.vlan["full"]) < 0,
         "VLAN was not removed successfully")
예제 #12
0
 def tearDown(self):
     """
     Teardown to update a physical network and shrink its vlan
     @return:
     """
     phy_networks = PhysicalNetwork.list(self.apiClient)
     self.assertNotEqual(len(phy_networks), 0,
         msg="There are no physical networks in the zone")
     self.network = phy_networks[0]
     self.networkid = phy_networks[0].id
     updateResponse = self.network.update(self.apiClient, id = self.networkid, vlan=self.existing_vlan)
     self.assert_(updateResponse.vlan.find(self.vlan["full_range"]) < 0,
         "VLAN was not removed successfully")
    def setUpClass(cls):
        testClient = super(TestVPCDistributedRouterOffering, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = Services().services

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype

        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"]
        )
        if cls.template == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
                                            cls.apiclient,
                                            cls.services["service_offering"]
                                            )
        cls._cleanup = [
                        cls.service_offering,
                        ]
        try:
            list_physical_networks = PhysicalNetwork.list(
                                                     cls.apiclient,
                                                     zoneid=cls.zone.id
                                                     )
            assert validateList(list_physical_networks)[0] == PASS,\
                "physical networks list validation failed"

            cls.isOvsPluginEnabled = False
            for i in range(0, len(list_physical_networks)):
                list_network_serviceprovider = NetworkServiceProvider.list(
                                                                       cls.apiclient,
                                                                       physicalnetworkid=list_physical_networks[i].id
                                                                       )
                for j in range(0, len(list_network_serviceprovider)):
                    if((str(list_network_serviceprovider[j].name).lower() == 'ovs') and
                        (str(list_network_serviceprovider[j].state).lower() == 'enabled')):
                        cls.isOvsPluginEnabled = True
                        break
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest(e)
        return
예제 #14
0
    def test_baremetal(self):
        self.debug("Test create baremetal network offering")
        networkoffering = NetworkOffering.create(
            self.apiclient, self.services["network_offering"])
        networkoffering.update(self.apiclient, state="Enabled")
        self.cleanup.append(networkoffering)

        physical_network = PhysicalNetwork.list(self.apiclient,
                                                zoneid=self.zoneid)[0]
        dhcp_provider = NetworkServiceProvider.list(
            self.apiclient,
            name="BaremetalDhcpProvider",
            physical_network_id=physical_network.id)[0]
        NetworkServiceProvider.update(self.apiclient,
                                      id=dhcp_provider.id,
                                      state='Enabled')
        pxe_provider = NetworkServiceProvider.list(
            self.apiclient,
            name="BaremetalPxeProvider",
            physical_network_id=physical_network.id)[0]
        NetworkServiceProvider.update(self.apiclient,
                                      id=pxe_provider.id,
                                      state='Enabled')
        userdata_provider = NetworkServiceProvider.list(
            self.apiclient,
            name="BaremetalUserdataProvider",
            physical_network_id=physical_network.id)[0]
        NetworkServiceProvider.update(self.apiclient,
                                      id=userdata_provider.id,
                                      state='Enabled')

        network = Network.create(self.apiclient,
                                 self.services["network"],
                                 zoneid=self.zoneid,
                                 networkofferingid=networkoffering.id)
        self.cleanup.insert(0, network)

        pod = Pod.list(self.apiclient)[0]
        cmd = createVlanIpRange.createVlanIpRangeCmd()
        cmd.podid = pod.id
        cmd.networkid = network.id
        cmd.gateway = "10.1.1.1"
        cmd.netmask = "255.255.255.0"
        cmd.startip = "10.1.1.20"
        cmd.endip = "10.1.1.40"
        cmd.forVirtualNetwork = "false"
        self.apiclient.createVlanIpRange(cmd)
    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()

        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        self.physicalnetworks = PhysicalNetwork.list(self.apiclient,
                                                     zoneid=self.zone.id)
        self.assertNotEqual(
            len(self.physicalnetworks), 0,
            "Check if the list physical network API returns a non-empty response"
        )
        self.clusters = Cluster.list(self.apiclient, hypervisor='VMware')
        self.assertNotEqual(
            len(self.clusters), 0,
            "Check if the list cluster API returns a non-empty response")

        self.cleanup = []
        return
예제 #16
0
 def test_baremetal(self):
     self.debug("Test create baremetal network offering")
     networkoffering = NetworkOffering.create(self.apiclient, self.services["network_offering"])
     networkoffering.update(self.apiclient, state="Enabled")
     self.cleanup.append(networkoffering)
     
     physical_network = PhysicalNetwork.list(self.apiclient, zoneid=self.zoneid)[0];
     dhcp_provider = NetworkServiceProvider.list(self.apiclient, name="BaremetalDhcpProvider", physical_network_id=physical_network.id)[0]
     NetworkServiceProvider.update(
                                       self.apiclient,
                                       id=dhcp_provider.id,
                                       state='Enabled'
                                       )
     pxe_provider = NetworkServiceProvider.list(self.apiclient, name="BaremetalPxeProvider", physical_network_id=physical_network.id)[0]
     NetworkServiceProvider.update(
                                       self.apiclient,
                                       id=pxe_provider.id,
                                       state='Enabled'
                                       )
     userdata_provider = NetworkServiceProvider.list(self.apiclient, name="BaremetalUserdataProvider", physical_network_id=physical_network.id)[0]
     NetworkServiceProvider.update(
                                       self.apiclient,
                                       id=userdata_provider.id,
                                       state='Enabled'
                                       )
     
     network = Network.create(self.apiclient, self.services["network"], zoneid=self.zoneid, networkofferingid=networkoffering.id)
     self.cleanup.insert(0, network)
     
     pod = Pod.list(self.apiclient)[0]
     cmd = createVlanIpRange.createVlanIpRangeCmd()
     cmd.podid = pod.id
     cmd.networkid = network.id
     cmd.gateway = "10.1.1.1"
     cmd.netmask = "255.255.255.0"
     cmd.startip = "10.1.1.20"
     cmd.endip = "10.1.1.40"
     cmd.forVirtualNetwork="false"
     self.apiclient.createVlanIpRange(cmd)
    def validatePhysicalNetworkVlan(self, physicalNetworkId, vlan):
        """Validate whether the physical network has the updated vlan

        params:

        @physicalNetworkId: The id of physical network which needs to be validated
        @vlan: vlan with which physical network was updated. This should match with the vlan of listed
               physical network

        Raise Exception if not matched
        """

        self.debug("Listing physical networks with id: %s" % physicalNetworkId)

        physicalnetworks = PhysicalNetwork.list(self.apiclient,
                                                id=physicalNetworkId)

        self.assertTrue(
            isinstance(physicalnetworks, list),
            "PhysicalNetwork.list should return a \
                        valid list object")

        self.assertTrue(
            len(physicalnetworks) > 0,
            "physical networks list should not be empty")

        self.debug(
            "Checking if physical network vlan matches with the passed vlan")

        vlans = xsplit(vlan, [','])

        for virtualLan in vlans:
            self.assert_(
                physicalnetworks[0].vlan.find(virtualLan) != -1,
                "vlan range %s \
                        is not present in physical network: %s" %
                (virtualLan, physicalNetworkId))

        return
    def test_04_remove_unused_range(self):
        """
        Test removing unused vlan range
        """
        # 1. Add new non contiguous range to existing vlan range
        # 2. Remove unused vlan range
        # 3. Unused vlan range should gte removed successfully

        vlan1 = self.existingvlan + "," + self.vlan["partial_range"][0]
        self.physicalnetwork.update(self.apiClient,
                                    id=self.physicalnetworkid,
                                    vlan=vlan1)

        self.debug("Removing vlan : %s" % self.vlan["partial_range"][0])

        self.physicalnetwork.update(self.apiClient,
                                    id=self.physicalnetworkid,
                                    vlan=self.existingvlan)

        physicalnetworks = PhysicalNetwork.list(self.apiclient,
                                                id=self.physicalnetworkid)

        self.assertTrue(
            isinstance(physicalnetworks, list),
            "PhysicalNetwork.list should return a \
                        valid list object")

        self.assertTrue(
            len(physicalnetworks) > 0,
            "physical networks list should not be empty")

        vlanranges = physicalnetworks[0].vlan

        self.assert_(
            vlanranges.find(self.vlan["partial_range"][0]) == -1,
            "vlan range is not removed")

        return
예제 #19
0
    def test_01_list_sec_storage_vm(self):
        """Test List secondary storage VMs
        """

        # Validate the following:
        # 1. listSystemVM (systemvmtype=secondarystoragevm)
        #    should return only ONE SSVM per zone
        # 2. The returned SSVM should be in Running state
        # 3. listSystemVM for secondarystoragevm should list publicip,
        #    privateip and link-localip
        # 4. The gateway programmed on the ssvm by listSystemVm should be
        #    the same as the gateway returned by listVlanIpRanges
        # 5. DNS entries must match those given for the zone

        list_ssvm_response = list_ssvms(
            self.apiclient,
            systemvmtype='secondarystoragevm',
            state='Running',
        )
        self.assertEqual(
            isinstance(list_ssvm_response, list),
            True,
            "Check list response returns a valid list"
        )
        # Verify SSVM response
        self.assertNotEqual(
            len(list_ssvm_response),
            0,
            "Check list System VMs response"
        )

        list_zones_response = list_zones(self.apiclient)

        self.assertEqual(
            isinstance(list_zones_response, list),
            True,
            "Check list response returns a valid list"
        )

        self.debug("Number of zones: %s" % len(list_zones_response))
        self.debug("Number of SSVMs: %s" % len(list_ssvm_response))
        # Number of Sec storage VMs = No of Zones
        self.assertEqual(
            len(list_ssvm_response),
            len(list_zones_response),
            "Check number of SSVMs with number of zones"
        )
        # For each secondary storage VM check private IP,
        # public IP, link local IP and DNS
        for ssvm in list_ssvm_response:

            self.debug("SSVM state: %s" % ssvm.state)
            self.assertEqual(
                ssvm.state,
                'Running',
                "Check whether state of SSVM is running"
            )

            self.assertEqual(
                hasattr(ssvm, 'privateip'),
                True,
                "Check whether SSVM has private IP field"
            )

            self.assertEqual(
                hasattr(ssvm, 'linklocalip'),
                True,
                "Check whether SSVM has link local IP field"
            )

            self.assertEqual(
                hasattr(ssvm, 'publicip'),
                True,
                "Check whether SSVM has public IP field"
            )

            # Fetch corresponding ip ranges information from listVlanIpRanges
            ipranges_response = list_vlan_ipranges(
                self.apiclient,
                zoneid=ssvm.zoneid
            )
            self.assertEqual(
                isinstance(ipranges_response, list),
                True,
                "Check list response returns a valid list"
            )
            iprange = ipranges_response[0]

            # Fetch corresponding Physical Network of SSVM's Zone
            listphyntwk = PhysicalNetwork.list(
                self.apiclient,
                zoneid=ssvm.zoneid
            )

            # Execute the following assertion in all zones except EIP-ELB Zones
            if not (
                self.zone.networktype.lower() == 'basic' and isinstance(
                    NetScaler.list(
                        self.apiclient,
                        physicalnetworkid=listphyntwk[0].id),
                    list) is True):
                self.assertEqual(
                    ssvm.gateway,
                    iprange.gateway,
                    "Check gateway with that of corresponding ip range"
                )

            # Fetch corresponding zone information from listZones
            zone_response = list_zones(
                self.apiclient,
                id=ssvm.zoneid
            )
            self.assertEqual(
                isinstance(zone_response, list),
                True,
                "Check list response returns a valid list"
            )
            self.assertEqual(
                ssvm.dns1,
                zone_response[0].dns1,
                "Check DNS1 with that of corresponding zone"
            )

            self.assertEqual(
                ssvm.dns2,
                zone_response[0].dns2,
                "Check DNS2 with that of corresponding zone"
            )
        return
    def setUpClass(cls):
        cls.testClient = super(TestNccIntegrationDedicated,
                               cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()
        cls._cleanup = []

        cls.logger = logging.getLogger('TestNccIntegrationDedicated')
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls.template = get_template(cls.api_client, cls.zone.id,
                                    cls.services["ostype"])
        ncc_ip = cls.services["NCC"]["NCCIP"]
        ns_ip = cls.services["NSDedicated"]["NSIP"]
        cls.debug("NS IP - Dedicated: %s" % ns_ip)

        mgmt_srv_ip = cls.config.__dict__["mgtSvr"][0].__dict__["mgtSvrIp"]
        #ncc_ip = "10.102.195.215"
        #ns_ip = "10.102.195.210"
        cls.ns = ncc.NCC(ncc_ip, ns_ip, mgmt_srv_ip, logger=cls.logger)
        cls.ns.registerCCP(cls.api_client)
        cls.ns.registerNS()
        cls.ns.assignNStoCSZone()
        spname = cls.services["servicepackage_dedicated"]["name"]

        # Create Service package and get device group id, tenant group id and service package id
        # These would be needed later for clean up

        (cls.dv_group_id, cls.tnt_group_id,
         cls.srv_pkg_id) = cls.ns.createServicePackages(
             spname, "NetScalerVPX", ns_ip, isolation_policy="dedicated")
        cls.debug("Created service package in NCC")
        cls.debug("dv_group, tnt_group, srv_pkg_id: %s %s %s" %
                  (cls.dv_group_id, cls.tnt_group_id, cls.srv_pkg_id))

        srv_pkg_list = RegisteredServicePackage.list(cls.api_client)
        # Choose the one created
        cls.srv_pkg_uuid = None
        for sp in srv_pkg_list:
            if sp.name == spname:
                cls.srv_pkg_uuid = sp.id
        #srv_pkg_id = srv_pkg_list[0].id

        cls.account = Account.create(cls.api_client, cls.services["account"])
        cls._cleanup.append(cls.account)

        try:
            cls.services["nw_off_ncc_DedicatedSP"][
                "servicepackageuuid"] = cls.srv_pkg_uuid
            cls.services["nw_off_ncc_DedicatedSP"][
                "servicepackagedescription"] = "A NetScalerVPX is dedicated per network."
            cls.network_offering = NetworkOffering.create(
                cls.api_client, cls.services["nw_off_ncc_DedicatedSP"])
        except Exception as e:
            raise Exception(
                "Unable to create network offering with Service package % s due to exception % s"
                % (cls.srv_pkg_uuid, e))

        # Network offering should be removed so that service package may be deleted later
        cls._cleanup.append(cls.network_offering)

        cls.network_offering.update(cls.api_client, state="Enabled")
        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"])
        cls.services["small"]["template"] = cls.template.id

        # Enable Netscaler Service Provider

        cls.phy_nws = PhysicalNetwork.list(cls.api_client, zoneid=cls.zone.id)
        if isinstance(cls.phy_nws, list):
            physical_network = cls.phy_nws[0]

        try:
            cls.ns_service_provider = NetworkServiceProvider.list(
                cls.api_client, name='Netscaler')
            if isinstance(cls.ns_service_provider, list):
                ns_provider = cls.ns_service_provider[0]
        except:
            raise Exception("Netscaler service provider not found!!")

        try:
            if ns_provider.state != "Enabled":
                NetworkServiceProvider.update(
                    cls.api_client,
                    id=ns_provider.id,
                    physicalnetworkid=physical_network.id,
                    state="Enabled")
        except:
            raise Exception(
                "Enabling Netscaler Service provider failed. Unable to proceed"
            )

        return
    def setUpClass(cls):
        cls.testClient = super(TestNccIntegrationShared, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()
        cls._cleanup = []

        cls.logger = logging.getLogger('TestNccIntegrationShared')
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls.template = get_template(
            cls.api_client,
            cls.zone.id,
            cls.services["ostype"] )
        ncc_ip=cls.services["NCC"]["NCCIP"]
        ns_ip=cls.services["NSShared"]["NSIP"]
        cls.debug("NS IP: Shared: %s" % ns_ip)

        mgmt_srv_ip = cls.config.__dict__["mgtSvr"][0].__dict__["mgtSvrIp"]
        #ncc_ip = "10.102.195.215"
        #ns_ip = "10.102.195.210"
        cls.ns = ncc.NCC(ncc_ip, ns_ip, mgmt_srv_ip, logger=cls.logger)
        cls.ns.registerCCP(cls.api_client)
        cls.ns.registerNS()
        cls.ns.assignNStoCSZone()
        spname = cls.services["servicepackage_shared"]["name"]
        cls.debug("SPname (Shared): %s" % spname)
        #spname="SharedSP9"
        # Create Service package and get device group id, tenant group id and service package id
        # These would be needed later for clean up

        (cls.dv_group_id, cls.tnt_group_id, cls.srv_pkg_id) = cls.ns.createServicePackages(
            spname,
            "NetScalerVPX",
            ns_ip)
        srv_pkg_list = RegisteredServicePackage.list(cls.api_client)
        # Choose the one created
        cls.srv_pkg_uuid = None
        for sp in srv_pkg_list:
            if sp.name == spname:
                cls.srv_pkg_uuid = sp.id
        #srv_pkg_id = srv_pkg_list[0].id

        cls.account = Account.create(
            cls.api_client,
            cls.services["account"]
        )
        cls._cleanup.append(cls.account)

        try:
            cls.services["nw_off_ncc_SharedSP"]["servicepackageuuid"] = cls.srv_pkg_uuid
            cls.services["nw_off_ncc_SharedSP"]["servicepackagedescription"] = "A NetScalerVPX is shared across all networks."
            cls.network_offering = NetworkOffering.create(
                cls.api_client,
                cls.services["nw_off_ncc_SharedSP"])
        except Exception as e:
            raise Exception ("Unable to create network offering with Service package % s due to exception % s"
                             % (cls.srv_pkg_uuid, e))

        # Network offering should be removed so that service package may be deleted later
        cls._cleanup.append(cls.network_offering)

        cls.network_offering.update(cls.api_client, state = "Enabled")
        cls.service_offering_shared = ServiceOffering.create(
                cls.api_client,
                cls.services["service_offering"]
            )
        cls.services["small"]["template"] = cls.template.id

        # Enable Netscaler Service Provider

        cls.phy_nws = PhysicalNetwork.list(cls.api_client,zoneid=cls.zone.id)
        if isinstance(cls.phy_nws, list):
            physical_network = cls.phy_nws[0]

        try:
            cls.ns_service_provider = NetworkServiceProvider.list(cls.api_client,name='Netscaler')
            if isinstance(cls.ns_service_provider, list):
                ns_provider = cls.ns_service_provider[0]
        except:
            raise Exception ("Netscaler service provider not found!!")

        try:
            if ns_provider.state != "Enabled":
                NetworkServiceProvider.update(cls.api_client, id=ns_provider.id, physicalnetworkid=physical_network.id, state="Enabled")
        except:
            raise Exception ("Enabling Netscaler Service provider failed. Unable to proceed")

        return
예제 #22
0
    def test_01_list_sec_storage_vm(self):
        """Test List secondary storage VMs
        """

        # Validate the following:
        # 1. listSystemVM (systemvmtype=secondarystoragevm)
        #    should return only ONE SSVM per zone
        # 2. The returned SSVM should be in Running state
        # 3. listSystemVM for secondarystoragevm should list publicip,
        #    privateip and link-localip
        # 4. The gateway programmed on the ssvm by listSystemVm should be
        #    the same as the gateway returned by listVlanIpRanges
        # 5. DNS entries must match those given for the zone

        list_ssvm_response = list_ssvms(
            self.apiclient,
            systemvmtype='secondarystoragevm',
            state='Running',
        )
        self.assertEqual(isinstance(list_ssvm_response, list), True,
                         "Check list response returns a valid list")
        # Verify SSVM response
        self.assertNotEqual(len(list_ssvm_response), 0,
                            "Check list System VMs response")

        list_zones_response = list_zones(self.apiclient)

        self.assertEqual(isinstance(list_zones_response, list), True,
                         "Check list response returns a valid list")

        self.debug("Number of zones: %s" % len(list_zones_response))
        self.debug("Number of SSVMs: %s" % len(list_ssvm_response))
        # Number of Sec storage VMs = No of Zones
        self.assertEqual(len(list_ssvm_response), len(list_zones_response),
                         "Check number of SSVMs with number of zones")
        # For each secondary storage VM check private IP,
        # public IP, link local IP and DNS
        for ssvm in list_ssvm_response:

            self.debug("SSVM state: %s" % ssvm.state)
            self.assertEqual(ssvm.state, 'Running',
                             "Check whether state of SSVM is running")

            self.assertEqual(hasattr(ssvm, 'privateip'), True,
                             "Check whether SSVM has private IP field")

            self.assertEqual(hasattr(ssvm, 'linklocalip'), True,
                             "Check whether SSVM has link local IP field")

            self.assertEqual(hasattr(ssvm, 'publicip'), True,
                             "Check whether SSVM has public IP field")

            # Fetch corresponding ip ranges information from listVlanIpRanges
            ipranges_response = list_vlan_ipranges(self.apiclient,
                                                   zoneid=ssvm.zoneid)
            self.assertEqual(isinstance(ipranges_response, list), True,
                             "Check list response returns a valid list")
            iprange = ipranges_response[0]

            # Fetch corresponding Physical Network of SSVM's Zone
            listphyntwk = PhysicalNetwork.list(self.apiclient,
                                               zoneid=ssvm.zoneid)

            # Execute the following assertion in all zones except EIP-ELB Zones
            if not (self.zone.networktype.lower() == 'basic' and isinstance(
                    NetScaler.list(self.apiclient,
                                   physicalnetworkid=listphyntwk[0].id), list)
                    is True):
                self.assertEqual(
                    ssvm.gateway, iprange.gateway,
                    "Check gateway with that of corresponding ip range")

            # Fetch corresponding zone information from listZones
            zone_response = list_zones(self.apiclient, id=ssvm.zoneid)
            self.assertEqual(isinstance(zone_response, list), True,
                             "Check list response returns a valid list")
            self.assertEqual(ssvm.dns1, zone_response[0].dns1,
                             "Check DNS1 with that of corresponding zone")

            self.assertEqual(ssvm.dns2, zone_response[0].dns2,
                             "Check DNS2 with that of corresponding zone")
        return
예제 #23
0
    def test_02_list_cpvm_vm(self):
        """Test List console proxy VMs
        """

        # Validate the following:
        # 1. listSystemVM (systemvmtype=consoleproxy) should return
        #    at least ONE CPVM per zone
        # 2. The returned ConsoleProxyVM should be in Running state
        # 3. listSystemVM for console proxy should list publicip, privateip
        #    and link-localip
        # 4. The gateway programmed on the console proxy should be the same
        #    as the gateway returned by listZones
        # 5. DNS entries must match those given for the zone

        list_cpvm_response = list_ssvms(
            self.apiclient,
            systemvmtype='consoleproxy',
            state='Running',
        )
        self.assertEqual(
            isinstance(list_cpvm_response, list),
            True,
            "Check list response returns a valid list"
        )
        # Verify CPVM response
        self.assertNotEqual(
            len(list_cpvm_response),
            0,
            "Check list System VMs response"
        )
        list_zones_response = list_zones(self.apiclient)
        # Number of Console Proxy VMs = No of Zones

        self.assertEqual(
            isinstance(list_zones_response, list),
            True,
            "Check list response returns a valid list"
        )

        self.debug("Number of zones: %s" % len(list_zones_response))
        self.debug("Number of CPVMs: %s" % len(list_cpvm_response))

        self.assertEqual(
            len(list_cpvm_response),
            len(list_zones_response),
            "Check number of CPVMs with number of zones"
        )
        # For each CPVM check private IP, public IP, link local IP and DNS
        for cpvm in list_cpvm_response:

            self.debug("CPVM state: %s" % cpvm.state)
            self.assertEqual(
                cpvm.state,
                'Running',
                "Check whether state of CPVM is running"
            )

            self.assertEqual(
                hasattr(cpvm, 'privateip'),
                True,
                "Check whether CPVM has private IP field"
            )

            self.assertEqual(
                hasattr(cpvm, 'linklocalip'),
                True,
                "Check whether CPVM has link local IP field"
            )

            self.assertEqual(
                hasattr(cpvm, 'publicip'),
                True,
                "Check whether CPVM has public IP field"
            )
            # Fetch corresponding ip ranges information from listVlanIpRanges
            ipranges_response = list_vlan_ipranges(
                self.apiclient,
                zoneid=cpvm.zoneid
            )
            self.assertEqual(
                isinstance(ipranges_response, list),
                True,
                "Check list response returns a valid list"
            )

            # Fetch corresponding Physical Network of SSVM's Zone
            listphyntwk = PhysicalNetwork.list(
                self.apiclient,
                zoneid=cpvm.zoneid
            )

            # Execute the following assertion in all zones except EIP-ELB Zones
            if not (
                self.zone.networktype.lower() == 'basic' and isinstance(
                    NetScaler.list(
                        self.apiclient,
                        physicalnetworkid=listphyntwk[0].id),
                    list) is True):
                gatewayFound = False
                for iprange in ipranges_response:
                    if iprange.gateway == cpvm.gateway:
                        gatewayFound = True
                        break
                self.assertTrue(
                    gatewayFound,
                    "Check gateway with that of corresponding ip range"
                )

            # Fetch corresponding zone information from listZones
            zone_response = list_zones(
                self.apiclient,
                id=cpvm.zoneid
            )

            self.assertEqual(
                cpvm.dns1,
                zone_response[0].dns1,
                "Check DNS1 with that of corresponding zone"
            )

            self.assertEqual(
                cpvm.dns2,
                zone_response[0].dns2,
                "Check DNS2 with that of corresponding zone"
            )
예제 #24
0
    def test_02_list_cpvm_vm(self):
        """Test List console proxy VMs
        """

        # Validate the following:
        # 1. listSystemVM (systemvmtype=consoleproxy) should return
        #    at least ONE CPVM per zone
        # 2. The returned ConsoleProxyVM should be in Running state
        # 3. listSystemVM for console proxy should list publicip, privateip
        #    and link-localip
        # 4. The gateway programmed on the console proxy should be the same
        #    as the gateway returned by listZones
        # 5. DNS entries must match those given for the zone

        list_cpvm_response = list_ssvms(
            self.apiclient,
            systemvmtype='consoleproxy',
            state='Running',
        )
        self.assertEqual(isinstance(list_cpvm_response, list), True,
                         "Check list response returns a valid list")
        # Verify CPVM response
        self.assertNotEqual(len(list_cpvm_response), 0,
                            "Check list System VMs response")
        list_zones_response = list_zones(self.apiclient)
        # Number of Console Proxy VMs = No of Zones

        self.assertEqual(isinstance(list_zones_response, list), True,
                         "Check list response returns a valid list")

        self.debug("Number of zones: %s" % len(list_zones_response))
        self.debug("Number of CPVMs: %s" % len(list_cpvm_response))

        self.assertEqual(len(list_cpvm_response), len(list_zones_response),
                         "Check number of CPVMs with number of zones")
        # For each CPVM check private IP, public IP, link local IP and DNS
        for cpvm in list_cpvm_response:

            self.debug("CPVM state: %s" % cpvm.state)
            self.assertEqual(cpvm.state, 'Running',
                             "Check whether state of CPVM is running")

            self.assertEqual(hasattr(cpvm, 'privateip'), True,
                             "Check whether CPVM has private IP field")

            self.assertEqual(hasattr(cpvm, 'linklocalip'), True,
                             "Check whether CPVM has link local IP field")

            self.assertEqual(hasattr(cpvm, 'publicip'), True,
                             "Check whether CPVM has public IP field")
            # Fetch corresponding ip ranges information from listVlanIpRanges
            ipranges_response = list_vlan_ipranges(self.apiclient,
                                                   zoneid=cpvm.zoneid)
            self.assertEqual(isinstance(ipranges_response, list), True,
                             "Check list response returns a valid list")

            # Fetch corresponding Physical Network of SSVM's Zone
            listphyntwk = PhysicalNetwork.list(self.apiclient,
                                               zoneid=cpvm.zoneid)

            # Execute the following assertion in all zones except EIP-ELB Zones
            if not (self.zone.networktype.lower() == 'basic' and isinstance(
                    NetScaler.list(self.apiclient,
                                   physicalnetworkid=listphyntwk[0].id), list)
                    is True):
                gatewayFound = False
                for iprange in ipranges_response:
                    if iprange.gateway == cpvm.gateway:
                        gatewayFound = True
                        break
                self.assertTrue(
                    gatewayFound,
                    "Check gateway with that of corresponding ip range")

            # Fetch corresponding zone information from listZones
            zone_response = list_zones(self.apiclient, id=cpvm.zoneid)

            self.assertEqual(cpvm.dns1, zone_response[0].dns1,
                             "Check DNS1 with that of corresponding zone")

            self.assertEqual(cpvm.dns2, zone_response[0].dns2,
                             "Check DNS2 with that of corresponding zone")
예제 #25
0
    if clusters:
      for cluster in clusters:
        print "cluster name={}, id={}".format(cluster.name, cluster.id)
        if cluster.allocationstate == 'Enabled':
          print "Delete Cluster"
          c = Cluster(tmp_dict)
          c.id = cluster.id
          c.delete(apiClient)

    ipranges = PublicIpRange.list(apiClient)
    if ipranges:
      for iprange in ipranges:
        print "ip range name={}, id={}".format(iprange.name, iprange.id)

    if clusters:
      nets = PhysicalNetwork.list(apiClient)
      if nets:
        for net in nets:
          print "net name={}, id={}".format(net.name, net.id)
          print "Delete PhysicalNetwork"
          n = PhysicalNetwork(tmp_dict)
          n.id = net.id
          n.delete(apiClient)

    pods = Pod.list(apiClient)
    if pods:
      for pod in pods:
        print "pod name={}, id={}".format(pod.name, pod.id)
        print "Delete Pod"
        p = Pod(tmp_dict)
        p.id = pod.id
예제 #26
0
def get_free_vlan(apiclient, zoneid):
    """
    Find an unallocated VLAN outside the range allocated to the physical network.

    @note: This does not guarantee that the VLAN is available for use in
    the deployment's network gear
    @return: physical_network, shared_vlan_tag
    """
    list_physical_networks_response = PhysicalNetwork.list(
        apiclient,
        zoneid=zoneid
    )
    assert isinstance(list_physical_networks_response, list)
    assert len(
        list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid

    physical_network = list_physical_networks_response[0]

    networks = list_networks(apiclient, zoneid=zoneid, type='Shared')
    usedVlanIds = []

    if isinstance(networks, list) and len(networks) > 0:
        usedVlanIds = [int(nw.vlan)
                       for nw in networks if nw.vlan != "untagged"]

    if hasattr(physical_network, "vlan") is False:
        while True:
            shared_ntwk_vlan = random.randrange(1, 4095)
            if shared_ntwk_vlan in usedVlanIds:
                continue
            else:
                break
    else:
        vlans = xsplit(physical_network.vlan, ['-', ','])

        assert len(vlans) > 0
        assert int(vlans[0]) < int(
            vlans[-1]), "VLAN range  %s was improperly split" % physical_network.vlan

        # Assuming random function will give different integer each time
        retriesCount = 20

        shared_ntwk_vlan = None

        while True:

            if retriesCount == 0:
                break

            free_vlan = int(vlans[-1]) + random.randrange(1, 20)

            if free_vlan > 4095:
                free_vlan = int(vlans[0]) - random.randrange(1, 20)
            if free_vlan < 0 or (free_vlan in usedVlanIds):
                retriesCount -= 1
                continue
            else:
                shared_ntwk_vlan = free_vlan
                break

    return physical_network, shared_ntwk_vlan
예제 #27
0
def setNonContiguousVlanIds(apiclient, zoneid):
    """
    Form the non contiguous ranges based on currently assigned range in physical network
    """

    NonContigVlanIdsAcquired = False

    list_physical_networks_response = PhysicalNetwork.list(
        apiclient,
        zoneid=zoneid
    )
    assert isinstance(list_physical_networks_response, list)
    assert len(
        list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid

    for physical_network in list_physical_networks_response:

        vlans = xsplit(physical_network.vlan, ['-', ','])

        assert len(vlans) > 0
        assert int(vlans[0]) < int(
            vlans[-1]), "VLAN range  %s was improperly split" % physical_network.vlan

        # Keep some gap between existing vlan and the new vlans which we are going to add
        # So that they are non contiguous

        non_contig_end_vlan_id = int(vlans[-1]) + 6
        non_contig_start_vlan_id = int(vlans[0]) - 6

        # Form ranges which are consecutive to existing ranges but not immediately contiguous
        # There should be gap in between existing range and new non contiguous
        # ranage

        # If you can't add range after existing range, because it's crossing 4095, then
        # select VLAN ids before the existing range such that they are greater than 0, and
        # then add this non contiguoud range
        vlan = {"partial_range": ["", ""], "full_range": ""}

        if non_contig_end_vlan_id < 4095:
            vlan["partial_range"][0] = str(
                non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id - 3)
            vlan["partial_range"][1] = str(
                non_contig_end_vlan_id - 1) + '-' + str(non_contig_end_vlan_id)
            vlan["full_range"] = str(
                non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id)
            NonContigVlanIdsAcquired = True

        elif non_contig_start_vlan_id > 0:
            vlan["partial_range"][0] = str(
                non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 1)
            vlan["partial_range"][1] = str(
                non_contig_start_vlan_id + 3) + '-' + str(non_contig_start_vlan_id + 4)
            vlan["full_range"] = str(
                non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 4)
            NonContigVlanIdsAcquired = True

        else:
            NonContigVlanIdsAcquired = False

        # If failed to get relevant vlan ids, continue to next physical network
        # else break from loop as we have hot the non contiguous vlan ids for
        # the test purpose

        if not NonContigVlanIdsAcquired:
            continue
        else:
            break

    # If even through looping from all existing physical networks, failed to get relevant non
    # contiguous vlan ids, then fail the test case

    if not NonContigVlanIdsAcquired:
        return None, None

    return physical_network, vlan
예제 #28
0
    def setUpClass(cls, zone=None):
        cls.debug("setUpClass nuageTestCase")

        # We want to fail quicker, if it's a failure
        socket.setdefaulttimeout(60)

        test_client = super(nuageTestCase, cls).getClsTestClient()
        cls.api_client = test_client.getApiClient()
        cls.db_client = test_client.getDbConnection()
        cls.test_data = test_client.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        cls.zone = get_zone(cls.api_client,
                            zone_name=zone.name if zone else None,
                            zone_id=zone.id if zone else None)
        cls.domain = get_domain(cls.api_client)
        cls.template = get_template(cls.api_client, cls.zone.id,
                                    cls.test_data["ostype"])
        cls.test_data["virtual_machine"]["zoneid"] = cls.zone.id
        cls.test_data["virtual_machine"]["template"] = cls.template.id

        # Create service offering
        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.test_data["service_offering"])
        cls._cleanup = [cls.service_offering]

        # Check if the host hypervisor type is simulator
        cls.isSimulator = Hypervisor.list(
            cls.api_client, zoneid=cls.zone.id)[0].name == "Simulator"

        # Get configured Nuage VSP device details
        try:
            physical_networks = PhysicalNetwork.list(cls.api_client,
                                                     zoneid=cls.zone.id)
            for pn in physical_networks:
                if pn.isolationmethods == "VSP":
                    cls.vsp_physical_network = pn
                    break
            cls.nuage_vsp_device = Nuage.list(
                cls.api_client,
                physicalnetworkid=cls.vsp_physical_network.id)[0]
            pns = cls.config.zones[0].physical_networks
            providers = filter(
                lambda physical_network: "VSP" in physical_network.
                isolationmethods, pns)[0].providers
            devices = filter(lambda provider: provider.name == "NuageVsp",
                             providers)[0].devices
            cls.nuage_vsp_device.username = devices[0].username
            cls.nuage_vsp_device.password = devices[0].password
            cls.cms_id = cls.nuage_vsp_device.cmsid
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest(
                "Warning: Could not get configured Nuage VSP device details - %s"
                % e)

        # VSD is a programmable policy and analytics engine of Nuage VSP SDN platform
        # vspk is a Python SDK for Nuage VSP's VSD
        # libVSD is a library that wraps vspk package
        try:
            vspk_module = "vspk." + cls.nuage_vsp_device.apiversion if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \
                else "vspk.vsdk." + cls.nuage_vsp_device.apiversion
            cls.vsdk = importlib.import_module(vspk_module)
            from libVSD import ApiClient, VSDHelpers
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest(
                "Warning: vspk (and/or) libVSD package import failure - %s" %
                e)

        # Configure VSD session
        cls._session = cls.vsdk.NUVSDSession(
            username=cls.nuage_vsp_device.username,
            password=cls.nuage_vsp_device.password,
            enterprise="csp",
            api_url="https://%s:%d" %
            (cls.nuage_vsp_device.hostname, cls.nuage_vsp_device.port))
        cls._session.start()

        # Configure libVSD session
        root = logging.getLogger()
        log_handler = logging.StreamHandler(sys.stdout)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        log_handler.setFormatter(formatter)
        root.addHandler(log_handler)
        vsd_info = cls.nuage_vsp_device.__dict__
        cls.debug("Nuage VSP device (VSD) details - %s" % vsd_info)
        vsd_api_client = ApiClient(address=vsd_info["hostname"],
                                   user=vsd_info["username"],
                                   password=vsd_info["password"],
                                   version=vsd_info["apiversion"][1] + "." +
                                   vsd_info["apiversion"][3])
        vsd_api_client.new_session()
        cls.vsd = VSDHelpers(vsd_api_client)

        cls.debug("setUpClass nuageTestCase [DONE]")
예제 #29
0
    def setUpClass(cls, zone=None):
        cls.debug("setUpClass nuageTestCase")

        # We want to fail quicker, if it's a failure
        socket.setdefaulttimeout(60)

        test_client = super(nuageTestCase, cls).getClsTestClient()
        cls.api_client = test_client.getApiClient()
        cls.db_client = test_client.getDbConnection()
        cls.test_data = test_client.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.zone = get_zone(cls.api_client,
                            zone_name=zone.name if zone else None,
                            zone_id=zone.id if zone else None
                            )
        cls.domain = get_domain(cls.api_client)
        cls.template = get_template(cls.api_client,
                                    cls.zone.id,
                                    cls.test_data["ostype"]
                                    )
        cls.test_data["virtual_machine"]["zoneid"] = cls.zone.id
        cls.test_data["virtual_machine"]["template"] = cls.template.id

        # Create service offering
        cls.service_offering = ServiceOffering.create(cls.api_client,
                                                      cls.test_data["service_offering"]
                                                      )
        cls._cleanup = [cls.service_offering]

        # Get configured Nuage VSP device details
        try:
            physical_networks = PhysicalNetwork.list(cls.api_client, zoneid=cls.zone.id)
            for pn in physical_networks:
                if pn.isolationmethods == "VSP":
                    cls.vsp_physical_network = pn
                    break
            cls.nuage_vsp_device = Nuage.list(cls.api_client,
                                              physicalnetworkid=cls.vsp_physical_network.id
                                              )[0]
            pns = cls.config.zones[0].physical_networks
            providers = filter(lambda physical_network: "VSP" in physical_network.isolationmethods, pns)[0].providers
            devices = filter(lambda provider: provider.name == "NuageVsp", providers)[0].devices
            cls.nuage_vsp_device.username = devices[0].username
            cls.nuage_vsp_device.password = devices[0].password
            cls.cms_id = cls.nuage_vsp_device.cmsid
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Warning: Couldn't get configured Nuage VSP device details: %s" % e)

        # Check if the host hypervisor type is simulator
        cls.isSimulator = Hypervisor.list(cls.api_client, zoneid=cls.zone.id)[0].name == "Simulator"

        # VSD is a programmable policy and analytics engine of Nuage VSP SDN platform
        # vspk is a Python SDK for Nuage VSP's VSD
        # cms_vspk_wrapper is a library that wraps vspk package
        try:
            vspk_module = "vspk." + cls.nuage_vsp_device.apiversion if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \
                else "vspk.vsdk." + cls.nuage_vsp_device.apiversion
            cls.vsdk = importlib.import_module(vspk_module)
            vspk_utils_module = "vspk.utils" if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \
                else "vspk.vsdk." + cls.nuage_vsp_device.apiversion + ".utils"
            vsdk_utils = importlib.import_module(vspk_utils_module)
            set_log_level = getattr(vsdk_utils, "set_log_level")
            from cms_vspk_wrapper.cms_vspk_wrapper import Cms_vspk_wrapper
        except:
            raise unittest.SkipTest("vspk (and/or) cms_vspk_wrapper import failure")

        # Configure VSD session
        cls._session = cls.vsdk.NUVSDSession(username=cls.nuage_vsp_device.username,
                                             password=cls.nuage_vsp_device.password,
                                             enterprise="csp", api_url="https://%s:%d" %
                                                                       (cls.nuage_vsp_device.hostname,
                                                                        cls.nuage_vsp_device.port)
                                             )
        cls._session.start()

        # Configure cms_vspk_wrapper session
        cls.log_handler = logging.getLogger("CSLog").handlers[0]
        vsd_info = cls.nuage_vsp_device.__dict__
        vsd_info["port"] = str(vsd_info["port"])
        cls.vsd = Cms_vspk_wrapper(vsd_info, cls.log_handler)

        set_log_level(logging.INFO)

        cls.debug("setUpClass nuageTestCase [DONE]")
예제 #30
0
def setNonContiguousVlanIds(apiclient, zoneid):
    """
    Form the non contiguous ranges based on currently assigned range in physical network
    """

    NonContigVlanIdsAcquired = False

    list_physical_networks_response = PhysicalNetwork.list(apiclient, zoneid=zoneid)
    assert isinstance(list_physical_networks_response, list)
    assert len(list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid

    for physical_network in list_physical_networks_response:

        vlans = xsplit(physical_network.vlan, ["-", ","])

        assert len(vlans) > 0
        assert int(vlans[0]) < int(vlans[-1]), "VLAN range  %s was improperly split" % physical_network.vlan

        # Keep some gap between existing vlan and the new vlans which we are going to add
        # So that they are non contiguous

        non_contig_end_vlan_id = int(vlans[-1]) + 6
        non_contig_start_vlan_id = int(vlans[0]) - 6

        # Form ranges which are consecutive to existing ranges but not immediately contiguous
        # There should be gap in between existing range and new non contiguous
        # ranage

        # If you can't add range after existing range, because it's crossing 4095, then
        # select VLAN ids before the existing range such that they are greater than 0, and
        # then add this non contiguoud range
        vlan = {"partial_range": ["", ""], "full_range": ""}

        if non_contig_end_vlan_id < 4095:
            vlan["partial_range"][0] = str(non_contig_end_vlan_id - 4) + "-" + str(non_contig_end_vlan_id - 3)
            vlan["partial_range"][1] = str(non_contig_end_vlan_id - 1) + "-" + str(non_contig_end_vlan_id)
            vlan["full_range"] = str(non_contig_end_vlan_id - 4) + "-" + str(non_contig_end_vlan_id)
            NonContigVlanIdsAcquired = True

        elif non_contig_start_vlan_id > 0:
            vlan["partial_range"][0] = str(non_contig_start_vlan_id) + "-" + str(non_contig_start_vlan_id + 1)
            vlan["partial_range"][1] = str(non_contig_start_vlan_id + 3) + "-" + str(non_contig_start_vlan_id + 4)
            vlan["full_range"] = str(non_contig_start_vlan_id) + "-" + str(non_contig_start_vlan_id + 4)
            NonContigVlanIdsAcquired = True

        else:
            NonContigVlanIdsAcquired = False

        # If failed to get relevant vlan ids, continue to next physical network
        # else break from loop as we have hot the non contiguous vlan ids for
        # the test purpose

        if not NonContigVlanIdsAcquired:
            continue
        else:
            break

    # If even through looping from all existing physical networks, failed to get relevant non
    # contiguous vlan ids, then fail the test case

    if not NonContigVlanIdsAcquired:
        return None, None

    return physical_network, vlan
예제 #31
0
    def setUpClass(cls, zone=None):
        cls.debug("setUpClass nuageTestCase")

        # We want to fail quicker, if it's a failure
        socket.setdefaulttimeout(60)

        test_client = super(nuageTestCase, cls).getClsTestClient()
        cls.api_client = test_client.getApiClient()
        cls.db_client = test_client.getDbConnection()
        cls.test_data = test_client.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        cls.zone = get_zone(cls.api_client,
                            zone_name=zone.name if zone else None,
                            zone_id=zone.id if zone else None
                            )
        cls.domain = get_domain(cls.api_client)
        cls.template = get_template(cls.api_client,
                                    cls.zone.id,
                                    cls.test_data["ostype"]
                                    )
        cls.test_data["virtual_machine"]["zoneid"] = cls.zone.id
        cls.test_data["virtual_machine"]["template"] = cls.template.id

        # Create service offering
        cls.service_offering = ServiceOffering.create(cls.api_client,
                                                      cls.test_data["service_offering"]
                                                      )
        cls._cleanup = [cls.service_offering]

        # Check if the host hypervisor type is simulator
        cls.isSimulator = Hypervisor.list(cls.api_client, zoneid=cls.zone.id)[0].name == "Simulator"

        # Get configured Nuage VSP device details
        try:
            physical_networks = PhysicalNetwork.list(cls.api_client, zoneid=cls.zone.id)
            for pn in physical_networks:
                if pn.isolationmethods == "VSP":
                    cls.vsp_physical_network = pn
                    break
            cls.nuage_vsp_device = Nuage.list(cls.api_client,
                                              physicalnetworkid=cls.vsp_physical_network.id
                                              )[0]
            pns = cls.config.zones[0].physical_networks
            providers = filter(lambda physical_network: "VSP" in physical_network.isolationmethods, pns)[0].providers
            devices = filter(lambda provider: provider.name == "NuageVsp", providers)[0].devices
            cls.nuage_vsp_device.username = devices[0].username
            cls.nuage_vsp_device.password = devices[0].password
            cls.cms_id = cls.nuage_vsp_device.cmsid
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Warning: Could not get configured Nuage VSP device details - %s" % e)

        # VSD is a programmable policy and analytics engine of Nuage VSP SDN platform
        # vspk is a Python SDK for Nuage VSP's VSD
        # libVSD is a library that wraps vspk package
        try:
            vspk_module = "vspk." + cls.nuage_vsp_device.apiversion if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \
                else "vspk.vsdk." + cls.nuage_vsp_device.apiversion
            cls.vsdk = importlib.import_module(vspk_module)
            from libVSD import ApiClient, VSDHelpers
        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Warning: vspk (and/or) libVSD package import failure - %s" % e)

        # Configure VSD session
        cls._session = cls.vsdk.NUVSDSession(username=cls.nuage_vsp_device.username,
                                             password=cls.nuage_vsp_device.password,
                                             enterprise="csp",
                                             api_url="https://%s:%d" % (cls.nuage_vsp_device.hostname,
                                                                        cls.nuage_vsp_device.port)
                                             )
        cls._session.start()

        # Configure libVSD session
        root = logging.getLogger()
        log_handler = logging.StreamHandler(sys.stdout)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        log_handler.setFormatter(formatter)
        root.addHandler(log_handler)
        vsd_info = cls.nuage_vsp_device.__dict__
        cls.debug("Nuage VSP device (VSD) details - %s" % vsd_info)
        vsd_api_client = ApiClient(address=vsd_info["hostname"],
                                   user=vsd_info["username"],
                                   password=vsd_info["password"],
                                   version=vsd_info["apiversion"][1] + "." + vsd_info["apiversion"][3]
                                   )
        vsd_api_client.new_session()
        cls.vsd = VSDHelpers(vsd_api_client)

        cls.debug("setUpClass nuageTestCase [DONE]")