mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #54240 from Ch3LL/get_image_ec2
Fix TypeError python3 in get_image_id ec2 cloud
This commit is contained in:
commit
ba81ca3e3f
3 changed files with 30 additions and 4 deletions
|
@ -77,6 +77,7 @@ To use the EC2 cloud module, set up the cloud configuration at
|
|||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
from functools import cmp_to_key
|
||||
import os
|
||||
import sys
|
||||
import stat
|
||||
|
@ -1226,7 +1227,7 @@ def get_imageid(vm_):
|
|||
_t = lambda x: datetime.datetime.strptime(x['creationDate'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||
image_id = sorted(aws.query(params, location=get_location(),
|
||||
provider=get_provider(), opts=__opts__, sigver='4'),
|
||||
lambda i, j: salt.utils.compat.cmp(_t(i), _t(j))
|
||||
key=cmp_to_key(lambda i, j: salt.utils.compat.cmp(_t(i), _t(j)))
|
||||
)[-1]['imageId']
|
||||
get_imageid.images[image] = image_id
|
||||
return image_id
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
ec2-test:
|
||||
provider: ec2-config
|
||||
image: ami-3ecc8f46
|
||||
image: ''
|
||||
size: c5.large
|
||||
sh_username: centos
|
||||
script_args: '-P'
|
||||
|
@ -8,7 +8,7 @@ ec2-test:
|
|||
ec2-win2012r2-test:
|
||||
provider: ec2-config
|
||||
size: c5.large
|
||||
image: ami-004d6bbd25fdba500
|
||||
image: ''
|
||||
smb_port: 445
|
||||
win_installer: ''
|
||||
win_username: Administrator
|
||||
|
@ -22,7 +22,7 @@ ec2-win2012r2-test:
|
|||
ec2-win2016-test:
|
||||
provider: ec2-config
|
||||
size: c5.large
|
||||
image: ami-013c9f19b48ddfd08
|
||||
image: ''
|
||||
smb_port: 445
|
||||
win_installer: ''
|
||||
win_username: Administrator
|
||||
|
|
|
@ -87,3 +87,28 @@ class EC2TestCase(TestCase, LoaderModuleMockMixin):
|
|||
)
|
||||
assert ret['passwordData'] == PASS_DATA
|
||||
assert ret['password'] == 'testp4ss!'
|
||||
|
||||
@patch('salt.cloud.clouds.ec2.config.get_cloud_config_value')
|
||||
@patch('salt.cloud.clouds.ec2.get_location')
|
||||
@patch('salt.cloud.clouds.ec2.get_provider')
|
||||
@patch('salt.cloud.clouds.ec2.aws.query')
|
||||
def test_get_imageid(self, aws_query, get_provider, get_location, config):
|
||||
'''
|
||||
test querying imageid function
|
||||
'''
|
||||
vm = {}
|
||||
ami = 'ami-1234'
|
||||
config.return_value = 'test/*'
|
||||
get_location.return_value = 'us-west2'
|
||||
get_provider.return_value = 'ec2'
|
||||
aws_query.return_value = [{'imageId': ami}]
|
||||
|
||||
# test image filter
|
||||
self.assertEqual(ec2.get_imageid(vm), ami)
|
||||
|
||||
# test ami-image
|
||||
config.return_value = ami
|
||||
self.assertEqual(ec2.get_imageid(vm), ami)
|
||||
|
||||
# we should have only ran aws.query once when testing the aws filter
|
||||
aws_query.assert_called_once()
|
||||
|
|
Loading…
Add table
Reference in a new issue