weizhouapache commented on a change in pull request #5769: URL: https://github.com/apache/cloudstack/pull/5769#discussion_r778642363
########## File path: test/integration/smoke/test_user_shared_network.py ########## @@ -0,0 +1,630 @@ +# 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. + +""" +Tests of user-shared networks +""" + +import logging +import time + +from nose.plugins.attrib import attr +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.utils import cleanup_resources, random_gen + +from marvin.lib.base import (Account, + Domain, + Project, + Configurations, + ServiceOffering, + Zone, + Network, + NetworkOffering, + VPC, + VpcOffering) + +from marvin.lib.common import (get_domain, + get_zone, + get_template) + +NETWORK_STATE_ALLOCATED = "Allocated" +NETWORK_STATE_IMPLEMENTED = "Implemented" +NETWORK_STATE_SETUP = "Setup" +NETWORK_STATE_REMOVED = "Removed" + +class TestUserSharedNetworks(cloudstackTestCase): + """ + Test user-shared networks + """ + @classmethod + def setUpClass(cls): + cls.testClient = super( + TestUserSharedNetworks, + cls).getClsTestClient() + cls.apiclient = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + + zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) + cls.zone = Zone(zone.__dict__) + cls.template = get_template(cls.apiclient, cls.zone.id) + cls._cleanup = [] + + cls.logger = logging.getLogger("TestUserSharedNetworks") + cls.stream_handler = logging.StreamHandler() + cls.logger.setLevel(logging.DEBUG) + cls.logger.addHandler(cls.stream_handler) + + cls.domain = get_domain(cls.apiclient) + + # Create sub-domain + cls.sub_domain = Domain.create( + cls.apiclient, + cls.services["acl"]["domain1"] + ) + + # Create domain admin and normal user + cls.domain_admin = Account.create( + cls.apiclient, + cls.services["acl"]["accountD1A"], + admin=True, + domainid=cls.sub_domain.id + ) + cls.normal_user = Account.create( + cls.apiclient, + cls.services["acl"]["accountD1B"], + domainid=cls.sub_domain.id + ) + # Create project + cls.project = Project.create( + cls.apiclient, + cls.services["project"], + account=cls.domain_admin.name, + domainid=cls.domain_admin.domainid + ) + + # Create small service offering + cls.service_offering = ServiceOffering.create( + cls.apiclient, + cls.services["service_offerings"]["small"] + ) + + # Create network offering for user-shared networks (specifyVlan=true) + cls.network_offering_withvlan = NetworkOffering.create( + cls.apiclient, + cls.services["network_offering_shared"] + ) + cls.network_offering_withvlan.update(cls.apiclient, state='Enabled') + + # Create network offering for user-shared networks (specifyVlan=false) + cls.services["network_offering_shared"]["specifyVlan"] = "False" + cls.network_offering_novlan = NetworkOffering.create( + cls.apiclient, + cls.services["network_offering_shared"] + ) + cls.network_offering_novlan.update(cls.apiclient, state='Enabled') + + # Create network offering for isolated networks + cls.network_offering_isolated = NetworkOffering.create( + cls.apiclient, + cls.services["network_offering"] + ) + cls.network_offering_isolated.update(cls.apiclient, state='Enabled') + + # Create vpc offering + cls.vpc_offering = VpcOffering.create( + cls.apiclient, + cls.services["vpc_offering_multi_lb"]) + cls.vpc_offering.update(cls.apiclient, state='Enabled') + + # Create network offering for vpc tiers + cls.network_offering_vpc = NetworkOffering.create( + cls.apiclient, + cls.services["nw_offering_isolated_vpc"], + conservemode=False + ) + cls.network_offering_vpc.update(cls.apiclient, state='Enabled') + + # Create api clients for domain admin and normal user + cls.domainadmin_user = cls.domain_admin.user[0] + cls.domainapiclient = cls.testClient.getUserApiClient( + cls.domainadmin_user.username, cls.sub_domain.name + ) + cls.normaluser_user = cls.normal_user.user[0] + cls.normaluser_apiclient = cls.testClient.getUserApiClient( + cls.normaluser_user.username, cls.sub_domain.name + ) + + cls._cleanup.append(cls.service_offering) + cls._cleanup.append(cls.network_offering_withvlan) + cls._cleanup.append(cls.network_offering_novlan) + cls._cleanup.append(cls.network_offering_isolated) + cls._cleanup.append(cls.network_offering_vpc) + cls._cleanup.append(cls.vpc_offering) + + cls._cleanup.append(cls.sub_domain) + cls._cleanup.append(cls.normal_user) + cls._cleanup.append(cls.domain_admin) + cls._cleanup.append(cls.project) + + @classmethod + def tearDownClass(cls): + super(TestUserSharedNetworks, cls).tearDownClass() + + def setUp(self): + self.cleanup = [] + + def tearDown(self): + super(TestUserSharedNetworks, self).tearDown() + + def create_shared_network_for_account(self, apiclient, domain, account, expected=True): + return self.create_shared_network_with_associated_network(apiclient, domain, account, None, None, expected) + + def create_shared_network_with_associated_network_for_domain(self, apiclient, domain, associated_network, expected=True): + return self.create_shared_network_with_associated_network(apiclient, domain, None, None, associated_network, expected) + + def create_shared_network_with_associated_network_for_caller(self, apiclient, project, associated_network, expected=True): + return self.create_shared_network_with_associated_network(apiclient, None, None, project, associated_network, expected) + + def create_shared_network_with_associated_network(self, apiclient, domain, account, project, associated_network, expected=True): + self.services["network2"]["acltype"] = "Account" + self.services["network2"]["name"] = "Test Network Shared - " + random_gen() + domain_id = None + account_name = None + project_id = None + if domain: + self.services["network2"]["acltype"] = "Domain" + domain_id = domain.id + if account: + self.services["network2"]["acltype"] = "Account" + account_name = account.name + if project: + self.services["network2"]["acltype"] = "Account" + project_id = project.id + associated_network_id = None + if associated_network: + associated_network_id = associated_network.id + try: + network = Network.create( + apiclient, + self.services["network2"], + domainid=domain_id, + accountid=account_name, + projectid=project_id, + associatednetworkid=associated_network_id, + zoneid=self.zone.id + ) Review comment: @DaanHoogland these networks will be cleaned when remove the project and account. networks will be removed by following order: shared, isolated network or vpc. it is complicated to manage the order in smoke test. therefore I would like to keep like this. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
