void testAssociationClass(CIMClient & client, const CIMName & className) { cout << "Testing Association Class " << (const char *)className.getString().getCString() << "..."; Array<CIMInstance> instances = testAnyClass(client, className); for(unsigned int i = 0, n = instances.size(); i < n; ++i) { // // Now make sure that the references are valid and that association // traversal between them is working properly. // CIMObjectPath referenceA; CIMObjectPath referenceB; CIMInstance currentInstance = instances[i]; CIMObjectPath currentInstanceName = currentInstance.getPath(); if(currentInstanceName.getNameSpace().isNull()) currentInstanceName.setNameSpace(interopNamespace); for(unsigned int j = 0, m = currentInstance.getPropertyCount(); j < m; ++j) { CIMProperty currentProp = currentInstance.getProperty(j); if(currentProp.getValue().getType() == CIMTYPE_REFERENCE) { if(referenceA.getKeyBindings().size() == 0) { currentProp.getValue().get(referenceA); } else { currentProp.getValue().get(referenceB); break; } } } if(referenceA.getKeyBindings().size() == 0 || referenceB.getKeyBindings().size() == 0) { exitFailure( String("Could not find reference properties for ") + String("association: ") + currentInstanceName.toString()); } try { client.getInstance(referenceA.getNameSpace(), referenceA); client.getInstance(referenceB.getNameSpace(), referenceB); } catch(CIMException &) { exitFailure(String("Could not get instances for association : ") + currentInstanceName.toString()); } Boolean associationFailure = false; try { Array<CIMObjectPath> results = client.associatorNames( referenceA.getNameSpace(), referenceA, className); Boolean found = false; for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath result = results[j]; result.setHost(referenceB.getHost()); result.setNameSpace(referenceB.getNameSpace()); if(result == referenceB) { found = true; break; } } if(found) { results = client.associatorNames(referenceB.getNameSpace(), referenceB, className); for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath result = results[j]; result.setHost(referenceA.getHost()); result.setNameSpace(referenceA.getNameSpace()); if(result == referenceA) { found = true; break; } } } if(!found) { associationFailure = true; } } catch(CIMException & e) { cout << "Exception: " << e.getMessage() << endl; associationFailure = true; } if(associationFailure) { exitFailure(String("Association traversal failed between ") + String("instances of association: ") + currentInstanceName.toString()); } Boolean referencesFailure = false; try { Array<CIMObjectPath> results = client.referenceNames( referenceA.getNameSpace(), referenceA, className); Boolean found = false; for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath currentPath = results[j]; if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); if(currentPath.getHost().size() != 0) currentPath.setHost(String::EMPTY); if(currentPath == currentInstanceName) { found = true; break; } } if(found) { results = client.referenceNames(referenceB.getNameSpace(), referenceB, className); for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath currentPath = results[j]; if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); if(currentPath.getHost().size() != 0) currentPath.setHost(String::EMPTY); if(currentPath == currentInstanceName) { found = true; break; } } } if(!found) { referencesFailure = true; } } catch(CIMException &) { referencesFailure = true; } if(referencesFailure) { exitFailure(String("References operation failed for ") + String("instances of association: ") + currentInstanceName.toString()); } } cout << "Test Complete" << endl; }
int main(const int argc, const char **argv) { // error if no args if (argv[1] == 0) { _usage(); return 1; } SSLContext *sslContext = 0; // initialized for unencrypted connection _c.setTimeout(TIMEOUT); // Get hostname from environment, if defined char *p = getenv("CIM_HOST"); if (p) _hostName = p; // Get port number, if defined char *pn = getenv("CIM_PORT"); if (pn) _portNumber = atol(pn); if (p) { // hostname was specified, we will not connect local // so decide whether encrypted or not char *s = getenv("CIM_NOSSL"); if (s) // don't use ssl (not encrypted) { if (!pn) _portNumber = 5988; // use 5988 if no port specified } else { try { sslContext = new SSLContext(PEGASUS_SSLCLIENT_CERTIFICATEFILE, verifyServerCertificate, PEGASUS_SSLCLIENT_RANDOMFILE /* "/var/opt/wbem/ssl.rnd" */); } catch (Exception &e) { cerr << e.getMessage() << endl; return 1; } if (!pn) _portNumber = 5989; // use 5989 if no port specified } } // Get namespace from environment or use default p = getenv("CIM_NAMESPACE"); _nameSpace = (p==0)? DEFAULT_NAMESPACE:p; // Get user from environment or don't specify p = getenv("CIM_USER"); _userName = (p==0)? String::EMPTY : p; // Get password from environment or use empty p = getenv("CIM_PASSWORD"); _passWord = (p==0)? String::EMPTY : p; try { if (String::equal(_hostName,String::EMPTY)) _c.connectLocal(); else // hostname was specified; do remote connect { if (sslContext) _c.connect(_hostName, _portNumber, *sslContext, _userName, _passWord); else _c.connect(_hostName, _portNumber, _userName, _passWord); } } catch(Exception& e) { cerr << e.getMessage() << endl; return 1; } // command is first arg const char *cmd = argv[1]; if (String::equalNoCase(cmd,"getClass") || String::equalNoCase(cmd,"gc")) return _getClass(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"enumerateClasses") || String::equalNoCase(cmd,"ec")) return _enumerateClasses(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"enumerateClassNames") || String::equalNoCase(cmd,"ecn")) return _enumerateClassNames(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"getInstance") || String::equalNoCase(cmd,"gi")) return _getInstance(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"enumerateInstances") || String::equalNoCase(cmd,"ei")) return _enumerateInstances(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"enumerateInstanceNames") || String::equalNoCase(cmd,"ein")) return _enumerateInstanceNames(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"getProperty") || String::equalNoCase(cmd,"gp")) return _getProperty(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"setProperty") || String::equalNoCase(cmd,"sp")) return _setProperty(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"invokeMethod") || String::equalNoCase(cmd,"im")) return _invokeMethod(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"createClass") || String::equalNoCase(cmd,"cc")) return _createClass(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"modifyClass") || String::equalNoCase(cmd,"mc")) return _modifyClass(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"deleteClass") || String::equalNoCase(cmd,"dc")) return _deleteClass(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"createInstance") || String::equalNoCase(cmd,"ci")) return _createInstance(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"modifyInstance") || String::equalNoCase(cmd,"mi")) return _modifyInstance(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"deleteInstance") || String::equalNoCase(cmd,"di")) return _deleteInstance(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"associators") || String::equalNoCase(cmd,"a")) return _associators(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"associatorNames") || String::equalNoCase(cmd,"an")) return _associatorNames(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"references") || String::equalNoCase(cmd,"r")) return _references(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"referenceNames") || String::equalNoCase(cmd,"rn")) return _referenceNames(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"execQuery") || String::equalNoCase(cmd,"exq")) return _execQuery(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"getQualifier") || String::equalNoCase(cmd,"gq")) return _getQualifier(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"setQualifier") || String::equalNoCase(cmd,"sq")) return _setQualifier(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"deleteQualifier") || String::equalNoCase(cmd,"dq")) return _deleteQualifier(argc-2,&argv[2]); else if (String::equalNoCase(cmd,"enumerateQualifiers") || String::equalNoCase(cmd,"eq")) return _enumerateQualifiers(argc-2,&argv[2]); else { cerr << cmd << ": Invalid CIM operation."<< endl; _usage(); return 1; } }
int main(int argc, char** argv) { verbose = (getenv("PEGASUS_TEST_VERBOSE")) ? true : false; // // Check for command line option // if (argc != 2) { cerr << "Usage: TestCMPIAssociation {namespace}" << endl; return(1); } providerNamespace = CIMNamespaceName (argv[1]); CIMClient client; // Connect to server try { client.connectLocal(); } catch (Exception& e) { _errorExit(e.getMessage()); } // ======================================================================= // Test passing Instance object path to the Association Methods // ======================================================================= // Get the instance object paths for the Person and Vehicle class // Array<CIMObjectPath> personRefs; Array<CIMObjectPath> vehicleRefs; try { personRefs = client.enumerateInstanceNames(providerNamespace, CMPI_TEST_PERSON); vehicleRefs = client.enumerateInstanceNames(providerNamespace, CMPI_TEST_VEHICLE); } catch (Exception& e) { cerr << "enumerateInstanceNames() failed." << endl; _errorExit(e.getMessage()); } for(Uint32 i=0;i<personRefs.size();i++) { cout<<"PersonRefs values : "<<personRefs[i].toString()<<endl; } for(Uint32 i=0;i<vehicleRefs.size();i++) { cout<<"VehicleRefs values : "<<vehicleRefs[i].toString()<<endl; } Uint32 numPersonInstances = personRefs.size(); Uint32 numVehicleInstances = vehicleRefs.size(); cout << "Number of PersonInstances: " << numPersonInstances << endl; cout << "Number of VehicleInstances: " << numVehicleInstances << endl; // ======================================================================= // Test associators // // Get the CIM instances that are associated with the specified source CIM // instance via an instance of a specified association class. // ======================================================================= if (verbose) { cout << "+++++ Test associators" << endl; } for (Uint32 i = 0; i < numPersonInstances; i++) { _testAssociators( client, CMPI_TEST_RACING, personRefs[i], resultArray_asso_P1[i]); } for (Uint32 i = 0; i < numVehicleInstances; i++) { _testAssociators(client, CMPI_TEST_RACING, vehicleRefs[i], resultArray_asso_V1[i]); } // ======================================================================= // Test associatorNames // // Get the names of the CIM instances that are associated with the specified // source CIM instance via an instance of a association class. // ======================================================================= if (verbose) { cout << "+++++ Test associatorNames" << endl; } for (Uint32 i = 0; i < numPersonInstances; i++) { _testAssociatorNames(client, CMPI_TEST_RACING, personRefs[i], resultArray_asso_P1[i]); } for (Uint32 i = 0; i < numVehicleInstances; i++) { _testAssociatorNames(client, CMPI_TEST_RACING, vehicleRefs[i], resultArray_asso_V1[i]); } // ======================================================================= // Test references // // Get the association instances that refer to the specified target CIM // instance. // ======================================================================= if (verbose) { cout << "+++++ Test references" << endl; } for (Uint32 i = 0; i < numPersonInstances; i++) { _testReferences(client, personRefs[i], resultArray_ref_P[i]); } for (Uint32 i = 0; i < numVehicleInstances; i++) { _testReferences(client, vehicleRefs[i], resultArray_ref_V[i]); } // ======================================================================= // Test property filter for associators and references // ======================================================================= _testCMPIFilterOfAssociation(client); // ======================================================================= // Test referenceNames // // Get the names of the association instances that refer to the specified // source CIM instance. // ======================================================================= if (verbose) { cout << "+++++ Test referenceNames" << endl; } for (Uint32 i = 0; i < numPersonInstances; i++) { _testReferenceNames(client, personRefs[i], resultArray_ref_P[i]); } for (Uint32 i = 0; i < numVehicleInstances; i++) { _testReferenceNames(client, vehicleRefs[i], resultArray_ref_V[i]); } // ======================================================================= // Test passing Class object path to the Association Methods // ======================================================================= if (verbose) { cout << "+++++ Test association class operations" << endl; } _testCMPIAssociationClassOperations(client, CMPI_TEST_PERSON); _testCMPIAssociationClassOperations(client, CMPI_TEST_VEHICLE); // ======================================================================= // Association tests completed // ======================================================================= cout << argv[0] << " +++++ passed all tests" << endl; return(0); }
// enumerate instances normalization (with request permutations) void Test3(CIMClient& client) { if(verbose) { cout << "Test3()" << endl; } { Boolean deepInheritance = false; Boolean localOnly = false; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; if(verbose) { cout << "deepInheritance = " << (deepInheritance ? "true" : "false") << endl; cout << "localOnly = " << (localOnly ? "true" : "false") << endl; cout << "includeQualifiers = " << (includeQualifiers ? "true" : "false") << endl; cout << "includeClassOrigin = " << (includeClassOrigin ? "true" : "false") << endl; } Array<CIMInstance> cimInstances = client.enumerateInstances( NAMESPACE, CLASSNAME, deepInheritance, localOnly, includeQualifiers, includeClassOrigin, CIMPropertyList()); for(Uint32 i = 0, n = cimInstances.size(); i < n; i++) { if(verbose) { cout << (isValid(cimInstances[i].getPath()) ? "GOOD" : "BAD") << ": " << cimInstances[i].getPath().toString() << endl; XmlWriter::printInstanceElement(cimInstances[i]); } } } { Boolean deepInheritance = true; Boolean localOnly = false; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; if(verbose) { cout << "deepInheritance = " << (deepInheritance ? "true" : "false") << endl; cout << "localOnly = " << (localOnly ? "true" : "false") << endl; cout << "includeQualifiers = " << (includeQualifiers ? "true" : "false") << endl; cout << "includeClassOrigin = " << (includeClassOrigin ? "true" : "false") << endl; } Array<CIMInstance> cimInstances = client.enumerateInstances( NAMESPACE, CLASSNAME, deepInheritance, localOnly, includeQualifiers, includeClassOrigin, CIMPropertyList()); for(Uint32 i = 0, n = cimInstances.size(); i < n; i++) { if(verbose) { cout << (isValid(cimInstances[i].getPath()) ? "GOOD" : "BAD") << ": " << cimInstances[i].getPath().toString() << endl; XmlWriter::printInstanceElement(cimInstances[i]); } } } { Boolean deepInheritance = true; Boolean localOnly = false; Boolean includeQualifiers = true; Boolean includeClassOrigin = false; if(verbose) { cout << "deepInheritance = " << (deepInheritance ? "true" : "false") << endl; cout << "localOnly = " << (localOnly ? "true" : "false") << endl; cout << "includeQualifiers = " << (includeQualifiers ? "true" : "false") << endl; cout << "includeClassOrigin = " << (includeClassOrigin ? "true" : "false") << endl; } Array<CIMInstance> cimInstances = client.enumerateInstances( NAMESPACE, CLASSNAME, deepInheritance, localOnly, includeQualifiers, includeClassOrigin, CIMPropertyList()); for(Uint32 i = 0, n = cimInstances.size(); i < n; i++) { if(verbose) { cout << (isValid(cimInstances[i].getPath()) ? "GOOD" : "BAD") << ": " << cimInstances[i].getPath().toString() << endl; XmlWriter::printInstanceElement(cimInstances[i]); } } } { Boolean deepInheritance = true; Boolean localOnly = false; Boolean includeQualifiers = true; Boolean includeClassOrigin = true; if(verbose) { cout << "deepInheritance = " << (deepInheritance ? "true" : "false") << endl; cout << "localOnly = " << (localOnly ? "true" : "false") << endl; cout << "includeQualifiers = " << (includeQualifiers ? "true" : "false") << endl; cout << "includeClassOrigin = " << (includeClassOrigin ? "true" : "false") << endl; } Array<CIMInstance> cimInstances = client.enumerateInstances( NAMESPACE, CLASSNAME, deepInheritance, localOnly, includeQualifiers, includeClassOrigin, CIMPropertyList()); for(Uint32 i = 0, n = cimInstances.size(); i < n; i++) { if(verbose) { cout << (isValid(cimInstances[i].getPath()) ? "GOOD" : "BAD") << ": " << cimInstances[i].getPath().toString() << endl; XmlWriter::printInstanceElement(cimInstances[i]); } } } }
int main(const int argc, const char **argv) { // output looks like: // PG_OperatingSystem /// Namespaces: root/cimv2 // Provider: PG_OperatingSystemProvider // Type: Instance // Module: OperatingSystemModule // File: libOSProvider.sl _c.setTimeout(PEGASUS_DEFAULT_CLIENT_TIMEOUT_MILLISECONDS); // everything in big try/catch to display errors try { _c.connectLocal(); // Start by enumerating PG_ProviderCapabilities Array<CIMObjectPath> capRef = _c.enumerateInstanceNames(PEGASUS_NAMESPACENAME_INTEROP, "PG_ProviderCapabilities"); for (int i=0; i<capRef.size(); i++) { // get the instance CIMInstance cap = _c.getInstance(PEGASUS_NAMESPACENAME_INTEROP,capRef[i]); // get referenced instance of PG_ProviderModule for later use String pMod; cap.getProperty( cap.findProperty("ProviderModuleName")).getValue().get(pMod); CIMObjectPath modRef(String("PG_ProviderModule.Name=\"") + pMod + "\""); CIMInstance mod = _c.getInstance(PEGASUS_NAMESPACENAME_INTEROP,modRef); // display name of class instrumented String className; cap.getProperty(cap.findProperty("ClassName")).getValue().get(className); cout << endl << className << endl; // display namespaces Array<String> nameSpaces; cap.getProperty( cap.findProperty("Namespaces")).getValue().get(nameSpaces); cout << " Namespaces:"; for (int j=0; j<nameSpaces.size(); j++) cout << " " << nameSpaces[j]; cout << endl; // display name of provider String pName; cap.getProperty(cap.findProperty("ProviderName")).getValue().get(pName); cout << " Provider: " << pName << endl; // display type of provider Array<Uint16> pType; cap.getProperty(cap.findProperty("ProviderType")).getValue().get(pType); cout << " Type: "; for (int j=0; j<pType.size(); j++) cout << " " << _providerType[ pType[j] ]; cout << endl; // display state Array<Uint16> state; mod.getProperty( mod.findProperty("OperationalStatus")).getValue().get(state); cout << " State: "; for (int j=0; j<state.size(); j++) cout << " " << _providerState[ state[j] ]; cout << endl; // display module cout << " Module: " << pMod << endl; // display file (PG_ProviderModule.Location) String loc; mod.getProperty(mod.findProperty("Location")).getValue().get(loc); cout << " File: lib" << loc << ".sl" << endl; } } catch (Exception &e) { cerr << e.getMessage() << endl; return 1; } return 0; }
void _testCMPIAssociationClassOperations(CIMClient& client, CIMName className) { Array<CIMObjectPath> resultObjectPaths; Array<CIMObject> resultObjects; CIMObjectPath op(className.getString()); CIMName assocClass; CIMName resultClass; String role; String resultRole; // ======================================================================= // associators // // Get the CIM classes that are associated with the specified CIM Class // ======================================================================= if (verbose) { cout << "+++++ Test associators for (" << className.getString(); cout << ")" << endl; } try { // get the association classes resultObjects = client.associators(providerNamespace, op, assocClass, resultClass, role, resultRole); // display result _displayResult(resultObjects); } catch (Exception& e) { // Do nothing. _errorExit(e.getMessage()); } // ======================================================================= // associatorNames // // Get the name of the CIM classes that are associated with the specified // CIM class. // ======================================================================= if (verbose) { cout << "+++++ Test associatorNames for (" << className.getString(); cout << ")" << endl; } try { resultObjectPaths = client.associatorNames( providerNamespace, op, assocClass, resultClass, role, resultRole); // display result _displayResult(resultObjectPaths); } catch (Exception& e) { // Do nothing. _errorExit(e.getMessage()); } // ======================================================================= // references // // Get the association classes that refer to the specified CIM class. // ======================================================================= if (verbose) { cout << "+++++ Test references for (" << className.getString() << ")" << endl; } try { resultObjects = client.references( providerNamespace, op, resultClass, role); // display result _displayResult(resultObjects); } catch (Exception& e) { // Do nothing. _errorExit(e.getMessage()); } // ======================================================================= // referenceNames // // Get the names of the association classes that refer to the specified // CIM class. // ======================================================================= if (verbose) { cout << "+++++ Test referenceNames for (" << className.getString(); cout << ")" << endl; } try { resultObjectPaths = client.referenceNames(providerNamespace, op, resultClass, role); // display result _displayResult(resultObjectPaths); } catch (Exception& e) { // Do nothing. _errorExit(e.getMessage()); } }
static void TestNamespaceHierarchy1 ( CIMClient& client, Boolean activeTest, Boolean verboseTest) { Array<CIMNamespaceName> namespaces; String instanceName; namespaces.append(CIMNamespaceName ("test1")); namespaces.append(CIMNamespaceName ("test2")); namespaces.append(CIMNamespaceName ("test3")); namespaces.append(CIMNamespaceName ("test4")); namespaces.append(CIMNamespaceName ("test5")); namespaces.append(CIMNamespaceName ("test6")); namespaces.append(CIMNamespaceName ("test1/test2")); namespaces.append(CIMNamespaceName ("test1/test2/test3")); namespaces.append(CIMNamespaceName ("test1/test2/test3/test4")); namespaces.append(CIMNamespaceName ("test1/test2/test3/test4/test5")); namespaces.append(CIMNamespaceName ("test1/test2/test3/test4/test5/test6")); if(verboseTest) { cout << "++ Cleanup existing test namespaces" << endl; } for (Sint32 i = namespaces.size()-1; i > -1; i--) { // Build the instance name for __namespace CIMNamespaceName testNamespaceName = namespaces[i]; instanceName.clear(); instanceName.append(CLASSNAME.getString()); instanceName.append( ".Name=\""); instanceName.append(testNamespaceName.getString()); instanceName.append("\""); try { CIMObjectPath myReference(instanceName); if(verboseTest) cout << "Deleting " << testNamespaceName << endl; client.deleteInstance(__NAMESPACE_NAMESPACE, myReference); } catch(...) { //Ignore errors we are just trying to cleanup } } if(verboseTest) { cout << "++ Create test namespaces" << endl; } for (Uint32 i = 0; i < namespaces.size(); i++) { // Build the instance name for __namespace CIMNamespaceName testNamespaceName = namespaces[i]; String instanceName = CLASSNAME.getString(); instanceName.append( ".Name=\""); instanceName.append(testNamespaceName.getString()); instanceName.append("\""); if(verboseTest) { cout << "Creating " << testNamespaceName << endl; } try { // Build the new instance CIMInstance newInstance(CLASSNAME); newInstance.addProperty(CIMProperty(CIMName ("name"), testNamespaceName.getString())); client.createInstance(__NAMESPACE_NAMESPACE, newInstance); } catch(Exception& e) { PEGASUS_STD(cerr) << "Exception NameSpace Creation: " << e.getMessage() << " Creating " << instanceName << PEGASUS_STD(endl); exit(1); } } for (Sint32 i = namespaces.size()-1; i > -1; i--) { // Build the instance name for __namespace CIMNamespaceName testNamespaceName = namespaces[i]; instanceName.clear(); instanceName.append(CLASSNAME.getString()); instanceName.append( ".Name=\""); instanceName.append(testNamespaceName.getString()); instanceName.append("\""); try { CIMObjectPath myReference(instanceName); if(verboseTest) cout << "getInstance " << testNamespaceName << endl; CIMInstance namespaceInstance = client.getInstance(__NAMESPACE_NAMESPACE, myReference); } catch(Exception& e) { PEGASUS_STD(cerr) << "Exception NameSpace Deletion1: " << e.getMessage() << " Deleting " << instanceName << PEGASUS_STD(endl); exit(1); } } if(verboseTest) cout << "++ Delete test namespaces " << endl; for (Sint32 i = namespaces.size()-1; i > -1; i--) { // Build the instance name for __namespace CIMNamespaceName testNamespaceName = namespaces[i]; instanceName.clear(); instanceName.append(CLASSNAME.getString()); instanceName.append( ".Name=\""); instanceName.append(testNamespaceName.getString()); instanceName.append("\""); try { CIMObjectPath myReference(instanceName); if(verboseTest) cout << "Deleting " << testNamespaceName << endl; client.deleteInstance(__NAMESPACE_NAMESPACE, myReference); } catch(Exception& e) { PEGASUS_STD(cerr) << "Exception NameSpace Deletion 2: " << e.getMessage() << " Deleting " << instanceName << PEGASUS_STD(endl); exit(1); } } }
int main(int argc, char** argv) { char *ptr; Uint32 port = 0; String host = "localhost:5988"; String userName; String password; Boolean enumInst = true; Boolean enumInstNames = true; Boolean getInst = true; Boolean verboseTest = false; // check if have a "verbose" on the command line if (argv[1] != 0) { const char *arg = argv[1]; if ((strcmp(arg, "-verbose") == 0) || (strcmp(arg, "verbose") == 0)) verboseTest = true; } ptr = getenv("CIM_HOST"); if (ptr != NULL) host.assign(ptr); ptr = getenv("CIM_PORT"); if (ptr != NULL) port = atol(ptr); ptr = getenv("CIM_USER"); if (ptr != NULL) userName.assign(ptr); ptr = getenv("CIM_PASSWORD"); if (ptr != NULL) password.assign(ptr); // need to first connect to the CIMOM // use null string for user and password, port 5988 if (verboseTest) cout << "Starting NIS Client test" << endl; try { if (verboseTest) cout << "Create client" << endl; // specify the timeout value for the connection (if inactive) // in milliseconds, thus setting to one minute CIMClient client; client.setTimeout(60 * 1000); if (verboseTest) cout << "Client created" << endl; cout << "NISTestClient connecting to " << host << endl; if (port == 0) { // Connect to local host client.connectLocal(); } else { // Conect to remote host client.connect(host, port, userName, password); } cout << "NISTestClient Connected" << endl; NISTestClient testClient(client); if (enumInstNames) { testClient.testEnumerateInstanceNames(client, verboseTest); } if (enumInst) { testClient.testEnumerateInstances(client, verboseTest); } if (getInst) { testClient.testGetInstance(client, verboseTest); } cout << "NISTestClient disconnecting from CIMOM " << endl; client.disconnect(); } catch (Exception& e) { cout << "---- NIS Provider Test Failed " << e.getMessage() << endl; } return 0; }
int main(int argc, char** argv) { Boolean enumInst = true; Boolean enumInstNames = true; Boolean getInst = true; Boolean verboseTest = false; // check if have a "verbose" on the command line if (argv[1] != 0) { const char *arg = argv[1]; if ((strcmp(arg, "-verbose") == 0) || (strcmp(arg, "verbose") == 0)) verboseTest = true; } // need to first connect to the CIMOM // use null string for user and password, port 5988 if (verboseTest) cout << "Starting OS Client test" << endl; try { if (verboseTest) cout << "Create client" << endl; // specify the timeout value for the connection (if inactive) // in milliseconds, thus setting to one minute CIMClient client; client.setTimeout(60 * 1000); if (verboseTest) cout << "Client created" << endl; cout << "OSTestClient connecting via connectLocal() " << endl; client.connectLocal (); cout << "OSTestClient Connected" << endl; OSTestClient testClient(client); if (enumInstNames) { testClient.testEnumerateInstanceNames(client, verboseTest); } if (enumInst) { testClient.testEnumerateInstances(client, verboseTest); } if (getInst) { testClient.testGetInstance(client, verboseTest); } cout << "OSTestClient disconnecting from CIMOM " << endl; client.disconnect(); } catch(Exception& e) { cout << "---- OS Provider Test Failed " << e.getMessage() << endl; } return 0; }
int main(int argc, char** argv) { // char connection[50] = "localhost:5988"; char *address_string = NULL; Uint32 repetitions = 1; // Get environment variables: String pegasusHome; pegasusHome = "/"; // GetEnvironmentVariables(argv[0], pegasusHome); // Get options (from command line and from configuration file); this // removes corresponding options and their arguments fromt he command // line. // Get options (from command line and from configuration file); this // removes corresponding options and their arguments fromt he command // line. OptionManager om; try { GetOptions(om, argc, argv, pegasusHome); } catch (Exception& e) { cerr << argv[0] << ": " << e.getMessage() << endl; exit(1); } // Check to see if user asked for help (-h otpion): if (om.valueEquals("help", "true")) { String header = "Usage "; header.append(argv[0]); header.append(" -parameters host [host]"); String trailer = "Assumes localhost:5988 if host not specified"; trailer.append("\nHost may be of the form name or name:port"); trailer.append("\nPort 5988 assumed if port number missing."); om.printOptionsHelpTxt(header, trailer); exit(0); } String localNameSpace; om.lookupValue("namespace", localNameSpace); globalNamespace = localNameSpace; cout << "Namespace = " << localNameSpace << endl; String userName; om.lookupValue("user", userName); if (userName != String::EMPTY) { cout << "Username = "******"verbose"); String password; om.lookupValue("password", password); if (password != String::EMPTY) { cout << "password = "******"repeat", repeatTestCount)) repeatTestCount = 1; /* if (om.lookupValue("repeat", repeats)) { repeatTestCount = atol(repeats.getCString()); } else repeatTestCount = 1; */ if(verboseTest) cout << "Test repeat count " << repeatTestCount << endl; // Setup the active test flag. Determines if we change repository. Boolean activeTest = false; if (om.valueEquals("active", "true")) activeTest = true; // here we determine the list of systems to test. // All arguments remaining in argv go into list. Boolean localConnection = (om.valueEquals("local", "true"))? true: false; cout << "localConnection " << (localConnection ? "true" : "false") << endl; Array<String> connectionList; if (argc > 1 && !localConnection) for (Sint32 i = 1; i < argc; i++) connectionList.append(argv[i]); // substitute the default if no params if(argc < 2) connectionList.append("localhost:5988"); // Expand host to add port if not defined Boolean useSSL = om.isTrue("ssl"); // Show the connectionlist cout << "Connection List size " << connectionList.size() << endl; for (Uint32 i = 0; i < connectionList.size(); i++) cout << "Connection " << i << " address " << connectionList[i] << endl; for(Uint32 numTests = 1; numTests <= repeatTestCount; numTests++) { cout << "Test Repetition # " << numTests << endl; for (Uint32 i = 0; i < connectionList.size(); i++) { cout << "Start Try Block" << endl; try { cout << "Set Stopwatch" << endl; Stopwatch elapsedTime; cout << "Create client" << endl; CIMClient client; client.setTimeout(60 * 1000); cout << "Client created" << endl; // // Get host and port number from connection list entry // Uint32 index = connectionList[i].find (':'); String host = connectionList[i].subString (0, index); Uint32 portNumber = 0; if (index != PEG_NOT_FOUND) { String portStr = connectionList[i].subString (index + 1, connectionList[i].size ()); sscanf (portStr.getCString (), "%u", &portNumber); } if (useSSL) { // // Get environment variables: // const char* pegasusHome = getenv("PEGASUS_HOME"); String certpath = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE); String randFile; #ifdef PEGASUS_SSL_RANDOMFILE randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE); #endif SSLContext sslcontext(certpath,verifyServerCertificate, randFile); if (om.isTrue("local")) { cout << "Using local SSL connection mechanism " << endl; client.connectLocal(); } else { cout << "connecting to " << connectionList[i] << " using SSL" << endl; client.connect (host, portNumber, sslcontext, userName, password); } } else { if (om.isTrue("local")) { cout << "Using local connection mechanism " << endl; client.connectLocal(); } else { cout << "Connecting to " << connectionList[i] << endl; client.connect (host, portNumber, userName, password); } } cout << "Client Connected" << endl; testStart("Test NameSpace Operations - Relative Name"); elapsedTime.reset(); elapsedTime.start(); TestNamespaceHierarchy1(client, activeTest, verboseTest); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test NameSpace Operations - Absolute Name"); elapsedTime.reset(); elapsedTime.start(); TestNamespaceHierarchy2(client, activeTest, verboseTest); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); client.disconnect(); } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); exit(1); } } } PEGASUS_STD(cout) << "+++++ "<< argv[0] << " Terminated Normally" << PEGASUS_STD(endl); return 0; }
int main (int argc, char ** argv) { try { CIMClient client; // // Connect to CIM Server // try { client.connectLocal (); } catch(Exception& e) { cerr << "Exception thown by client.connectLocal(): " << e.getMessage() << endl; return -1; } if (argc > 2) { _usage (); return 1; } else if (argc == 1) { try { _subscribe (client); } catch(Exception& e) { cerr << "Exception thrown by _subscribe method: " << e.getMessage() << endl; return -1; } Sint32 result = _sendTestIndications (client); if (result == 0) { cout << "Successfully sent test indications" << endl; } else { cerr << "Failed to send test indications" << endl; } try { _unsubscribe (client); } catch(Exception& e) { cerr << "Exception thrown by _unsubscribe method: " << e.getMessage() << endl; return -1; } } else { const char * opt = argv [1]; if (String::equalNoCase (opt, "subscribe")) { try { _subscribe (client); } catch(Exception& e) { cerr << "Exception thrown by _subscribe method: " << e.getMessage() << endl; return -1; } } else if (String::equalNoCase (opt, "sendTestIndications")) { Sint32 result = _sendTestIndications (client); if (result == 0) { cout << "Successfully sent test indications" << endl; } else { cerr << "Failed to send test indications" << endl; } } else if (String::equalNoCase (opt, "unsubscribe")) { try { _unsubscribe (client); } catch(Exception& e) { cerr << "Exception thrown by _unsubscribe method: " << e.getMessage() << endl; return -1; } } else { cerr << "Invalid option: " << opt << endl; _usage (); return -1; } } } catch (Exception & e) { cerr << "SendTestIndications failed: " << e.getMessage () << endl; return -1; } return 0; }
// =========================================================================== // Main // Options: // Test or show - TBD // =========================================================================== int main() { //verbose = getenv("PEGASUS_TEST_VERBOSE"); verbose = "test"; cout << "+++++ Testing AssociationTest Provider" << endl; // Build array of classes Array<CIMName> Classes; Classes.append("TST_ClassA"); Classes.append("TST_ClassB"); Classes.append("TST_ClassC"); Classes.append("TST_ClassD"); Classes.append("TSTDY_ClassA"); Classes.append("TSTDY_ClassB"); Classes.append("TSTDY_ClassC"); Classes.append("TSTDY_ClassD"); Array<CIMName> AssocClasses; AssocClasses.append("TST_AssocI1"); AssocClasses.append("TST_AssocI2"); AssocClasses.append("TST_AssocI3"); AssocClasses.append("TST_AssocI4"); AssocClasses.append("TST_AssocI5"); AssocClasses.append("TST_AssocI6"); AssocClasses.append("TST_AssocNI1"); AssocClasses.append("TST_AssocNI2"); AssocClasses.append("TST_AssocNI3"); AssocClasses.append("TST_AssocNI4"); AssocClasses.append("TST_AssocNI5"); AssocClasses.append("TST_AssocNI6"); // Connect try { c.connect (HOST, PORTNUMBER, String::EMPTY, String::EMPTY); } catch (Exception& e) { errorExit(e); } int rc; // Start by confirming the existence of the classes, etc. if ((rc = testClassList(Classes)) != 0) return rc; if ((rc = testClassList(AssocClasses)) != 0) return rc; // Now start the association tests. // Reference Names Test // Class A Refrence Names Test ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName(), "", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName(), "to", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName(), "from", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI1"), "", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI1"), "to", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI1"), "from", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI3"), "", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI3"), "to", 0)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI3"), "from", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI5"), "", 0)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI5"), "to", 0)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"),CIMName("TST_AssocI5"), "from", 0)); // Class B Refrence Names Test ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName(), "", 4)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName(), "to", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName(), "from", 4)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI2"), "", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI2"), "to", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI2"), "from", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI2"), "", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI2"), "to", 0)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI2"), "from", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI5"), "", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI5"), "to", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"),CIMName("TST_AssocI5"), "from", 1)); // TODO TestReferences for class c and class d // testRefernceName Instances from static store ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName(), "", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName(), "to", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName(), "from", 2)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI1"), "", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI1"), "to", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI1"), "from", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI3"), "", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI3"), "to", 0)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI3"), "from", 1)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI5"), "", 0)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI5"), "to", 0)); ASRT(testReferenceNames(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName("TST_AssocI5"), "from", 0)); // Lets make the previous a common test between ref and ref names. // References // Limited test since we learned most in the previous test of reference names CIMPropertyList NullPL; NullPL.clear(); CIMPropertyList emptyPL; CIMPropertyList fullPL; Array<CIMName> fullPLinput; fullPLinput.append("name"); fullPL.set(fullPLinput); CIMPropertyList errorPL ; Array<CIMName> errorPLinput; errorPLinput.append("junk"); errorPL.set(errorPLinput); ASRT(testReferences(CIMObjectPath("TST_ClassA"),CIMName(), "", emptyPL,2)); ASRT(testReferences(CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),CIMName(), "", fullPL,2)); // Testing associators and and associator names functions. ASRT(testAssocNames(CIMObjectPath("TST_ClassA"),CIMName(),CIMName(),"", "", 3)); cout << "+++++ passed all tests" << endl; return 0; }
int main(int argc, char** argv) { // TestCertClient Parameters // Parameter 1: Client Certification File // Parameter 2: Client Private Key File // Parameter 3: Random Key File // Parameter 4: User Name // Parameter 5: Password // Parameter 6: Expected Result // Parameter 7: Expected Identity if ((argc < 3) || (argc > 8)) { PEGASUS_STD(cout) << "Wrong number of arguments" << PEGASUS_STD(endl); exit(1); } String certpath; if (strcmp(argv[1],"NONE") != 0) { certpath = argv[1]; } String keypath; if (strcmp(argv[2],"NONE") != 0) { keypath = argv[2]; } String randFile; if (argc >=4) { if (strcmp(argv[3],"CONFIG") == 0) { const char* pegasusHome = getenv("PEGASUS_HOME"); randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE); } else if (strcmp(argv[3],"NONE") != 0) { randFile = argv[3]; } } String userName; if (argc >= 5) { userName = argv[4]; } String password; if (argc >= 6) { password = argv[5]; } expectedResultType expectedResult = NONE; expectedErrorType expectedError = ERROR_TYPE_NONE; String expectedUserName; if (argc >= 7) { if (strcmp(argv[6],"PASS") == 0) { expectedResult = PASS; if (argc >= 8) { if (strcmp(argv[7],"NONE") != 0) { expectedUserName = argv[7]; } } } else if (strcmp(argv[6],"FAIL") == 0) { expectedResult = FAIL; if (argc >= 8) { if (strcmp(argv[7],"NONE") == 0) { expectedError = ERROR_TYPE_NONE; } else if (strcmp(argv[7],"HTTP_401") == 0) { expectedError = ERROR_TYPE_HTTP_401; } else if (strcmp(argv[7],"CANNOT_CONNECT") == 0) { expectedError = ERROR_TYPE_CANNOT_CONNECT; } else { PEGASUS_STD(cout) << "Invalid expectedError parameter: " << argv[7] << PEGASUS_STD(endl); exit(1); } } } else if (strcmp(argv[6],"NONE") == 0) { expectedResult = NONE; } else { PEGASUS_STD(cout) << "Invalid expectedResult parameter: " << argv[6] << PEGASUS_STD(endl); exit(1); } } try { AutoPtr<SSLContext> pCtx; if (certpath != String::EMPTY) { pCtx.reset( new SSLContext(String::EMPTY, certpath, keypath, 0, randFile)); } else { pCtx.reset(new SSLContext(String::EMPTY, 0, randFile)); } PEGASUS_STD(cout)<< "TestCertClient::Connecting to 127.0.0.1:5989" << PEGASUS_STD(endl); CIMClient client; client.connect("127.0.0.1", 5989, *pCtx, userName, password); Array<CIMParamValue> inParams; Array<CIMParamValue> outParams; CIMValue retValue = client.invokeMethod( CIMNamespaceName("test/TestProvider"), CIMObjectPath("Test_MethodProviderClass"), CIMName("getIdentity"), inParams, outParams); if (expectedResult == FAIL) { throw Exception("Failure: Connection unexpectedly succeeded"); } String retUserName; retValue.get(retUserName); if (expectedUserName != String::EMPTY) { if (expectedUserName != retUserName) { throw Exception("Provider returned unexpected Identity: " + retUserName); } } CIMClass c = client.getClass("root/cimv2", "CIM_ComputerSystem", false, false, true); PEGASUS_STD(cout) << "Result: " << c.getClassName().getString() << PEGASUS_STD(endl); } catch (CIMClientHTTPErrorException& httpException) { if ((expectedResult == FAIL) && (httpException.getCode() == 401) && (expectedError == ERROR_TYPE_HTTP_401)) { PEGASUS_STD(cout) << "+++++ "<< argv[0] << " +++++ passed all tests" << PEGASUS_STD(endl); exit(0); } PEGASUS_STD(cout) << "Exception: " << httpException.getMessage() << PEGASUS_STD(endl); exit(1); } catch (CannotConnectException& connectException) { if ((expectedResult == FAIL) && (expectedError == ERROR_TYPE_CANNOT_CONNECT)) { PEGASUS_STD(cout) << "+++++ "<< argv[0] << " +++++ passed all tests" << PEGASUS_STD(endl); exit(0); } PEGASUS_STD(cout) << "Exception: " << connectException.getMessage() << PEGASUS_STD(endl); exit(1); } catch (Exception& ex) { PEGASUS_STD(cout) << "Exception: " << ex.getMessage() << PEGASUS_STD(endl); exit(1); } catch (...) { PEGASUS_STD(cout) << "Unknown exception" << PEGASUS_STD(endl); exit(1); } if (expectedResult == PASS) { PEGASUS_STD(cout) << "+++++ "<< argv[0] << " +++++ passed all tests" << PEGASUS_STD(endl); } else { PEGASUS_STD(cout) << "+++++ "<< "TestCertClient" << " Terminated Normally" << PEGASUS_STD(endl); } exit(0); }
void ClientProvider::invokeMethod( const OperationContext & context, const CIMObjectPath & objectReference, const CIMName & methodName, const Array<CIMParamValue> & inParameters, MethodResultResponseHandler & handler) { handler.processing(); if (objectReference.getClassName().equal ("Sample_ClientProviderClass")) { if (methodName.equal ("DoConnect")) { if( inParameters.size() > 0 ) { String connectType = String::EMPTY; CIMValue paramVal; CIMClient client; paramVal = inParameters[0].getValue(); paramVal.get( connectType ); if( connectType == "Local" ) { client.connectLocal(); // Enumerate Instances. Array<CIMObjectPath> instanceNames = client.enumerateInstanceNames( "root/cimv2", "CIM_ManagedElement"); client.disconnect(); handler.deliver(CIMValue(0)); } else if ( connectType == "Remote" ) { String HOST = "localhost"; Uint32 PORT = 5989; String USER = "******"; String PASSWORD = "******"; const char* pegasusHome = getenv("PEGASUS_HOME"); String certpath = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE); String randFile = String::EMPTY; randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE); SSLContext sslcontext( certpath, verifyCertificate, randFile); client.connect( HOST, PORT, sslcontext, USER, PASSWORD ); } // Enumerate Instances. Array<CIMObjectPath> instanceNames = client.enumerateInstanceNames( "root/cimv2", "CIM_ManagedElement"); client.disconnect(); handler.deliver(CIMValue(0)); } else { handler.deliver(CIMValue(1)); } } } handler.complete(); }
int createErrorInstance(CIMClient& client) { // Build the embedded instance Array<CIMKeyBinding> embeddedPathKeys; CIMName key1Name("key1"); CIMValue key1Value(String("fake-key1")); CIMName key2Name("key2"); CIMValue key2Value(String("fake-key2")); embeddedPathKeys.append(CIMKeyBinding(key1Name, key1Value)); embeddedPathKeys.append(CIMKeyBinding(key2Name, key2Value)); CIMObjectPath embeddedPath( "localhost", TEST_NAMESPACE, CIMName("PG_EmbeddedClass"), embeddedPathKeys); embeddedInstance.reset(new CIMInstance(CIMName("PG_EmbeddedClass"))); //embeddedInstance->setPath(embeddedPath); embeddedInstance->addProperty(CIMProperty(key1Name, key1Value)); embeddedInstance->addProperty(CIMProperty(key2Name, key2Value)); embeddedInstance->addProperty(CIMProperty(CIMName("prop01"), Uint8(234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop02"), Uint16(16234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop03"), Uint32(32234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop04"), Uint64(64234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop05"), Sint8(-234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop06"), Sint16(-16234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop07"), Sint32(-32234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop08"), Sint64(-64234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop09"), Real32(-64234.46))); embeddedInstance->addProperty(CIMProperty(CIMName("prop10"), Real64(-23464234.78))); embeddedInstance->addProperty(CIMProperty(CIMName("prop11"), CIMDateTime(60, true))); // Build the embedded instance Array<CIMKeyBinding> errorPathKeys; CIMName errorKeyName("errorKey"); CIMValue errorKeyValue(String("error key 1")); errorPathKeys.append(CIMKeyBinding(errorKeyName, errorKeyValue)); CIMObjectPath localErrorPath( "localhost", TEST_NAMESPACE, CIMName("PG_EmbeddedError"), errorPathKeys); errorInstance.reset(new CIMInstance(CIMName("PG_EmbeddedError"))); errorInstance->setPath(localErrorPath); errorInstance->addProperty(CIMProperty(errorKeyName, errorKeyValue)); errorInstance->addProperty(CIMProperty(CIMName("EmbeddedInst"), CIMValue(*embeddedInstance))); try { errorPath = client.createInstance(TEST_NAMESPACE, *errorInstance); PEGASUS_STD(cout) << "Created EmbeddedError: " << errorPath.toString() << PEGASUS_STD(endl); errorInstance->setPath(errorPath); } catch (Exception& e) { PEGASUS_STD(cout) << "Exception while creating Error Instance: " << e.getMessage() << PEGASUS_STD(endl); return -1; } return 0; }
/* testGetInstance of the NIS provider. */ void NISTestClient::testGetInstance( CIMClient &client, Boolean verboseTest) { CIMObjectPath getTestRef; // will need an instance for Get try { Boolean localOnly = true; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; testLog("NIS Provider Test GetInstance"); // first do an EnumerateInstanceNames - select one to play with // doesn't hurt to keep testing enumerate :-) Array<CIMObjectPath> cimReferences = client.enumerateInstanceNames(NAMESPACE, CLASS_NAME); Uint32 numberInstances = cimReferences.size(); if (verboseTest) cout << numberInstances << " instances of PG_NISServerService" << endl; for (Uint32 i = 0; i < cimReferences.size(); i++) { CIMName className = cimReferences[i].getClassName(); if (!className.equal(CLASS_NAME)) { errorExit("EnumInstanceNames failed - wrong class"); } // add in some content checks on the keys returned if (verboseTest) cout << " Validate keys of PG_NISServerService ... " <<endl; _validateKeys(cimReferences[i], verboseTest); // let's just take the first instance found getTestRef = cimReferences[i]; } // end for looping through instances if (verboseTest) cout << "EnumerateInstanceNames for Get Instance completed" << endl; // now call GetInstance with the appropriate references CIMInstance getTestInstance = client.getInstance( NAMESPACE, getTestRef, localOnly, includeQualifiers, includeClassOrigin); // now validate the properties returned _validateProperties(getTestInstance, verboseTest); testLog("NIS Provider Test Get Instance passed "); } catch(Exception& e) { errorExit(e.getMessage()); } }
int retrieveErrorInstance(CIMClient& client) { try { PEGASUS_STD(cout) << "Getting error instance: " << errorPath.toString() << PEGASUS_STD(endl); CIMInstance ret = client.getInstance( TEST_NAMESPACE, errorPath, true, false, false, errorPropList); ret.setPath(errorPath); if (!errorInstance->identical(ret)) { if (!ret.getPath().identical(errorInstance->getPath())) { PEGASUS_STD(cout) << "Object Paths not identical" << PEGASUS_STD(endl); } PEGASUS_STD(cout) << "Error Instance and instance retrieved " << "through GetInstance operation not the same\n" << PEGASUS_STD(endl); PEGASUS_STD(cout) << "Local Error Instance: " << errorInstance->getPath().toString() << PEGASUS_STD(endl); for (unsigned int i = 0, n = errorInstance->getPropertyCount(); i < n; i++) { CIMProperty prop = errorInstance->getProperty(i); PEGASUS_STD(cout) << i << ". " << prop.getName().getString() << prop.getValue().toString() << PEGASUS_STD(endl); } PEGASUS_STD(cout) << "Retrieved Error Instance: " << ret.getPath().toString() << PEGASUS_STD(endl); for (unsigned int i = 0, n = ret.getPropertyCount(); i < n; i++) { CIMProperty prop = ret.getProperty(i); PEGASUS_STD(cout) << i << ". " << prop.getName().getString() << prop.getValue().toString() << PEGASUS_STD(endl); } CIMProperty localEmbeddedProp = errorInstance->getProperty( errorInstance->findProperty("EmbeddedInst")); CIMProperty retEmbeddedProp = ret.getProperty( ret.findProperty("EmbeddedInst")); CIMInstance localEmbeddedInst; CIMInstance retEmbeddedInst; localEmbeddedProp.getValue().get(localEmbeddedInst); retEmbeddedProp.getValue().get(retEmbeddedInst); CIMObjectPath localEmbeddedPath = localEmbeddedInst.getPath(); CIMObjectPath retEmbeddedPath = retEmbeddedInst.getPath(); PEGASUS_STD(cout) << "Local Embedded Path: " << localEmbeddedPath.toString() << PEGASUS_STD(endl); PEGASUS_STD(cout) << "Ret Embedded Path: " << retEmbeddedPath.toString() << PEGASUS_STD(endl); return -1; } } catch (Exception& e) { cout << "Exception caught while getting error instance: " << e.getMessage() << endl; return -1; } try { Array<CIMInstance> ret = client.enumerateInstances( TEST_NAMESPACE, "PG_EmbeddedError", true, true, false, false, errorPropList); int count = ret.size(); for (int i = 0; i < count; i++) { if (!errorInstance->identical(ret[i])) { printf("Error instance and instance retrieved through " "EnumerateInstances operation not the same\n"); return -1; } } } catch (Exception& e) { cout << "Exception caught while enumerating error instances: " << e.getMessage() << endl; return -1; } return 0; }
int _getClass(const int argc, const char **argv) { CIMClass cldef; try { cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] ); } catch (Exception& e) { cerr << /* "getClass: " << */ e.getMessage() << endl; return 1; } // Display the class definition // without qualifiers, for the moment // First the class name and superclass cout << "class " << cldef.getClassName().getString() << " : " << cldef.getSuperClassName().getString() << endl; cout << "{" << endl; // Now the properties // No qualifiers except [key], but specify type, array for (int i=0; i<cldef.getPropertyCount(); i++) { CIMProperty p = cldef.getProperty(i); cout << " "; // output key, if required if (_isKey(p)) cout << "[ Key ] "; // prepare to output type, but // first, if type is "reference", find target class if (p.getType() == CIMTYPE_REFERENCE) cout << p.getReferenceClassName().getString() << " REF "; // output type else cout << cimTypeToString(p.getType()) << " "; // output name cout << p.getName().getString(); // output array, if required if (p.isArray()) cout << "[]"; // final eol cout << ";" << endl; } // need to do methods for (int i=0; i<cldef.getMethodCount(); i++) { CIMMethod m = cldef.getMethod(i); // output type cout << " " << cimTypeToString(m.getType()) << " "; // output name cout << m.getName().getString() << "("; // output parameters // new line if there are any parameters for (int j=0; j<m.getParameterCount(); j++) { CIMParameter p = m.getParameter(j); // output IN/OUT qualifiers on a fresh line cout << endl << " [ "; // loop through qualifiers looking for IN, OUT for (int k=0; k<p.getQualifierCount(); k++) { // when one found, output its value CIMQualifier q = p.getQualifier(k); if (q.getName().equal("in") || q.getName().equal("out")) { cout << q.getName().getString() << " "; } } // Now the type cout << "] " << cimTypeToString(p.getType()) << " "; // finally the name cout << p.getName().getString(); // array brackets if (p.isArray()) cout << "[]"; // closing , on parameter if not last if (j != m.getParameterCount()-1) cout << ","; } // after last param, indent before closing paren // close paren cout << ")"; // if (m.isArray()) cout << "[]"; // finish output cout << ";" << endl; } // final brace and done cout << "};" << endl; return 0; }
int createSubscription(CIMClient& client) { // Create a Listener Destination CIMInstance destinationInstance("CIM_ListenerDestinationCIMXML"); destinationInstance.addProperty(CIMProperty( CIMName("SystemCreationClassName"), System::getSystemCreationClassName())); // destinationInstance.addProperty(CIMProperty(CIMName("SystemName"), // System::getFullyQualifiedHostName())); // destinationInstance.addProperty(CIMProperty(CIMName("CreationClassName"), // String("CIM_ListenerDestinationCIMXML"))); destinationInstance.addProperty(CIMProperty(CIMName("Name"), String("EmbeddedInstance Test Handler"))); destinationInstance.addProperty(CIMProperty(CIMName("Destination"), String("http://localhost:2003"))); try { destinationPath = client.createInstance(TEST_NAMESPACE, destinationInstance); } catch (Exception& e) { cout << "Exception caught while creating listener destination: " << e.getMessage() << endl; return -1; } // Create a Filter CIMInstance filterInstance("CIM_IndicationFilter"); filterInstance.addProperty(CIMProperty( CIMName("SystemCreationClassName"), System::getSystemCreationClassName())); filterInstance.addProperty(CIMProperty(CIMName("SystemName"), System::getFullyQualifiedHostName())); filterInstance.addProperty(CIMProperty(CIMName("CreationClassName"), String("CIM_IndicationFilter"))); filterInstance.addProperty(CIMProperty(CIMName("Name"), String("Embedded Instance Test Filter"))); filterInstance.addProperty(CIMProperty(CIMName("Query"), String("SELECT * FROM PG_InstMethodIndication"))); filterInstance.addProperty(CIMProperty(CIMName("QueryLanguage"), String("CIM:CQL"))); filterInstance.addProperty(CIMProperty(CIMName("SourceNamespace"), TEST_NAMESPACE.getString())); try { filterPath = client.createInstance (TEST_NAMESPACE, filterInstance); } catch (Exception& e) { cout << "Exception caught while creating indication filter: " << e.getMessage() << endl; return -1; } // Create a Subscription CIMInstance subscriptionInstance("CIM_IndicationSubscription"); subscriptionInstance.addProperty(CIMProperty(CIMName("Filter"), filterPath, 0, "CIM_IndicationFilter")); subscriptionInstance.addProperty(CIMProperty(CIMName("Handler"), destinationPath, 0, "CIM_ListenerDestinationCIMXML")); subscriptionInstance.addProperty(CIMProperty( CIMName("SubscriptionState"), CIMValue((Uint16) 2))); try { subscriptionPath = client.createInstance(TEST_NAMESPACE, subscriptionInstance); } catch (Exception& e) { cout << "Exception caught while creating subscription: " << e.getMessage() << endl; return -1; } return 0; }
/** Connects to cimserver. @param outPrintWriter the ostream to which error output should be written @exception Exception if an error is encountered in creating the connection */ void OSInfoCommand::_connectToServer( CIMClient& client, ostream& outPrintWriter ) { String host = String (); Uint32 portNumber = 0; Boolean connectToLocal = false; // // Construct host address // if ((!_hostNameSet) && (!_portNumberSet) && (!_userNameSet) && (!_passwordSet)) { connectToLocal = true; } else { if (!_hostNameSet) { _hostName = System::getHostName(); } if( !_portNumberSet ) { if( _useSSL ) { #ifdef PEGASUS_HAS_SSL _portNumber = System::lookupPort( WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT ); #else PEGASUS_ASSERT(false); #endif } else { _portNumber = System::lookupPort( WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT ); } char buffer[32]; sprintf( buffer, "%lu", (unsigned long) _portNumber ); _portNumberStr = buffer; } } host = _hostName; portNumber = _portNumber; if( connectToLocal ) { client.connectLocal(); } else { if (!_userNameSet) { _userName = System::getEffectiveUserName(); } if (!_passwordSet) { _password = _promptForPassword( outPrintWriter ); } if( _useSSL ) { #ifdef PEGASUS_HAS_SSL // // Get environment variables: // const char* pegasusHome = getenv("PEGASUS_HOME"); String certpath = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE); String randFile; #ifdef PEGASUS_SSL_RANDOMFILE randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE); #endif SSLContext sslcontext (certpath, verifyCertificate, randFile); client.connect(host, portNumber, sslcontext, _userName, _password ); #else PEGASUS_ASSERT(false); #endif } else { client.connect(host, portNumber, _userName, _password ); } } }
void test03 (CIMClient & client) { CIMObjectPath instanceName; instanceName.setNameSpace (providerNamespace); instanceName.setClassName (CLASSNAME); Array < CIMParamValue > inParams; Array < CIMParamValue > outParams; /* uint32 TestCMPIBroker ( * [IN, Description ( * "The requested are to test different * CMPI data structure operations."), * ValueMap { "1", "2", "3", "4", "5", "6"}, * Values {"CDGetType", "CDToString", "CDIsOfType", * "CMGetMessage", "CMLogMessage","CDTraceMessage"}] * uint32 Operation, * [OUT, Description ( * " The result of what the operation carried out.")] * string Result); * */ { /* CDGetType */ inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (1)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); _checkStringValue (paramValue, "CMPIArgs"); } inParams.clear (); outParams.clear (); { /* CDToString */ inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (2)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); _checkStringValue (paramValue, " Operation:2\n"); } inParams.clear (); outParams.clear (); { /* CDIsOfType */ inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (3)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); _checkStringValue (paramValue, "++++ CMPIArgs = Yes"); } inParams.clear (); outParams.clear (); { /* CMGetMessage */ inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (4)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); // If PEGASUS_USE_DEFAULT_MESSAGES is not set, we can't make an // assumption about what the value of the msg will be. if (useDefaultMsg) { _checkStringValue (paramValue, "CIM_ERR_SUCCESS: Successful."); } } inParams.clear (); outParams.clear (); { /* CMLogMessage */ inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (5)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear (); outParams.clear (); { /* CMTraceMessage */ inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (6)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear (); outParams.clear (); { // CMGetMessage2 inParams.append(CIMParamValue( "Operation", CIMValue(Uint32(7)))); inParams.append(CIMParamValue( "msgFile", CIMValue(String("test/pegasusTest")))); inParams.append(CIMParamValue( "msgId", CIMValue(String("CIMStatusCode.CIM_ERR_SUCCESS")))); inParams.append(CIMParamValue( "insert1", CIMValue(String("rab oof is foo bar backwards")))); inParams.append(CIMParamValue( "insert2", CIMValue(Uint32(64001)))); AcceptLanguageList accLangs; accLangs.insert(LanguageTag("en-US"),Real32(1.0)); accLangs.insert(LanguageTag("fr"),Real32(0.8)); client.setRequestAcceptLanguages(accLangs); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); // If PEGASUS_USE_DEFAULT_MESSAGES is not set, we can't make an // assumption about what the value of the msg will be, or the // ContentLanguage. #ifdef PEGASUS_HAS_MESSAGES if (useDefaultMsg) { #endif _checkStringValue (paramValue, "CIM_ERR_SUCCESS: Successful."); #ifdef PEGASUS_HAS_MESSAGES } else { ContentLanguageList contLangs; contLangs = client.getResponseContentLanguages(); cout << "ContentLanguage size == " << contLangs.size() << endl; PEGASUS_TEST_ASSERT(contLangs.size() == 1); cout << "ContentLanguage == " << contLangs.getLanguageTag(0).toString(); PEGASUS_TEST_ASSERT( contLangs.getLanguageTag(0).toString() == "en-US"); } #endif // Reset client accLangs.clear(); client.setRequestAcceptLanguages(accLangs); } inParams.clear(); outParams.clear(); { // _testCMPIEnumeration inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (8)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { // _testCMPIArray inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (9)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { // _testCMPIcontext inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (10)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { // _testCMPIDateTime inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (11)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { // _testCMPIInstance inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (12)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { // _testCMPIObjectPath inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (13)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { // _testCMPIResult inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (14)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { // _testCMPIString inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (15)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); // Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { //_testCMPIArgs inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (16)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); //Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } inParams.clear(); outParams.clear(); { //_testCMPIBroker inParams.append (CIMParamValue ("Operation", CIMValue (Uint32 (17)))); CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "TestCMPIBroker", inParams, outParams); //Check the return value. Make sure it is 0. _checkUint32Value (retValue, 0); // Nothing is returned PEGASUS_TEST_ASSERT (outParams.size () == 1); CIMValue paramValue = outParams[0].getValue (); PEGASUS_TEST_ASSERT (paramValue.isNull ()); } }
void _testCMPIFilterOfAssociation(CIMClient& client) { try { Array<CIMObjectPath> personRefs; Uint32 numPersonInstances ; personRefs = client.enumerateInstanceNames(providerNamespace,CMPI_TEST_PERSON); numPersonInstances = personRefs.size(); CIMName resultClass; String role; String resultRole; cout<<"++++++++Filtering the NULL propery list+++"<<endl; for (Uint32 i = 0; i < numPersonInstances; ++i) { Array<CIMObject> resultObjects = client.associators( providerNamespace, personRefs[i], CMPI_TEST_RACING, resultClass, role, resultRole, false, false, CIMPropertyList()); Uint32 size = resultObjects.size(); for(Uint32 j = 0;j<size;j++) { Uint32 propCount = resultObjects[j].getPropertyCount(); Uint32 propNameCount = 0; if(propCount != 0) { String propName= resultObjects[j].getProperty(0).getName().getString(); if(verbose) { cout<<"Property Name of :"<<i<<":"<<propName<<endl; } if(propName == "vehiclename") { propNameCount++; } } if((size != 0)&&(propCount == 1) &&(propNameCount == 1)) { cout<<"Filter associator test on CMPI_TEST_RACING SUCCEEDED" <<":Filtering the ciminstance with a NULL property list" <<" returned all properties as expected"<<endl; } else { cout<<"Filter associator test on CMPI_TEST_RACING FAILED" <<":Filtering the ciminstance with a NULL property list" <<" did not return all properties as expected"<<endl; PEGASUS_TEST_ASSERT(false); } } } cout<<"++++++Filtering the empty propery list+++"<<endl; Array<CIMName> propList; for (Uint32 i = 0; i < numPersonInstances; ++i) { Array<CIMObject> resultObjects = client.associators( providerNamespace, personRefs[i], CMPI_TEST_RACING, resultClass, role, resultRole, false, false, CIMPropertyList(propList)); Uint32 size = resultObjects.size(); for(Uint32 j = 0;j<size;j++) { Uint32 propCount = resultObjects[j].getPropertyCount(); if((size != 0)&&(propCount == 0)) { cout<<"Filter associator test on CMPI_TEST_RACING SUCCEEDED" <<":Filtering the ciminstance with a empty property " <<"list returned zero properties as expected"<<endl; } else { cout<<"Filter associators test on CMPI_TEST_RACING FAILED" <<":Filtering the ciminstance with a empty property " <<"list returned some properties which is not expected" <<endl; PEGASUS_TEST_ASSERT(false); } } } cout<<"+++filtering the wrong properties ++++++"<<endl; Array<CIMName> propList1; propList1.append(CIMName(String("nam"))); for (Uint32 i = 0; i < numPersonInstances; ++i) { Array<CIMObject> resultObjects = client.associators( providerNamespace, personRefs[i], CMPI_TEST_RACING, resultClass, role, resultRole, false, false, CIMPropertyList(propList1)); Uint32 size = resultObjects.size(); for(Uint32 j = 0;j<size;j++) { Uint32 propCount = resultObjects[j].getPropertyCount(); if((size != 0)&&(propCount == 0)) { cout<<"Filter associators test on CMPI_TEST_RACING " <<"SUCCEEDED:Filtering the ciminstance with a wrong " <<"property list returned zero properties as " <<"expected"<<endl; } else { cout<<"Filter associators test on CMPI_TEST_RACING FAILED" <<":Filtering the ciminstance with a wrong property " <<"list returned some properties which is not" <<" expected"<<endl; PEGASUS_TEST_ASSERT(false); } } } cout<<"++++++++Filtering the mentioned propery list+++"<<endl; Array<CIMName> propArr; propArr.append(CIMName(String("vehiclename"))); for (Uint32 i = 0; i < numPersonInstances; ++i) { Array<CIMObject> resultObjects = client.associators( providerNamespace, personRefs[i], CMPI_TEST_RACING, resultClass, role, resultRole, false, false, CIMPropertyList( propArr)); Uint32 size = resultObjects.size(); for(Uint32 j = 0;j<size;j++) { Uint32 propCount = resultObjects[j].getPropertyCount(); Uint32 propNameCount = 0; if(propCount != 0) { String propName= resultObjects[j].getProperty(0).getName().getString(); if(verbose) { cout<<"Property Name of :"<<i<<":"<<propName<<endl; } if(propName == "vehiclename") { propNameCount++; } } if((size != 0)&&(propCount == 1) &&(propNameCount == 1)) { cout<<"Filter associators test on CMPI_TEST_RACING " <<"SUCCEEDED:Filtering the ciminstance with a " <<"mentioned property list returned all properties" <<" as expected"<<endl; } else { cout<<"Filter associators test on CMPI_TEST_RACING FAILED" <<":Filtering the ciminstance with a mentioned property" <<" list did not return properties as expected "<<endl; PEGASUS_TEST_ASSERT(false); } } } } catch(Exception& e) { cerr << "enumerateInstanceNames() failed." << endl; _errorExit(e.getMessage()); } }
/** * This tests the embedded instance functionality through the CMPI Test * Method Provider. It first invokes the returnInstance() method to retrieve * an instance that can be used */ void test09 (CIMClient & client) { CIMObjectPath instanceName; instanceName.setNameSpace (providerNamespace); instanceName.setClassName (CLASSNAME); Array < CIMParamValue > inParams; Array < CIMParamValue > outParams; /* [EmbeddedObject] String returnInstance(); */ CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "returnInstance", inParams, outParams); PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT); PEGASUS_TEST_ASSERT (!retValue.isArray ()); PEGASUS_TEST_ASSERT (!retValue.isNull ()); CIMObject result; retValue.get (result); CIMObjectPath objPath = result.getPath(); CIMInstance inputInstance(result); CIMInstance outputInstance; inParams.append( CIMParamValue(String("inputInstance"), CIMValue(inputInstance))); retValue = client.invokeMethod (providerNamespace, instanceName, "processEmbeddedInstance", inParams, outParams); // First test the return value PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } // Now test the output parameter PEGASUS_TEST_ASSERT(outParams.size() == 1); retValue = outParams[0].getValue(); PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } }
void call_func() { try { // Connect. CIMClient client; client.connectLocal(); // // uint32 AssignSpares( // [IN(false), OUT] CIM_ConcreteJob REF Job, // [IN, OUT(false)] CIM_StoragePool REF InPool, // [Required, IN, OUT (false)] CIM_StorageExtent REF InExtents[], // [IN, OUT (false)] CIM_StorageRedundancySet REF RedundancySet); // // Build input arguments. Array<CIMParamValue> in; // InPool: CIMObjectPath InPool("CIM_StoragePool.InstanceID=\"1\""); in.append(CIMParamValue("InPool", InPool)); // InExtents: CIMObjectPath StorageExtent( "root/cimv2:MyStorageExtent." "CreationClassName=\"Aristos_DiskStorageExtent\"," "DeviceID=\"3:5000c500003ac807\"," "SystemCreationClassName=\"Aristos_ControllerSystem\"," "SystemName=\"500062E987654391\""); Array<CIMObjectPath> InExtents; InExtents.append(StorageExtent); InExtents.append(StorageExtent); InExtents.append(StorageExtent); in.append(CIMParamValue("InExtents", InExtents)); // RedundancySet: CIMObjectPath RedundancySet( "CIM_StorageRedundancySet.InstanceID=\"1\""); in.append(CIMParamValue("RedundancySet", RedundancySet)); // Invoke method. CIMObjectPath target("SNIA_SpareConfigurationService." "SystemCreationClassName=\"Mike\"," "SystemName=\"Mike\"," "CreationClassName=\"SNIA_SpareConfigurationService\""); Array<CIMParamValue> out; CIMValue value = client.invokeMethod( "root/cimv2", target, "AssignSpares", in, out); // Expect one output argument. assert(out.size() == 1); // Check return value. assert(value.getType() == CIMTYPE_UINT32); Uint32 return_value = 0; value.get(return_value); assert(return_value == 100); } catch(Exception& e) { cerr << "Error: " << e.getMessage() << endl; exit(1); } }
void test14 (CIMClient & client) { CIMObjectPath instanceName; instanceName.setNameSpace (providerNamespace); instanceName.setClassName (CLASSNAME); Array < CIMParamValue > inParams; Array < CIMInstance> eObjs; Array < CIMParamValue > outParams; CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "returnInstance", inParams, outParams); PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT); PEGASUS_TEST_ASSERT (!retValue.isArray ()); PEGASUS_TEST_ASSERT (!retValue.isNull ()); CIMObject result; retValue.get (result); CIMObjectPath objPath = result.getPath(); CIMInstance inputInstance(result); CIMInstance outputInstance; eObjs.append(inputInstance); eObjs.append(inputInstance); eObjs.append(inputInstance); inParams.append ( CIMParamValue(String("inputInstances"), CIMValue(eObjs))); retValue = client.invokeMethod (providerNamespace, instanceName, "processArrayEmbeddedInstance", inParams, outParams); // First test the return value PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } // Now test the output parameters PEGASUS_TEST_ASSERT(outParams.size() == 3); CIMValue outParamValue = outParams[0].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); Array<CIMInstance> instances; outParamValue.get(instances); for (unsigned int j = 0; j < instances.size () ; ++j) { outputInstance = instances[j]; PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == eObjs[j].getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(eObjs[j].getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } } outParamValue = outParams[1].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); Array<CIMObject> objs; outParamValue.get(objs); for (unsigned int j = 0; j < objs.size () ; ++j) { outputInstance = CIMInstance(objs[j]); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == eObjs[j].getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(eObjs[j].getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } } outParamValue = outParams[2].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); outParamValue.get(objs); for (Uint32 j = 0, m = objs.size(); j < m ; ++j) { outputInstance = CIMInstance(objs[j]); Uint32 id; CIMInstance emInstance; CIMObject emObject; outputInstance.getProperty( outputInstance.findProperty("id")).getValue().get(id); outputInstance.getProperty( outputInstance.findProperty("emInstance")). getValue().get(emInstance); outputInstance.getProperty( outputInstance.findProperty("emObject")).getValue().get(emObject); PEGASUS_TEST_ASSERT(eObjs[j].identical(emInstance)); PEGASUS_TEST_ASSERT(eObjs[j].identical(CIMInstance(emObject))); PEGASUS_TEST_ASSERT(id == j+1); } }
// get instance normalization (with request permutations) void Test2(CIMClient& client) { if(verbose) { cout << "Test2()" << endl; } Array<CIMObjectPath> cimInstanceNames = client.enumerateInstanceNames( NAMESPACE, CLASSNAME); { Boolean localOnly = false; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; if(verbose) { cout << "localOnly = " << (localOnly ? "true" : "false") << endl; cout << "includeQualifiers = " << (includeQualifiers ? "true" : "false") << endl; cout << "includeClassOrigin = " << (includeClassOrigin ? "true" : "false") << endl; } for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++) { if(verbose) { cout << (isValid(cimInstanceNames[i]) ? "GOOD" : "BAD") << ": " << cimInstanceNames[i].toString() << endl; } if(isValid(cimInstanceNames[i])) { CIMInstance cimInstance; try { cimInstance = client.getInstance( NAMESPACE, cimInstanceNames[i], localOnly, includeQualifiers, includeClassOrigin, CIMPropertyList()); if(verbose) { XmlWriter::printInstanceElement(cimInstance); } } catch(CIMException & e) { if(verbose) { cout << "CIMException(" << e.getCode() << "): " << e.getMessage() << endl; } } } else { if(verbose) { cout << "skipping getInstance() because of bad class name (tolerated for now)." << endl << endl; } } } } { Boolean localOnly = false; Boolean includeQualifiers = true; Boolean includeClassOrigin = false; if(verbose) { cout << "localOnly = " << (localOnly ? "true" : "false") << endl; cout << "includeQualifiers = " << (includeQualifiers ? "true" : "false") << endl; cout << "includeClassOrigin = " << (includeClassOrigin ? "true" : "false") << endl; } for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++) { if(verbose) { cout << (isValid(cimInstanceNames[i]) ? "GOOD" : "BAD") << ": " << cimInstanceNames[i].toString() << endl; } if(isValid(cimInstanceNames[i])) { try { CIMInstance cimInstance = client.getInstance( NAMESPACE, cimInstanceNames[i], localOnly, includeQualifiers, includeClassOrigin, CIMPropertyList()); if(verbose) { XmlWriter::printInstanceElement(cimInstance); } } catch(CIMException & e) { if(verbose) { cout << "CIMException(" << e.getCode() << "): " << e.getMessage() << endl; } } } else { if(verbose) { cout << "skipping getInstance() because of bad class name (tolerated for now)." << endl << endl; } } } } { Boolean localOnly = false; Boolean includeQualifiers = true; Boolean includeClassOrigin = true; if(verbose) { cout << "localOnly = " << (localOnly ? "true" : "false") << endl; cout << "includeQualifiers = " << (includeQualifiers ? "true" : "false") << endl; cout << "includeClassOrigin = " << (includeClassOrigin ? "true" : "false") << endl; } for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++) { if(verbose) { cout << (isValid(cimInstanceNames[i]) ? "GOOD" : "BAD") << ": " << cimInstanceNames[i].toString() << endl; } if(isValid(cimInstanceNames[i])) { try { CIMInstance cimInstance = client.getInstance( NAMESPACE, cimInstanceNames[i], localOnly, includeQualifiers, includeClassOrigin, CIMPropertyList()); if(verbose) { XmlWriter::printInstanceElement(cimInstance); } } catch(CIMException & e) { if(verbose) { cout << "CIMException(" << e.getCode() << "): " << e.getMessage() << endl; } } } else { if(verbose) { cout << "skipping getInstance() because of bad class name (tolerated for now)." << endl << endl; } } } } }
int main(int argc, char** argv) { try { CIMClient client; client.connectLocal(); // Define instance name: CIMObjectPath instanceName("Methods.key=7777"); // Define input arguments: Array<CIMParamValue> in; Array<CIMParamValue> out; // Invoke the method: const String NAMESPACE = "root/cimv2"; const String methodName = "foo5"; Uint32 in_arg = 234567; Uint32 in_out_arg = 123456; in.append(CIMParamValue("in_arg", in_arg)); in.append(CIMParamValue("in_out_arg", in_out_arg)); CIMValue value = client.invokeMethod( NAMESPACE, instanceName, methodName, in, out); { assert(value.getType() == CIMTYPE_UINT32); Uint32 t; value.get(t); assert(t == 1200); } // Check output argument: assert(out.size() == 2); { Uint32 pos = 0; assert((pos = findParam(out, "in_out_arg")) != -1); assert(out[pos].getParameterName() == "in_out_arg"); CIMValue value = out[0].getValue(); Uint32 in_out_arg_rtn; value.get(in_out_arg_rtn); assert(in_out_arg_rtn == in_out_arg); assert((pos = findParam(out, "out_arg")) != -1); assert(out[pos].getParameterName() == "out_arg"); CIMValue value1 = out[1].getValue(); Uint32 out_arg_rtn; value1.get(out_arg_rtn); assert(out_arg_rtn == in_arg); } } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); exit(1); } PEGASUS_STD(cout) << "+++++ passed all tests" << PEGASUS_STD(endl); return 0; }
int main() { cout << "Starting Server Profile Tests" << endl << endl; // Create a locally-connected client CIMClient client; try { client.connectLocal(); client.setTimeout(60000); // Set the timeout to one minute } catch(Exception &) { exitFailure(String("Could not connect to server")); } CIMName currentClass; try { currentClass = CIMName("CIM_ComputerSystem"); testInstanceClass(client, currentClass); currentClass = CIMName("CIM_ObjectManager"); testInstanceClass(client, currentClass); currentClass = CIMName("CIM_RegisteredSubProfile"); testInstanceClass(client, currentClass); currentClass = CIMName("CIM_RegisteredProfile"); testInstanceClass(client, currentClass); currentClass = CIMName("CIM_CIMXMLCommunicationMechanism"); testInstanceClass(client, currentClass); currentClass = CIMName("CIM_Namespace"); testInstanceClass(client, currentClass); currentClass = CIMName("CIM_SoftwareIdentity"); testInstanceClass(client, currentClass); currentClass = CIMName("CIM_HostedService"); testAssociationClass(client, currentClass); currentClass = CIMName("CIM_ElementConformsToProfile"); testAssociationClass(client, currentClass); currentClass = CIMName("CIM_SubprofileRequiresProfile"); testAssociationClass(client, currentClass); currentClass = CIMName("CIM_ReferencedProfile"); testAssociationClass(client, currentClass); currentClass = CIMName("CIM_ElementSoftwareIdentity"); testAssociationClass(client, currentClass); currentClass = CIMName("CIM_CommMechanismForManager"); testAssociationClass(client, currentClass); } catch(Exception & e) { exitFailure(String("Caught exception while testing class ") + currentClass.getString() + String(": ") + e.getMessage()); } catch(...) { exitFailure(String("Caught unknown exception while testing class ") + currentClass.getString()); } testDMTFProfileInstances(client); #ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT testIndicationProfileInstances(client); #endif //testAssociationTraversal(client); cout << endl << "Server Profile Tests complete" << endl; return 0; }
int _getProperty(const int argc, const char **argv) { if (argc < 2) { _gpUsage(); return 1; } // need to get class definition to find keys // first arg is name of class CIMClass cldef; try { cldef = _c.getClass( _nameSpace, argv[0] ); } catch(Exception& e) { cerr << /* "getProperty: " << */ e.getMessage() << endl; return 1; } CIMObjectPath ref; CIMInstance inst; // If next arg is "ask", prompt user for keys if (String::equalNoCase("ask",argv[1])) ref = CIMObjectPath(String::EMPTY, _nameSpace, argv[0], _inputInstanceKeys(cldef) ); // else if the next arg and is "list", enumInstNames and print // a list from which user will select else if (String::equalNoCase("list",argv[1])) { ref = _selectInstance( argv[0] ); if (ref.identical(CIMObjectPath())) return 0; } // else there's another arg but it's invalid else { _gpUsage(); return 1; } CIMProperty pDef; // if no more args, display property names and ask which if (argc < 3) { int n; for (n=0; n<cldef.getPropertyCount(); n++) { pDef=cldef.getProperty(n); cout << n+1 << ": "; cout << cimTypeToString(pDef.getType()) << " "; cout << pDef.getName().getString(); if (pDef.isArray()) cout << "[]"; cout << endl; } cout << "Property (1.." << cldef.getPropertyCount() << ")? " << flush; cin >> n; pDef = cldef.getProperty(n-1); }