cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject [1/2] git commit: updated refs/heads/4.2-forward to 64460df
Date Thu, 22 Aug 2013 07:09:13 GMT
Updated Branches:
  refs/heads/4.2-forward 5528ba4b2 -> 64460df55


CLOUDSTACK-4442: Include a test for creating networks with sourcenat only

The test attempts to create a network with offering serving only
dhcp,dns and sourcenat. However the source NAT functionality itself
isn't tested as reported in the bug. So the test will pass.

TODO: come up with a way to test source nat without enabling additional
services for pf/staticnat

Signed-off-by: Prasanna Santhanam <tsp@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e2122b72
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e2122b72
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e2122b72

Branch: refs/heads/4.2-forward
Commit: e2122b72300b3e490ad1eb03450ff589b10f66ca
Parents: 5528ba4
Author: Prasanna Santhanam <tsp@apache.org>
Authored: Thu Aug 22 12:34:19 2013 +0530
Committer: Prasanna Santhanam <tsp@apache.org>
Committed: Thu Aug 22 12:38:50 2013 +0530

----------------------------------------------------------------------
 .../component/test_network_offering.py          | 143 +++++++++++++++++++
 1 file changed, 143 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e2122b72/test/integration/component/test_network_offering.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_network_offering.py b/test/integration/component/test_network_offering.py
index 31a5c7d..e8a7b97 100644
--- a/test/integration/component/test_network_offering.py
+++ b/test/integration/component/test_network_offering.py
@@ -89,6 +89,19 @@ class Services:
                                             "StaticNat": 'VirtualRouter',
                                         },
                                     },
+                         "network_offering_sourcenat" : {
+                                    "name": 'Network offering - SourceNat only',
+                                    "displaytext": 'Network offering - SourceNat only',
+                                    "guestiptype": 'Isolated',
+                                    "supportedservices": 'SourceNat,Dhcp,Dns',
+                                    "traffictype": 'GUEST',
+                                    "availability": 'Optional',
+                                    "serviceProviderList": {
+                                            "Dhcp": 'VirtualRouter',
+                                            "Dns": 'VirtualRouter',
+                                            "SourceNat": 'VirtualRouter',
+                                        },
+                                    },
                          "network": {
                                   "name": "Test Network",
                                   "displaytext": "Test Network",
@@ -1794,4 +1807,134 @@ class TestNetworkUpgrade(cloudstackTestCase):
         return
 
 
+class TestNOWithOnlySourceNAT(cloudstackTestCase):
+    @classmethod
+    def setUpClass(cls):
+        cls.apiclient = super(
+            TestNOWithOnlySourceNAT,
+            cls
+        ).getClsTestClient().getApiClient()
+        cls.services = Services().services
+        # Get Zone, Domain and templates
+        cls.domain = get_domain(cls.apiclient, cls.services)
+        cls.zone = get_zone(cls.apiclient, cls.services)
+        cls.services['mode'] = cls.zone.networktype
+        cls.template = get_template(
+            cls.apiclient,
+            cls.zone.id,
+            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,
+        ]
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.apiclient, cls.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
 
+    @attr(tags=["advanced", "advancedns"])
+    def test_create_network_with_snat(self):
+        """Test to create a network with SourceNAT service only"""
+
+        # Validate the following
+        # 1. create a network offering with source nat service
+        # 2. create a network and deploy a vm within the network
+        # 3. deployment and network creation should be successful
+        # 4. attempt to create a fw rule. should fail since offering hasn't allowed it
+        # 5. try to ping out of the guest to www.google.com to check SourceNAT is working
+
+        self.account = Account.create(
+            self.apiclient,
+            self.services["account"],
+            admin=False,
+            domainid=self.domain.id
+        )
+        self.cleanup.append(self.account)
+
+        # Create a network offering VR and only SourceNAT service
+        self.debug(
+            "creating network offering with source NAT only"
+        )
+        self.network_offering = NetworkOffering.create(
+            self.apiclient,
+            self.services["network_offering_sourcenat"]
+        )
+        # Enable Network offering
+        self.network_offering.update(self.apiclient, state='Enabled')
+        self.debug("Created n/w offering with ID: %s" %
+                   self.network_offering.id)
+
+        # Creating network using the network offering created
+        self.debug("Creating network with network offering: %s" %
+                   self.network_offering.id)
+        self.network = Network.create(
+            self.apiclient,
+            self.services["network"],
+            accountid=self.account.name,
+            domainid=self.account.domainid,
+            networkofferingid=self.network_offering.id,
+            zoneid=self.zone.id
+        )
+        self.debug("Created guest network with ID: %s within account %s" % (self.network.id,
self.account.name))
+
+        self.debug("Deploying VM in account: %s on the network %s" % (self.account.name,
self.network.id))
+        # Spawn an instance in that network
+        virtual_machine = VirtualMachine.create(
+            self.apiclient,
+            self.services["virtual_machine"],
+            accountid=self.account.name,
+            domainid=self.account.domainid,
+            serviceofferingid=self.service_offering.id,
+            networkids=[str(self.network.id)]
+        )
+        self.debug("Deployed VM in network: %s" % self.network.id)
+
+        src_nat_list = PublicIPAddress.list(
+            self.apiclient,
+            associatednetworkid=self.network.id,
+            account=self.account.name,
+            domainid=self.account.domainid,
+            listall=True,
+            issourcenat=True,
+        )
+        self.assertEqual(
+            isinstance(src_nat_list, list),
+            True,
+            "List Public IP should return a valid source NAT"
+        )
+        self.assertNotEqual(
+            len(src_nat_list),
+            0,
+            "Length of response from listPublicIp should not be 0"
+        )
+
+        src_nat = src_nat_list[0]
+
+        self.debug("Successfully implemented network with source NAT IP: %s" %
+                   src_nat.ipaddress)
+
+        with self.assertRaises(Exception):
+            FireWallRule.create(
+                self.apiclient,
+                ipaddressid=src_nat.id,
+                protocol='TCP',
+                cidrlist=[self.services["fw_rule"]["cidr"]],
+                startport=self.services["fw_rule"]["startport"],
+                endport=self.services["fw_rule"]["endport"]
+            )
+        return


Mime
View raw message