Testing
Follow the installation steps above to have the application ready, then add these steps for developing code.
Making Your System an SNMP Server
Switchmap uses SNMP to gather data from network devices. As a developer it may be difficult to get access to test equipment. This section outlines how to run SNMP on your local machine as an SNMP server.
- When the server is running and correctly configured, it will provide data about its interfaces via SNMP.
- You'll need to use an SNMP client to extract the data from the server.
Here are some links to get you started:
- Windows 11:
- SNMP Server:
- Setting up the Server: Enable SNMP on Windows
- SNMP Client:
- Software: Net-SNMP Download
- Tutorial: SNMP Walk Examples for Windows
- SNMP Server:
- Ubuntu:
- This page includes both server and client setup.
- Testing configuration example for the
/etc/snmp/snmpd.conf
file.- Add this sample SNMPv2 configuration in the
/etc/snmp/snmpd.conf
file adding the community stringswitchmap
with the ability to scan the entire SNMP tree.view switchmap-view included .1
rocommunity switchmap default -V switchmap-view
rocommunity6 switchmap default -V switchmap-view - Restart the
snmpd
daemon.$ systemctl restart snmpd
- Test by running this command.
$ snmpwalk -v2c -c switchmap localhost .1.3.6.1.2.1.2
- You can get more useful information by commenting out the
mibs:
line in the/etc/snmp/snmp.conf
file. The output of the previous command will be more complete.# Contents of file etc/snmp/snmp.conf
#mibs : - Run the command again.
$ snmpwalk -v2c -c switchmap localhost .1.3.6.1.2.1.2
- Add these configuration parameters to the
etc/config.yaml
filezones:
- zone: TEST
hostnames:
- localhost
snmp_groups:
- group_name: Localhost-Test
snmp_version: 2
snmp_secname:
snmp_community: switchmap
snmp_port: 161
snmp_authprotocol:
snmp_authpassword:
snmp_privprotocol:
snmp_privpassword:
enabled: True - This testing command for the new
localhost
entry will show results.sudo venv/bin/python3 bin/tools/switchmap_poller_test.py --hostname localhost
- Add this sample SNMPv2 configuration in the
SwitchMap-NG Setup for Developers
Follow the installation steps above to have the application ready, then add these steps for developing code.
Database Configuration
Create the switchmap_unittest
database, and grant privileges to a
switchmap_unittest
user with the password switchmap_unittest
.
$ sudo mysql
CREATE DATABASE switchmap_unittest;
GRANT ALL PRIVILEGES ON switchmap_unittest.* TO 'switchmap_unittest'@'localhost' IDENTIFIED BY 'switchmap_unittest';
FLUSH PRIVILEGES;
EXIT;
Setup the Test Config File
Create the testing configuration file which will be stored in a hidden
directory in $HOME
(venv) $ tests/bin/test_db_config_setup.py
Accessing the Web UI Dashboard
The steps for this are simple:
- Ensure that the poller, ingester, server and dashboard services are all running.
- Visit the Web UI's Dashboard URL. The URL to access will be:
http://localhost:7001/switchmap/
You can now access the various device screens.
API Interactive GraphQL Interaction
This is useful for:
- Developing queries for API clients.
- Troubleshooting your code.
- Creating new features.
On the API server you'll be able to make GraphQL queries in an easy to use interactive web page.
- Enter your query in the left hand panel
- Press the
Play
button - Observe the results
Interactive GraphQL URL
The steps for this are simple:
- Ensure that the poller, ingester, server and dashboard services are all running
- Visit the API's GraphQL URL. The URL to access will be:
http://localhost:7000/switchmap/api/igraphql
You can now do your queries.
Interactive GraphQL Screenshot
Here is a sample of what to you can do with interactive queries.
Important File Locations
These locations are important for developers:
Module Library Layout
Modules are arranged like this:
- The API modules are located in
switchmap/server
- The Poller modules are located in
switchmap/poller
- The Web UI modules are located in
switchmap/dashboard
- Modules that are shared with all three are located in
switchmap/core
Database and GraphQL
Reviewing these files will be important.
- The Database SQLAlchemy ORM definitions can be found in the
switchmap/server/db/models.py
file. - The GraphQL schema are located in the
switchmap/server/db/schema.py
file. - The GraphQL schema attributes are located in the
switchmap/server/db/attributes.py
file.
Run the Test Suite
NOTE: The test cases are written to be run only from the root directory of the repository this to ensure no errors in importing both the required test and code modules.
You can run all the tests with this command.
(venv) $ cd /path/to/switchmap
(venv) $ pytest tests/switchmap_
You can run individual tests with this command.
```bash
(venv) $ cd /path/to/switchmap
(venv) $ pytest tests/switchmap_/path/to/test.py
Populating the Database Using the Ingester
Pollers post network data to the Switchmap-NG server. The Ingester process reads this posted data and uses it to update the database.
You may not have access to network devices for testing, however there is test data data that can be imported using the ingester.
An easy way to populate the database using this data is to:
- Configure switchmap
- Copy the test files in
tests/testdata_
to the configurecache_directory
- Start or restart the poller daemon or app
- The updated data should now be visible in the web UI
Running Tests with Coverage Report
To run the test suite and generate a coverage report, use this command:
(venv) $ cd /path/to/switchmap
(venv) $ pytest --cov=switchmap --cov-report=lcov:coverage/coverage.lcov --cov-report=term-missing tests/switchmap_