Re: [389-devel] Instance discovery tools in lib389

2015-08-12 Thread William Brown
On Thu, 2015-08-13 at 07:49 +0930, William wrote:
> > > 
> > > I hope this demonstrates how I want to tie together the other 
> > > contributions I
> > > have made into tools, but also making it possible to test other 
> > > aspects of
> > > 389ds.
> > > 
> > > Comments and advice welcome.
> > Hi William,
> > 
> > This looks good to me, it's definitely a good start.  I see no reason 
> > not to push the patch once you think it's ready and polished enough. 
> > Don't forget to add the license text to new files.  > needs 
> > to be done for many of the files in lib389 - I'll open a ticket for 
> > that>
> 
> Thanks! I think that the main piece of polish is the helper.py library
> that backs the cli tools to make them a bit easier to write. I'll make
> this a bit nicer now and send this back in for another review.
> 
> Thanks for your time,
> 
> Sincerely,
> 

Here is a slightly more polished CliTools helper, and the addition of a more
"interesting" command line tool example of an attribute query tool. You give it
an attribute type and it will provide a list of object classes that Must or May
take that attribute. I have found this a very useful tool in my work place where
we have a complex custom schema, so it's great to know what objectclass to put
on objects when you need to put certain attributes on them.

The biggest outstanding part for me now is how to best format the output of the
tool. Should I use the same logging tool as lib389? Or print things out in the
current form? Or something else. 

Sincerely,

-- 
William Brown From 007118ee71651e1ba3af0ff502c0351a5c2d Mon Sep 17 00:00:00 2001
From: William Brown 
Date: Thu, 6 Aug 2015 10:11:25 +0930
Subject: [PATCH] Example of commandline tools implementation for listing all
 attribute types and instances

---
 clitools/__init__.py  | 43 +++
 clitools/ds_list_instances.py | 18 ++
 clitools/ds_schema_attributetype_list.py  | 24 +
 clitools/ds_schema_attributetype_query.py | 31 +
 lib389/__init__.py| 58 ++-
 lib389/_constants.py  | 15 
 6 files changed, 180 insertions(+), 9 deletions(-)
 create mode 100644 clitools/__init__.py
 create mode 100644 clitools/ds_list_instances.py
 create mode 100644 clitools/ds_schema_attributetype_list.py
 create mode 100644 clitools/ds_schema_attributetype_query.py

diff --git a/clitools/__init__.py b/clitools/__init__.py
new file mode 100644
index 000..ecc708f
--- /dev/null
+++ b/clitools/__init__.py
@@ -0,0 +1,43 @@
+# Probably need some helpers for argparse and instance selection
+
+from argparse import ArgumentParser
+from getpass import getpass
+from lib389 import DirSrv
+from lib389._constants import *
+
+class CliTool(object):
+def __init__(self, args=None):
+self.ds = DirSrv()
+if args is not None:
+self.args = args
+
+def populate_instance_dict(self, instance):
+insts = self.ds.list(serverid=instance)
+if len(insts) != 1:
+# Raise an exception here?
+self.inst = None
+else:
+self.inst = insts[0]
+
+def get_rootdn_pass(self):
+#There is a dict get key thing somewhere ...
+if self.inst.get(SER_ROOT_PW, None) is None:
+self.inst[SER_ROOT_PW] = getpass('Enter password for %s on instance %s: ' % (self.inst[SER_ROOT_DN], self.inst[SER_SERVERID_PROP]))
+return
+
+def connect(self):
+self.get_rootdn_pass()
+self.ds.allocate(self.inst)
+self.ds.open()
+
+def disconnect(self):
+# Is there a ds unbind / disconnect?
+self.ds.close()
+
+def _clitools_parser():
+parser = ArgumentParser(add_help=False)
+parser.add_argument('--instance', '-i', help='The name of the DS instance to connect to and work upon.')
+return parser
+
+clitools_parser = _clitools_parser()
+
diff --git a/clitools/ds_list_instances.py b/clitools/ds_list_instances.py
new file mode 100644
index 000..8647187
--- /dev/null
+++ b/clitools/ds_list_instances.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+
+from lib389._constants import *
+from clitools import CliTool
+
+class ListTool(CliTool):
+def list_instances(self):
+# Remember, the prefix can be set with the os environment
+instances = self.ds.list(all=True)
+print('Instances on this system:')
+for instance in instances:
+print(instance[CONF_SERVER_ID])
+
+if __name__ == '__main__':
+listtool = ListTool()
+listtool.list_instances()
+
+
diff --git a/clitools/ds_schema_attributetype_list.py b/clitools/ds_schema_attributetype_list.py
new file mode 100644
index 000..0239ac3
--- /dev/null
+++ b/clitools/ds_schema_attributetype_list.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+#from clitools import clitools_parser, get_instance_dict, get_rootdn_pass
+from clitools import CliTool, clitools_parser
+#from 

Re: [389-devel] Instance discovery tools in lib389

2015-08-12 Thread William

> > 
> > I hope this demonstrates how I want to tie together the other 
> > contributions I
> > have made into tools, but also making it possible to test other 
> > aspects of
> > 389ds.
> > 
> > Comments and advice welcome.
> Hi William,
> 
> This looks good to me, it's definitely a good start.  I see no reason 
> not to push the patch once you think it's ready and polished enough. 
> Don't forget to add the license text to new files.  needs 
> to be done for many of the files in lib389 - I'll open a ticket for 
> that>

Thanks! I think that the main piece of polish is the helper.py library
that backs the cli tools to make them a bit easier to write. I'll make
this a bit nicer now and send this back in for another review.

Thanks for your time,

Sincerely,

-- 
William 
--
389-devel mailing list
389-devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/389-devel

Re: [389-devel] Instance discovery tools in lib389

2015-08-12 Thread Mark Reynolds



On 08/11/2015 07:40 AM, William Brown wrote:

Hi,


Ultimately, I would like to see some of your new functionally go into
the existing core module, and then write your tools based off of those.
This way it can be leveraged outside of your "specific task" tools - for
use in other new/future tools.  Of course I am specualting a bit,
because I have not seen what you are working on yet.

You have already seen my work, and acked most of the functionality into the
core
modules. Additionally the aci.py module is waiting in your inbox for informal
review.

For example:

https://fedorahosted.org/389/ticket/48236 <- Will be used in conjunction with
aci.py to evaluate and test aci functionality is working as expected, both in
the aci evaluation engine in 389ds, but also from a semantic point of view of
user acis

https://fedorahosted.org/389/ticket/48238 <- Is all the functionality needed
to
make the schema query tool I was discussing before.

Here is a patch with an example of what I have in mind. It's not perfected, or
polished, but it demonstrates what I have in mind.

To use it:

python clitools/ds_list_instances.py

python clitools/ds_schema_attributetype_list.py -i "instance name"

The main details are:

* It must be run on the same system as the ds instance.
* It respects PREFIX for your DS instances.
* This tool requires permissions to read dse.ldif of the instance. It currently
doesn't handle permission denied gracefully, as after all it's a POC.

I hope this demonstrates how I want to tie together the other contributions I
have made into tools, but also making it possible to test other aspects of
389ds.

Comments and advice welcome.

Hi William,

This looks good to me, it's definitely a good start.  I see no reason 
not to push the patch once you think it's ready and polished enough.  
Don't forget to add the license text to new files. to be done for many of the files in lib389 - I'll open a ticket for that>


Thanks,
Mark




--
389-devel mailing list
389-devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/389-devel


--
389-devel mailing list
389-devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/389-devel

[389-devel] Review Request for a new ACL testcase

2015-08-12 Thread Simon Pichugin
Hi,  

I have automated one testcase for:
https://fedorahosted.org/389/ticket/47569 

This is my patch:
https://fedorahosted.org/389/attachment/ticket/47569/0001-Ticket-47569-Added-a-testcase-to-ACL-testsuite.patch

Please, review my change.

Kind regards,
Simon Pichugin

--
389-devel mailing list
389-devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/389-devel