Fix linter errors

This commit is contained in:
Daniel A. Wozniak 2018-06-06 09:39:53 -07:00
parent 6c8daa2b85
commit 23ab2727be
No known key found for this signature in database
GPG Key ID: 166B9D2C06C82D61
2 changed files with 14 additions and 10 deletions

View File

@ -4762,7 +4762,7 @@ def get_password_data(
rsa_key = kwargs['key']
pwdata = base64.b64decode(pwdata)
if HAS_M2:
key = RSA.load_key_string(rsa_key.encode())
key = RSA.load_key_string(rsa_key.encode('ascii'))
password = key.private_decrypt(pwdata, RSA.pkcs1_padding)
else:
dsize = Crypto.Hash.SHA.digest_size

View File

@ -8,14 +8,15 @@ import tempfile
# Import Salt Libs
from salt.cloud.clouds import ec2
from salt.exceptions import SaltCloudSystemExit
import salt.utils.files
# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, PropertyMock
from tests.support.paths import TMP
from tests.unit.test_crypt import PRIVKEY_DATA
import mock
PASS_DATA = (
b'qOjCKDlBdcNEbJ/J8eRl7sH+bYIIm4cvHHY86gh2NEUnufFlFo0gGVTZR05Fj0cw3n/w7gR'
@ -27,19 +28,24 @@ PASS_DATA = (
@skipIf(NO_MOCK, NO_MOCK_REASON)
class EC2TestCase(TestCase):
class EC2TestCase(TestCase, LoaderModuleMockMixin):
'''
Unit TestCase for salt.cloud.clouds.ec2 module.
'''
def setUp(self):
super(EC2TestCase, self).setUp()
with tempfile.NamedTemporaryFile(dir=TMP, suffix='.pem', delete=True) as fp:
self.key_file = fp.name
def tearDown(self):
super(EC2TestCase, self).tearDown()
if os.path.exists(self.key_file):
os.remove(self.key_file)
def setup_loader_modules(self):
return {ec2: {'__opts__': {}}}
def test__validate_key_path_and_mode(self):
# Key file exists
@ -61,10 +67,10 @@ class EC2TestCase(TestCase):
self.assertRaises(
SaltCloudSystemExit, ec2._validate_key_path_and_mode, 'key_file')
@mock.patch('salt.cloud.clouds.ec2._get_node')
@mock.patch('salt.cloud.clouds.ec2.get_location')
@mock.patch('salt.cloud.clouds.ec2.get_provider')
@mock.patch('salt.utils.aws.query')
@patch('salt.cloud.clouds.ec2._get_node')
@patch('salt.cloud.clouds.ec2.get_location')
@patch('salt.cloud.clouds.ec2.get_provider')
@patch('salt.utils.aws.query')
def test_get_password_data(self, query, get_provider, get_location, _get_node):
query.return_value = [
{
@ -74,9 +80,7 @@ class EC2TestCase(TestCase):
_get_node.return_value = {'instanceId': 'i-abcdef'}
get_location.return_value = 'us-west2'
get_provider.return_value = 'ec2'
ec2.__opts__ = {}
ec2.__active_provider_name__ = None
with open(self.key_file, 'w') as fp:
with salt.utils.files.fopen(self.key_file, 'w') as fp:
fp.write(PRIVKEY_DATA)
ret = ec2.get_password_data(
name='i-abcddef', kwargs={'key_file': self.key_file}, call='action'