{"id":60,"date":"2007-12-12T17:58:07","date_gmt":"2007-12-12T17:58:07","guid":{"rendered":"http:\/\/blog.danplanet.com\/wordpress\/?p=60"},"modified":"2011-11-29T16:27:43","modified_gmt":"2011-11-29T16:27:43","slug":"testing-with-pywbem","status":"publish","type":"post","link":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/","title":{"rendered":"Testing with pywbem"},"content":{"rendered":"<p>Recently a colleague <a href=\"https:\/\/www.redhat.com\/archives\/libvirt-cim\/2007-December\/msg00187.html\">pointed out<\/a> that our VirtualSystemManagementService&#8217;s RemoveResourceSettings method (in <a href=\"http:\/\/libvirt.org\/CIM\">libvirt-cim<\/a>) was marked with the wrong type.\u00a0 This was done early on, and probably was just a mistake, given that AddResourceSettings and ModifyResourceSettings both took the same type: an EmbeddedObject.\u00a0 RemoveResourceSettings takes a reference, since anything you could possibly delete would be representable as a reference.\u00a0 It&#8217;s the right way, but annoying, given that I had already built a common resource management infrastructure around the idea of having a list of resource objects to (Add,Modify,Remove).<\/p>\n<p>Anyway, I coded up the <a href=\"https:\/\/www.redhat.com\/archives\/libvirt-cim\/2007-December\/msg00219.html\">change<\/a> to the provider itself and set out to test it.\u00a0 I quickly realized that I didn&#8217;t know what the CIMXML for a method call with an array of references looked like.\u00a0 Up to this point, I have been unit testing the method providers by just hacking up a CIMXML template and stuffing it into wbemexec or wbemcat.\u00a0 It sucks, but it works.<\/p>\n<p>However, this time I was stuck.\u00a0 I didn&#8217;t have an example, and some guessing didn&#8217;t work in a short amount of time.\u00a0 I decided to try to work up something in pywbem to see if I could get not only the method call made for testing, but also a glimpse at what the CIMXML for it looked like.\u00a0 I ended up with this very small bit of python code that was extremely helpful:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>from pywbem import WBEMConnection, CIMInstanceName<\/p><\/blockquote>\n<p>c = WBEMConnection(&#8220;http:\/\/localhost&#8221;,<br \/>\n(&#8220;root&#8221;, &#8220;password&#8221<img decoding=\"async\" src=\"https:\/\/www.danplanet.com\/blog\/wp-content\/themes\/wordpress-grey-opaque-master\/images\/smilies\/icon_wink.gif\" alt=\"Smilie: ;)\" title=\"Smilie: ;)\" \/>,<br \/>\n&#8220;root\/virt&#8221<img decoding=\"async\" src=\"https:\/\/www.danplanet.com\/blog\/wp-content\/themes\/wordpress-grey-opaque-master\/images\/smilies\/icon_wink.gif\" alt=\"Smilie: ;)\" title=\"Smilie: ;)\" \/><br \/>\nc.debug = True<\/p>\n<p>r = CIMInstanceName(&#8220;Xen_DiskResourceAllocationSettingData&#8221;,<br \/>\nkeybindings={&#8220;InstanceID&#8221;:&#8221;pv0\/xvda&#8221;})<\/p>\n<p>res = c.InvokeMethod(&#8220;RemoveResourceSettings&#8221;,<br \/>\n&#8220;Xen_VirtualSystemManagementService&#8221;,<br \/>\nResourceSettings=[r])<\/p>\n<p>print c.last_request<\/p>\n<p>This connects to localhost, creates a reference, and makes the method call with that reference as a single-element array.\u00a0 After the operation, the &#8220;last_request&#8221; field contains the CIMXML it sent to the server, but <em>only<\/em> if the &#8220;debug&#8221; property is set to True (something the documentation conveniently leaves out).\u00a0 The result (with the boiler-plate cut out) looks like this:<\/p>\n<blockquote><p>&lt;PARAMVALUE NAME=&#8221;ResourceSettings&#8221; PARAMTYPE=&#8221;reference&#8221;&gt;<br \/>\n&lt;VALUE.REFARRAY&gt;<br \/>\n&lt;VALUE.REFERENCE&gt;<br \/>\n&lt;INSTANCENAME CLASSNAME=&#8221;Xen_DiskResourceAllocationSettingData&#8221;&gt;<br \/>\n&lt;KEYBINDING NAME=&#8221;InstanceID&#8221;&gt;<br \/>\n&lt;KEYVALUE VALUETYPE=&#8221;string&#8221;&gt;<br \/>\npv0\/xvda<br \/>\n&lt;\/KEYVALUE&gt;<br \/>\n&lt;\/KEYBINDING&gt;<br \/>\n&lt;\/INSTANCENAME&gt;<br \/>\n&lt;\/VALUE.REFERENCE&gt;<br \/>\n&lt;\/VALUE.REFARRAY&gt;<br \/>\n&lt;\/PARAMVALUE&gt;<\/p><\/blockquote>\n<p>Not that I really need it at this point, given that the pywbem case was so easy to write.\u00a0 However, it provides a good example of how to not only use pywbem to figure out the proper CIMXML for an operation, but also debug it if it&#8217;s wrong.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently a colleague pointed out that our VirtualSystemManagementService&#8217;s RemoveResourceSettings method (in libvirt-cim) was marked with the wrong type.\u00a0 This was done early on, and probably was just a mistake, given that AddResourceSettings and ModifyResourceSettings both took the same type: an &hellip; <a href=\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[28,39],"class_list":["post-60","post","type-post","status-publish","format-standard","hentry","category-codemonkeying","tag-cim","tag-pywbem"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Testing with pywbem - Right Angles<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Testing with pywbem - Right Angles\" \/>\n<meta property=\"og:description\" content=\"Recently a colleague pointed out that our VirtualSystemManagementService&#8217;s RemoveResourceSettings method (in libvirt-cim) was marked with the wrong type.\u00a0 This was done early on, and probably was just a mistake, given that AddResourceSettings and ModifyResourceSettings both took the same type: an &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/\" \/>\n<meta property=\"og:site_name\" content=\"Right Angles\" \/>\n<meta property=\"article:published_time\" content=\"2007-12-12T17:58:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2011-11-29T16:27:43+00:00\" \/>\n<meta name=\"author\" content=\"Dan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/\"},\"author\":{\"name\":\"Dan\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"headline\":\"Testing with pywbem\",\"datePublished\":\"2007-12-12T17:58:07+00:00\",\"dateModified\":\"2011-11-29T16:27:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/\"},\"wordCount\":435,\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"keywords\":[\"CIM\",\"pywbem\"],\"articleSection\":[\"Codemonkeying\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/\",\"url\":\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/\",\"name\":\"Testing with pywbem - Right Angles\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\"},\"datePublished\":\"2007-12-12T17:58:07+00:00\",\"dateModified\":\"2011-11-29T16:27:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.danplanet.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Testing with pywbem\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\",\"url\":\"https:\/\/www.danplanet.com\/blog\/\",\"name\":\"Right Angles\",\"description\":\"If they&#039;re not right...they&#039;re wrong\",\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\",\"name\":\"Dan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"caption\":\"Dan\"},\"logo\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.danplanet.com\/blog\/author\/dan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Testing with pywbem - Right Angles","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/","og_locale":"en_US","og_type":"article","og_title":"Testing with pywbem - Right Angles","og_description":"Recently a colleague pointed out that our VirtualSystemManagementService&#8217;s RemoveResourceSettings method (in libvirt-cim) was marked with the wrong type.\u00a0 This was done early on, and probably was just a mistake, given that AddResourceSettings and ModifyResourceSettings both took the same type: an &hellip; Continue reading &rarr;","og_url":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/","og_site_name":"Right Angles","article_published_time":"2007-12-12T17:58:07+00:00","article_modified_time":"2011-11-29T16:27:43+00:00","author":"Dan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/#article","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/"},"author":{"name":"Dan","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"headline":"Testing with pywbem","datePublished":"2007-12-12T17:58:07+00:00","dateModified":"2011-11-29T16:27:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/"},"wordCount":435,"publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"keywords":["CIM","pywbem"],"articleSection":["Codemonkeying"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/","url":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/","name":"Testing with pywbem - Right Angles","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/#website"},"datePublished":"2007-12-12T17:58:07+00:00","dateModified":"2011-11-29T16:27:43+00:00","breadcrumb":{"@id":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.danplanet.com\/blog\/2007\/12\/12\/testing-with-pywbem\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.danplanet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Testing with pywbem"}]},{"@type":"WebSite","@id":"https:\/\/www.danplanet.com\/blog\/#website","url":"https:\/\/www.danplanet.com\/blog\/","name":"Right Angles","description":"If they&#039;re not right...they&#039;re wrong","publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c","name":"Dan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","caption":"Dan"},"logo":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.danplanet.com\/blog\/author\/dan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":1,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"predecessor-version":[{"id":144,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/60\/revisions\/144"}],"wp:attachment":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}