Move amazon unit tests and apply fixes.

- Update import for relocated tests.
- Fix test to expect changed from update_tags.
- Add checks for boto3 and botocore to tests.
- Set check mode with kwarg.
- Python 3 fixes for unit tests.
- Python 2.6 fix for unit tests.
This commit is contained in:
Matt Clay 2016-10-31 16:44:06 -07:00
parent e56229747a
commit 37271867b1
5 changed files with 36 additions and 14 deletions

View file

View file

@ -1,6 +1,17 @@
#!/usr/bin/python
import boto3
from nose.plugins.skip import SkipTest
try:
import boto3
import botocore
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
if not HAS_BOTO3:
raise SkipTest("test_ec2_vpc_nat_gateway.py requires the python module 'boto3' and 'botocore'")
import unittest
from collections import namedtuple
@ -10,7 +21,7 @@ from ansible.inventory import Inventory
from ansible.playbook.play import Play
from ansible.executor.task_queue_manager import TaskQueueManager
import cloud.amazon.ec2_vpc_nat_gateway as ng
import ansible.modules.extras.cloud.amazon.ec2_vpc_nat_gateway as ng
Options = (
namedtuple(
@ -127,7 +138,7 @@ class AnsibleVpcNatGatewayTasks(unittest.TestCase):
play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
tqm, results = run(play)
self.failUnless(tqm._stats.ok['localhost'] == 2)
self.assertFalse(tqm._stats.changed.has_key('localhost'))
self.assertFalse('localhost' in tqm._stats.changed)
def test_create_gateway_using_eip_address(self):
play_source = dict(
@ -193,7 +204,7 @@ class AnsibleVpcNatGatewayTasks(unittest.TestCase):
play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
tqm, results = run(play)
self.failUnless(tqm._stats.ok['localhost'] == 2)
self.assertFalse(tqm._stats.changed.has_key('localhost'))
self.assertFalse('localhost' in tqm._stats.changed)
def test_create_gateway_in_subnet_only_if_one_does_not_exist_already(self):
play_source = dict(
@ -226,7 +237,7 @@ class AnsibleVpcNatGatewayTasks(unittest.TestCase):
play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
tqm, results = run(play)
self.failUnless(tqm._stats.ok['localhost'] == 2)
self.assertFalse(tqm._stats.changed.has_key('localhost'))
self.assertFalse('localhost' in tqm._stats.changed)
def test_delete_gateway(self):
play_source = dict(
@ -259,21 +270,21 @@ class AnsibleVpcNatGatewayTasks(unittest.TestCase):
play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
tqm, results = run(play)
self.failUnless(tqm._stats.ok['localhost'] == 2)
self.assertTrue(tqm._stats.changed.has_key('localhost'))
self.assertTrue('localhost' in tqm._stats.changed)
class AnsibleEc2VpcNatGatewayFunctions(unittest.TestCase):
def test_convert_to_lower(self):
example = ng.DRY_RUN_GATEWAY_UNCONVERTED
converted_example = ng.convert_to_lower(example[0])
keys = converted_example.keys()
keys = list(converted_example.keys())
keys.sort()
for i in range(len(keys)):
if i == 0:
self.assertEqual(keys[i], 'create_time')
if i == 1:
self.assertEqual(keys[i], 'nat_gateway_addresses')
gw_addresses_keys = converted_example[keys[i]][0].keys()
gw_addresses_keys = list(converted_example[keys[i]][0].keys())
gw_addresses_keys.sort()
for j in range(len(gw_addresses_keys)):
if j == 0:
@ -379,7 +390,7 @@ class AnsibleEc2VpcNatGatewayFunctions(unittest.TestCase):
)
)
self.assertEqual(err_msg, 'EIP 52.52.52.52 does not exist')
self.assertIsNone(allocation_id)
self.assertTrue(allocation_id is None)
def test_allocate_eip_address(self):
client = boto3.client('ec2', region_name=aws_region)

View file

@ -1,9 +1,20 @@
#!/usr/bin/python
import boto3
from nose.plugins.skip import SkipTest
try:
import boto3
import botocore
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
if not HAS_BOTO3:
raise SkipTest("test_kinesis_stream.py requires the python module 'boto3' and 'botocore'")
import unittest
import cloud.amazon.kinesis_stream as kinesis_stream
import ansible.modules.extras.cloud.amazon.kinesis_stream as kinesis_stream
aws_region = 'us-west-2'
@ -19,7 +30,7 @@ class AnsibleKinesisStreamFunctions(unittest.TestCase):
'StreamStatus': 'ACTIVE'
}
converted_example = kinesis_stream.convert_to_lower(example)
keys = converted_example.keys()
keys = list(converted_example.keys())
keys.sort()
for i in range(len(keys)):
if i == 0:
@ -81,7 +92,7 @@ class AnsibleKinesisStreamFunctions(unittest.TestCase):
def test_get_tags(self):
client = boto3.client('kinesis', region_name=aws_region)
success, err_msg, tags = kinesis_stream.get_tags(client, 'test', True)
success, err_msg, tags = kinesis_stream.get_tags(client, 'test', check_mode=True)
self.assertTrue(success)
should_return = [
{
@ -168,7 +179,7 @@ class AnsibleKinesisStreamFunctions(unittest.TestCase):
'env': 'development',
'service': 'web'
}
success, err_msg = (
success, changed, err_msg = (
kinesis_stream.update_tags(
client, 'test', tags, check_mode=True
)