Skip to content

Commit

Permalink
Fixes #991: Fixed mock scripts and added testcases for namespace crea…
Browse files Browse the repository at this point in the history
…tion

Details:

* Increased minimum version of pywbem to 1.4.0 (for now, pulling from
  branch).

* Fixed the simple_interop_mock_script.py mock script so that it now
  creates the Interop MOF always in the interop namespace. The user
  MOF continues to be created in the default namespace.

* Added a simple_foo_mock_script.py mock script that prepares an
  Interop namespace and then compiles user MOF into a namespace
  determined by the pragma namespace in the MOF.

* Added a new test file test_namespace_creation.py for various cases
  of namespace creation.

* For consistency, changed the simple_disablepull_mock_script.py
  mock script to also set up the Interop namespace in the same way,
  and to compile user MOF into root/cimv2, resulting in the same
  namespace setup as before the change.

* This allowed deletion of the no longer used
  simple_interop_mock_model.mof file, which was a somewhat simple minded
  approach to setting up an Interop namespace.

* Adjusted the expected error message for Interop namespace not found
  due to a corresponding change in pywbem 1.4.0.

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Jan 2, 2022
1 parent 3a9493f commit 69d8578
Show file tree
Hide file tree
Showing 11 changed files with 869 additions and 53 deletions.
10 changes: 8 additions & 2 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,22 @@ Released: not yet
for documentation. Modify pywbemcli.py mutually excluseive options --server,
--name, and --mock-server to use this class.

* Increased minimum version of pywbem to 1.3.0. (issue #1020)
* Increased minimum version of pywbem to 1.4.0. (issue #1020 and issue #991)

* Support for Python 3.10: Added Python 3.10 in GitHub Actions tests, and in
package metadata.

* Implement an end-end test for the subscription command group.

* Changed output format for table output of instance enumerate --no option to
* Changed output format for table output of instance enumerate --no option to
show each key as a column in the table so that keys are more readable.

* The '-v' option now displays better information about namespace creation
and deletion, particularly in mock environments. (related to issue #991)

* Test: Added testcases for namespace creation and deletion. (related to
issue #991)

**Cleanup:**

* Prepared the development environment for having more than one pywbemtools
Expand Down
3 changes: 2 additions & 1 deletion minimum-constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ wheel==0.33.5; python_version >= '3.8'
# Direct dependencies for install (must be consistent with requirements.txt)


pywbem==1.3.0
# TODO: Go back to released version 1.4.0 once available
# pywbem==1.4.0
# When using the GitHub master branch of pywbem, simply comment out the line
# above, since links are not allowed in constraint files - the minimum will be
# ensured by requirements.txt then.
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

# Direct dependencies (except pip, setuptools, wheel):

pywbem>=1.3.0
# TODO: Go back to released version 1.4.0 once available
# pywbem>=1.4.0
# When using the GitHub master branch of pywbem, comment out the line above,
# activate the GitHub link based dependency below.
# In that case, some of the install tests need to be disabled by setting
# the 'PYWBEM_FROM_REPO' variable in in tests/install/test_install.sh.
# git+https://github.com/pywbem/pywbem.git@master#egg=pywbem
git+https://github.com/pywbem/pywbem.git@master#egg=pywbem

nocaselist>=1.0.3
nocasedict>=1.0.1
Expand Down
52 changes: 28 additions & 24 deletions tests/unit/pywbemcli/simple_disablepull_mock_script.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
"""
Test mock script that installs the pywbem provided namespace provider
CIMNamespaceProvider and the simple Interop and user namespace model
defined in simple_interop_mock_model.mof and then sets the pywbem_mock
server to disable pull operations. This script is used to test the
general options around enabling and disabling pull operations
This mock script sets up a mock_environment with an interop namespace
and a user namespace populaed with the simple_mock_model but with pull
operations disabled so any execution of a pull operation
directly returns a NOT_SUPPORTED error. It is used to test the operation
of the pywbemcli client on servers where pull does not exist.
Test mock script that prepares an Interop namespace and namespace provider,
compiles MOF into user namespace 'root/cimv2', and then disables pull operations
on the mock connection.
This script is used to test the general options around enabling and disabling
pull operations.
This mock script uses 'new-style' setup for Python >=3.5 and 'old-style' setup
otherwise, and is therefore useable for all supported Python versions.
Expand Down Expand Up @@ -52,9 +47,6 @@ def _setup(conn, server, verbose):
verbose (bool): Verbose flag
"""

if INTEROP_NAMESPACE not in conn.cimrepository.namespaces:
conn.add_namespace(INTEROP_NAMESPACE)

conn.disable_pull_operations # pylint: disable=pointless-statement

if sys.version_info >= (3, 5):
Expand All @@ -64,23 +56,35 @@ def _setup(conn, server, verbose):
# of the current script when it is executed using exec(), so we hard
# code the file path. This requires that the tests are run from the
# repo main directory.
this_file_path = 'tests/unit/pywbemcli/simple_interop_mock_script.py'
this_file_path = \
'tests/unit/pywbemcli/simple_disablepull_mock_script.py'
assert os.path.exists(this_file_path)

mof_file = 'simple_interop_mock_model.mof'
dependent_files = [mof_file,
'mock_interop.mof',
'simple_mock_model.mof']
mof_path = os.path.join(os.path.dirname(this_file_path), mof_file)
conn.compile_mof_file(mof_path, namespace=None)
# Prepare an Interop namespace and namespace provider

# Disable the pull operations for this test
conn.disable_pull_operations = True
interop_mof_file = 'mock_interop.mof'
if INTEROP_NAMESPACE not in conn.cimrepository.namespaces:
conn.add_namespace(INTEROP_NAMESPACE, verbose=verbose)

interop_mof_path = os.path.join(
os.path.dirname(this_file_path), interop_mof_file)
conn.compile_mof_file(interop_mof_path, namespace=INTEROP_NAMESPACE,
verbose=verbose)
register_dependents(conn, this_file_path, interop_mof_file)

register_dependents(conn, this_file_path, dependent_files)
ns_provider = pywbem_mock.CIMNamespaceProvider(conn.cimrepository)
conn.register_provider(ns_provider, INTEROP_NAMESPACE, verbose=verbose)

# Compile a MOF file into the default namespace

mof_file = 'simple_mock_model.mof'
mof_path = os.path.join(os.path.dirname(this_file_path), mof_file)
conn.compile_mof_file(mof_path, namespace='root/cimv2', verbose=verbose)
register_dependents(conn, this_file_path, mof_file)

# Disable the pull operations for this test
conn.disable_pull_operations = True


if sys.version_info >= (3, 5):
# New-style setup
Expand Down
225 changes: 225 additions & 0 deletions tests/unit/pywbemcli/simple_foo_mock_model.mof
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
// This is a simple mof model that creates the qualifier declarations,
// classes, and instances for a very simplistic model to be used in the
// pywbemcli mock test environment. This model is used for the user
// namespace.

#pragma locale ("en_US")
#pragma namespace ("foo")

Qualifier Association : boolean = false,
Scope(association),
Flavor(DisableOverride, ToSubclass);

Qualifier Indication : boolean = false,
Scope(class, indication),
Flavor(DisableOverride, ToSubclass);

Qualifier Abstract : boolean = false,
Scope(class, association, indication),
Flavor(EnableOverride, Restricted);

Qualifier Aggregate : boolean = false,
Scope(reference),
Flavor(DisableOverride, ToSubclass);

Qualifier EmbeddedInstance : string = null,
Scope(property, method, parameter);

Qualifier EmbeddedObject : boolean = false,
Scope(property, method, parameter),
Flavor(DisableOverride, ToSubclass);

Qualifier Description : string = null,
Scope(any),
Flavor(EnableOverride, ToSubclass, Translatable);

Qualifier In : boolean = true,
Scope(parameter),
Flavor(DisableOverride, ToSubclass);

Qualifier Key : boolean = false,
Scope(property, reference),
Flavor(DisableOverride, ToSubclass);

Qualifier Out : boolean = false,
Scope(parameter),
Flavor(DisableOverride, ToSubclass);

Qualifier Override : string = null,
Scope(property, reference, method),
Flavor(EnableOverride, Restricted);

Qualifier Static : boolean = false,
Scope(property, method),
Flavor(DisableOverride, ToSubclass);

[Abstract, Description ("Base class for classes that are referenced")]
class CIM_BaseRef {
[Key, Description ("This is key property.")]
string InstanceID;
};

[Description ("Class 1 that is referenced")]
class CIM_FooRef1 : CIM_BaseRef {};

[Description ("Class 2 that is referenced")]
class CIM_FooRef2 : CIM_BaseRef {};

[Association, Description ("Simple CIM Association")]
class CIM_FooAssoc {

[Key, Description ("This is key property.")]
CIM_FooRef1 REF Ref1;

[Key, Description ("This is key property.")]
CIM_FooRef2 REF Ref2;
};

[Abstract, Description ("Base class for classes having embedded instances")]
class CIM_BaseEmb {};

[Description ("Class 1 that has embedded instances")]
class CIM_FooEmb1 : CIM_BaseEmb {};

[Description ("Class 2 that has embedded instances")]
class CIM_FooEmb2 : CIM_BaseEmb {};

[Description ("Class 3 that has embedded instances")]
class CIM_FooEmb3 : CIM_BaseEmb {};

[Description ("Simple CIM Class")]
class CIM_Foo {
[Key, Description ("This is key property.")]
string InstanceID;

[Description ("This is Uint32 property.")]
uint32 IntegerProp;

[Description("Embedded instance property"), EmbeddedInstance("CIM_FooEmb3")]
string cimfoo_emb3;

[Description ("Method with in and out parameters")]
uint32 Fuzzy(
[IN, OUT, Description("Define data to be returned in output parameter")]
string TestInOutParameter,
[IN, OUT, Description ( "Test of ref in/out parameter")]
CIM_FooRef1 REF TestRef,
[IN ( false ), OUT, Description("Rtns method name if exists on input")]
string OutputParam,
[IN , Description("Defines return value if provided.")]
uint32 OutputRtnValue);

[Description ("Static method with in and out parameters"), Static]
uint32 FuzzyStatic(
[IN, OUT, Description("Define data to be returned in output parameter")]
string TestInOutParameter,
[IN, OUT, Description ( "Test of ref in/out parameter")]
CIM_Foo REF TestRef,
[IN ( false ), OUT, Description("Rtns method name if exists on input")]
string OutputParam,
[IN , Description("Defines return value if provided.")]
uint32 OutputRtnValue,
[IN, Description("Embedded instance parameter"), EmbeddedInstance("CIM_FooEmb1")]
string cimfoo_emb1);

[ Description("Method with no parameters but embedded instance return"),
EmbeddedInstance("CIM_FooEmb2") ]
string DeleteNothing();
};

[Description ("Subclass of CIM_Foo")]
class CIM_Foo_sub : CIM_Foo {
string cimfoo_sub;
};

[Description ("Subclass of CIM_Foo_sub")]
class CIM_Foo_sub_sub : CIM_Foo_sub {
string cimfoo_sub_sub;
[Description("Sample method with input and output parameters")]
uint32 Method1(
[IN ( false), OUT, Description("Response param 2")]
string OutputParam2);
};

class CIM_Foo_sub2 : CIM_Foo {
string cimfoo_sub2;
};


// 1 instance of each CIM_FooRef* class

instance of CIM_FooRef1 as $fooref11 {
InstanceID = "CIM_FooRef11";
};

instance of CIM_FooRef2 as $fooref21 {
InstanceID = "CIM_FooRef21";
};


// 1 instance of CIM_FooAssoc

instance of CIM_FooAssoc as $fooassoc1 {
Ref1 = $fooref11;
Ref2 = $fooref21;
};


// 5 instances of CIM_Foo class

instance of CIM_Foo as $foo1 {
InstanceID = "CIM_Foo1";
IntegerProp = 1;
};

instance of CIM_Foo as $foo2 {
InstanceID = "CIM_Foo2";
IntegerProp = 2;
};

instance of CIM_Foo as $foo3 { InstanceID = "CIM_Foo3"; };

instance of CIM_Foo as $foo3 { InstanceID = "CIM_Foo30"; };

instance of CIM_Foo as $foo3 { InstanceID = "CIM_Foo31"; };


// 4 instances of CIM_Foo_sub class

instance of CIM_Foo_sub as $foosub1{
InstanceID = "CIM_Foo_sub1";
IntegerProp = 4;
};

instance of CIM_Foo_sub as $foosub1{
InstanceID = "CIM_Foo_sub2";
IntegerProp = 5;
};

instance of CIM_Foo_sub as $foosub1{
InstanceID = "CIM_Foo_sub3";
IntegerProp = 6;
};

instance of CIM_Foo_sub as $foosub1{
InstanceID = "CIM_Foo_sub4";
IntegerProp = 7;
};

// 3 instances of CIM_Foo_sub_sub

instance of CIM_Foo_sub_sub as $foosubsub1{
InstanceID = "CIM_Foo_sub_sub1";
IntegerProp = 8;
};

instance of CIM_Foo_sub_sub as $foosubsub1{
InstanceID = "CIM_Foo_sub_sub2";
IntegerProp = 9;
};

instance of CIM_Foo_sub_sub as $foosubsub1{
InstanceID = "CIM_Foo_sub_sub3";
IntegerProp = 10;

};
Loading

0 comments on commit 69d8578

Please sign in to comment.