rename attributes->properties when referring to uevent fields
properties: key-value pairs in the uevent message attributes: file contents in sysfs
This commit is contained in:
parent
7aa8633cde
commit
7d00b39249
@ -22,24 +22,24 @@
|
|||||||
(..
|
(..
|
||||||
(string.format "%s@%s\0" e.action e.path)
|
(string.format "%s@%s\0" e.action e.path)
|
||||||
(table.concat
|
(table.concat
|
||||||
(icollect [k v (pairs e.attributes)]
|
(icollect [k v (pairs e.properties)]
|
||||||
(string.format "%s=%s" (string.upper k) v ))
|
(string.format "%s=%s" (string.upper k) v ))
|
||||||
"\n")))
|
"\n")))
|
||||||
|
|
||||||
(fn event-matches? [e terms]
|
(fn event-matches? [e terms]
|
||||||
(accumulate [match? true
|
(accumulate [match? true
|
||||||
name value (pairs terms)]
|
name value (pairs terms)]
|
||||||
(and match? (= value (. e.attributes name)))))
|
(and match? (= value (. e.properties name)))))
|
||||||
|
|
||||||
(fn parse-event [s]
|
(fn parse-event [s]
|
||||||
(let [at (string.find s "@" 1 true)
|
(let [at (string.find s "@" 1 true)
|
||||||
(nl nxt) (string.find s "\0" 1 true)
|
(nl nxt) (string.find s "\0" 1 true)
|
||||||
attributes
|
properties
|
||||||
(collect [k v (string.gmatch
|
(collect [k v (string.gmatch
|
||||||
(string.sub s (+ 1 nxt))
|
(string.sub s (+ 1 nxt))
|
||||||
"(%g-)=(%g+)")]
|
"(%g-)=(%g+)")]
|
||||||
(k:lower) v)]
|
(k:lower) v)]
|
||||||
{ : attributes
|
{ : properties
|
||||||
:path (string.sub s (+ at 1) (- nl 1))
|
:path (string.sub s (+ at 1) (- nl 1))
|
||||||
:action (string.sub s 1 (- at 1))
|
:action (string.sub s 1 (- at 1))
|
||||||
:format format-event
|
:format format-event
|
||||||
|
@ -52,8 +52,8 @@ MINOR=17")
|
|||||||
(example
|
(example
|
||||||
"I can parse an event"
|
"I can parse an event"
|
||||||
(let [e (parse-event sdb1-insert)]
|
(let [e (parse-event sdb1-insert)]
|
||||||
(expect= e.attributes.seqnum "82381")
|
(expect= e.properties.seqnum "82381")
|
||||||
(expect= e.attributes.devname "/dev/sdb1")
|
(expect= e.properties.devname "/dev/sdb1")
|
||||||
(expect= e.path "/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1")
|
(expect= e.path "/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1")
|
||||||
(expect= e.action :add)
|
(expect= e.action :add)
|
||||||
(expect= e (parse-event (e:format)))))
|
(expect= e (parse-event (e:format)))))
|
||||||
@ -77,8 +77,8 @@ MINOR=17")
|
|||||||
(let [db (database)]
|
(let [db (database)]
|
||||||
(db:add sda-uevent)
|
(db:add sda-uevent)
|
||||||
(let [[m & more] (db:find {:devname "sda"})]
|
(let [[m & more] (db:find {:devname "sda"})]
|
||||||
(expect= m.attributes.devname "sda")
|
(expect= m.properties.devname "sda")
|
||||||
(expect= m.attributes.major "8")
|
(expect= m.properties.major "8")
|
||||||
(expect= more []))))
|
(expect= more []))))
|
||||||
|
|
||||||
(example
|
(example
|
||||||
@ -92,8 +92,8 @@ MINOR=17")
|
|||||||
(let [db (database)]
|
(let [db (database)]
|
||||||
(db:add sda-uevent)
|
(db:add sda-uevent)
|
||||||
(let [m (db:at-path "/devices/pci0000:00/0000:00:13.0/usb1/1-1/1-1:1.0/host0/target0:0:0/0:0:0:0/block/sda")]
|
(let [m (db:at-path "/devices/pci0000:00/0000:00:13.0/usb1/1-1/1-1:1.0/host0/target0:0:0/0:0:0:0/block/sda")]
|
||||||
(expect= m.attributes.devname "sda")
|
(expect= m.properties.devname "sda")
|
||||||
(expect= m.attributes.major "8"))))
|
(expect= m.properties.major "8"))))
|
||||||
|
|
||||||
(example
|
(example
|
||||||
"when I add and then remove a device, I cannot retrieve it by path"
|
"when I add and then remove a device, I cannot retrieve it by path"
|
||||||
|
Loading…
Reference in New Issue
Block a user