void saImmOmCcbObjectModify_2_12(void)
{
    const SaImmAdminOwnerNameT adminOwnerName = (SaImmAdminOwnerNameT) __FUNCTION__;
    SaImmAdminOwnerHandleT ownerHandle;
    SaImmCcbHandleT ccbHandle;
    SaImmAccessorHandleT accessorHandle;
    const SaNameT *objectNames[] = {&rootObj, NULL};
    SaStringT strValue = "";
    SaStringT* strValues[] = {&strValue};
    SaImmAttrValuesT_2 v1 = {"attr4", SA_IMM_ATTR_SASTRINGT, 1, (void**)strValues};
    SaImmAttrModificationT_2 attrMod = {SA_IMM_ATTR_VALUES_REPLACE, v1};
    const SaImmAttrModificationT_2 *attrMods[] = {&attrMod, NULL};
    const SaImmAttrNameT attributeNames[2] = { "attr4", NULL };
    SaImmAttrValuesT_2 **attributes;
    SaStringT str;

    safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK);
    safassert(saImmOmAdminOwnerInitialize(immOmHandle, adminOwnerName, SA_TRUE, &ownerHandle), SA_AIS_OK);
    safassert(saImmOmAdminOwnerSet(ownerHandle, objectNames, SA_IMM_ONE), SA_AIS_OK);
    safassert(config_object_create(immOmHandle, ownerHandle, &rootObj), SA_AIS_OK);
    safassert(saImmOmAdminOwnerSet(ownerHandle, dnObjs, SA_IMM_ONE), SA_AIS_OK);
    safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK);

    safassert(saImmOmCcbObjectModify_2(ccbHandle, &dnObj1, attrMods), SA_AIS_OK);
    safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK);

    safassert(saImmOmAccessorInitialize(immOmHandle, &accessorHandle), SA_AIS_OK);
    safassert(saImmOmAccessorGet_2(accessorHandle, &dnObj1, attributeNames, &attributes), SA_AIS_OK);

    assert(attributes);
    assert(attributes[0]);

    assert(attributes[0]->attrValuesNumber == 1);
    str = *(SaStringT *)attributes[0]->attrValues[0];

    assert(str);
    assert(strlen(str) == 0);

    safassert(saImmOmAccessorFinalize(accessorHandle), SA_AIS_OK);

    test_validate(SA_AIS_OK, SA_AIS_OK);

    safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK);
    safassert(config_object_delete(immOmHandle, ownerHandle), SA_AIS_OK);
    safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK);
    safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK);
}
Example #2
0
pid_t find_connect_imm(pid_t pid){
    SaAisErrorT rc;
    int ret = 0;
    int retry = 0;
    //find object with pid and return its connect pid if exist, otherwise return 0
    while(retry>=0){
        SaImmHandleT immOmHandle;
        SaSelectionObjectT immOmSelectionObject;//use for admin callback
        rc = immom_initialize(&immOmHandle,&immOmSelectionObject);
        printf("DEBUG: immom_initialize() return %d\n",rc);
        if (rc == SA_AIS_OK) {
            SaImmAccessorHandleT accessorHandle;
            rc = saImmOmAccessorInitialize(immOmHandle, &accessorHandle);
            printf("DEBUG: saImmOmAccessorInitialize() return %d\n",rc);
            if (rc == SA_AIS_OK) {
                SaNameT objectName;
                sprintf((char*)objectName.value,"ChatClientId=%d,ChatServerId=1",pid);
                objectName.length = sizeof(objectName.value)-1;
                SaImmAttrValuesT_2 **attributes;
                rc = saImmOmAccessorGet_2(accessorHandle, &objectName, NULL, &attributes);
                printf("DEBUG: saImmOmAccessorGet_2() return %d\n",rc);
                if (rc == SA_AIS_OK){
                    int i = 0;
                    while (attributes[i] != NULL) {
                        if(!strcmp(attributes[i]->attrName,"connect")){
                            if(attributes[i]->attrValuesNumber > 0)
                                ret = *((int *)attributes[i]->attrValues[0]);
                            break;
                        }
                        i++;
                    }
                }else if (rc == SA_AIS_ERR_NOT_EXIST) {
                    syslog(LOG_INFO, "object %s does not exist",objectName.value);
                    ret = -1;
                    rc = SA_AIS_OK;
                }
            }
        }
        immom_finalize(immOmHandle);
        if (rc == SA_AIS_OK)
            return ret;
        retry--;
        usleep(300000);//300ms
    }
    syslog(LOG_INFO,"find_connect_imm(%d) failed %d",pid,rc);
    return 0;
}
static void *test_saImmOmAccessorGet_2(void *arg)
{
    SaNameT *dn = (SaNameT *) arg;
    SaImmAttrNameT attributeName = attrMod1.modAttr.attrName;
    SaImmAttrNameT attributeNames[2] = {attributeName, NULL};

    TRACE_ENTER();

    safassert(saImmOmInitialize(&immOmHandle, &immOmCallbacks, &immVersion), SA_AIS_OK);
    safassert(saImmOmAccessorInitialize(immOmHandle, &accessorHandle), SA_AIS_OK);
    safassert(saImmOmAccessorGet_2(accessorHandle, dn, attributeNames, &attributes), SA_AIS_OK);
    safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK);
    assert(attributes[0]->attrValueType == SA_IMM_ATTR_SAINT32T);
    assert(*((SaInt32T*) attributes[0]->attrValues[0]) == int1Value);

    TRACE_LEAVE();
    return NULL;
}
Example #4
0
static PyObject *
immom_saImmOmAccessorGet(PyObject *self, PyObject *args)
{
    SaAisErrorT rc;
    SaImmAccessorHandleT accessorHandle;
    SaImmAttrValuesT_2** attributes;
    SaNameT searchroot;
    char const* root;
    PyObject* rlist;

    if (!PyArg_ParseTuple(args, "s", &root)) 
        return NULL;
    if (immom_saName(root, &searchroot) == NULL)
        return NULL;

    rc = saImmOmAccessorInitialize(immOmHandle, &accessorHandle);
    if (rc != SA_AIS_OK) return immom_aisException(rc);

    rc = saImmOmAccessorGet_2(
        accessorHandle, &searchroot, NULL, &attributes);
    if (rc != SA_AIS_OK) {
        (void)saImmOmAccessorFinalize(accessorHandle);
        return immom_aisException(rc);
    }

    rlist = PyList_New(0);
    if (rlist == NULL) return NULL;

    while (*attributes != NULL) {
        SaImmAttrValuesT_2* a = *attributes;
        char const* t = valuetype2str(a->attrValueType);
	PyObject* aval = Py_BuildValue("(ss[])", a->attrName, t);
	if (immom_makeValueList(a, PyTuple_GetItem(aval, 2)) == NULL) 
		return NULL;
	if (PyList_Append(rlist, aval) < 0) return NULL;
        attributes++;
    }

    (void)saImmOmAccessorFinalize(accessorHandle);
    return rlist;
}
static void saImmOmLongDn_07(void) {
	SaImmHandleT immHandle;
	SaImmAccessorHandleT accessorHandle;
	SaAisErrorT rc;
	SaNameT dn;
	SaImmAttrValuesT_2 **attributes;
	int i;
	int score = 0;

	osaf_extended_name_lend(longDn, &dn);

	setupLongDn();

	safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK);

	safassert(saImmOmAccessorInitialize(immHandle, &accessorHandle), SA_AIS_OK);
	rc = saImmOmAccessorGet_2(accessorHandle, &dn, NULL, &attributes);
	if(rc == SA_AIS_OK) {
		for(i=0; attributes[i]; i++) {
			if(!strcmp(attributes[i]->attrName, "rdn") || !strcmp(attributes[i]->attrName, "attr8")) {
				assert(attributes[i]->attrValuesNumber > 0);
				assert(strcmp(osaf_extended_name_borrow((SaNameT *)(attributes[i]->attrValues[0])), longDn) == 0);
				score++;
			}
		}

		// Both SaNameT values are correct
		assert(score == 2);
	}
	safassert(saImmOmAccessorFinalize(accessorHandle), SA_AIS_OK);

	safassert(saImmOmFinalize(immHandle), SA_AIS_OK);

	test_validate(rc, SA_AIS_OK);

	cleanLongDn();
}
void saImmOmCcbObjectModify_2_13(void)
{
    const SaImmAdminOwnerNameT adminOwnerName = (SaImmAdminOwnerNameT) __FUNCTION__;
    SaImmAdminOwnerHandleT ownerHandle;
    SaImmCcbHandleT ccbHandle;
    SaImmAccessorHandleT accessorHandle;
    const SaNameT *objectNames[] = {&rootObj, NULL};
    SaAnyT anyValue = { 0, (SaUint8T *)"" };
    SaAnyT* anyValues[] = { &anyValue, &anyValue, &anyValue };
    SaImmAttrValuesT_2 any5 = {"attr5", SA_IMM_ATTR_SAANYT, 1, (void **)anyValues};
    SaImmAttrValuesT_2 any6 = {"attr6", SA_IMM_ATTR_SAANYT, 3, (void **)anyValues};
    SaImmAttrModificationT_2 attrMod5 = {SA_IMM_ATTR_VALUES_REPLACE, any5};
    SaImmAttrModificationT_2 attrMod6 = {SA_IMM_ATTR_VALUES_REPLACE, any6};
    const SaImmAttrModificationT_2 *attrMods[] = {&attrMod5, &attrMod6, NULL};
    SaImmAttrValuesT_2 **attributes;
    int i, k, counter;

    safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK);
    safassert(saImmOmAdminOwnerInitialize(immOmHandle, adminOwnerName, SA_TRUE, &ownerHandle), SA_AIS_OK);
    safassert(saImmOmAdminOwnerSet(ownerHandle, objectNames, SA_IMM_ONE), SA_AIS_OK);
    safassert(config_object_create(immOmHandle, ownerHandle, &rootObj), SA_AIS_OK);
    safassert(saImmOmAdminOwnerSet(ownerHandle, dnObjs, SA_IMM_ONE), SA_AIS_OK);
    safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK);

    safassert(saImmOmCcbObjectModify_2(ccbHandle, &dnObj1, attrMods), SA_AIS_OK);
    safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK);

    safassert(saImmOmAccessorInitialize(immOmHandle, &accessorHandle), SA_AIS_OK);
    safassert(saImmOmAccessorGet_2(accessorHandle, &dnObj1, NULL, &attributes), SA_AIS_OK);

    counter = 0;
    for(i=0; attributes[i]; i++) {
    	SaAnyT *any;
    	if(!strcmp(attributes[i]->attrName, "attr5")) {
    		counter++;
    		/* Test that there is one SaAnyT value */
    		assert(attributes[i]->attrValuesNumber == 1);
    		/* ... and it's not NULL */
    		assert(attributes[i]->attrValues);
    		any = (SaAnyT *)(attributes[i]->attrValues[0]);
    		/* ... and return value is empty string */
    		assert(any);
    		assert(any->bufferSize == 0);
    	} else if(!strcmp(attributes[i]->attrName, "attr6")) {
    		counter++;
    		/* Test that there are three SaAnyT values */
    		assert(attributes[i]->attrValuesNumber == 3);
    		assert(attributes[i]->attrValues);
    		/* All three values are empty strings */
    		for(k=0; k<3; k++) {
				any = (SaAnyT *)(attributes[i]->attrValues[k]);
				assert(any);
				assert(any->bufferSize == 0);
    		}
    	}
    }

    /* We have tested both parameters */
    assert(counter == 2);

    /* If we come here, then the test is successful */
    test_validate(SA_AIS_OK, SA_AIS_OK);

    safassert(saImmOmAccessorFinalize(accessorHandle), SA_AIS_OK);
    safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK);
    safassert(config_object_delete(immOmHandle, ownerHandle), SA_AIS_OK);
    safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK);
    safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK);
}
void saImmOmThreadInterference_01(void) {
	SaImmHandleT immHandle;
	SaImmOiHandleT immOiHandle;
	SaImmAdminOwnerHandleT ownerHandle;
	SaImmSearchHandleT searchHandle;
	SaImmCcbHandleT ccbHandle;
	pthread_t threadid1, threadid2;
	SaAisErrorT rc;
	SaImmAttrDefinitionT_2 attrDef = { "rdn", SA_IMM_ATTR_SASTRINGT, SA_IMM_ATTR_RDN | SA_IMM_ATTR_CONFIG, NULL };
	const SaImmAttrDefinitionT_2 *attrDefs[2] = { &attrDef, NULL };
	SaImmClassCategoryT classCategory;
	SaImmAttrDefinitionT_2 **attrDefinitions;
	SaImmAccessorHandleT accessorHandle;
	SaImmAttrNameT attributeNames[2] = { "SaImmAttrClassName", NULL};
	SaImmAttrValuesT_2 **attributes;
	SaImmAttrValueT objNames[2] = { &objectName, NULL };
	SaImmAttrValuesT_2 attrValue = { (SaImmAttrNameT)"rdn", SA_IMM_ATTR_SANAMET, 1, (SaImmAttrValueT *)objNames };
	const SaImmAttrValuesT_2 *attrValues[2] = { &attrValue, NULL };
	SaImmAttrValueT modAttrValue[2] = { "Test", NULL };
	const SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, { "attr4", SA_IMM_ATTR_SASTRINGT, 1, modAttrValue } };
	const SaImmAttrModificationT_2 *attrMods[] = { &attrMod, NULL };

	objectName.length = strlen("Obj1");
	strcpy((char *)objectName.value, "Obj1");

	/* management */
	safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK);
	safassert(saImmOmAdminOwnerInitialize(immHandle, adminOwnerName, SA_TRUE, &ownerHandle), SA_AIS_OK);
	/* create test object */
	safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK);
	safassert(saImmOmCcbObjectCreate_2(ccbHandle, configClassName, NULL, attrValues), SA_AIS_OK);
	safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK);
	safassert(saImmOmAdminOwnerSet(ownerHandle, objectNames, SA_IMM_ONE), SA_AIS_OK);

	/* implementer */
	isReady = 0;
	isOiDone = 0;
	safassert(saImmOiInitialize_2(&immOiHandle, &immOiCallbacks, &immVersion), SA_AIS_OK);
	safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK);
	safassert(saImmOiObjectImplementerSet(immOiHandle, &objectName, SA_IMM_ONE), SA_AIS_OK);
	assert(!pthread_create(&threadid1, NULL, implementer_thread, &immOiHandle));

	while(!isReady)
		usleep(100);

	/* "lock" IMM OM handle */
	isReady = 0;
	isOmDone = 0;
	isAdminOperDone = 0;
	assert(!pthread_create(&threadid2, NULL, lockomhandle_thread, &ownerHandle));

	while(!isReady)
		usleep(100);

	/* OM function tests */
	if((rc = saImmOmFinalize(immHandle)) !=  SA_AIS_ERR_LIBRARY) goto done;

	if((rc = saImmOmClassCreate_2(immHandle, (const SaImmClassNameT)"TestClass", SA_IMM_CLASS_CONFIG, (const SaImmAttrDefinitionT_2 **)attrDefs)) !=  SA_AIS_ERR_LIBRARY) goto done;
	if((rc = saImmOmClassDescriptionGet_2(immHandle, (const SaImmClassNameT)"TestClass", &classCategory, &attrDefinitions)) !=  SA_AIS_ERR_LIBRARY) goto done;
	if((rc = saImmOmClassDelete(immHandle, (const SaImmClassNameT)"TestClass")) !=  SA_AIS_ERR_LIBRARY) goto done;

	if((rc = saImmOmSearchInitialize_2(immHandle, NULL, SA_IMM_SUBTREE,
			SA_IMM_SEARCH_ONE_ATTR | SA_IMM_SEARCH_GET_NO_ATTR, NULL, NULL, &searchHandle)) !=  SA_AIS_ERR_LIBRARY) goto done;

	safassert(saImmOmAccessorInitialize(immHandle, &accessorHandle), SA_AIS_OK);
	if((rc = saImmOmAccessorGet_2(accessorHandle, &objectName, attributeNames, &attributes)) !=  SA_AIS_ERR_LIBRARY) goto done;
	safassert(saImmOmAccessorFinalize(accessorHandle), SA_AIS_OK);

	if((rc = saImmOmCcbObjectModify_2(ccbHandle, &objectName, attrMods)) !=  SA_AIS_ERR_LIBRARY) goto done;
	if((rc = saImmOmCcbObjectDelete(ccbHandle, &objectName)) !=  SA_AIS_ERR_LIBRARY) goto done;

done:
	isAdminOperDone = 1;
	while(!isOmDone)
		usleep(200);

	test_validate(rc, SA_AIS_ERR_LIBRARY);

	/* Finalize OI handle */
	safassert(saImmOiObjectImplementerRelease(immOiHandle, &objectName, SA_IMM_ONE), SA_AIS_OK);
	safassert(saImmOiImplementerClear(immOiHandle), SA_AIS_OK);
	safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK);

	/* Use pthread_detach() to remove pthread_create@@GLIBC leak from valgrind */
	pthread_detach(threadid1);
	pthread_detach(threadid2);

	while(!isOiDone)
		usleep(200);

	/* Remove test object and test class */
	safassert(saImmOmCcbObjectDelete(ccbHandle, &objectName), SA_AIS_OK);
	safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK);

	/* Finalize OM handles */
	saImmOmCcbFinalize(ccbHandle);
	saImmOmAdminOwnerRelease(ownerHandle, objectNames, SA_IMM_ONE);
	saImmOmAdminOwnerFinalize(ownerHandle);
	saImmOmFinalize(immHandle);
}