|
| 1 | + |
| 2 | +# Run Addon tests in local environment |
| 3 | + |
| 4 | +## With Docker |
| 5 | + |
| 6 | +### Prerequisitory: |
| 7 | +- Git |
| 8 | +- Python3 (>=3.7) |
| 9 | +- Python2 |
| 10 | +- crudini |
| 11 | +- Docker |
| 12 | +- Docker-compose |
| 13 | + |
| 14 | +### Steps: |
| 15 | + |
| 16 | +1. Clone the repository |
| 17 | +```bash |
| 18 | +git clone [email protected]:splunk/ <repo name >.git |
| 19 | +cd <repo dir> |
| 20 | +git submodule update --init --recursive |
| 21 | +``` |
| 22 | + |
| 23 | +2. Install Requirements and Generate Addon |
| 24 | +```bash |
| 25 | +pip3 install -r requirements_dev.txt |
| 26 | +ucc-gen |
| 27 | + |
| 28 | +# Execute only if TEST_TYPE is modinput_functional or modinput_others |
| 29 | +curl -s https://api.github.com/repos/splunk/splunk-add-on-for-modinput-test/releases/latest | grep "Splunk_TA.*tar.gz" | grep -v search_head | grep -v indexer | grep -v forwarder | cut -d : -f 2,3 | tr -d \" | wget -qi -; tar -xvzf *.tar.gz -C deps/apps/ |
| 30 | +``` |
| 31 | + |
| 32 | +3. Set Variables |
| 33 | +```bash |
| 34 | +export SPLUNK_VERSION=<splunk_version> [i.e. latest, 8.1.0] |
| 35 | +export SPLUNK_APP_ID=$(crudini --get package/default/app.conf id name) [i.e. Splunk_TA_addon-name] |
| 36 | +export SPLUNK_APP_PACKAGE=output/$(ls output/) [i.e. output/Splunk_TA_addon-name] |
| 37 | +export TEST_TYPE=<knowledge|ui|modinput_functional|modinput_others> |
| 38 | +export TEST_SET=tests/$TEST_TYPE [i.e. tests/knowledge] |
| 39 | +export IMAGE_TAG="3.7-browsers" |
| 40 | +export SC4S_VERSION=<sc4s_version> [i.e. latest, 1.51.0] |
| 41 | + |
| 42 | +# If TEST_TYPE is ui also set the following variables |
| 43 | +export TEST_BROWSER=<browser_name> [i.e. chrome, firefox] |
| 44 | +export JOB_NAME=<LocalRun::[addon_name]-[browser]> |
| 45 | +export SAUCE_USERNAME=<sauce_username> |
| 46 | +export SAUCE_PASSWORD=<sauce_password> |
| 47 | +export SAUCE_IDENTIFIER=$SAUCE_IDENTIFIER-$(cat /proc/sys/kernel/random/uuid) |
| 48 | +export UI_TEST_HEADLESS="true" |
| 49 | +``` |
| 50 | +**Note:** If TEST_TYPE is `modinput_functional`, `modinput_others` or `ui`, also set all variables in [test_credentials.env](test_credentials.env) file with appropriate values encoded with base64. |
| 51 | + |
| 52 | +4. Docker Build and test execution: |
| 53 | +```bash |
| 54 | +docker-compose -f docker-compose.yml build |
| 55 | + |
| 56 | +# Execute only if TEST_TYPE is ui |
| 57 | +[ -z $BROWSER ] || [ "$UI_TEST_HEADLESS" = "true" ] || docker-compose -f docker-compose.yml up -d sauceconnect |
| 58 | + |
| 59 | +docker-compose -f docker-compose.yml up -d splunk |
| 60 | +until docker-compose -f docker-compose.yml logs splunk | grep "Ansible playbook complete" ; do sleep 1; done |
| 61 | +docker-compose -f docker-compose.yml up --abort-on-container-exit test |
| 62 | +``` |
| 63 | + |
| 64 | + |
| 65 | +## With External |
| 66 | + |
| 67 | +### Prerequisitory: |
| 68 | +- Git |
| 69 | +- Python3 (>=3.7) |
| 70 | +- Python2 |
| 71 | +- Splunk along with addon installed and HEC token created |
| 72 | +- If Addon support the syslog data ingestion(sc4s) |
| 73 | + - Docker |
| 74 | + - Docker-compose |
| 75 | + |
| 76 | +### Steps: |
| 77 | + |
| 78 | +1. Clone the repository |
| 79 | +```bash |
| 80 | +git clone [email protected]:splunk/ <repo name >.git |
| 81 | +cd <repo dir> |
| 82 | +git submodule update --init --recursive |
| 83 | +``` |
| 84 | + |
| 85 | +2. Install Requirements |
| 86 | +```bash |
| 87 | +pip3 install -r requirements_dev.txt |
| 88 | +``` |
| 89 | + |
| 90 | +3. Set Variables (only if Addon supports sc4s) |
| 91 | + |
| 92 | +**Note:** Stop the existing splunk if it is running. New splunk will up after executing following steps with `Changed@11` splunk password. |
| 93 | +```bash |
| 94 | +export SPLUNK_VERSION=<splunk_version> [i.e. latest, 8.1.0] |
| 95 | +export SPLUNK_APP_ID=<Addon_id> [i.e. Splunk_TA_addon-name] |
| 96 | +export SPLUNK_APP_PACKAGE=<splunk_package> |
| 97 | +export IMAGE_TAG="3.7-browsers" |
| 98 | +export SC4S_VERSION=<sc4s_version> |
| 99 | + |
| 100 | +docker-compose -f docker-compose.yml build |
| 101 | +docker-compose -f docker-compose.yml up -d splunk |
| 102 | +``` |
| 103 | + |
| 104 | +4. Run Tests |
| 105 | + |
| 106 | +- Knowledge |
| 107 | + |
| 108 | +```bash |
| 109 | +pytest -vv --splunk-type=external --splunk-app=<path-to-addon-package> --splunk-data-generator=<path to pytest-splunk-addon-data.conf file> --splunk-host=<hostname> --splunk-port=<splunk-management-port> --splunk-user=<username> --splunk-password=<password> --splunk-hec-token=<splunk_hec_token> --sc4s-host=<sc4s_host> --sc4s-port=<sc4s_port> |
| 110 | +``` |
| 111 | + |
| 112 | +- UI: |
| 113 | + |
| 114 | +1. Set all variables in environment mentioned at [test_credentials.env](test_credentials.env) file with appropriate values encoded with base64. |
| 115 | +2. Download Browser's specific driver |
| 116 | + - For Chrome: download chromedriver |
| 117 | + - For Firefox: download geckodriver |
| 118 | + - For IE: download IEdriverserver |
| 119 | +3. Put the downloaded driver into `test/ui/` directory, make sure that it is within the environment's PATH variable, and that it is executable |
| 120 | +4. For Internet explorer, The steps mentioned at below link must be performed: |
| 121 | +https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration |
| 122 | +5. Execute the test cases: |
| 123 | + ```script |
| 124 | +pytest -vv --browser=<browser> --local --splunk-host=<web_url> --splunk-port=<mgmt_url> --splunk-user=<username> --splunk-password=<password> |
| 125 | + ``` |
| 126 | + |
| 127 | +- Modinput: |
| 128 | + |
| 129 | +Install [splunk-add-on-for-modinput-test](https://github.com/splunk/splunk-add-on-for-modinput-test/releases/latest/) addon in splunk and set all variables in environment mentioned at [test_credentials.env](test_credentials.env) file with appropriate values encoded with base64 or add variables in pytest command mentioned in conftest file. |
| 130 | +```bash |
| 131 | +pytest -vv --username=<splunk_username> --password=<splunk_password> --splunk-url=<splunk_url> --remote |
| 132 | +``` |
0 commit comments