summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2014-09-08 12:03:16 -0400
committerBernard Normier <bernard@zeroc.com>2014-09-08 12:03:16 -0400
commita0f6b6fc1a619c40979f5ba00d71dc661cfc6499 (patch)
tree81b40da86417ed18a186d595c119bb7823b17fcf /py
parentICE-5658 - NPM support for IceJS distribution (diff)
downloadice-a0f6b6fc1a619c40979f5ba00d71dc661cfc6499.tar.bz2
ice-a0f6b6fc1a619c40979f5ba00d71dc661cfc6499.tar.xz
ice-a0f6b6fc1a619c40979f5ba00d71dc661cfc6499.zip
Fixed ICE-5667: Added Communicator::createAdmin in C++, Java, C# and Python
Diffstat (limited to 'py')
-rw-r--r--py/modules/IcePy/Communicator.cpp52
-rw-r--r--py/python/Ice.py3
-rw-r--r--py/test/Ice/admin/AllTests.py111
3 files changed, 111 insertions, 55 deletions
diff --git a/py/modules/IcePy/Communicator.cpp b/py/modules/IcePy/Communicator.cpp
index 593988ce462..976f6cdabb9 100644
--- a/py/modules/IcePy/Communicator.cpp
+++ b/py/modules/IcePy/Communicator.cpp
@@ -795,6 +795,56 @@ communicatorEndFlushBatchRequests(CommunicatorObject* self, PyObject* args)
extern "C"
#endif
static PyObject*
+communicatorCreateAdmin(CommunicatorObject* self, PyObject* args)
+{
+ PyObject* adapter;
+ PyObject* identityType = lookupType("Ice.Identity");
+ PyObject* id;
+ if(!PyArg_ParseTuple(args, STRCAST("OO!"), &adapter, identityType, &id))
+ {
+ return 0;
+ }
+
+ Ice::ObjectAdapterPtr oa;
+
+ PyObject* adapterType = lookupType("Ice.ObjectAdapter");
+ if(adapter != Py_None && !PyObject_IsInstance(adapter, adapterType))
+ {
+ PyErr_Format(PyExc_ValueError, STRCAST("expected ObjectAdapter or None"));
+ return 0;
+ }
+
+ if(adapter != Py_None)
+ {
+ oa = unwrapObjectAdapter(adapter);
+ }
+
+ Ice::Identity identity;
+ if(!getIdentity(id, identity))
+ {
+ return 0;
+ }
+
+ assert(self->communicator);
+ Ice::ObjectPrx proxy;
+ try
+ {
+ proxy = (*self->communicator)->createAdmin(oa, identity);
+ assert(proxy);
+
+ return createProxy(proxy, *self->communicator);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return 0;
+ }
+}
+
+#ifdef WIN32
+extern "C"
+#endif
+static PyObject*
communicatorGetAdmin(CommunicatorObject* self)
{
assert(self->communicator);
@@ -1475,6 +1525,8 @@ static PyMethodDef CommunicatorMethods[] =
PyDoc_STR(STRCAST("begin_flushBatchRequests([_ex][, _sent]) -> Ice.AsyncResult")) },
{ STRCAST("end_flushBatchRequests"), reinterpret_cast<PyCFunction>(communicatorEndFlushBatchRequests),
METH_VARARGS, PyDoc_STR(STRCAST("end_flushBatchRequests(Ice.AsyncResult) -> None")) },
+ { STRCAST("createAdmin"), reinterpret_cast<PyCFunction>(communicatorCreateAdmin), METH_VARARGS,
+ PyDoc_STR(STRCAST("createAdmin(adminAdapter, adminIdentity) -> Ice.ObjectPrx")) },
{ STRCAST("getAdmin"), reinterpret_cast<PyCFunction>(communicatorGetAdmin), METH_NOARGS,
PyDoc_STR(STRCAST("getAdmin() -> Ice.ObjectPrx")) },
{ STRCAST("addAdminFacet"), reinterpret_cast<PyCFunction>(communicatorAddAdminFacet), METH_VARARGS,
diff --git a/py/python/Ice.py b/py/python/Ice.py
index 9be78a0d465..33234632965 100644
--- a/py/python/Ice.py
+++ b/py/python/Ice.py
@@ -616,6 +616,9 @@ class CommunicatorI(Communicator):
def end_flushBatchRequests(self, r):
return self._impl.end_flushBatchRequests(r)
+ def createAdmin(self, adminAdapter, adminIdentity):
+ return self._impl.createAdmin(adminAdapter, adminIdentity)
+
def getAdmin(self):
return self._impl.getAdmin()
diff --git a/py/test/Ice/admin/AllTests.py b/py/test/Ice/admin/AllTests.py
index 364a70a3ee4..77f99b568c4 100644
--- a/py/test/Ice/admin/AllTests.py
+++ b/py/test/Ice/admin/AllTests.py
@@ -13,9 +13,11 @@ def test(b):
if not b:
raise RuntimeError('test assertion failed')
-def testFacets(com):
- test(com.findAdminFacet("Properties") != None)
- test(com.findAdminFacet("Process") != None)
+def testFacets(com, builtInFacets = True):
+
+ if builtInFacets:
+ test(com.findAdminFacet("Properties") != None)
+ test(com.findAdminFacet("Process") != None)
f1 = TestI.TestFacetI()
f2 = TestI.TestFacetI()
@@ -32,13 +34,13 @@ def testFacets(com):
try:
com.addAdminFacet(f1, "Facet1")
- test(false)
+ test(False)
except Ice.AlreadyRegisteredException:
pass # Expected
try:
com.removeAdminFacet("Bogus")
- test(false)
+ test(False)
except Ice.NotRegisteredException:
pass # Expected
@@ -48,7 +50,7 @@ def testFacets(com):
try:
com.removeAdminFacet("Facet1")
- test(false)
+ test(False)
except Ice.NotRegisteredException:
pass # Expected
@@ -84,6 +86,28 @@ def allTests(communicator):
# Test: Verify that the operations work correctly with the Admin object disabled.
#
com = Ice.initialize()
+ testFacets(com, False)
+ com.destroy()
+
+ #
+ # Test: Verify that the operations work correctly when Ice.Admin is enabled.
+ #
+ init = Ice.InitializationData()
+ init.properties = Ice.createProperties()
+ init.properties.setProperty("Ice.Admin.Enabled", "1")
+ com = Ice.initialize(init)
+ test(com.getAdmin() == None)
+ identity = com.stringToIdentity("test-admin")
+ try:
+ com.createAdmin(None, identity)
+ test(False)
+ except Ice.InitializationException:
+ pass
+
+ adapter = com.createObjectAdapter("")
+ test(com.createAdmin(adapter, identity) != None)
+ test(com.getAdmin() != None)
+
testFacets(com)
com.destroy()
@@ -146,8 +170,7 @@ def allTests(communicator):
# Test: PropertiesAdmin::getProperties()
#
pd = pa.getPropertiesForPrefix("")
- test(len(pd) == 6)
- test(pd["Ice.Default.CollocationOptimized"] == "0")
+ test(len(pd) == 5)
test(pd["Ice.Admin.Endpoints"] == "tcp -h 127.0.0.1")
test(pd["Ice.Admin.InstanceName"] == "Test")
test(pd["Prop1"] == "1")
@@ -216,18 +239,11 @@ def allTests(communicator):
props["Ice.Admin.Facets"] = "Properties"
com = factory.createCommunicator(props)
obj = com.getAdmin()
- # TODO: Remote the try/catch once ICE-4862 is fixed
- try:
- proc = Ice.ProcessPrx.checkedCast(obj, "Process")
- test(proc == None)
- except Ice.FacetNotExistException:
- pass
- try:
- tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
- test(tf == None)
- except Ice.FacetNotExistException:
- pass
-
+
+ proc = Ice.ProcessPrx.checkedCast(obj, "Process")
+ test(proc == None)
+ tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
+ test(tf == None)
com.destroy()
#
@@ -240,17 +256,12 @@ def allTests(communicator):
props["Ice.Admin.Facets"] = "Process"
com = factory.createCommunicator(props)
obj = com.getAdmin()
- # TODO: Remote the try/catch once ICE-4862 is fixed
- try:
- pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
- test(pa == None)
- except Ice.FacetNotExistException:
- pass
- try:
- tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
- test(tf == None)
- except Ice.FacetNotExistException:
- pass
+
+ pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
+ test(pa == None)
+ tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
+ test(tf == None)
+
com.destroy()
#
@@ -263,17 +274,13 @@ def allTests(communicator):
props["Ice.Admin.Facets"] = "TestFacet"
com = factory.createCommunicator(props)
obj = com.getAdmin()
- # TODO: Remote the try/catch once ICE-4862 is fixed
- try:
- pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
- test(pa == None)
- except Ice.FacetNotExistException:
- pass
- try:
- proc = Ice.ProcessPrx.checkedCast(obj, "Process")
- test(proc == None)
- except Ice.FacetNotExistException:
- pass
+
+ pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
+ test(pa == None)
+
+ proc = Ice.ProcessPrx.checkedCast(obj, "Process")
+ test(proc == None)
+
com.destroy()
#
@@ -290,13 +297,9 @@ def allTests(communicator):
test(pa.getProperty("Ice.Admin.InstanceName") == "Test")
tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
tf.op()
- # TODO: Remote the try/catch once ICE-4862 is fixed
- try:
- proc = Ice.ProcessPrx.checkedCast(obj, "Process")
- test(proc == None)
- except Ice.FacetNotExistException:
- pass
-
+
+ proc = Ice.ProcessPrx.checkedCast(obj, "Process")
+ test(proc == None)
com.destroy()
#
@@ -309,12 +312,10 @@ def allTests(communicator):
props["Ice.Admin.Facets"] = "TestFacet, Process"
com = factory.createCommunicator(props)
obj = com.getAdmin()
- # TODO: Remote the try/catch once ICE-4862 is fixed
- try:
- pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
- test(pa == None)
- except Ice.FacetNotExistException:
- pass
+
+ pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
+ test(pa == None)
+
tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
tf.op()
proc = Ice.ProcessPrx.checkedCast(obj, "Process")