RackHD Test Framework Common Functions and Resources

This page documents the common functions available via the RackHD test framework for use by test scripts.

This page needs updates.


 

Test Environment Values and Config file parameters

The command line and default configuration file parameters supported via fit_common are accessible via using the fitcfg() module and the following modules:                                                                                                         

  install_default.json            - accessible via fitinstall(), fitports(), fitglobals(), fitproxy(), fitskupack()                                                

  credentials_default.json    - accessible via fitcreds(),                                                                                                     

  rackhd_default.json          - accessible via fitrackhd()                                                                                                     

  stack_config.json              - accessible via fitcfg()                                                                                                        

  command line arguments  - accessible via fitargs()                                                                                                       

                                                                                    

Libraries and Modules

Common methods and API

There is a set of common functions contained in fit_common.py and other files under the common directory.

https://github.com/RackHD/RackHD/tree/master/test/common fit_common.py     The main funtions to use when creating test scripts from fit_common include:         rackhdapi()  - this routine is used to make the specified RackHD API call                      - it includes getting necessary authentication tokens if needed                      - it returns the full result data structure and status         remote_shell() - this routine is used to send and perform a command via remote ssh                        - the routine expects a supplied command, ip, username, password                        - the routine will return stdout, stderr and status to be used or not         node_select() - this routine will return a list of nodes from the server                       - script can use this call to get the starting list of nodes (or node) via several methods.                       - returns a list of nodeids
api_utils and test_api_utils.py These files contain several utility functions the user can incorporate into their tests. They are helper routines to avoid duplicating code for commonly created routines such as getting a list of pollers or nodes. When writing routines for within these files, the routines should not presume a pass/fail or assert status.  The routines should always return the information back to the test script, allowing the test script to determine pass/fail status and assert as they desire.       ie. someone may expect an emplty list of nodes, so return the empty list as opposed to raising an assert saying nothing was returne       ie. a test may expect to see a 404 response code, as opposed to a 200.  Just resturn the response code to the calling script.     NOTE:       api_utils uses the rackhd api libraries that are created during the virtual environment setup  (site-packages/on_http_*)       test_api_utils uses the routines from fit_common.py

Generated RackHD API libraries

Existing CIT scripts make use of the generated API library that are created when you instantiate your virtual environment.

ie. mkenv.sh myenv

The libraries are located under your .venv/path/lib/python2.7/site-packages.

   ~/sandbox-github/rackhd/eh/test/.venv/myenv_eh-ub16/lib/python2.7/site-packages$     drwxr-xr-x 4 hohene cfyG_user 288 Jan 30 16:36 on_http_api1_1     drwxr-xr-x 2 hohene cfyG_user 195 Jan 30 16:36 on_http_api1_1-1.0.2.dist-info     drwxr-xr-x 4 hohene cfyG_user 288 Jan 30 16:36 on_http_api2_0     drwxr-xr-x 2 hohene cfyG_user 195 Jan 30 16:36 on_http_api2_0-1.0.10.dist-info     drwxr-xr-x 4 hohene cfyG_user 288 Jan 30 16:36 on_http_redfish_1_0     drwxr-xr-x 2 hohene cfyG_user 195 Jan 30 16:36 on_http_redfish_1_0-1.0.5.dist-info

CIT modules

  https://github.com/RackHD/RackHD/tree/master/test/modules      amqp, httpd      These modules are used mainly by CIT test scripts and Benchmark so far.      The logger.py will be deprecated, in FIT it is replaced by the stream-monitor plugin.      The amqp.py will be deprecated, in FIT it will be replaced by the stream-monitor plugin (not ready).


Making RackHD API calls in the test scripts

Making API calls to rackHD -   api 1.1, 2.0, redfish

rackhdapi():

Existing FIT test scripts make use of the function call rackhdapi() This function supports any of the API options (1.1, 2.0, redfish). The user specifies the call to make in the test script:       url = /api/1.1/nodes       url = /api/2.0/nodes       url = /redfish/v1/Systems The function will return to the caller:       rest status       rest data The function will take care of authentication setup/teardown for the api call


api calls via generated interface:

These functions require the user to do the authentication setup/teardown.     (when not running localhost/vagrant) When the user makes an API call, another call needs to be make to get the response object. The response object has status and data.   The user needs to make sure they are getting the response for their api call, (ie. if doing multiple calls, need to take care.)


In a single test script, user stick with one API path.     Use rackhdapi() or use generated API libraries.

    Both will be supported, both work and have different advatages.     FIT uses rackhdapi(), so that is preferred currently, but not mandated.



fit_common.py  Functions

The following helper functions are intended to be used by test scripts to execute common routines.

this section needs updates.

fit_common.countdown(sleep_time, sleep_interval=1)

Perform a sleep and display a countdown on the console. No return value.

Arguments:

"sleep_time" - (required) is the number of intervals as an integer

"sleep_interval" - the length of each interval with a default of one second as an integer

Example:

test_common.countdown(10)

Displays a ten second countdown.

fit_common.fit_args()

No arguments.

Returns a string containing the runtime command line arguments of the host script with the -t value removed. Used to pass arguments to test scripts from the wrapper script.

fit_common.mongo_reset()

No arguments, no return values.

Clears the Mongo database and conductor log. RestartsOnrackprocesses.

fit_common.rackhdapi(url_cmd, action='get', payload=[], timeout=None)

Used to execute Monorail API call to the stack or server specified in the command line. If the Monorail port (8080) is already enabled, it just executes the command, otherwise it opens the port, executes, then closes the port. All API calls, responses, headers, and payloads are logged automatically.

Arguments:

url_cmd - (required) Send the URL without the http:hostname:port prefix such as '/get/current/catalogs'

action - 'get', 'put', 'post', 'patch, or 'delete', default is 'get' as a string

payload - the payload as a Python dict

timeout - timeout in seconds as an integer

Return value:

data['json'] - if the command returns valid JSON, this will be a dict containing the JSON data

data['text'] - command return as text

data['status'] - the HTTP return or status code as an integer

data['headers'] - the HTTP headers

Examples:

This is a typical 'get' API command:

data = test_common.monorailapi('/api/current/workflows')

This is a typical 'post', 'put' or 'patch' command:

payload_data = {"identifiers": ["00:1e:67:98:bc:7e"],"profile": "diskboot.ipxe", "name": "test"}

data = test_common.monorailapi('/api/current/nodes?identifiers=00:1e:67:98:bc:7e', action='post', payload=payload_data

fit_common.premature_exit(reason='Premature exit', code=0)

Exit the test script gracefully with optional message and exit code. Use when a fatal error is detected.

fit_common.remote_shell(shell_cmd, expect_receive, expect_send)

Run a shell command on the appliance. This function performs all login and sudo overhead. Returns a list value with std_out and exit code. All commands, STDOUT, and exit codes are logged automatically.

Arguments:

shell_cmd - (required) the shell command to be executed on the server as a string

expect_receive - optional 'expect' string to be used as a trigger to send the 'expect_send' string, used for filling in passwords etc.

expect_send - string to send when the 'expect_receive' trigger is detected

Return value:

data[stdout] - text of std_out from the server

data[exitcode] - exit or return code of shell command

Example:

data = test_common.remote_shell("/opt/onrack/bin/monorail status")

data['exitcode'] = 0

data['stdout'] =

"

Status of ISC DHCP server: dhcpd is running.

on-dhcp-proxy start/running, process 2018

on-http start/running, process 2023

on-tftp start/running, process 2021

on-syslog start/running, process 2022

on-taskgraph start/running, process 2020

fit_common.sshinit()

No arguments, no return values.

Creates a new ssh key for use by remote_shell(). Execute once at the beginning of any script that uses remote_shell().

fit_common.node_select()

No Arguments.

Returns list of node IDs that meet the following conditions:

  • if no -sku or -obmmac arguments are specified  at the command line, then all nodes that are not 'unmanaged' or 'unknown'
  • if -sku is specified, then any nodes that match that string in the 'sku' or 'model' fileds
  • if -obmmac is specified, then a single node will be returned that matches the MAC address of the OBM setting