st2-run-pack-tests not setting environment variables for ST2 API
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6.5k
- Forks
- 787
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to write some tests for the msexchange pack and hitting some issues with the BaseActionTestCase because the pack uses the st2 client to read and write cache entries...
from collections import namedtuple
import os
from st2common.runners.base_action import Action
from st2client.client import Client
from st2client.models import KeyValuePair
from exchangelib import Account, Credentials, Configuration, DELEGATE, EWSTimeZone
CacheEntry = namedtuple('CacheEntry', 'ews_url ews_auth_type primary_smtp_address')
class BaseExchangeAction(Action):
def __init__(self, config):
super(BaseExchangeAction, self).__init__(config)
api_url = os.environ.get('ST2_ACTION_API_URL', None)
token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
self.client = Client(api_url=api_url, token=token)
On both CircleCI for the pack and when I test using the Vagrant image, because the ST2_ACTION_AUTH_TOKEN is not set on the runner. What is the correct way to get around this?
======================================================================
5) ERROR: test_run_get_test_folder (search_items_test_case.SearchItemsActionTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
tests/search_items_test_case.py line 9 in test_run_get_test_folder
result = self.get_action_instance(config=self._test_config).run(
/opt/stackstorm/st2/lib/python3.6/site-packages/st2tests/actions.py line 48 in get_action_instance
action_service=self.action_service)
/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/runners/utils.py line 143 in get_action_class_instance
action_instance = action_cls(**kwargs)
actions/base/action.py line 27 in __init__
cache = self._get_cache()
actions/base/action.py line 70 in _get_cache
name='exchange_ews_url')
/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py line 42 in decorate
return func(*args, **kwargs)
/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py line 294 in get_by_name
instances = self.query(name=name, **kwargs)
/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py line 42 in decorate
return func(*args, **kwargs)
/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py line 281 in query
instances, _ = self._query_details(**kwargs)
/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py line 274 in _query_details
self.handle_error(response)
/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py line 168 in handle_error
response.raise_for_status()
/opt/stackstorm/st2/lib/python3.6/site-packages/requests/models.py line 941 in raise_for_status
raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized
MESSAGE: Unauthorized - One of Token or API key required. for url: http://127.0.0.1:9101/v1/keys/?name=exchange_ews_url
-------------------- >> begin captured logging << --------------------
st2.st2common.runners.utils: DEBUG: Action class (ABCMeta) constructor doesn't take "action_service" argument, falling back to late assignment...
urllib3.connectionpool: DEBUG: Starting new HTTP connection (1): 127.0.0.1:9101
urllib3.connectionpool: DEBUG: http://127.0.0.1:9101 "GET /v1/keys/?name=exchange_ews_url HTTP/1.1" 401 73
--------------------- >> end captured logging << ---------------------
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pack test runner and the setup used by tests/search_items_test_case.py, then trace how actions/base/action.py obtains ST2_ACTION_API_URL and ST2_ACTION_AUTH_TOKEN. Reproduce the 401 against the keys API and determine how st2-run-pack-tests should provide authentication. Done means the msexchange pack tests can access cache entries without the unauthorized error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100