aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-06-19 12:32:42 +0200
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-06-19 13:00:59 +0200
commitf675926009194dc7bbf9ba550c37f5352ce9bc88 (patch)
tree7b86060bb429448501a434522d9a51fe503099f1
parent3b8c0df0d336fada163abc3c366735e1043b2963 (diff)
Setup tox runner for simulator-cli tests
Change-Id: If006ab2cf6a3cb22af9c0134daf29aab6e479ad3 Issue-ID: INT-1632 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
-rw-r--r--simulator-cli/README.md129
-rw-r--r--simulator-cli/requirements.txt1
-rw-r--r--simulator-cli/tox.ini10
3 files changed, 78 insertions, 62 deletions
diff --git a/simulator-cli/README.md b/simulator-cli/README.md
index 5dc6f76..4771749 100644
--- a/simulator-cli/README.md
+++ b/simulator-cli/README.md
@@ -3,29 +3,34 @@
### Overview
Anytime you want to see a basic usage of a tool, you can run fully descriptive help using command:
```
-./{tool_name}.py -h # --help argument is also acceptable
-```
+./{tool_name}.py -h # --help argument is also acceptable
+```
#### PNF Simulator CLI
-PNF Simulator CLI provides command line interface to remotely interact with running PNF Simulator.
+PNF Simulator CLI provides command line interface to remotely interact with running PNF Simulator.
-Using the PNF Simulator CLI user is able to trigger events, retrieve simulator's configuration and change default VES url stored
-inside simulator.
+Using the PNF Simulator CLI user is able to trigger events, retrieve simulator's configuration and change default VES url stored
+inside simulator.
#### Netconf Simulator CLI
-Dedicated tool to help with management of the Netconf Server is also available.
+Dedicated tool to help with management of the Netconf Server is also available.
-Using the Netconf Simulator CLI user is able to retrieve simulator's cm history stored inside simulator as well as open the live session to actively listen for new configuration changes.
+Using the Netconf Simulator CLI user is able to retrieve simulator's cm history stored inside simulator as well as open the live session to actively listen for new configuration changes.
### Requirements and installation
Requirements
-* Python > 3.5
+* Python > 3.5
Installation:
* Go to directory containing setup.py and invoke `python setup.py install`
* Go to cli directory
* Add executable privilege to pnf_simulator.py and netconf_simulator.py (for example `chmod +x <path_to_pnf_simulator.py>`)
+### Development and testing
+To run unit tests for PNF and Netconf simulators cli execute `tox`.
+
+To develop unit tests run `tox`, then `source .tox/pytest/bin/activate` and after each code change run `pytest`.
+
### Pnf simulator
#### Usage
* [send](#send-action)
@@ -39,7 +44,7 @@ Installation:
Invoke `pnf_simulator.py [send|configure|get-config] -h` to display help.
##### Send Action
-Send action allows user to trigger sending events from Simulator to VES Collector.
+Send action allows user to trigger sending events from Simulator to VES Collector.
*sending repeating events backed by template persisted in db
`usage: pnf_simulator.py send template [-h] --address ADDRESS --name NAME
@@ -48,29 +53,29 @@ Send action allows user to trigger sending events from Simulator to VES Collecto
[--ves-server-url VES_SERVER_URL] [--verbose]
`
-Parameters
-` --address ADDRESS` `IP address of simulator`
+Parameters
+` --address ADDRESS` `IP address of simulator`
` --name NAME` `Name of template file which should be used as a base for event.
- Cannot be used simultaneously with parameter: event.`
+ Cannot be used simultaneously with parameter: event.`
` --patch PATCH` `Json which should be merged into template to override parameters.
Acceptable format: valid json wrapped using single quotes (example:'{"abc":1}').
- Cannot be used simultaneously with parameter: event.`
-` --repeats REPEATS` `Number of events to be send`
-` --interval INTERVAL` `Interval between two consecutive events (in seconds)`
-` --ves-server-url VES_SERVER_URL` `Well-formed URL which will override current VES endpoint stored in simulator's DB`
-` --verbose` `Displays additional logs`
+ Cannot be used simultaneously with parameter: event.`
+` --repeats REPEATS` `Number of events to be send`
+` --interval INTERVAL` `Interval between two consecutive events (in seconds)`
+` --ves-server-url VES_SERVER_URL` `Well-formed URL which will override current VES endpoint stored in simulator's DB`
+` --verbose` `Displays additional logs`
*sending event only once by passing path to file with complete event
`usage: pnf_simulator.py send event [-h] --address ADDRESS --filepath FILEPATH
[--ves-server-url VES_SERVER_URL] [--verbose]
`
-Parameters
-` --address ADDRESS` `IP address of simulator`
+Parameters
+` --address ADDRESS` `IP address of simulator`
` --filepath FILEPATH` `Path to file with full, legitimate event that is to be send directly to VES only once.
- This event is not associated with template and will not be persisted in db.
+ This event is not associated with template and will not be persisted in db.
Cannot be used simultaneously with parameters: template and patch.`
-` --ves-server-url VES_SERVER_URL` `Well-formed URL which will override current VES endpoint stored in simulator's DB`
+` --ves-server-url VES_SERVER_URL` `Well-formed URL which will override current VES endpoint stored in simulator's DB`
` --verbose` `Displays additional logs`
example content of file with complete event:
@@ -85,46 +90,46 @@ example content of file with complete event:
```
##### Configure Action
-Configure action allows user to change Simulator's configuration (VES Server URL)
+Configure action allows user to change Simulator's configuration (VES Server URL)
`usage: pnf_simulator.py configure [-h] --address ADDRESS --ves-server-url
VES_SERVER_URL [--verbose]
-`
+`
-Parameters
+Parameters
-` --address ADDRESS` `IP address of simulator`
-` --ves-server-url VES_SERVER_URL` `Well-formed URL which should be set as a default VES Server URL in simulator`
+` --address ADDRESS` `IP address of simulator`
+` --ves-server-url VES_SERVER_URL` `Well-formed URL which should be set as a default VES Server URL in simulator`
` --verbose` `Displays additional logs`
##### Get Config Action
-Get Config action allows user to retrieve actual Simulator's configuration
-`usage: pnf_simulator.py get-config [-h] --address ADDRESS [--verbose] `
+Get Config action allows user to retrieve actual Simulator's configuration
+`usage: pnf_simulator.py get-config [-h] --address ADDRESS [--verbose] `
Parameters
-`--address ADDRESS` `IP address of simulator`
+`--address ADDRESS` `IP address of simulator`
`--verbose` `Displays additional logs`
##### Template Action
Template action allows user to:
* retrieve a single template by name
-* list all available templates.
+* list all available templates.
* upload template to PNF Simulator (can overwrite existing template)
`usage: pnf_simulator.py template [-h]
(--list | --get-content NAME | --upload FILENAME)
- [--override] --address ADDRESS [--verbose]`
+ [--override] --address ADDRESS [--verbose]`
Parameters
-`--get-content NAME` `Gets the template by name`
-`--list` `List all templates`
-`--upload FILENAME [--override]` `Uploads the template given as FILENAME file. Optionally overrides any exisitng templates with matching filename`
-`--address ADDRESS` `IP address of simulator`
-`--verbose` `Displays additional logs`
+`--get-content NAME` `Gets the template by name`
+`--list` `List all templates`
+`--upload FILENAME [--override]` `Uploads the template given as FILENAME file. Optionally overrides any exisitng templates with matching filename`
+`--address ADDRESS` `IP address of simulator`
+`--verbose` `Displays additional logs`
#### Filter Templates Action
-Filter template action allows to search through templates in order to find names of those that satisfy given criteria.
+Filter template action allows to search through templates in order to find names of those that satisfy given criteria.
Criteria are passed in JSON format, as key-values pairs. Relation between pairs with criteria is AND (all conditions must be satisfied by template to have it returned).
No searching for null values is supported.
Search expression must be valid JSON, thus no duplicate keys are allowed - user could specify the same parameter multiple times, but only last occurrence will be applied to query.
@@ -132,12 +137,12 @@ Search expression must be valid JSON, thus no duplicate keys are allowed - user
`usage: pnf_simulator.py filter [-h]
--criteria CRITERIA --address ADDRESS [--verbose]`
-
+
Parameters
-`--criteria CRITERIA` `Json with criteria as key-value pairs, where values can be one of following data types: string, integer, double, boolean.
+`--criteria CRITERIA` `Json with criteria as key-value pairs, where values can be one of following data types: string, integer, double, boolean.
Acceptable format: valid json wrapped using single quotes (example:'{"searchedInt":1}').
- Cannot be used simultaneously with parameter: event.`
-`--address ADDRESS` `IP address of simulator`
+ Cannot be used simultaneously with parameter: event.`
+`--address ADDRESS` `IP address of simulator`
`--verbose` `Displays additional logs`
@@ -156,8 +161,8 @@ Invoke `netconf_simulator.py [tailf|less|cm-history] -h` to display help.
#### Load-model action
-Loads to netconf server new YANG model that corresponds with schema passed as yang-model parameter,
-assigns name specified in module-name and initializes model with startup configuration passed in config file.
+Loads to netconf server new YANG model that corresponds with schema passed as yang-model parameter,
+assigns name specified in module-name and initializes model with startup configuration passed in config file.
`usage: netconf_simulator.py load-module [-h] --address ADDRESS ---module-name MODULE_NAME --yang-model YANG_MODEL_FILEPATH --config <XML_CONFIG_FILEPATH> [--verbose]`
example YANG schema (file content for YANG_MODEL)
@@ -187,7 +192,7 @@ example startup configuration (file content of XML_CONFIG)
<itemValue2>200</itemValue2>
<itemValue3>300</itemValue3>
</config>
-```
+```
example output (without verbose flag):
@@ -197,11 +202,11 @@ Successfully started
```
#### Delete-model action
-Deletes a YANG model loaded in the netconf server.
+Deletes a YANG model loaded in the netconf server.
`usage: netconf_simulator.py delete-model [-h] --address ADDRESS --model-name
MODEL_NAME [--verbose]`
-
+
Example output (without verbose flag):
```
Response status: 200
@@ -210,8 +215,8 @@ Successfully deleted
#### Get-config Action
Returns active running configurations.
-By default it returns all running configurations. To retrieve one specific configuration (represented by _/'module_name':'container'_ ) user needs to pass module-name and container.
-Example:
+By default it returns all running configurations. To retrieve one specific configuration (represented by _/'module_name':'container'_ ) user needs to pass module-name and container.
+Example:
`
netconf_simulator.py get-config --address localhost --module-name pnf-simulator --container config
`
@@ -231,7 +236,7 @@ Response status: 200
#### Edit-config Action
Modifies existing configuration (e.g. change parameter values, modify or remove parameter from model).
-To edit configuration, netconf compliant XML file should be prepared and used as one of edit-config parameters.
+To edit configuration, netconf compliant XML file should be prepared and used as one of edit-config parameters.
`usage: netconf_simulator.py edit-config [-h] --address ADDRESS --config <XML_CONFIG_FILEPATH> [--verbose]`
example - parameter values modification
@@ -252,46 +257,46 @@ Response status: 202
<itemValue2>2</itemValue2>
<itemValue3>3</itemValue3>
</config>
-```
+```
##### Less Action
-Less action allows user to watch historical configuration changes.
+Less action allows user to watch historical configuration changes.
Size of the configuration changes list is limited to the 100 last cm events by default, but can be incresed/decresead using a 'limit' attribute.
-`usage: netconf_simulator.py less [-h] --address ADDRESS [--limit LIMIT] [--verbose]`
+`usage: netconf_simulator.py less [-h] --address ADDRESS [--limit LIMIT] [--verbose]`
Output from the command can be easily piped into other tools like native less, more, etc. e.g.:
`netconf_simulator.py less --address 127.0.0.1 | less`
-Last known configuration is last printed to the output, so order of the printed configuration events complies with time when the configuration was stored inside the simulator.
+Last known configuration is last printed to the output, so order of the printed configuration events complies with time when the configuration was stored inside the simulator.
Parameters:
`--address ADDRESS` - `IP address of simulator`
-`--limit LIMIT` - ` Number of configurations to print at output`
+`--limit LIMIT` - ` Number of configurations to print at output`
-`--verbose` - ` Displays additional logs`
+`--verbose` - ` Displays additional logs`
Single message is represented as a pair of timestamp in epoch format and suitable configuration entry.
##### Tailf Action
-Tailf action allows user to actively listen for new uploaded configuration changes.
+Tailf action allows user to actively listen for new uploaded configuration changes.
Size of the historical configuration changes list is limited to the 10 last cm events.
-`usage: netconf_simulator.py tailf [-h] --address ADDRESS [--verbose]`
+`usage: netconf_simulator.py tailf [-h] --address ADDRESS [--verbose]`
-The listener can be easily terminated at anytime using `CTRL+C` shortcut.
+The listener can be easily terminated at anytime using `CTRL+C` shortcut.
Parameters:
`--address ADDRESS` - `IP address of simulator`
-`--verbose` - ` Displays additional logs`
+`--verbose` - ` Displays additional logs`
Single message is represented as a pair of timestamp in epoch format and suitable configuration entry.
##### Cm-history Action
-Cm-history action allows user to view list of all uploaded configuration changes.
-`usage: netconf_simulator.py cm-history [-h] --address ADDRESS [--verbose]`
+Cm-history action allows user to view list of all uploaded configuration changes.
+`usage: netconf_simulator.py cm-history [-h] --address ADDRESS [--verbose]`
Last known configuration is last printed to the output, so order of the printed configuration events complies with time when the configuration was stored inside the simulator.
@@ -299,6 +304,6 @@ Parameters:
`--address ADDRESS` - `IP address of simulator`
-`--verbose` - ` Displays additional logs`
+`--verbose` - ` Displays additional logs`
Single message is represented as a pair of timestamp in epoch format and suitable configuration entry.
diff --git a/simulator-cli/requirements.txt b/simulator-cli/requirements.txt
index 4f962de..afa6725 100644
--- a/simulator-cli/requirements.txt
+++ b/simulator-cli/requirements.txt
@@ -21,3 +21,4 @@ requests==2.20.1
websockets==7.0
asynctest
mock
+pytest
diff --git a/simulator-cli/tox.ini b/simulator-cli/tox.ini
new file mode 100644
index 0000000..e6c360f
--- /dev/null
+++ b/simulator-cli/tox.ini
@@ -0,0 +1,10 @@
+[tox]
+envlist = pytest
+skipsdist = true
+
+[testenv]
+basepython = python3
+deps = -rrequirements.txt
+
+[testenv:pytest]
+commands = pytest -v