You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/07/08 10:11:20 UTC

[GitHub] [cloudstack] DaanHoogland commented on a diff in pull request #6338: test: add, refactor ipv6 network, vpc tests

DaanHoogland commented on code in PR #6338:
URL: https://github.com/apache/cloudstack/pull/6338#discussion_r916673320


##########
test/integration/smoke/test_vpc_ipv6.py:
##########
@@ -0,0 +1,901 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+""" BVT test for IPv6 VPC"""
+
+#Import Local Modules
+from marvin.codes import FAILED
+from marvin.cloudstackTestCase import cloudstackTestCase
+from marvin.cloudstackAPI import (createGuestNetworkIpv6Prefix,
+                                  listGuestNetworkIpv6Prefixes,
+                                  deleteGuestNetworkIpv6Prefix)
+from marvin.lib.utils import (isAlmostEqual,
+                              random_gen,
+                              get_process_status,
+                              get_host_credentials)
+from marvin.lib.base import (Configurations,
+                             Domain,
+                             NetworkOffering,
+                             VpcOffering,
+                             Account,
+                             PublicIpRange,
+                             Network,
+                             VPC,
+                             Router,
+                             ServiceOffering,
+                             VirtualMachine,
+                             NIC,
+                             Host,
+                             NetworkACLList,
+                             NetworkACL)
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_test_template,
+                               get_template)
+from marvin.sshClient import SshClient
+from marvin.cloudstackException import CloudstackAPIException
+from marvin.lib.decoratorGenerators import skipTestIf
+
+from nose.plugins.attrib import attr
+from ipaddress import IPv6Network
+from random import getrandbits, choice, randint
+import time
+import logging
+import threading
+
+ipv6_offering_config_name = "ipv6.offering.enabled"
+ULA_BASE = IPv6Network("fd00::/8")
+PREFIX_OPTIONS = [i for i in range(48, 65, 4)]
+ACL_TABLE = "ip6_acl"
+ACL_CHAINS_SUFFIX = {
+    "Ingress": "_ingress_policy",
+    "Egress": "_egress_policy"
+}
+CIDR_IPV6_ANY = "::/0"
+ICMPV6_TYPE = {
+    1: "destination-unreachable",
+    2: "packet-too-big",
+    3: "time-exceeded",
+    4: "parameter-problem",
+    128: "echo-request",
+    129: "echo-reply",
+    130: "mld-listener-query",
+    131: "mld-listener-report",
+    132: "mld-listener-done",
+    133: "nd-router-solicit",
+    134: "nd-router-advert",
+    135: "nd-neighbor-solicit",
+    136: "nd-neighbor-advert",
+    137: "nd-redirect",
+    138: "router-renumbering",
+    141: "ind-neighbor-solicit",
+    142: "ind-neighbor-advert",
+    143: "mld2-listener-report"
+}
+ICMPV6_CODE_TYPE = {
+    0: "no-route",
+    1: "admin-prohibited",
+    3: "addr-unreachable",
+    4: "port-unreachable",
+    5: "policy-fail",
+    6: "reject-route"
+}
+ICMPV6_TYPE_ANY = "{ destination-unreachable, packet-too-big, time-exceeded, parameter-problem, echo-request, echo-reply, mld-listener-query, mld-listener-report, mld-listener-done, nd-router-solicit, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, nd-redirect, router-renumbering }"
+TCP_UDP_PORT_ANY = "{ 0-65535 }"
+VPC_ROUTER_PUBLIC_NIC = "eth1"
+VPC_ROUTER_GUEST_NIC = "eth2"
+VPC_DATA = {
+    "cidr": "10.1.0.0/22",
+    "tier1_gateway": "10.1.1.1",
+    "tier2_gateway": "10.1.2.1",
+    "tier_netmask": "255.255.255.0"
+}
+ROUTE_TEST_VPC_DATA = {
+    "cidr": "10.2.0.0/22",
+    "tier1_gateway": "10.2.1.1",
+    "tier_netmask": "255.255.255.0"
+}
+SLEEP_BEFORE_VR_CHANGES = 90
+PING_RETRIES = 5
+PING_SLEEP = 20
+
+
+class TestIpv6Vpc(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        testClient = super(TestIpv6Vpc, cls).getClsTestClient()
+        cls.services = testClient.getParsedTestDataConfig()
+        cls.apiclient = testClient.getApiClient()
+        cls.dbclient = testClient.getDbConnection()
+        cls.test_ipv6_guestprefix = None
+        cls.initial_ipv6_offering_enabled = None
+        cls._cleanup = []
+        cls.routerDetailsMap = {}
+        cls.vpcAllowAllAclDetailsMap = {}
+
+        cls.logger = logging.getLogger('TestIpv6Vpc')
+
+        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
+        cls.services['mode'] = cls.zone.networktype
+        cls.ipv6NotSupported = False
+
+        ipv6_guestprefix = cls.getGuestIpv6Prefix()
+        if ipv6_guestprefix == None:
+            cls.ipv6NotSupported = True
+        if cls.ipv6NotSupported == False:
+            ipv6_publiciprange = cls.getPublicIpv6Range()
+            if ipv6_publiciprange == None:
+                cls.ipv6NotSupported = True
+
+        if cls.ipv6NotSupported == False:
+            cls.initial_ipv6_offering_enabled = Configurations.list(
+                cls.apiclient,
+                name=ipv6_offering_config_name)[0].value
+            Configurations.update(cls.apiclient,
+                ipv6_offering_config_name,
+                "true")
+            cls.domain = get_domain(cls.apiclient)
+            cls.account = Account.create(
+                cls.apiclient,
+                cls.services["account"],
+                admin=True,
+                domainid=cls.domain.id
+            )
+            cls._cleanup.append(cls.account)
+            cls.hypervisor = testClient.getHypervisorInfo()
+            cls.template = get_test_template(
+               cls.apiclient,
+               cls.zone.id,
+               cls.hypervisor)
+        else:
+            cls.debug("IPv6 is not supported, skipping tests!")
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        if cls.initial_ipv6_offering_enabled != None:
+            Configurations.update(cls.apiclient,
+                ipv6_offering_config_name,
+                cls.initial_ipv6_offering_enabled)
+        try:
+            super(TestIpv6Vpc, cls).tearDownClass()
+        finally:
+            if cls.test_ipv6_guestprefix != None:
+                cmd = deleteGuestNetworkIpv6Prefix.deleteGuestNetworkIpv6PrefixCmd()
+                cmd.id = cls.test_ipv6_guestprefix.id
+                cls.apiclient.deleteGuestNetworkIpv6Prefix(cmd)
+
+    @classmethod
+    def getGuestIpv6Prefix(cls):
+        cmd = listGuestNetworkIpv6Prefixes.listGuestNetworkIpv6PrefixesCmd()
+        cmd.zoneid = cls.zone.id
+        ipv6_prefixes_response = cls.apiclient.listGuestNetworkIpv6Prefixes(cmd)
+        if isinstance(ipv6_prefixes_response, list) == True and len(ipv6_prefixes_response) > 0:
+            return ipv6_prefixes_response[0]
+        ipv6_guestprefix_service = cls.services["guestip6prefix"]
+        cmd = createGuestNetworkIpv6Prefix.createGuestNetworkIpv6PrefixCmd()
+        cmd.zoneid = cls.zone.id
+        cmd.prefix = ipv6_guestprefix_service["prefix"]
+        ipv6_guestprefix = cls.apiclient.createGuestNetworkIpv6Prefix(cmd)
+        cls.test_ipv6_guestprefix = ipv6_guestprefix
+        return ipv6_guestprefix
+
+    @classmethod
+    def getPublicIpv6Range(cls):
+        list_public_ip_range_response = PublicIpRange.list(
+            cls.apiclient,
+            zoneid=cls.zone.id
+        )
+        ipv4_range_vlan = None
+        if isinstance(list_public_ip_range_response, list) == True and len(list_public_ip_range_response) > 0:
+            for ip_range in list_public_ip_range_response:
+                if ip_range.ip6cidr != None and ip_range.ip6gateway != None:
+                    return ip_range
+                if ip_range.netmask != None and ip_range.gateway != None:
+                    vlan = ip_range.vlan
+                    if ipv4_range_vlan == None and vlan.startswith("vlan://"):
+                        vlan = vlan.replace("vlan://", "")
+                        if vlan == "untagged":
+                            ipv4_range_vlan = None
+                        else:
+                            ipv4_range_vlan = int(vlan)
+        ipv6_publiciprange_service = cls.services["publicip6range"]
+        ipv6_publiciprange_service["zoneid"] = cls.zone.id
+        ipv6_publiciprange_service["vlan"] = ipv4_range_vlan
+        ipv6_publiciprange = PublicIpRange.create(
+            cls.apiclient,
+            ipv6_publiciprange_service
+        )
+        cls._cleanup.append(ipv6_publiciprange)
+        return ipv6_publiciprange
+
+    def setUp(self):
+        self.services = self.testClient.getParsedTestDataConfig()
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.thread = None
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        try:
+            if self.thread and self.thread.is_alive():
+                self.thread.join(5*60)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        finally:
+            super(TestIpv6Vpc, self).tearDown()
+        return
+
+    def getRandomIpv6Cidr(self):
+        prefix_length = choice(PREFIX_OPTIONS)
+        random_suffix = getrandbits(40) << (128-prefix_length)
+        base_address = ULA_BASE.network_address + random_suffix
+        return str(IPv6Network((base_address, prefix_length)))
+
+    def createTinyServiceOffering(self):
+        self.service_offering = ServiceOffering.create(
+            self.apiclient,
+            self.services["service_offerings"]["big"],
+        )
+        self.cleanup.append(self.service_offering)
+
+    def createVpcOfferingInternal(self, is_redundant, is_ipv6):
+        off_service = self.services["vpc_offering"]
+        if is_redundant:
+            off_service["serviceCapabilityList"] = {
+                "SourceNat": {
+                    "RedundantRouter": 'true'
+                },
+            }
+        if is_ipv6:
+            off_service["internetprotocol"] = "dualstack"
+        vpc_offering = VpcOffering.create(
+            self.apiclient,
+            off_service
+        )
+        self.cleanup.append(vpc_offering)
+        vpc_offering.update(self.apiclient, state='Enabled')
+        return vpc_offering
+
+    def createIpv4VpcOffering(self, is_redundant=False):
+        self.vpc_offering = self.createVpcOfferingInternal(is_redundant, False)
+
+    def createIpv6VpcOffering(self, is_redundant=False):
+        self.vpc_offering = self.createVpcOfferingInternal(is_redundant, True)
+
+    def createIpv6VpcOfferingForUpdate(self, is_redundant=False):
+        self.vpc_offering_update = self.createVpcOfferingInternal(is_redundant, True)
+
+    def createNetworkTierOfferingInternal(self, is_ipv6, remove_lb=True):
+        off_service = self.services["nw_offering_isolated_vpc"]
+        if not remove_lb: # Remove Lb service
+            if "serviceProviderList" in off_service and "Lb" in off_service["serviceProviderList"].keys():
+                providers = off_service["serviceProviderList"]
+                providers.pop("Lb")
+                off_service["serviceProviderList"] = providers
+            if "supportedservices" in off_service and "Lb" in off_service["supportedservices"]:
+                supportedServices = off_service["supportedservices"].split(",")
+                supportedServices.remove("Lb")
+                off_service["supportedservices"] = ",".join(supportedServices)
+        if is_ipv6:
+            off_service["internetprotocol"] = "dualstack"
+        network_offering = NetworkOffering.create(
+            self.apiclient,
+            off_service,
+            conservemode=False
+        )
+        network_offering.update(self.apiclient, state='Enabled')
+        self.cleanup.append(network_offering)

Review Comment:
   if `update()` throws an exception ...
   ```suggestion
           self.cleanup.append(network_offering)
           network_offering.update(self.apiclient, state='Enabled')
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org