invokust icon indicating copy to clipboard operation
invokust copied to clipboard

Locust exception ImportError("cannot import name 'User'",)

Open supunsandeeptha opened this issue 5 years ago • 6 comments

Locust exception ImportError("cannot import name 'User'",) END RequestId: 0fec6b92-8c39-42a7-8c14-16629a464c67

NOTE: when i used the import with HttpUser, it gives the same error. I'm trying to use the invokust with AWS Lambda, but no luck so far, below are the steps that i followed,

  • installing invokust in to the python target folder (sudo pip3 install invokust --target=python-packages)
  • Created the locustfile and lambda_locust(handler).
  • Created a zip with all 3 files (zip -q -r lambda_locust.zip lambda_locust.py princess_locustfile.py python-packages )
  • Created the lambda
  • and invoked from the console.

supunsandeeptha avatar Dec 07 '20 05:12 supunsandeeptha

On what OS did you run sudo pip3 install invokust --target=python-packages?

FutureSharks avatar Dec 07 '20 08:12 FutureSharks

I tried on Ubuntu 18.04

supunsandeeptha avatar Dec 07 '20 21:12 supunsandeeptha

More Information About the Operating System @FutureSharks Virtualization: xen Operating System: Ubuntu 18.04.5 LTS Kernel: Linux 5.4.0-1030-aws Architecture: x86-64

supunsandeeptha avatar Dec 07 '20 23:12 supunsandeeptha

I think you'll have to paste your locust file also.

FutureSharks avatar Dec 08 '20 15:12 FutureSharks

Locust File ` from locust import HttpLocust, TaskSet, task, between from os import environ

class WebsiteUser(HttpLocust): wait_time = between(5.0, 9.0)

@task()
def get_home_page(self):
    """
    Gets /
    """
    self.client.get("/")

`

Lambda_Locust File ` import sys sys.path.insert(0, "python-packages")

import logging import json from invokust.aws_lambda import get_lambda_runtime_info from invokust import LocustLoadTest, create_settings

logging.basicConfig(level=logging.INFO)

def handler(event=None, context=None): try: if event: settings = create_settings(**event) else: settings = create_settings(from_environment=True)

    loadtest = LocustLoadTest(settings)
    loadtest.run()

except Exception as e:
    logging.error("Locust exception {0}".format(repr(e)))

else:
    locust_stats = loadtest.stats()
    lambda_runtime_info = get_lambda_runtime_info(context)
    loadtest_results = locust_stats.copy()
    loadtest_results.update(lambda_runtime_info)
    json_results = json.dumps(loadtest_results)

    logging.info(json_results)
    return json_results

`

Lambda Test Json Object { "locustfile": "princess_locustfile.py", "host": "https://cms.mod.studio/", "num_clients": "30", "hatch_rate": "1", "run_time": "5m" }

The newest Error That I'm getting

image

supunsandeeptha avatar Dec 10 '20 01:12 supunsandeeptha

Your code blocks are all messed up so it's difficult to read what you have written. But it looks like you're not importing User anywhere so the issue title does not make sense?

FutureSharks avatar Dec 10 '20 10:12 FutureSharks