[augeas-devel] augeas: master - Cgconfig: lens and tests for libcgroup config
David Lutterkort
lutter at fedoraproject.org
Thu Feb 11 18:48:48 UTC 2010
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=d075fc3c19f8eacbafc0af3bef5c3e2b3f8e46d3
Commit: d075fc3c19f8eacbafc0af3bef5c3e2b3f8e46d3
Parent: c9822a13628e72e3ae4f0a63433db5adc18b87ef
Author: Ivana Hutarova Varekova <varekova at redhat.com>
AuthorDate: Mon Feb 8 11:38:41 2010 -0800
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Thu Feb 11 10:47:43 2010 -0800
Cgconfig: lens and tests for libcgroup config
See http://libcg.sourceforge.net/
---
AUTHORS | 1 +
doc/naturaldocs/conf/lenses/Menu.txt | 1 +
lenses/cgconfig.aug | 119 ++++++++++++++++
lenses/tests/test_cgconfig.aug | 255 ++++++++++++++++++++++++++++++++++
tests/Makefile.am | 1 +
5 files changed, 377 insertions(+), 0 deletions(-)
diff --git a/AUTHORS b/AUTHORS
index d39e506..85f4a62 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -26,4 +26,5 @@ Contributions by:
Satoru SATOH <satoru.satoh at gmail.com>
Nahum Shalman <nshalman elys com>
Laine Stump <laine at laine.org>
+ Ivana Hutarova Varekova <varekova at redhat.com>
Dean Wilson <dwilson at blueowl.it>
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..d2f8a97
--- /dev/null
+++ b/lenses/cgconfig.aug
@@ -0,0 +1,119 @@
+(*
+Module: cgconfig
+ Parses /etc/cgconfig.conf
+
+Author:
+ Ivana Hutarova Varekova <varekova at redhat.com>
+ Raphael Pinson <raphink at gmail.com>
+
+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 = key_value name address
+
+(* 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 . 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..44c2f45
--- /dev/null
+++ b/lenses/tests/test_cgconfig.aug
@@ -0,0 +1,255 @@
+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" = "user"
+ { }
+ { "controller" = "cpuacct"
+ { }
+ { "lll" = "jjj" }
+ { } }
+ { }
+ { "controller" = "cpu" { } }
+ { } }
+
+let group2="
+group aa{
+ perm {
+ task { }
+ admin { }
+ }
+}"
+
+test Cgconfig.lns get group2 =
+ { }
+ { "group" = "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" = "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 group4 =
+ { }
+ { "#comment" = "group daemons {" }
+ { "#comment" = "cpuacct{" }
+ { "#comment" = "}" }
+ { "#comment" = "}" }
+ { }
+ { "group" = "daemons/ftp"
+ { }
+ { "controller" = "cpuacct" { } }
+ { } }
+ { }
+ { }
+ { "group" = "daemons/www"
+ { }
+ { "perm"
+ { }
+ { "task"
+ { }
+ { "uid" = "root" }
+ { }
+ { "gid" = "root" }
+ { } }
+ { }
+ { "admin"
+ { }
+ { "uid" = "root" }
+ { }
+ { "gid" = "root" }
+ { } }
+ { } }
+ { }
+ { "#comment" = "cpu {" }
+ { "#comment" = "cpu.shares = 1000;" }
+ { "#comment" = "}" } }
+ { }
+ { }
+ { }
+ { }
+ { "mount"
+ { }
+ { "devices" = "/mnt/cgroups/devices" }
+ { "cpuacct" = "/mnt/cgroups/cpuset" }
+ { }
+ { "cpuset" = "/mnt/cgroups/cpuset" }
+ { }
+ { }
+ { }
+ { "cpu" = "/mnt/cpu" }
+ { }
+ { "#comment" = "cpuset = /mnt/cgroups/cpuset2;" } }
+ { }
+ { "mount"
+ { }
+ { "devices" = "/mnt/cgroups/devices" }
+ { }
+ { "#comment" = "cpuacct = /mnt/cgroups/cpuacct;" }
+ { "ns" = "/mnt/cgroups/ns" }
+ { }
+ { } }
+ { }
+ { }
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 \
More information about the augeas-devel
mailing list