Module Name: configParser.py
Directory: framework/core/configParser.py
Purpose:
- Organize Configuration: Manages your test configuration files in a structured way.
- Handle Multiple Platforms: Parses configuration settings that are specific to different device platforms.
- Image Management: Helps you locate and work with the correct image files (e.g., firmware) for different devices.
- Memory Map Support: Enables you to work with memory maps, which describe where specific data is stored within a device's memory.
Key Sections:
-
local- General test configuration settings.
- Example:
workspaceDirectory: Location to store logs and temporary files.
-
cpe- Device-specific configurations. Entries are typically named after platforms (e.g., "cpeSTB123").
- Important Fields:
platform: The platform identifier this configuration entry is for.validImage: Defines available valid image files and their locations.negativeImageLocation: Location of a negative image (used for testing failure states).memoryMap: Specifies the name of the memory map configuration to use with this platform.alternative_platform: A list of other platforms that can be treated as compatible with this one.
-
memoryMap- Describes the layout of a device's memory. Entries are also typically named after platforms.
- Important Fields:
offsets: Defines names and memory addresses of specific data elements you might reference in tests (e.g., "bootStatus" at address 0x12345678).
How to Use It:
-
Loading Configuration:
import configParser as cp my_config = cp.configParser(config_file) # Load from your configuration file
-
Retrieving Values:
# General Setting workspace = my_config.getWorkspaceDirectory() # Platform-Specific platform = "STB123" valid_image_url = my_config.getValidImageUrlViaPlatform("PCI1_image", platform) memory_map_offset = my_config.getMemoryMapValueViaPlatform(platform, "bootStatus")
-
Image Handling
image_name = "PCI2_image" platform = "STB456" image_url = my_config.getImageField(image_name, "platform", platform)
Example Configuration Structure:
local:
workspaceDirectory: /home/user/raft-tests
cpeSTB123:
platform: STB123
validImage:
PCI1_image: http://images/stb123/PCI1.img
PCI2_image: http://images/stb123/PCI2.img
negativeImageLocation: http://images/stb123/negative.img
memoryMap: memoryMapSTB123
memoryMapSTB123:
offsets:
bootStatus: 0x12345678Module Name: configParserBase.py
Directory framework/core/configParseBase.py
Purpose:
- Foundation for Parsers: Provides the basic building blocks for creating more specialized configuration file parsers within your test system.
- Handles Common Structures: Defines how to extract and store configuration parameters that are likely to be present across different types of test configuration files.
Key Functions:
-
__init__(self, config, log=None)- Constructor: Initializes the parser object.
config: The configuration data, typically loaded from a file and represented as a dictionary.log: An optional logging object to use for reporting.
- Constructor: Initializes the parser object.
-
decodeTable(self, parent, config)- Processes Tables: Handles cases where your configuration file contains nested tables (i.e., dictionaries within dictionaries).
parent: The dictionary where the decoded table should be stored.config: The table (as a dictionary) to be parsed
-
decodeParam(self, parent, name, value)- Handles Individual Parameters: Extracts single key-value pairs from the configuration.
- Updates the
parentdictionary with thenameandvalueextracted.
How It Relates to Your Test Framework
Think of the configParserBase module as a blueprint for creating parsers that understand the specific formats of your configuration files. Let's illustrate this with a hypothetical example:
Scenario:
- You have a
rack_config.yamlfile that defines test environments (e.g., racks, devices). - You need to load settings from this file into your test scripts.
Steps:
-
Create a Subclass:
from configParserBase import configParserBase class RackConfigParser(configParserBase): # ... your specific parser logic here ...
-
Customize Parsing: In your
RackConfigParserclass, you would override thedecodeTableanddecodeParammethods to match the structure of yourrack_config.yamlfile.
Benefits
- Code Structure: Provides a consistent way to handle different configuration file formats throughout your framework.
- Centralized Logic: Common parsing tasks are handled in the base class, reducing code duplication.
Note: The configParserBase itself is usually not used directly. It's the specialized subclasses (like the hypothetical RackConfigParser) that are integrated into your test scripts.