Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
supunsandeeptha opened this issue Dec 7, 2020 · 6 comments
Open

Comments

@supunsandeeptha
Copy link

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.
@FutureSharks
Copy link
Owner

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

@supunsandeeptha
Copy link
Author

I tried on Ubuntu 18.04

@supunsandeeptha
Copy link
Author

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

@FutureSharks
Copy link
Owner

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

@supunsandeeptha
Copy link
Author

supunsandeeptha commented Dec 10, 2020

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

@FutureSharks
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants