|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +""" BVT tests for Network Life Cycle |
| 18 | +""" |
| 19 | + |
| 20 | +from marvin.cloudstackTestCase import cloudstackTestCase |
| 21 | +from marvin.lib.utils import cleanup_resources |
| 22 | +from marvin.lib.base import (Account, |
| 23 | + Network, |
| 24 | + NetworkOffering |
| 25 | + ) |
| 26 | +from marvin.lib.common import (get_domain, |
| 27 | + get_zone |
| 28 | + ) |
| 29 | +from nose.plugins.attrib import attr |
| 30 | + |
| 31 | + |
| 32 | +class TestIsolatedNetworkInvalidGw(cloudstackTestCase): |
| 33 | + |
| 34 | + def setUp(self): |
| 35 | + self.apiclient = self.testClient.getApiClient() |
| 36 | + |
| 37 | + @classmethod |
| 38 | + def setUpClass(cls): |
| 39 | + testClient = super(TestIsolatedNetworkInvalidGw, cls).getClsTestClient() |
| 40 | + cls.apiclient = testClient.getApiClient() |
| 41 | + cls.services = testClient.getParsedTestDataConfig() |
| 42 | + |
| 43 | + # Get Zone, Domain and templates |
| 44 | + cls.domain = get_domain(cls.apiclient) |
| 45 | + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) |
| 46 | + cls.services['mode'] = cls.zone.networktype |
| 47 | + # Create Accounts |
| 48 | + cls.account = Account.create( |
| 49 | + cls.apiclient, |
| 50 | + cls.services["account"], |
| 51 | + admin=True, |
| 52 | + domainid=cls.domain.id |
| 53 | + ) |
| 54 | + |
| 55 | + cls.services["network"]["zoneid"] = cls.zone.id |
| 56 | + |
| 57 | + cls.network_offering = NetworkOffering.create( |
| 58 | + cls.apiclient, |
| 59 | + cls.services["network_offering"], |
| 60 | + ) |
| 61 | + # Enable Network offering |
| 62 | + cls.network_offering.update(cls.apiclient, state='Enabled') |
| 63 | + |
| 64 | + cls.services["network"]["networkoffering"] = cls.network_offering.id |
| 65 | + cls._cleanup = [ |
| 66 | + cls.account, |
| 67 | + cls.network_offering |
| 68 | + ] |
| 69 | + return |
| 70 | + |
| 71 | + @classmethod |
| 72 | + def tearDownClass(cls): |
| 73 | + try: |
| 74 | + # Cleanup resources used |
| 75 | + cleanup_resources(cls.apiclient, cls._cleanup) |
| 76 | + except Exception as e: |
| 77 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 78 | + return |
| 79 | + |
| 80 | + @attr(tags=["advanced", "advancedns", "smoke", "dvs"], required_hardware="false") |
| 81 | + def test_isolated_nw_invalid_gw(self): |
| 82 | + |
| 83 | + self.debug("Trying to create a network with Gateway as 192.168.3.0. This should fail") |
| 84 | + with self.assertRaises(Exception): |
| 85 | + Network.create( |
| 86 | + self.apiclient, |
| 87 | + self.services["network"], |
| 88 | + self.account.name, |
| 89 | + self.account.domainid, |
| 90 | + gateway="192.168.3.0", |
| 91 | + netmask="255.255.255.0", |
| 92 | + ) |
| 93 | + |
| 94 | + self.debug("Trying to create a network with Gateway as 192.168.3.255") |
| 95 | + with self.assertRaises(Exception): |
| 96 | + Network.create( |
| 97 | + self.apiclient, |
| 98 | + self.services["network"], |
| 99 | + self.account.name, |
| 100 | + self.account.domainid, |
| 101 | + gateway="192.168.3.255", |
| 102 | + netmask="255.255.255.0" |
| 103 | + ) |
| 104 | + |
| 105 | + self.debug("Trying to create a network with Gateway as 192.168.3.0 and Subnet mask as 255.0.255.0") |
| 106 | + with self.assertRaises(Exception): |
| 107 | + Network.create( |
| 108 | + self.apiclient, |
| 109 | + self.services["network"], |
| 110 | + self.account.name, |
| 111 | + self.account.domainid, |
| 112 | + gateway="192.168.3.0", |
| 113 | + netmask="255.0.255.0", |
| 114 | + ) |
| 115 | + |
| 116 | + self.debug("Trying to create a network with Subnet mask as 255.0.255.0") |
| 117 | + with self.assertRaises(Exception): |
| 118 | + Network.create( |
| 119 | + self.apiclient, |
| 120 | + self.services["network"], |
| 121 | + self.account.name, |
| 122 | + self.account.domainid, |
| 123 | + gateway="192.168.3.1", |
| 124 | + netmask="255.0.255.0", |
| 125 | + ) |
| 126 | + return |
| 127 | + |
0 commit comments