Exemplo n.º 1
0
def createEnabledNetworkOffering(apiclient, networkServices):
    """Create and enable network offering according to the type

       @output: List, containing [ Result,Network Offering,Reason ]
                 Ist Argument('Result') : FAIL : If exception or assertion error occurs
                                          PASS : If network offering
                                          is created and enabled successfully
                 IInd Argument(Net Off) : Enabled network offering
                                                In case of exception or
                                                assertion error, it will be None
                 IIIrd Argument(Reason) :  Reason for failure,
                                              default to None
    """
    try:
        resultSet = [FAIL, None, None]
        # Create network offering
        network_offering = NetworkOffering.create(apiclient, networkServices, conservemode=False)

        # Update network offering state from disabled to enabled.
        NetworkOffering.update(network_offering, apiclient, id=network_offering.id,
                               state="enabled")
    except Exception as e:
        resultSet[2] = e
        return resultSet
    return [PASS, network_offering, None]
    def create_network_offering(cls, network_offering_type):
        network_offering = NetworkOffering.create(
            cls.api_client,
            cls.services[network_offering_type],
            conservemode=False)

        # Update network offering state from disabled to enabled.
        NetworkOffering.update(network_offering,
                               cls.api_client,
                               id=network_offering.id,
                               state="enabled")
        return network_offering
    def setUpClass(cls):
        try:
            testClient = super(TestGatewayOnSharedNetwork,
                               cls).getClsTestClient()
            cls.apiclient = testClient.getApiClient()
            cls.services = testClient.getParsedTestDataConfig()
            cls._cleanup = []
            # Get Zone, Domain and templates
            cls.domain = get_domain(cls.apiclient)
            cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
            cls.services['mode'] = cls.zone.networktype
            cls.hypervisor = testClient.getHypervisorInfo()

            cls.service_offering = ServiceOffering.create(
                cls.apiclient, cls.services["service_offering"])
            cls._cleanup.append(cls.service_offering)

            builtin_info = get_builtin_template_info(cls.apiclient,
                                                     cls.zone.id)
            cls.services["template"]["url"] = builtin_info[0]
            cls.services["template"]["hypervisor"] = builtin_info[1]
            cls.services["template"]["format"] = builtin_info[2]

            cls.template = get_template(cls.apiclient, cls.zone.id)

            # # Register new template
            # cls.template = Template.register(
            #     cls.apiclient,
            #     cls.services["template"],
            #     zoneid=cls.zone.id,
            #     hypervisor=cls.hypervisor
            # )
            # cls._cleanup.append(cls.template)

            cls.services["shared_network_offering"]["specifyVlan"] = "True"
            cls.services["shared_network_offering"]["specifyIpRanges"] = "True"
            cls.shared_network_offering = NetworkOffering.create(
                cls.apiclient,
                cls.services["shared_network_offering"],
                conservemode=False)
            cls._cleanup.append(cls.shared_network_offering)
            NetworkOffering.update(cls.shared_network_offering,
                                   cls.apiclient,
                                   id=cls.shared_network_offering.id,
                                   state="enabled")

        except Exception as e:
            cls.tearDownClass()
            raise unittest.SkipTest("Exception in setUpClass: %s" % e)
    def setUpClass(cls):
        cls.testClient = super(TestMulipleNicSupport, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.services = cls.testClient.getParsedTestDataConfig()
        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls._cleanup = []

        cls.skip = False
        if str(cls.zone.securitygroupsenabled) != "True":
            cls.skip = True
            return

        cls.logger = logging.getLogger("TestMulipleNicSupport")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.services['mode'] = cls.zone.networktype

        cls.template = get_template(cls.apiclient,
                                    cls.zone.id,
                                    hypervisor="KVM")
        if cls.template == FAILED:
            cls.skip = True
            return

        # Create new domain, account, network and VM
        cls.user_domain = Domain.create(
            cls.apiclient,
            services=cls.testdata["acl"]["domain2"],
            parentdomainid=cls.domain.id)

        # Create account
        cls.account1 = Account.create(cls.apiclient,
                                      cls.testdata["acl"]["accountD2"],
                                      admin=True,
                                      domainid=cls.user_domain.id)

        # Create small service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.testdata["service_offerings"]["small"])

        cls._cleanup.append(cls.service_offering)
        cls.services["network"]["zoneid"] = cls.zone.id
        cls.network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.services["network_offering"],
        )
        # Enable Network offering
        cls.network_offering.update(cls.apiclient, state='Enabled')

        cls._cleanup.append(cls.network_offering)
        cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id
        cls.testdata["virtual_machine"]["template"] = cls.template.id

        if cls.zone.securitygroupsenabled:
            # Enable networking for reaching to VM thorugh SSH
            security_group = SecurityGroup.create(
                cls.apiclient,
                cls.testdata["security_group"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

            # Authorize Security group to SSH to VM
            ingress_rule = security_group.authorize(
                cls.apiclient,
                cls.testdata["ingress_rule"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

            # Authorize Security group to SSH to VM
            ingress_rule2 = security_group.authorize(
                cls.apiclient,
                cls.testdata["ingress_rule_ICMP"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

        cls.testdata["shared_network_offering_sg"]["specifyVlan"] = 'True'
        cls.testdata["shared_network_offering_sg"]["specifyIpRanges"] = 'True'
        cls.shared_network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.testdata["shared_network_offering_sg"],
            conservemode=False)

        NetworkOffering.update(cls.shared_network_offering,
                               cls.apiclient,
                               id=cls.shared_network_offering.id,
                               state="enabled")

        physical_network, vlan = get_free_vlan(cls.apiclient, cls.zone.id)
        cls.testdata["shared_network_sg"][
            "physicalnetworkid"] = physical_network.id

        random_subnet_number = random.randrange(90, 99)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network1 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        random_subnet_number = random.randrange(100, 110)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network2 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        random_subnet_number = random.randrange(111, 120)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network3 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        try:
            cls.virtual_machine1 = VirtualMachine.create(
                cls.apiclient,
                cls.testdata["virtual_machine"],
                accountid=cls.account1.name,
                domainid=cls.account1.domainid,
                serviceofferingid=cls.service_offering.id,
                templateid=cls.template.id,
                securitygroupids=[security_group.id],
                networkids=cls.network1.id)
            for nic in cls.virtual_machine1.nic:
                if nic.isdefault:
                    cls.virtual_machine1.ssh_ip = nic.ipaddress
                    cls.virtual_machine1.default_network_id = nic.networkid
                    break
        except Exception as e:
            cls.fail("Exception while deploying virtual machine: %s" % e)

        try:
            cls.virtual_machine2 = VirtualMachine.create(
                cls.apiclient,
                cls.testdata["virtual_machine"],
                accountid=cls.account1.name,
                domainid=cls.account1.domainid,
                serviceofferingid=cls.service_offering.id,
                templateid=cls.template.id,
                securitygroupids=[security_group.id],
                networkids=[str(cls.network1.id),
                            str(cls.network2.id)])
            for nic in cls.virtual_machine2.nic:
                if nic.isdefault:
                    cls.virtual_machine2.ssh_ip = nic.ipaddress
                    cls.virtual_machine2.default_network_id = nic.networkid
                    break
        except Exception as e:
            cls.fail("Exception while deploying virtual machine: %s" % e)

        cls._cleanup.append(cls.virtual_machine1)
        cls._cleanup.append(cls.virtual_machine2)
        cls._cleanup.append(cls.network1)
        cls._cleanup.append(cls.network2)
        cls._cleanup.append(cls.network3)
        cls._cleanup.append(cls.shared_network_offering)
        if cls.zone.securitygroupsenabled:
            cls._cleanup.append(security_group)
        cls._cleanup.append(cls.account1)
        cls._cleanup.append(cls.user_domain)
Exemplo n.º 5
0
    def test_01_create_network_without_start_end_ip(self):
        """Create Shared network without start and end ip

            Steps:
            # 1. Update the global setting allow.empty.start.end.ipaddress to true
            # 2. Create a shared network without specifying start or end ip
            # 3. This should create the network
            # 4. Now Update the global setting allow.empty.start.end.ipaddress to false
            # 5. Create a shared network without specifying start or end ip
            # 6. Exception should be thrown since start and end ip are not specified
        :return:
        """
        # Create network offering
        self.network_offering = NetworkOffering.create(
            self.apiclient, self.testdata["network_offering_shared"])

        NetworkOffering.update(self.network_offering,
                               self.apiclient,
                               id=self.network_offering.id,
                               state="enabled")

        physical_network, vlan = get_free_vlan(self.apiclient, self.zone.id)
        self.testdata["shared_network_sg"][
            "physicalnetworkid"] = physical_network.id

        random_subnet_number = random.randrange(100, 199)
        self.testdata["shared_network_sg"]["specifyVlan"] = 'True'
        self.testdata["shared_network_sg"]["specifyIpRanges"] = 'True'
        self.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        self.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        self.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        self.testdata["shared_network_sg"]["startip"] = None
        self.testdata["shared_network_sg"]["endip"] = None
        self.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        self.testdata["shared_network_sg"]["netmask"] = "255.255.255.0"
        self.testdata["shared_network_sg"]["acltype"] = "account"

        # Update the global setting to true
        Configurations.update(self.apiclient,
                              name="allow.empty.start.end.ipaddress",
                              value="true")

        # Create network
        network = Network.create(self.apiclient,
                                 self.testdata["shared_network_sg"],
                                 networkofferingid=self.network_offering.id,
                                 zoneid=self.zone.id,
                                 accountid=self.account.name,
                                 domainid=self.account.domainid)

        self.logger.info("network id is %s" % network.id)
        self.cleanup.append(network)

        # Update the global setting to false
        Configurations.update(self.apiclient,
                              name="allow.empty.start.end.ipaddress",
                              value="false")

        # Exception should be thrown
        with self.assertRaises(Exception):
            self.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
                random_subnet_number)
            network2 = Network.create(
                self.apiclient,
                self.testdata["shared_network_sg"],
                networkofferingid=self.network_offering.id,
                zoneid=self.zone.id,
                accountid=self.account.name,
                domainid=self.account.domainid)

        # Restore the setting to default value which is true
        Configurations.update(self.apiclient,
                              name="allow.empty.start.end.ipaddress",
                              value="true")

        self.cleanup.append(self.network_offering)
Exemplo n.º 6
0
    def test_02_create_network_with_same_name(self):
        """Create Shared network with same name in same account

            Steps:
            # 1. Update the global setting allow.duplicate.networkname to true
            # 2. Create a shared network in an account
            # 3. Try to create another shared network with same name in the same account
            # 4. No exception should be thrown as multiple networks with same name can be created
            # 5. Now update the global setting allow.duplicate.networkname to false
            # 6. Try to create another shared network with same name in the same account
            # 7. Exception should be thrown as network with same name cant be created in the same account
        :return:
        """
        # Update the global setting to true
        Configurations.update(self.apiclient,
                              name="allow.duplicate.networkname",
                              value="true")

        # Create network offering
        self.network_offering = NetworkOffering.create(
            self.apiclient, self.testdata["network_offering_shared"])

        NetworkOffering.update(self.network_offering,
                               self.apiclient,
                               id=self.network_offering.id,
                               state="enabled")

        physical_network, vlan = get_free_vlan(self.apiclient, self.zone.id)
        self.testdata["shared_network_sg"][
            "physicalnetworkid"] = physical_network.id

        random_subnet_number = random.randrange(100, 199)
        self.testdata["shared_network_sg"]["specifyVlan"] = 'True'
        self.testdata["shared_network_sg"]["specifyIpRanges"] = 'True'
        self.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan-1"
        self.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan-1"
        self.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        self.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".1"
        self.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".10"
        self.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        self.testdata["shared_network_sg"]["netmask"] = "255.255.255.0"
        self.testdata["shared_network_sg"]["acltype"] = "account"

        # Create the first network
        network3 = Network.create(self.apiclient,
                                  self.testdata["shared_network_sg"],
                                  networkofferingid=self.network_offering.id,
                                  zoneid=self.zone.id,
                                  accountid=self.account.name,
                                  domainid=self.account.domainid)
        self.cleanup.append(network3)

        # Create the second network with same name. No exception should be thrown
        random_subnet_number = random.randrange(100, 199)
        self.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        network4 = Network.create(self.apiclient,
                                  self.testdata["shared_network_sg"],
                                  networkofferingid=self.network_offering.id,
                                  zoneid=self.zone.id,
                                  accountid=self.account.name,
                                  domainid=self.account.domainid)

        self.cleanup.append(network4)

        # Update the global setting to true
        Configurations.update(self.apiclient,
                              name="allow.duplicate.networkname",
                              value="false")

        # Exception should be thrown while creating another network with same name
        with self.assertRaises(Exception):
            random_subnet_number = random.randrange(100, 199)
            self.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
                random_subnet_number)
            network5 = Network.create(
                self.apiclient,
                self.testdata["shared_network_sg"],
                networkofferingid=self.network_offering.id,
                zoneid=self.zone.id,
                accountid=self.account.name,
                domainid=self.account.domainid)

        # Update the global setting to original value
        Configurations.update(self.apiclient,
                              name="allow.duplicate.networkname",
                              value="true")

        self.cleanup.append(self.network_offering)
Exemplo n.º 7
0
    def setUpClass(cls):
        cls.testClient = super(TestPublicIp, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls.logger = logging.getLogger("TestPublicIp")
        cls.domain = get_domain(cls.apiclient)
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"]
        )

        cls.use_system_ips_config_name = "use.system.public.ips"
        cls.use_system_ips_config = Configurations.list(
            cls.apiclient,
            name=cls.use_system_ips_config_name
        )
        cls.use_system_ips_config_value = cls.use_system_ips_config[0].value
        Configurations.update(
            cls.apiclient,
            name=cls.use_system_ips_config_name,
            value="false"
        )

        cls._cleanup = []
        cls.unsupportedHypervisor = False
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ['lxc']:
            cls.unsupportedHypervisor = True
            return

        # Create new domain1
        cls.domain1 = Domain.create(
            cls.apiclient,
            services=cls.services["acl"]["domain1"],
            parentdomainid=cls.domain.id)

        # Create account1
        cls.account1 = Account.create(
            cls.apiclient,
            cls.services["account"],
            # cls.services["acl"]["accountD1"],
            admin=True,
            domainid=cls.domain1.id
        )

        # Create new sub-domain
        cls.sub_domain = Domain.create(
            cls.apiclient,
            services=cls.services["acl"]["domain11"],
            parentdomainid=cls.domain1.id)

        # Create account for sub-domain
        cls.sub_account = Account.create(
            cls.apiclient,
            cls.services["acl"]["accountD11"],
            domainid=cls.sub_domain.id
        )

        # Create new domain2
        cls.domain2 = Domain.create(
            cls.apiclient,
            services=cls.services["acl"]["domain2"],
            parentdomainid=cls.domain.id)

        # Create account2
        cls.account2 = Account.create(
            cls.apiclient,
            cls.services["acl"]["accountD2"],
            domainid=cls.domain2.id
        )

        cls.services["publiciprange"]["zoneid"] = cls.zone.id
        cls.services["publiciprange"]["forvirtualnetwork"] = "true"

        # Create public ip range 1
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        random_subnet_number = random.randrange(10,20)
        cls.services["publiciprange"]["gateway"] = "10.100." + \
                                                   str(random_subnet_number) + ".254"
        cls.services["publiciprange"]["startip"] = "10.100." + \
                                                   str(random_subnet_number) + ".1"
        cls.services["publiciprange"]["endip"] = "10.100." + \
                                                 str(random_subnet_number) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range1 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"],
            account=cls.account1.name,
            domainid=cls.account1.domainid
        )

        # dedicate ip range to sub domain
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        random_subnet_number = random.randrange(10,20)
        cls.services["publiciprange"]["gateway"] = "10.110." + \
                                                    str(random_subnet_number) + ".254"
        cls.services["publiciprange"]["startip"] = "10.110." + \
                                                    str(random_subnet_number) + ".1"
        cls.services["publiciprange"]["endip"] = "10.110." + \
                                                  str(random_subnet_number) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range2 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"],
            account=cls.sub_account.name,
            domainid=cls.sub_account.domainid
        )

        # dedicate ip range to second domain
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        random_subnet_number = random.randrange(10,20)
        cls.services["publiciprange"]["gateway"] = "10.120." + \
                                                   str(random_subnet_number) + ".254"
        cls.services["publiciprange"]["startip"] = "10.120." + \
                                                   str(random_subnet_number) + ".1"
        cls.services["publiciprange"]["endip"] = "10.120." + \
                                                 str(random_subnet_number) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range3 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"],
            account=cls.account2.name,
            domainid=cls.account2.domainid
        )

        # create vpc offering and VPC
        cls.vpc_off = VpcOffering.create(
            cls.apiclient,
            cls.services["vpc_offering"]
        )
        cls.vpc_off.update(cls.apiclient, state='Enabled')

        # create network offering
        cls.isolated_network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.services["isolated_network_offering"],
            conservemode=False
        )

        NetworkOffering.update(
            cls.isolated_network_offering,
            cls.apiclient,
            id=cls.isolated_network_offering.id,
            state="enabled"
        )

        physical_network, shared_vlan = get_free_vlan(
            cls.apiclient, cls.zone.id)
        if shared_vlan is None:
            cls.fail("Failed to get free vlan id for shared network")

        cls.services["shared_network_offering"]["specifyVlan"] = "True"
        cls.services["shared_network_offering"]["specifyIpRanges"] = "True"

        cls.shared_network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.services["shared_network_offering"],
            conservemode=False
        )

        NetworkOffering.update(
            cls.shared_network_offering,
            cls.apiclient,
            id=cls.shared_network_offering.id,
            state="enabled"
        )

        # create network using the shared network offering created
        cls.services["shared_network"]["acltype"] = "Domain"
        cls.services["shared_network"][
            "networkofferingid"] = cls.shared_network_offering.id
        cls.services["shared_network"][
            "physicalnetworkid"] = physical_network.id
        cls.services["shared_network"]["vlan"] = shared_vlan
        shared_network_subnet_number = random.randrange(1, 254)

        cls.services["shared_network"]["netmask"] = "255.255.255.0"
        cls.services["shared_network"]["gateway"] = "172.16." + \
                                                     str(shared_network_subnet_number) + ".254"
        cls.services["shared_network"]["startip"] = "172.16." + \
                                                     str(shared_network_subnet_number) + ".1"
        cls.services["shared_network"]["endip"] = "172.16." + \
                                                   str(shared_network_subnet_number) + ".10"

        cls.guest_network = Network.create(
            cls.apiclient,
            cls.services["shared_network"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id
        )

        cls._cleanup.append(cls.guest_network)
        cls._cleanup.append(cls.shared_network_offering)
        cls._cleanup.append(cls.account1)
        cls._cleanup.append(cls.account2)
        cls._cleanup.append(cls.sub_account)
        cls._cleanup.append(cls.sub_domain)
        cls._cleanup.append(cls.domain1)
        cls._cleanup.append(cls.domain2)
        cls._cleanup.append(cls.public_ip_range1)
        cls._cleanup.append(cls.public_ip_range2)
        cls._cleanup.append(cls.public_ip_range3)
    def setUpClass(cls):
        testClient = super(TestCheckNetmask, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.testdata = testClient.getParsedTestDataConfig()
        cls.hypervisor = cls.testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())

        cls.template = get_template(cls.apiclient, cls.zone.id,
                                    cls.testdata["ostype"])

        cls._cleanup = []

        cls.skiptest = False

        if cls.hypervisor.lower() not in ["xenserver"]:
            cls.skiptest = True
            return

        try:

            # Create an account
            cls.account = Account.create(cls.apiclient,
                                         cls.testdata["account"],
                                         domainid=cls.domain.id)

            # Create Service offering
            cls.service_offering = ServiceOffering.create(
                cls.apiclient,
                cls.testdata["service_offering"],
            )

            cls.testdata["shared_network_offering"]["specifyVlan"] = 'True'
            cls.testdata["shared_network_offering"]["specifyIpRanges"] = 'True'

            cls.shared_network_offering = NetworkOffering.create(
                cls.apiclient, cls.testdata["shared_network_offering"])

            NetworkOffering.update(cls.shared_network_offering,
                                   cls.apiclient,
                                   id=cls.shared_network_offering.id,
                                   state="enabled")

            cls.network = Network.create(
                cls.apiclient,
                cls.testdata["network2"],
                networkofferingid=cls.shared_network_offering.id,
                zoneid=cls.zone.id,
                accountid=cls.account.name,
                domainid=cls.account.domainid)

            cls.vm = VirtualMachine.create(
                cls.apiclient,
                cls.testdata["small"],
                templateid=cls.template.id,
                accountid=cls.account.name,
                domainid=cls.account.domainid,
                serviceofferingid=cls.service_offering.id,
                zoneid=cls.zone.id,
                networkids=cls.network.id,
            )

            cls._cleanup.extend([
                cls.account, cls.service_offering, cls.shared_network_offering
            ])

        except Exception as e:
            cls.tearDownClass()
            raise e
        return