Hi Ivana,

On Tue, 2010-02-09 at 10:13 +0100, Ivana Hutarova Varekova wrote:
> I agree again - good idea.
> Do you prefer to get a patch for this two issues from me, or do you 
> preffer to create it yourself?

Here's the patch with those changes. The one thing to be careful about
is that there are now a few things that become the labels of tree nodes
(e.g. the name of a controller) - that only works if those strings do
not contain '/'. One place where I thought that _might_ happen is in
variable_setting. That's why I translate 'uvw = xyz' into

  { "variable" = "uvw" { "value" = "xyz" } }

instead of just { "uvw" = "xyz" }.

With all that, the patch with those changes is attached. Let me know if
it's ok, and I will commit it.

David


>From 40bf263c958ffbed5bef571843ebc9569d942aa3 Mon Sep 17 00:00:00 2001
From: Ivana Hutarova Varekova <[email protected]>
Date: Mon, 8 Feb 2010 11:38:41 -0800
Subject: [PATCH] Cgconfig: lens and tests for libcgroup config

See http://libcg.sourceforge.net/
---
 AUTHORS                              |    1 +
 doc/naturaldocs/conf/lenses/Menu.txt |    1 +
 lenses/cgconfig.aug                  |  121 ++++++++++++++++++
 lenses/tests/test_cgconfig.aug       |  226 ++++++++++++++++++++++++++++++++++
 tests/Makefile.am                    |    1 +
 5 files changed, 350 insertions(+), 0 deletions(-)
 create mode 100644 lenses/cgconfig.aug
 create mode 100644 lenses/tests/test_cgconfig.aug

diff --git a/AUTHORS b/AUTHORS
index 0d682a3..0c31bfc 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -25,4 +25,5 @@ Contributions by:
   Robin Lee Powell            <[email protected]>
   Satoru SATOH                <[email protected]>
   Nahum Shalman               <nshalman elys com>
+  Ivana Hutarova Varekova     <[email protected]>
   Dean Wilson                 <[email protected]>
diff --git a/doc/naturaldocs/conf/lenses/Menu.txt b/doc/naturaldocs/conf/lenses/Menu.txt
index ce4c350..ea2d7b7 100644
--- a/doc/naturaldocs/conf/lenses/Menu.txt
+++ b/doc/naturaldocs/conf/lenses/Menu.txt
@@ -54,6 +54,7 @@ Group: Main Site  {
 Group: Specific Modules  {
 
    File: Build  (build.aug)
+   File: cgconfig  (cgconfig.aug)
    File: Cron  (cron.aug)
    File: Dpkg  (dpkg.aug)
    File: Exports  (exports.aug)
diff --git a/lenses/cgconfig.aug b/lenses/cgconfig.aug
new file mode 100644
index 0000000..7e58354
--- /dev/null
+++ b/lenses/cgconfig.aug
@@ -0,0 +1,121 @@
+(*
+Module: cgconfig
+    Parses /etc/cgconfig.conf
+
+Author:
+    Ivana Hutarova Varekova <[email protected]>
+    Raphael Pinson          <[email protected]>
+
+About: Licence
+    This file is licensed under the LGPLv2+, like the rest of Augeas.
+
+About: Lens Usage
+    Sample usage of this lens in augtool
+        * print all mounted cgroups
+           print /files/etc/cgconfig.conf/mount
+
+About: Configuration files
+    This lens applies to /etc/cgconfig.conf. See <filter>.
+ *)
+
+module Cgconfig =
+   autoload xfm
+
+   let indent  = Util.indent
+   let eol     = Util.eol
+   let comment = Util.comment
+   let empty   = Util.empty
+
+   let id        = /[a-zA-Z0-9_\-\/\.]+/
+   let name      = /[^#= \n\t{}\/]+/
+   let cont_name = /(cpuacct|cpu|devices|ns|cpuset|memory|freezer|net_cls)/
+   let role_name = /(admin|task)/
+   let id_name   = /(uid|gid)/
+   let address   = /[^#; \n\t{}]+/
+
+   let lbracket = del /[ \t\n]*\{/ " {"
+   let rbracket = del /[ \t]*\}/ "}"
+   let eq       = indent . Util.del_str "=" . indent
+
+(******************************************
+ * Function to deal with abc=def; entries
+ ******************************************)
+
+   let key_value (key_rx:regexp) (val_rx:regexp) =
+     [ indent . key key_rx . eq . store val_rx
+         . indent . Util.del_str ";" ]
+
+   (* Function to deal with bracketted entries *)
+   let brack_entry_base (lnsa:lens) (lnsb:lens) =
+     [ indent . lnsa . lbracket . lnsb . rbracket ]
+
+   let brack_entry_key (kw:regexp) (lns:lens) =
+     let lnsa = key kw in
+     brack_entry_base lnsa lns
+
+   let brack_entry (kw:regexp) (lns:lens) =
+     let full_lns = (lns | comment | empty)* in
+     brack_entry_key kw full_lns
+
+(******************************************
+ * control groups
+ ******************************************)
+
+   let permission_setting = key_value id_name address
+
+(* task setting *)
+   let t_info =  brack_entry "task" permission_setting
+
+(* admin setting *)
+   let a_info =  brack_entry "admin" permission_setting
+
+(* permissions setting *)
+   let perm_info =
+     let ce = (comment|empty)* in
+     let perm_info_lns = ce .
+       ((t_info . ce . (a_info . ce)?)
+       |(a_info . ce . (t_info . ce)?))? in
+     brack_entry_key "perm" perm_info_lns
+
+   let variable_setting =
+     [ indent . label "variable" . store id . eq .
+         [ label "value" . store address . indent . Util.del_str ";" ] ]
+
+(* controllers setting *)
+   let controller_info =
+     let lnsa = label "controller" . store cont_name in
+     let lnsb = ( variable_setting | comment | empty ) * in
+     brack_entry_base lnsa lnsb
+
+(* group { ... } *)
+   let group_data  =
+     let lnsa = key "group" . indent . [ label "name"  . store id ] in
+     let lnsb = ( perm_info | controller_info | comment | empty )* in
+     brack_entry_base lnsa lnsb
+
+
+(*************************************************
+ * mount point
+ *************************************************)
+
+(* controller = mount_point; *)
+   let mount_point = key_value name address
+
+(* mount { .... } *)
+   let mount_data = brack_entry "mount" mount_point
+
+
+(****************************************************
+ * namespace
+ ****************************************************)
+
+(* controller = cgroup; *)
+   let namespace_instance = key_value name address
+
+
+(* namespace { .... } *)
+   let namespace = brack_entry "namespace" namespace_instance
+
+   let lns =  ( comment | empty | mount_data | group_data | namespace )*
+
+   let xfm = transform lns (incl "/etc/cgconfig.conf")
diff --git a/lenses/tests/test_cgconfig.aug b/lenses/tests/test_cgconfig.aug
new file mode 100644
index 0000000..c33c357
--- /dev/null
+++ b/lenses/tests/test_cgconfig.aug
@@ -0,0 +1,226 @@
+module Test_cgconfig =
+
+   let conf="#cgconfig test cofiguration file
+mount { 123 = 456; 456 = 789;}
+"
+   test Cgconfig.lns get conf =
+  { "#comment" = "cgconfig test cofiguration file" }
+  { "mount"
+      { "123" = "456" }
+      { "456" = "789" } }
+  {}
+
+(* white spaces before mount sign *)
+   let conf2="
+ mount { 123 = 456;}
+    mount { 123 = 456;}
+
+mount { 123 = 456;}mount { 123 = 456;}
+"
+   test Cgconfig.lns get conf2 =
+        { }
+        {"mount"
+           { "123" = "456"} }
+        { }
+        {"mount"
+           { "123" = "456"} }
+        { }
+        { }
+        {"mount"
+           { "123" = "456"} }
+        { "mount"
+           { "123"  = "456" } }
+        { }
+
+   let conf3="#cgconfig test cofiguration file
+mount { 123 = 456;
+#eswkh
+ 456 = 789;}
+"
+   test Cgconfig.lns get conf3 =
+  { "#comment" = "cgconfig test cofiguration file" }
+  { "mount"
+    { "123" = "456" }
+    {}
+    { "#comment" = "eswkh" }
+    { "456" = "789" } }
+  {}
+
+  let conf4="#cgconfig test cofiguration file
+mount {
+123 = 456;1245=456;
+}
+mount { 323=324;}mount{324=5343;  }# this is a comment
+"
+   test Cgconfig.lns get conf4 =
+      {"#comment" = "cgconfig test cofiguration file" }
+      {"mount"
+               {  }
+               { "123" = "456"}
+               { "1245" = "456" }
+               {  }}
+      { }
+      { "mount" { "323" = "324" } }
+      { "mount" { "324" = "5343" } }
+      { "#comment" = "this is a comment" }
+
+   let group1="
+group user {
+	cpuacct {
+      lll = jjj;
+	}
+	cpu {
+	}
+}"
+
+test Cgconfig.lns get group1 =
+     {  }
+     { "group"
+       { "name" = "user" }
+       {  }
+       { "controller" = "cpuacct"
+           {  }
+           { "variable" = "lll" { "value" = "jjj" } }
+           {  }
+       }
+       {  }
+       { "controller" = "cpu" {  } }
+       {  } }
+
+
+let group2="
+group aa{
+     perm {
+		 task { }
+		 admin { }
+      }
+}"
+
+test Cgconfig.lns get group2 =
+  {  }
+  { "group"
+    { "name" = "aa" }
+    {  }
+    { "perm"
+      {  }
+      { "task" }
+      {  }
+      { "admin" }
+      {  }
+    }
+    {  }
+  }
+
+
+let group3 ="
+group xx/www {
+ perm {
+	task {
+		gid = root;
+		uid = root;
+	}
+	admin {
+		gid = aaa;
+# no aaa
+		uid = aaa;
+	}
+}
+}
+"
+
+test Cgconfig.lns get group3 =
+  {  }
+  { "group"
+    { "name" = "xx/www" }
+    {  }
+    { "perm"
+      {  }
+      { "task"
+        {  }
+        { "gid" = "root" }
+        {  }
+        { "uid" = "root" }
+        {  } }
+      {  }
+      { "admin"
+        {  }
+        { "gid" = "aaa" }
+        {  }
+        { "#comment" = "no aaa" }
+        { "uid" = "aaa" }
+        {  } }
+      {  } }
+    {  } }
+  {  }
+
+let group4 ="
+#group daemons {
+#           cpuacct{
+#           }
+#}
+
+group daemons/ftp {
+                     cpuacct{
+                                          }
+}
+
+   group daemons/www {
+        perm {
+                task {
+                        uid = root;
+                        gid = root;
+                }
+                admin {
+                        uid = root;
+                        gid = root;
+                }
+        }
+#       cpu {
+#               cpu.shares = 1000;
+#       }
+}
+#
+#
+
+  mount {
+       devices = /mnt/cgroups/devices;cpuacct = /mnt/cgroups/cpuset;
+        cpuset = /mnt/cgroups/cpuset;
+
+
+        cpu = /mnt/cpu;
+#        cpuset = /mnt/cgroups/cpuset2;
+}
+mount   {
+devices = /mnt/cgroups/devices;
+#       cpuacct = /mnt/cgroups/cpuacct;
+        ns = /mnt/cgroups/ns;
+#
+}
+
+"
+
+test Cgconfig.lns get group3 =
+  {  }
+  { "group"
+    { "name" = "xx/www" }
+    {  }
+    { "perm"
+      {  }
+      { "task"
+        {  }
+        { "gid" = "root" }
+        {  }
+        { "uid" = "root" }
+        {  }
+      }
+      {  }
+      { "admin"
+        {  }
+        { "gid" = "aaa" }
+        {  }
+        { "#comment" = "no aaa" }
+        { "uid" = "aaa" }
+        {  } }
+      {  } }
+    {  } }
+  {  }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bc8e13a..c74b9e6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ lens_tests =			\
   lens-aptpreferences.sh	\
   lens-aptsource.sh		\
   lens-bbhosts.sh		\
+  lens-cgconfig.sh      \
   lens-cobblersettings.sh	\
   lens-cobblermodules.sh	\
   lens-cron.sh			\
-- 
1.6.6

_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to