def setUpClass(cls):
        cls.testClient = super(TestMultiplePublicIpSubnets,
                               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.skip = False

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

        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if cls.hypervisor.lower() not in ['kvm']:
            cls.skip = True
            return

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

        # Get Zone, Domain and templates
        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)
Ejemplo n.º 2
0
    def setUpClass(cls):
        cls.testClient = super(TestHosts, cls).getClsTestClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.apiclient = cls.testClient.getApiClient()
        cls.dbclient = cls.testClient.getDbConnection()
        cls._cleanup = []

        # get zone, domain etc
        cls.zone = Zone(get_zone(cls.apiclient, cls.testClient.getZoneForTests()).__dict__)
        cls.domain = get_domain(cls.apiclient)
        cls.pod = get_pod(cls.apiclient, cls.zone.id)

        cls.logger = logging.getLogger('TestHosts')
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        cls.storage_pool_db_id = None
        # list hosts
        hosts = list_hosts(cls.apiclient, type="Routing")
        i = 0
        while (i < len(hosts)):
            host_id = hosts[i].id
            cls.logger.debug("Trying host id : %s" % host_id)
            host_db_id = cls.dbclient.execute(
                "select id from host where uuid='%s';" %
                host_id)

            if host_db_id and host_db_id[0]:
                cls.logger.debug("found host db id : %s" % host_db_id)
                storage_pool_db_id = cls.dbclient.execute(
                    "select id from storage_pool where id='%s' and removed is null;" %
                    host_db_id[0][0])

                if storage_pool_db_id and storage_pool_db_id[0]:
                    cls.logger.debug("Found storage_pool_db_id  : %s" % storage_pool_db_id[0][0])
                    capacity_state = cls.dbclient.execute(
                        "select count(capacity_state) from op_host_capacity where host_id='%s' and capacity_type in (0,1,3) and capacity_state = 'Enabled'" %
                        host_db_id[0][0])

                    if capacity_state and capacity_state[0]:
                        cls.logger.debug("Check capacity count  : %s" % capacity_state[0][0])

                        if capacity_state[0][0] == 3:
                            cls.logger.debug("found host id : %s, can be used for this test" % host_id)
                            cls.my_host_id = host_id
                            cls.host_db_id = host_db_id
                            cls.storage_pool_db_id = storage_pool_db_id
                            break
            if not cls.storage_pool_db_id:
                i = i + 1


        if cls.storage_pool_db_id is None:
            raise unittest.SkipTest("There is no host and storage pool available in the setup to run this test")
    def setUpClass(cls):
        cls.testClient = super(
            TestProtocolNumberSecurityGroup,
            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.template = get_template(cls.apiclient, cls.zone.id)
        cls._cleanup = []

        if str(cls.zone.securitygroupsenabled) != "True":
            sys.exit(1)

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

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        testClient = super(TestProtocolNumberSecurityGroup, cls).getClsTestClient()
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype

        # 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.account = Account.create(
            cls.apiclient,
            cls.testdata["acl"]["accountD2"],
            admin=True,
            domainid=cls.user_domain.id
        )

        cls.service_offering = ServiceOffering.create(
            cls.apiclient,
            cls.testdata["service_offering"]
        )

        cls.testdata["domainid"] = cls.domain.id
        cls.testdata["virtual_machine_userdata"]["zoneid"] = cls.zone.id
        cls.testdata["virtual_machine_userdata"]["template"] = cls.template.id

        cls._cleanup.append(cls.service_offering)
        cls._cleanup.append(cls.account)
        cls._cleanup.append(cls.user_domain)
Ejemplo n.º 4
0
    def setUpClass(cls):
        cls.testClient = super(TestNetworkManagement, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.dbclient = cls.testClient.getDbConnection()
        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.logger = logging.getLogger("TestNetworkManagement")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        testClient = super(TestNetworkManagement, cls).getClsTestClient()
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        # 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.account = 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._cleanup.append(cls.account)
        cls._cleanup.append(cls.user_domain)
    def setUpClass(cls):
        cls.testClient = super(TestHosts, cls).getClsTestClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.apiclient = cls.testClient.getApiClient()
        cls.dbclient = cls.testClient.getDbConnection()
        cls._cleanup = []

        # get zone, domain etc
        cls.zone = Zone(
            get_zone(cls.apiclient, cls.testClient.getZoneForTests()).__dict__)
        cls.domain = get_domain(cls.apiclient)
        cls.pod = get_pod(cls.apiclient, cls.zone.id)

        # list hosts
        hosts = list_hosts(cls.apiclient, type="Routing")
        if len(hosts) > 0:
            cls.my_host_id = hosts[0].id
            cls.host_db_id = cls.dbclient.execute(
                "select id from host where uuid='%s';" % cls.my_host_id)
            cls.my_cluster_id = hosts[0].clusterid
        else:
            raise unittest.SkipTest("There is no host available in the setup")
    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)
Ejemplo n.º 7
0
          print "net name={}, id={}".format(net.name, net.id)
          print "Delete PhysicalNetwork"
          n = PhysicalNetwork(tmp_dict)
          n.id = net.id
          n.delete(apiClient)

    pods = Pod.list(apiClient)
    if pods:
      for pod in pods:
        print "pod name={}, id={}".format(pod.name, pod.id)
        print "Delete Pod"
        p = Pod(tmp_dict)
        p.id = pod.id
        p.delete(apiClient)

    img_storages = ImageStore.list(apiClient)
    if img_storages:
      for img_storage in img_storages:
        print "image store name={}, id={}".format(img_storage.name, img_storage.id)
        print "Delete ImageStore"
        i = ImageStore(tmp_dict)
        i.id = img_storage.id
        i.delete(apiClient)

    print "Delete Zone"
    z = Zone(tmp_dict)
    z.id = zone.id
    z.delete(apiClient)

  exit(0)
    def setUpClass(cls):
        cls.testClient = super(TestUserPrivateGateways, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        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("TestUserPrivateGateways")
        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["network_offering"])
        cls.network_offering_isolated.update(cls.apiclient, state='Enabled')
        cls._cleanup.append(cls.network_offering_isolated)

        # Create vpc offering
        cls.vpc_offering = VpcOffering.create(
            cls.apiclient, cls.services["vpc_offering_multi_lb"])
        cls.vpc_offering.update(cls.apiclient, state='Enabled')
        cls._cleanup.append(cls.vpc_offering)

        # 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')
        cls._cleanup.append(cls.network_offering_vpc)

        # 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.normal_user = Account.create(cls.apiclient,
                                         cls.services["acl"]["accountD1B"],
                                         domainid=cls.sub_domain.id)
        cls._cleanup.append(cls.normal_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.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)
Ejemplo n.º 9
0
    def setUpClass(cls):
        cls.testClient = super(TestVolumeDestroyRecover,
                               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._cleanup = []

        cls.logger = logging.getLogger("TestVolumeDestroyRecover")
        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.template = get_template(cls.apiclient,
                                    cls.zone.id,
                                    hypervisor="KVM")
        if cls.template == FAILED:
            sys.exit(1)
        cls.templatesize = (cls.template.size / (1024**3))

        cls.services['mode'] = cls.zone.networktype
        # Create Account
        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     admin=True,
                                     domainid=cls.domain.id)
        cls._cleanup.append(cls.account)
        accounts = Account.list(cls.apiclient, id=cls.account.id)
        cls.expectedCount = int(accounts[0].primarystoragetotal)
        cls.volumeTotal = int(accounts[0].volumetotal)

        if cls.zone.securitygroupsenabled:
            cls.services["shared_network_offering"]["specifyVlan"] = 'True'
            cls.services["shared_network_offering"]["specifyIpRanges"] = 'True'

            cls.network_offering = NetworkOffering.create(
                cls.apiclient, cls.services["shared_network_offering"])
            cls._cleanup.append(cls.network_offering)
            cls.network_offering.update(cls.apiclient, state='Enabled')

            cls.account_network = Network.create(
                cls.apiclient,
                cls.services["network2"],
                networkofferingid=cls.network_offering.id,
                zoneid=cls.zone.id,
                accountid=cls.account.name,
                domainid=cls.account.domainid)
            cls._cleanup.append(cls.account_network)
        else:
            cls.network_offering = NetworkOffering.create(
                cls.apiclient,
                cls.services["isolated_network_offering"],
            )
            cls._cleanup.append(cls.network_offering)
            # Enable Network offering
            cls.network_offering.update(cls.apiclient, state='Enabled')

            # Create account network
            cls.services["network"]["zoneid"] = cls.zone.id
            cls.services["network"][
                "networkoffering"] = cls.network_offering.id
            cls.account_network = Network.create(cls.apiclient,
                                                 cls.services["network"],
                                                 cls.account.name,
                                                 cls.account.domainid)
            cls._cleanup.append(cls.account_network)

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

        # Create disk offering
        cls.disk_offering = DiskOffering.create(
            cls.apiclient,
            cls.services["disk_offering"],
        )
        cls._cleanup.append(cls.disk_offering)
Ejemplo n.º 10
0
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestManagedSystemVMs, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        cls._connect_to_hypervisor()

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip], solidfire[TestData.username], solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = Zone(get_zone(cls.apiClient, zone_id=cls.testdata[TestData.zoneId]).__dict__)
        cls.cluster = list_clusters(cls.apiClient)[0]
        cls.template = get_template(cls.apiClient, cls.zone.id, cls.configData["ostype"])
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(
            cls.apiClient,
            cls.testdata["account"],
            admin=1
        )

        # Set up connection to make customized API calls
        cls.user = User.create(
            cls.apiClient,
            cls.testdata["user"],
            account=cls.account.name,
            domainid=cls.domain.id
        )

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, cls.user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey, userkeys.secretkey)

        cls.compute_offering = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering]
        )

        systemoffering = cls.testdata[TestData.systemOffering]

        systemoffering[TestData.name] = "Managed SSVM"
        systemoffering['systemvmtype'] = "secondarystoragevm"

        cls.secondary_storage_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        systemoffering[TestData.name] = "Managed CPVM"
        systemoffering['systemvmtype'] = "consoleproxy"

        cls.console_proxy_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        systemoffering[TestData.name] = "Managed VR"
        systemoffering['systemvmtype'] = "domainrouter"

        cls.virtual_router_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        # Resources that are to be destroyed
        cls._cleanup = [
            cls.secondary_storage_offering,
            cls.console_proxy_offering,
            cls.virtual_router_offering,
            cls.compute_offering,
            cls.user,
            cls.account
        ]
    def setUpClass(cls):
        cls.testClient = super(
            TestAcquireSpecifiedPublicIp,
            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 = []

        if str(cls.zone.securitygroupsenabled) == "True":
            sys.exit(1)

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

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)

        # 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["acl"]["accountD1"],
            domainid=cls.domain1.id
        )

        # Create 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"] = "172.16." + \
            str(random_subnet_number) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range1 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )
        PublicIpRange.dedicate(
            cls.apiclient,
            cls.public_ip_range1.vlan.id,
            domainid=cls.account1.domainid
        )

        # Create public ip range 2
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number + 1) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number + 1) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number + 1) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range2 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )
        PublicIpRange.dedicate(
            cls.apiclient,
            cls.public_ip_range2.vlan.id,
            account=cls.account1.name,
            domainid=cls.account1.domainid
        )

        # Create public ip range 3
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number + 2) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number + 2) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number + 2) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range3 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )
        PublicIpRange.dedicate(
            cls.apiclient,
            cls.public_ip_range3.vlan.id,
            domainid=cls.account2.domainid
        )

        # Create public ip range 4
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number + 3) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number + 3) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number + 3) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range4 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )
        PublicIpRange.dedicate(
            cls.apiclient,
            cls.public_ip_range4.vlan.id,
            account=cls.account2.name,
            domainid=cls.account2.domainid
        )

        # Create public ip range 5
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number + 4) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number + 4) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number + 4) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range5 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )

        cls._cleanup.append(cls.account1)
        cls._cleanup.append(cls.domain1)
        cls._cleanup.append(cls.account2)
        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)
        cls._cleanup.append(cls.public_ip_range4)
        cls._cleanup.append(cls.public_ip_range5)
Ejemplo n.º 12
0
    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._cleanup.append(cls.project_network)

        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._cleanup.append(cls.domainadmin_network)

        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)
        cls._cleanup.append(cls.user_network)