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
        vlan1 = 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 = 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")
Example #2
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

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

        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
    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)

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

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

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

        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"][1]) == -1, "vlan range is not removed")

        return
    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
Example #5
0
    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
Example #6
0
    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
Example #7
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
        vlan1 = 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 = 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")
Example #8
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

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

        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
 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, removevlan = self.vlan["full"])
     self.assert_(updateResponse.vlan.find(self.vlan["full"]) < 0,
         "VLAN was not removed successfully")
Example #10
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"]) < 0,
         "VLAN was not removed successfully")
Example #11
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
    def setNonContiguousVlanIds(self, 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:

            self.physicalnetwork = physical_network
            self.physicalnetworkid = physical_network.id
            self.existingvlan = physical_network.vlan

            vlans = xsplit(self.existingvlan, ['-', ','])

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

            # 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

            if non_contig_end_vlan_id < 4095:

                self.vlan["partial_range"][0] = str(
                    non_contig_end_vlan_id -
                    4) + '-' + str(non_contig_end_vlan_id - 3)
                self.vlan["partial_range"][1] = str(non_contig_end_vlan_id -
                                                    1) + '-' + str(
                                                        non_contig_end_vlan_id)
                self.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:

                self.vlan["partial_range"][0] = str(
                    non_contig_start_vlan_id) + '-' + str(
                        non_contig_start_vlan_id + 1)
                self.vlan["partial_range"][1] = str(
                    non_contig_start_vlan_id +
                    3) + '-' + str(non_contig_start_vlan_id + 4)
                self.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:
            self.fail(
                "Failed to set non contiguous vlan ids to test. Free some ids from \
                        from existing physical networks at extreme ends")

        return