tradel / vault-load-testing

Automated load tests for Vault and Consul using the locust.io Python framework
52 stars 21 forks source link

TypeError: 'NoneType' object is not subscriptable #1

Closed toddmichael closed 5 years ago

toddmichael commented 6 years ago

Hello, appreciate this project. Unfortunately, I'm struggling to get it to work.

Environment

Prepare

Prepare works as expected

$ TOKEN=$(cat ~/.vault-token) ./prepare.py --secrets=10
Creating test keys in Vault  [####################################]  100%

and testdata.json looks right:

$ cat testdata.json | jq .
{
  "token": "52480efd-bb44-cf48-d15f-acc20ad91239",
  "num_secrets": 10,
  "secret_size": 1024,
  "transit_size": 1048576,
  "keys": [
    "ab/ab7a03b44ec5d6cac11bcf9feb8ae5b7",
    "2a/2cc2512ad0a8eb05bcdbaaae1ba0f9cc",
    "5d/cbb7336f9a428ab7fdf5dfe008653622",
    "df/ac09d3d0dd3af20a83be99eaec1b3ec6",
    "a9/08c1ee02db4eeda9d8e9b47aa09112ca",
    "8a/be76eff7bfa3c82c73eee8bcb99f7d44",
    "bb/aac1befa0396c3dabff1b7190513da41",
    "ac/5c84521206bebeb9b7d826edd6baccdf",
    "3b/db34ecefcac9b84c3f0beb04a84a1e0f",
    "0c/215acd6f8f277beaa3620b6a246ced24"
  ]
}

Locust Run

Unfortunately when I run locust I get this:

$ locust -H http://localhost:8200 -c 1 -r 1 --no-web
[2018-08-21 14:02:26,106] stompy.local/INFO/locust.main: Starting Locust 0.8.1
[2018-08-21 14:02:26,107] stompy.local/INFO/locust.runners: Hatching and swarming 1 clients at the rate 1 clients/s...
 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                              0     0(0.00%)                                       0.00

[2018-08-21 14:02:26,116] stompy.local/ERROR/stderr: Traceback (most recent call last):
  File "/Users/tmichael/.pyenv/versions/3.6.6/lib/python3.6/site-packages/locust/core.py", line 271, in run
    self.execute_next_task()
  File "/Users/tmichael/.pyenv/versions/3.6.6/lib/python3.6/site-packages/locust/core.py", line 297, in execute_next_task
    self.execute_task(task["callable"], *task["args"], **task["kwargs"])
  File "/Users/tmichael/.pyenv/versions/3.6.6/lib/python3.6/site-packages/locust/core.py", line 309, in execute_task
    task(self, *args, **kwargs)
  File "/Users/tmichael/Documents/orgs/strata/vault/vault-load-testing/locusts/transit.py", line 23, in encrypt_block
    data = common.random_data(self.locust.testdata['transit_size'])
TypeError: 'NoneType' object is not subscriptable
...

Inspecting self.locust.testdata from within the function shows:

[2018-08-21 14:15:45,078] stompy.local/INFO/stdout: testdata type is None:

What am I missing? Thanks.

joemiller commented 6 years ago

Running into this as well. I have no idea how to Locust though. I was able to get a bit further along by calling the setup method to load the testdata.json. I'm not sure how this is supposed to be properly handled.

--- a/locusts/__init__.py      2018-08-22 18:23:25.000000000 -0700
+++ b/locusts/__init__.py        2018-08-22 18:13:02.000000000 -0700
@@ -13,6 +13,7 @@
     def __init__(self):
         super().__init__()
         self.client = VaultSession(base_url=self.host)
+        self.setup()

     def setup(self):
         with open('testdata.json', 'r') as f:
ankitforcode commented 6 years ago

https://github.com/hashicorp/vault-load-testing/pull/3

tradel commented 5 years ago

Thanks for reporting the issue. It looks like support for the setup and teardown methods didn't make it into Locust until version 0.9.0. I was building Locust from source, that's why it worked for me.

Upgrade Locust with pip install --upgrade Locust==0.9.0 and it should work. I will update the requirements.txt too.