• No results found

Testing Providers with PyWBEM

N/A
N/A
Protected

Academic year: 2021

Share "Testing Providers with PyWBEM"

Copied!
24
0
0

Loading.... (view fulltext now)

Full text

(1)

Testing Providers with PyWBEM

Tim Potter <[email protected]>

(2)

Overview

• PyWBEM basics

• Exploring with wbemcli.py

• Unit testing with unittest module

• Async client programming with Twisted • Using the MOF compiler

• Presentation materials available at

(3)

PyWBEM overview

• A pure-Python library for WBEM

−Sync and async CIM-XML client

−Provider interface

−MOF compiler

−Command line client

• Uses Python language features to provide easy to

(4)

Getting started

• Install PyWBEM

−Available in some distros

−http://pywbem.sourceforge.net

• Create connection

−WBEMConnection() for CIM-XML over http/https

−{Pegasus,OpenWBEM,SFCB}UDSConnection() for

unix domain socket access

• Use connection object to perform operations and

(5)

pywbem.CIMInstanceName

• Represents an object path/model path • Attributes

−host

−classname −namespace −keybindings

(6)

pywbem.CIMInstance

• Represents an instance of a class • Attributes

−host

−classname −namespace

−path (is a CIMInstanceName) −properties

(7)

Error handling

• Python exception is thrown when a CIM error

occurs

try:

    cli.EnumerateInstances('CIM_Foo') except pywbem.CIMError, arg:

    error = arg[0]  # error number     description = arg[1] # string

(8)

Other useful objects

CIMClass

−classname

−properties, methods, qualifiers

CIMDateTime

−Wrapper for datetime.{datetime,timedelta}

• CIM numeric types

−SintXX, UintXX, RealXX

CIMQualifier

(9)

Demo #1 and #2

• Making connections

• Performing simple WBEM operations • Accessing CIM object attributes

(10)

Testing Instance Providers

EnumerateInstanceNames(ClassName)

− List of CIMInstanceName

EnumerateInstances(ClassName)

− List of CIMInstance

GetInstance(InstanceName)

− List of CIMInstance

ModifyInstance(Instance) − None • DeleteInstance(InstanceName) − None • CreateInstance(Instance) − CIMInstanceName

(11)

Testing Association Providers

AssociatorNames(InstanceName, Args...) −List of CIMInstanceName

Associators(InstanceName, Args...) −List of CIMInstance

ReferenceNames(InstanceName, Args...) −List of CIMInstanceName

References(InstanceName, Args...) −List of CIMInstance

(12)

Testing Method Providers

InvokeMethod(MethodName, InstanceName,

    InParams)

−Tuple of method result and output parameters

Result, OutParams = cli.InvokeMethod(     'SetPowerState', cs, 

    PowerState = pywbem.Uint32(8),     Time = datetime.now())

(13)

wbemcli.py

• Command line tool for exploration and ad-hoc

testing

• Connects to a WBEM server then drops into Python

interactive interpreter

• Lots of extra goodies to make life easier for testing

(14)

wbemcli.py (cont)

• Usage: wbemcli.py HOST [­u USER] [­p PASS] \

    [­n NAMESPACE] [­­no­ssl] [­­port PORT]

• Features

−Uses full power of Python interactive interpreter

−Saves command line history to disk

−Aliases for common WBEM operations

(15)

Demo #3

(16)

Unit testing with unittest.py

• Built-in unit testing module using xUnit interface

−setUp(), runTest(), tearDown() −Test fixtures created for each test case

• Python version clunky but still usable • Can run tests individually

−By named test case

(17)

Demo #4

• Running unit tests based on Python's unittest.py

(18)

Asynchronous client programming

• Uses Twisted Python networking framework

• Event driven programming model – no threads

−“reactor” is central object in a Twisted program

• Uses callback model to respond to events

−“defered” is central object for using callbacks

• Go read tutorial and reference documentation at

(19)

Using the PyWBEM Twisted Client

• Basic process for performing a client operation:

1. Create a “factory” which creates instances of the operation you want to perform

2. Add callbacks

3. Call reactor.connectTCP() 4. Enter or return to event loop

• Return “deferred” objects to hang callbacks off

“A deferred is a promise that a function will at some point

(20)

Example: Create CIM_Indication filter

• CIM operations, twisted style

−Create CIMInstance object

−Create a “CreateInstance factory”

−Add success and failure callbacks

−Make TCP client connection

−Enter event loop

(21)

Creating a CIM Listener

• Basic process for listening for indications

−Create a twisted.web.server listening on port 5988

and port 5989

−Create a twisted.web.resource to handle POST

requests and parse received XML

−Call reactor.listenTCP() function or reactor.listenSSL()

−See irecv.py file in PyWBEM distribution

(22)

Using PyWBEM MOF Compiler

• Define a class with a PyWBEM server interface

−CreateClass, ModifyClass, EnumerateQualifiers, etc

• Create a mof_compiler.MOFCompiler instance • Call compile_file() for each MOF file to

(23)

Tricks & Traps

• Use DeepInheritance = True when

enumerating classes and class names

• Use LocalOnly = False when calling

GetClass() method

• Watch out for host attribute in return values from

associators

(24)

References

Related documents

Cardiff Council held a public consultation in spring 2013 on a proposal to establish a stand alone new 1.5 form entry (FE) English-medium primary school with a 32 full time

Additional endpoints of the study relate to blood glucose control, diabetic comorbidity control, indirect measures of insulin resistance and beta cell function, weight and weight

This outdoor fireplace is for you who will appreciate a fireplace of timeless Danish design for your garden, whilst also enjoying the option of cooking on your terrace. With

Exceptional Student Education Department / Fernandina Beach High School Marcie Barker, One-on-One ESE Paraprofessional, effective August 21, 2020. Exceptional Student

interdisciplinary lens I argue that RTR falls short in four major ways: it ignores and dismisses Portland’s racist history by omitting narratives of trauma caused by urban renewal,

As the name implies, this menu allows you to take point data in a shapefile and create gridfiles where each grid cell takes a value calculated based on the points that are

Accordingly, we can reasonably approximate trade freeness between French regions as well as between a French region and a foreign country by applying our previously

buprenorphine/naloxone combination for induction, clinical experience in office-based trials conducted by the National Institute on Drug Abuse (NIDA) has demonstrated that