Skip to content

Commit

Permalink
Merge pull request StackStorm#3932 from StackStorm/changelog_3929
Browse files Browse the repository at this point in the history
Changelog for StackStorm#3929, update st2client code and tests so it works under Python 3, run st2client Python 3 tests on Travis
  • Loading branch information
Kami authored Jan 9, 2018
2 parents 721e49f + 56910cc commit 6df54d7
Show file tree
Hide file tree
Showing 53 changed files with 274 additions and 81 deletions.
23 changes: 14 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
sudo: required
dist: precise
language: python
python:
- 2.7

branches:
only:
Expand All @@ -14,12 +12,18 @@ branches:
env:
global:
- CACHE_NAME=JOB1
matrix:
- TASK=ci-unit NODE_INDEX=0 NODE_TOTAL=2
- TASK=ci-unit NODE_INDEX=1 NODE_TOTAL=2
- TASK=ci-integration
- TASK="ci-checks ci-packs-tests"

matrix:
include:
- env: TASK=ci-unit NODE_INDEX=0 NODE_TOTAL=2
python: 2.7
- env: TASK=ci-unit NODE_INDEX=1 NODE_TOTAL=2
python: 2.7
- env: TASK=ci-integration
python: 2.7
- env: TASK="ci-checks ci-packs-tests"
python: 2.7
- env: TASK=ci-st2client-py3-tests
python: 3.6
addons:
apt:
sources:
Expand All @@ -46,9 +50,10 @@ cache:
pip: true
directories:
- virtualenv/
- .tox/

install:
- make requirements
- if [ ${TASK} = 'ci-st2client-py3-tests' ]; then pip install tox; else make requirements; fi
- if [ ${TASK} = 'ci-unit' ] || [ ${TASK} = 'ci-integration' ]; then pip install codecov; sudo .circle/add-itest-user.sh; fi

script:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Added
* Added flag `--auto-dict` to `st2 run` and `st2 execution re-run` commands. This flag must now
be specified in order to automatically convert list items to dicts based on presence of colon
(`:`) in all of the list items (new feature) #3909
* Update ``st2client`` package which is also utilized by the CLI so it also works under Python 3.

Note: Python 2.7 is only officially supported and tested Python version. Using Python 3 is at
your own risk - they are likely still many bugs related to Python 3 compatibility. You have been warned.
(new feature) #3929 #3932

Contributed by Anthony Shaw.

Changed
~~~~~~~
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,20 @@ ci: ci-checks ci-unit ci-integration ci-mistral ci-packs-tests
.PHONY: ci-checks
ci-checks: compile .generated-files-check .pylint .flake8 .bandit .st2client-dependencies-check .st2common-circular-dependencies-check circle-lint-api-spec .rst-check

.PHONY: ci-st2client-py3-tests
ci-st2client-py3-tests:
@echo
@echo "==================== ci-st2client-py3-tests ===================="
@echo
tox -e py36 -v

.PHONY: st2client-py3-tests
st2client-py3-tests:
@echo
@echo "==================== ci-st2client-py3-tests ===================="
@echo
tox -e py36 -vv

.PHONY: .rst-check
.rst-check:
@echo
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

import os
import pwd
import json
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

import os
import logging

Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import print_function
from __future__ import absolute_import

import abc
import six
import logging
Expand Down
4 changes: 3 additions & 1 deletion st2client/st2client/commands/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

import os
import ast
import copy
Expand All @@ -27,6 +28,8 @@

from os.path import join as pjoin

from six.moves import range

from st2client import models
from st2client.commands import resource
from st2client.commands.resource import ResourceNotFoundError
Expand All @@ -37,7 +40,6 @@
from st2client.utils.date import format_isodate_for_user_timezone
from st2client.utils.date import parse as parse_isotime
from st2client.utils.color import format_status
from six.moves import range

LOG = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/action_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.models import core
from st2client.models.action_alias import ActionAlias
from st2client.models.action_alias import ActionAliasMatch
Expand Down
4 changes: 2 additions & 2 deletions st2client/st2client/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# limitations under the License.

from __future__ import absolute_import

import getpass
import json
import logging
import six.moves.http_client

import requests
from six.moves.configparser import ConfigParser
Expand Down Expand Up @@ -191,7 +191,7 @@ def run_and_print(self, args, **kwargs):
except Exception as e:
response = getattr(e, 'response', None)
status_code = getattr(response, 'status_code', None)
is_unathorized_error = (status_code == six.moves.http_client.UNAUTHORIZED)
is_unathorized_error = (status_code == http_client.UNAUTHORIZED)

if response and is_unathorized_error:
print('Not authenticated')
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/inquiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

import json
import logging

Expand Down
5 changes: 4 additions & 1 deletion st2client/st2client/commands/keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
# limitations under the License.

from __future__ import absolute_import

import os
import json
import logging

from os.path import join as pjoin

import six

from st2client.commands import resource
from st2client.commands.noop import NoopCommand
from st2client.formatters import table
from st2client.models.keyvalue import KeyValuePair
from st2client.utils.date import format_isodate_for_user_timezone
import six

LOG = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

import logging

from st2client import models
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.formatters import table
from st2client.commands import resource
from st2client.models.rbac import Role
Expand Down
8 changes: 5 additions & 3 deletions st2client/st2client/commands/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
# limitations under the License.

from __future__ import absolute_import

import os
import abc
import six
import json
import logging
import six.moves.http_client
from functools import wraps
import traceback

from functools import wraps

import yaml
from six.moves import http_client

from st2client import commands
from st2client.exceptions.operations import OperationFailureException
Expand Down Expand Up @@ -166,7 +168,7 @@ def get_resource_by_pk(self, pk, **kwargs):
# Hack for "Unauthorized" exceptions, we do want to propagate those
response = getattr(e, 'response', None)
status_code = getattr(response, 'status_code', None)
if status_code and status_code == six.moves.http_client.UNAUTHORIZED:
if status_code and status_code == http_client.UNAUTHORIZED:
raise e

instance = None
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client import models
from st2client.commands import resource
from st2client.formatters import table
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/rule_enforcement.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client import models
from st2client.commands import resource
from st2client.formatters import table
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.models import Sensor
from st2client.commands import resource

Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.models import Timer
from st2client.commands import resource

Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.models import Resource, Trace, TriggerInstance, Rule, LiveAction
from st2client.exceptions.operations import OperationFailureException
from st2client.formatters import table
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.commands import resource
from st2client.models import TriggerType
from st2client.formatters import table
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/triggerinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.commands import resource
from st2client.formatters import table
from st2client.models import TriggerInstance
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/commands/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.models import Webhook
from st2client.commands import resource

Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

from __future__ import absolute_import

import os

from collections import defaultdict
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/exceptions/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

from st2client.exceptions.base import StackStormCLIBaseException


Expand Down
2 changes: 2 additions & 0 deletions st2client/st2client/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
# limitations under the License.

from __future__ import absolute_import

import abc
import logging

import six


Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/formatters/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

from __future__ import absolute_import

import json
import logging

Expand Down
13 changes: 10 additions & 3 deletions st2client/st2client/formatters/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# limitations under the License.

from __future__ import absolute_import

import ast
import logging
import sys
import struct

import yaml

Expand All @@ -29,6 +30,8 @@

LOG = logging.getLogger(__name__)

PLATFORM_MAXINT = 2 ** (struct.Struct('i').size * 8 - 1) - 1


class ExecutionResult(formatters.Formatter):

Expand Down Expand Up @@ -59,7 +62,7 @@ def format(cls, entry, *args, **kwargs):
# and likely we will see other issues like storage :P.
formatted_value = yaml.safe_dump({attr: value},
default_flow_style=False,
width=sys.maxint,
width=PLATFORM_MAXINT,
indent=2)[len(attr) + 2:-1]
value = ('\n' if isinstance(value, dict) else '') + formatted_value
value = strutil.dedupe_newlines(value)
Expand All @@ -73,4 +76,8 @@ def format(cls, entry, *args, **kwargs):
output += ('\n' if output else '') + '%s: %s' % \
(DisplayColors.colorize(attr, DisplayColors.BLUE), value)

return strutil.unescape(output).decode('unicode_escape').encode('utf-8')
if six.PY3:
return strutil.unescape(str(output))
else:
# Assume Python 2
return strutil.unescape(str(output)).decode('unicode_escape').encode('utf-8')
Loading

0 comments on commit 6df54d7

Please sign in to comment.