Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8918276
Fix bytes -> str handling in linux.dig action
blag Jul 15, 2020
85c6823
Update changelog
blag Jul 16, 2020
8c0b9ba
Merge branch 'master' into fix-dig-action
blag Jul 20, 2020
8666421
Merge branch 'master' into fix-dig-action
blag Jul 21, 2020
baf2c41
Merge branch 'master' into fix-dig-action
blag Jul 23, 2020
8326fa6
Merge branch 'master' into fix-dig-action
blag Jul 26, 2020
2935c55
Merge branch 'master' into fix-dig-action
blag Aug 3, 2020
efcc939
Merge branch 'fix-dig-action' of https://github.com/StackStorm/st2 in…
blag Aug 4, 2020
681871b
Add initial tests for linux.dig action
blag Aug 4, 2020
39689d5
Merge branch 'master' into fix-dig-action
blag Aug 5, 2020
54454f7
Use "The StackStorm Authors" in copyright
blag Aug 5, 2020
7cfcb80
Merge branch 'master' into fix-dig-action
blag Aug 10, 2020
cbde6c3
Don't use re.search to check for contains substring
blag Aug 10, 2020
cd92fe6
Use list comprehension and extend cmd_args with options
blag Aug 10, 2020
d1f62d9
Merge branch 'fix-dig-action' of https://github.com/StackStorm/st2 in…
blag Aug 10, 2020
5a6c8b1
Test that returned result is a str instance
blag Aug 10, 2020
a93b032
Fix to maintain Python 2 support
blag Aug 10, 2020
9035ea5
Split up tests
blag Aug 10, 2020
eac75cd
Fix happy path test
blag Aug 10, 2020
f1f68ec
Explicitly test empty queryopts string
blag Aug 10, 2020
f430b4e
Fix test assertions
blag Aug 10, 2020
7a1fda4
Update CHANGELOG
blag Aug 11, 2020
dee143c
Merge branch 'master' into fix-dig-action
nmaludy Aug 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Fixed
up correctly, specifically when specifying a bastion host / jump box. (bug fix) #4973

Contributed by Nick Maludy (@nmaludy Encore Technologies)
* Fixed a bytes/string encoding bug in the ``linux.dig`` action so it should work on Python 3
(bug fix) #4993

* Fixed a bug where a python3 sensor using ssl needs to be monkey patched earlier. See also #4832, #4975 and gevent/gevent#1016 (bug fix) #4976

Expand Down
14 changes: 9 additions & 5 deletions contrib/linux/actions/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

import errno
import locale
import subprocess
import random
import re
Expand Down Expand Up @@ -42,12 +43,15 @@ def run(self, rand, count, nameserver, hostname, queryopts):

cmd_args.append(hostname)

# This function might call getpreferred encoding unless we pass
# do_setlocale=False.
encoding = locale.getpreferredencoding(do_setlocale=False)
try:
result_list = filter(None, subprocess.Popen(cmd_args,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
.communicate()[0]
.split('\n'))
result_list = list(filter(None, subprocess.Popen(cmd_args,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
.communicate()[0].decode(encoding)
.split('\n')))

# NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat
# for Python3:
Expand Down
37 changes: 37 additions & 0 deletions contrib/linux/tests/test_action_dig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

# Copyright 2020 The StackStorm Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from st2tests.base import BaseActionTestCase

from dig import DigAction


class DigActionTestCase(BaseActionTestCase):
action_cls = DigAction

def test_run(self):
action = self.get_action_instance()

# Use the defaults from dig.yaml
result = action.run(rand=False, count=0, nameserver=None, hostname='', queryopts='short')
self.assertIsInstance(result, list)
self.assertEqual(len(result), 0)

result = action.run(rand=False, count=0, nameserver=None, hostname='google.com',
queryopts='')
self.assertIsInstance(result, list)
self.assertGreater(len(result), 0)