weizhouapache commented on a change in pull request #5769:
URL: https://github.com/apache/cloudstack/pull/5769#discussion_r778628113



##########
File path: test/integration/smoke/test_network_permissions.py
##########
@@ -0,0 +1,757 @@
+# 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 network permissions
+"""
+
+import logging
+
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase
+
+from marvin.lib.base import (Account,
+                             Configurations,
+                             Domain,
+                             Project,
+                             ServiceOffering,
+                             VirtualMachine,
+                             Zone,
+                             Network,
+                             NetworkOffering,
+                             NetworkPermission,
+                             NIC,
+                             PublicIPAddress,
+                             LoadBalancerRule,
+                             NATRule,
+                             StaticNATRule,
+
+                             SSHKeyPair)
+
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template)
+
+NETWORK_FILTER_ACCOUNT = 'account'
+NETWORK_FILTER_DOMAIN = 'domain'
+NETWORK_FILTER_ACCOUNT_DOMAIN = 'accountdomain'
+NETWORK_FILTER_SHARED = 'shared'
+NETWORK_FILTER_ALL = 'all'
+
+class TestNetworkPermissions(cloudstackTestCase):
+    """
+    Test user-shared networks
+    """
+    @classmethod
+    def setUpClass(cls):
+        cls.testClient = super(
+            TestNetworkPermissions,
+            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("TestNetworkPermissions")
+        cls.stream_handler = logging.StreamHandler()
+        cls.logger.setLevel(logging.DEBUG)
+        cls.logger.addHandler(cls.stream_handler)
+
+        cls.domain = get_domain(cls.apiclient)
+
+        # Create small service offering
+        cls.service_offering = ServiceOffering.create(
+            cls.apiclient,
+            cls.services["service_offerings"]["small"]
+        )
+        cls._cleanup.append(cls.service_offering)
+
+        # Create network offering for isolated networks
+        cls.network_offering_isolated = NetworkOffering.create(
+            cls.apiclient,
+            cls.services["isolated_network_offering"]
+        )
+        cls.network_offering_isolated.update(cls.apiclient, state='Enabled')
+        cls._cleanup.append(cls.network_offering_isolated)
+
+        # Create sub-domain
+        cls.sub_domain = Domain.create(
+            cls.apiclient,
+            cls.services["acl"]["domain1"]
+        )
+        cls._cleanup.append(cls.sub_domain)
+
+        # 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._cleanup.append(cls.domain_admin)
+
+        cls.network_owner = Account.create(
+            cls.apiclient,
+            cls.services["acl"]["accountD11A"],
+            domainid=cls.sub_domain.id
+        )
+        cls._cleanup.append(cls.network_owner)
+
+        cls.other_user = Account.create(
+            cls.apiclient,
+            cls.services["acl"]["accountD11B"],
+            domainid=cls.sub_domain.id
+        )
+        cls._cleanup.append(cls.other_user)
+
+        # Create project
+        cls.project = Project.create(
+          cls.apiclient,
+          cls.services["project"],
+          account=cls.domain_admin.name,
+          domainid=cls.domain_admin.domainid
+        )
+        cls._cleanup.append(cls.project)
+
+        # Create api clients for domain admin and normal user
+        cls.domainadmin_user = cls.domain_admin.user[0]
+        cls.domainadmin_apiclient = cls.testClient.getUserApiClient(
+            cls.domainadmin_user.username, cls.sub_domain.name
+        )
+        cls.networkowner_user = cls.network_owner.user[0]
+        cls.user_apiclient = cls.testClient.getUserApiClient(
+            cls.networkowner_user.username, cls.sub_domain.name
+        )
+
+        cls.otheruser_user = cls.other_user.user[0]
+        cls.otheruser_apiclient = cls.testClient.getUserApiClient(
+            cls.otheruser_user.username, cls.sub_domain.name
+        )
+
+        # Create networks for domain admin, normal user and project
+        cls.services["network"]["name"] = "Test Network Isolated - Project"
+        cls.project_network = Network.create(
+            cls.apiclient,
+            cls.services["network"],
+            networkofferingid=cls.network_offering_isolated.id,
+            domainid=cls.sub_domain.id,
+            projectid=cls.project.id,
+            zoneid=cls.zone.id
+        )
+
+        cls.services["network"]["name"] = "Test Network Isolated - Domain 
admin"
+        cls.domainadmin_network = Network.create(
+            cls.apiclient,
+            cls.services["network"],
+            networkofferingid=cls.network_offering_isolated.id,
+            domainid=cls.sub_domain.id,
+            accountid=cls.domain_admin.name,
+            zoneid=cls.zone.id
+        )
+
+        cls.services["network"]["name"] = "Test Network Isolated - Normal user"
+        cls.user_network = Network.create(
+            cls.apiclient,
+            cls.services["network"],
+            networkofferingid=cls.network_offering_isolated.id,
+            domainid=cls.sub_domain.id,
+            accountid=cls.network_owner.name,
+            zoneid=cls.zone.id
+        )
+
+    @classmethod
+    def tearDownClass(cls):
+        super().tearDownClass()

Review comment:
       @DaanHoogland this works actually. I will change it




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


Reply via email to