def do_add_network_service(net_service_xml_obj, l3_uuid, providers, \
        session_uuid):
    allservices = {}
    for ns in xmlobject.safe_list(net_service_xml_obj):
        puuid = providers.get(ns.provider_)
        if not puuid:
            raise test_util.TestError(
                'cannot find network service provider[%s], it may not have been added'
                % ns.provider_)

        servs = []
        for nst in xmlobject.safe_list(ns.serviceType):
            servs.append(nst.text_)
        allservices[puuid] = servs

    action = api_actions.AttachNetworkServiceToL3NetworkAction()
    action.sessionUuid = session_uuid
    action.l3NetworkUuid = l3_uuid
    action.networkServices = allservices
    try:
        evt = action.run()
    except Exception as e:
        exc_info.append(sys.exc_info())
        raise e
    test_util.test_logger(jsonobject.dumps(evt))
Пример #2
0
    def attach(self, target_vm):
	new_volume = vol_ops.attach_volume(self.get_volume().uuid, target_vm.get_vm().uuid)
        if not new_volume:
            test_lib.lib_get_vm_blk_status(target_vm.get_vm())
            #test_util.raise_exeception_no_cleanup('Attach Volume to VM failed with 5 retry.')
            raise test_util.TestError('Attach Volume to VM failed.')
        self.set_volume(new_volume)
        super(ZstackTestVolume, self).attach(target_vm)
Пример #3
0
def get_first_item_from_list(list_obj, list_obj_name, list_obj_value, action_name):
    '''
    Judge if list is empty. If not, return the 1st item.
    list_obj: the list for judgment and return;
    list_obj_name: the list item type name;
    list_obj_value: the list item's value when do previous query;
    action_name: which action is calling this function
    '''
    if not isinstance(list_obj, list):
        raise test_util.TestError("The first parameter is not a [list] type")

    if not list_obj:
        raise test_util.TestError("Did not find %s: [%s], when adding %s" % (list_obj_name, list_obj_value, action_name))

    if len(list_obj) > 1:
        raise test_util.TestError("Find more than 1 [%s] resource with name: [%s], when adding %s. Please check your deploy.xml and make sure resource do NOT have duplicated name " % (list_obj_name, list_obj_value, action_name))

    return list_obj[0]
Пример #4
0
    def _add_cluster(action, zone_ref, cluster, cluster_ref):
        evt = action.run()
        test_util.test_logger(jsonobject.dumps(evt))
        cinv = evt.inventory

        try:
            if xmlobject.has_element(cluster, 'primaryStorageRef'):
                for pref in xmlobject.safe_list(cluster.primaryStorageRef):
                    ps_name = generate_dup_name(generate_dup_name(pref.text_, zone_ref, 'z'), cluster_ref, 'c')

                    pinvs = res_ops.get_resource(res_ops.PRIMARY_STORAGE, session_uuid, name=ps_name)
                    pinv = get_first_item_from_list(pinvs, 'Primary Storage', ps_name, 'Cluster')

                    action_ps = api_actions.AttachPrimaryStorageToClusterAction()
                    action_ps.sessionUuid = session_uuid
                    action_ps.clusterUuid = cinv.uuid
                    action_ps.primaryStorageUuid = pinv.uuid
                    evt = action_ps.run()
                    test_util.test_logger(jsonobject.dumps(evt))
        except:
            exc_info.append(sys.exc_info())

        if cluster.allL2NetworkRef__ == 'true':
            #find all L2 network in zone and attach to cluster
            cond = res_ops.gen_query_conditions('zoneUuid', '=', \
                    action.zoneUuid)
            l2_count = res_ops.query_resource_count(res_ops.L2_NETWORK, \
                    cond, session_uuid)
            l2invs = res_ops.query_resource_fields(res_ops.L2_NETWORK, \
                    [{'name':'zoneUuid', 'op':'=', 'value':action.zoneUuid}], \
                    session_uuid, ['uuid'], 0, l2_count)
        else:
            l2invs = []
            if xmlobject.has_element(cluster, 'l2NetworkRef'):
                for l2ref in xmlobject.safe_list(cluster.l2NetworkRef):
                    l2_name = generate_dup_name(generate_dup_name(l2ref.text_, zone_ref, 'z'), cluster_ref, 'c')

                    cond = res_ops.gen_query_conditions('zoneUuid', '=', \
                            action.zoneUuid)
                    cond = res_ops.gen_query_conditions('name', '=', l2_name, \
                            cond)
                            
                    l2inv = res_ops.query_resource_fields(res_ops.L2_NETWORK, \
                            cond, session_uuid, ['uuid'])
                    if not l2inv:
                        raise test_util.TestError("Can't find l2 network [%s] in database." % l2_name)
                    l2invs.extend(l2inv)

        for l2inv in l2invs:
            action = api_actions.AttachL2NetworkToClusterAction()
            action.sessionUuid = session_uuid
            action.clusterUuid = cinv.uuid
            action.l2NetworkUuid = l2inv.uuid
            thread = threading.Thread(target=_thread_for_action, args=(action,))
            wait_for_thread_queue()
            thread.start()
    def _validate(self):
        '''
        The sum of all actions' percentage should not exceed 100%
        '''
        sum = 0
        for key, value in self.get_priority_action_dict().iteritems():
            if value[priorityType] != weight:
                sum += value[priorityValue]

        if sum > 100:
            import zstackwoodpecker.test_util as test_util
            raise test_util.TestError('The Sum of actions priority percentage should not exceed 100. Now it is : %s' % sum)
def add_instance_offering_config(root_xml, session_uuid=None):
    ios_xml = etree.SubElement(root_xml, 'instanceOfferings')

    #add user type instance offering
    cond = res_ops.gen_query_conditions('type', '=', 'UserVm')
    user_ios = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond, \
            session_uuid)
    for user_io in user_ios:
        if user_io.state != 'Enabled':
            continue
        io_xml = etree.SubElement(ios_xml, 'instanceOffering')
        set_xml_item_attr(io_xml, 'name', user_io.name)
        set_xml_item_attr(io_xml, 'description', user_io.description)
        set_xml_item_attr(io_xml, 'memoryCapacity', user_io.memorySize)
        set_xml_item_attr(io_xml, 'cpuNum', user_io.cpuNum)
        #set_xml_item_attr(io_xml, 'cpuSpeed', user_io.cpuSpeed)

    #add virtual router instance offering
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    vr_ios = res_ops.query_resource(res_ops.VR_OFFERING, cond, session_uuid)
    for vr_io in vr_ios:
        io_xml = etree.SubElement(ios_xml, 'virtualRouterOffering')
        set_xml_item_attr(io_xml, 'name', vr_io.name)
        set_xml_item_attr(io_xml, 'description', vr_io.description)
        set_xml_item_attr(io_xml, 'memoryCapacity', vr_io.memorySize)
        set_xml_item_attr(io_xml, 'cpuNum', vr_io.cpuNum)
        #set_xml_item_attr(io_xml, 'cpuSpeed', vr_io.cpuSpeed)
        set_xml_item_attr(io_xml, 'isDefault', vr_io.isDefault)
        cond = res_ops.gen_query_conditions('uuid', '=', \
                vr_io.publicNetworkUuid)
        l3 = res_ops.query_resource(res_ops.L3_NETWORK, cond, session_uuid)
        if not l3:
            raise test_util.TestError('Not find L3 Network for [uuid:] %s' % \
                    vr_io.publicNetworkUuid)

        l3_ref = etree.SubElement(io_xml, 'publicL3NetworkRef')
        l3_ref.text = l3[0].name

        cond = res_ops.gen_query_conditions('uuid', '=', \
                vr_io.managementNetworkUuid)
        l3 = res_ops.query_resource(res_ops.L3_NETWORK, cond, session_uuid)
        add_xml_item_value(io_xml, 'managementL3NetworkRef', l3[0].name)

        cond = res_ops.gen_query_conditions('uuid', '=', vr_io.zoneUuid)
        zones = res_ops.query_resource(res_ops.ZONE, cond, session_uuid)
        add_xml_item_value(io_xml, 'zoneRef', zones[0].name)

        cond = res_ops.gen_query_conditions('uuid', '=', vr_io.imageUuid)
        imgs = res_ops.query_resource(res_ops.IMAGE, cond, session_uuid)
        add_xml_item_value(io_xml, 'imageRef', imgs[0].name)