2014-07-23 17:23:50 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# import Python Libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2015-04-29 18:01:52 +00:00
|
|
|
|
2015-04-26 09:53:36 +00:00
|
|
|
# Import Salt Testing Libs
|
2017-02-19 22:28:46 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.case import TestCase
|
2014-07-23 17:23:50 +00:00
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.states.boto_secgroup as boto_secgroup
|
2015-04-26 09:53:36 +00:00
|
|
|
from salt.utils.odict import OrderedDict
|
2014-07-23 17:23:50 +00:00
|
|
|
|
|
|
|
|
2017-02-19 22:28:46 +00:00
|
|
|
class Boto_SecgroupTestCase(TestCase, LoaderModuleMockMixin):
|
2014-07-23 17:23:50 +00:00
|
|
|
'''
|
|
|
|
TestCase for salt.states.boto_secgroup module
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {boto_secgroup: {}}
|
2017-02-19 22:28:46 +00:00
|
|
|
|
2014-07-23 17:23:50 +00:00
|
|
|
def test__get_rule_changes_no_rules_no_change(self):
|
|
|
|
'''
|
|
|
|
tests a condition with no rules in present or desired group
|
|
|
|
'''
|
|
|
|
present_rules = []
|
|
|
|
desired_rules = []
|
|
|
|
self.assertEqual(boto_secgroup._get_rule_changes(desired_rules, present_rules), ([], []))
|
|
|
|
|
|
|
|
def test__get_rule_changes_create_rules(self):
|
|
|
|
'''
|
|
|
|
tests a condition where a rule must be created
|
|
|
|
'''
|
|
|
|
present_rules = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 22), ('to_port', 22), ('cidr_ip', '0.0.0.0/0')])]
|
|
|
|
desired_rules = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 22), ('to_port', 22), ('cidr_ip', '0.0.0.0/0')]),
|
|
|
|
OrderedDict([('ip_protocol', 'tcp'), ('from_port', 80), ('to_port', 80), ('cidr_ip', '0.0.0.0/0')])]
|
|
|
|
# can also use: rules_to_create = [rule for rule in desired_rules if rule not in present_rules]
|
|
|
|
rules_to_create = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 80), ('to_port', 80), ('cidr_ip', '0.0.0.0/0')])]
|
|
|
|
self.assertEqual(boto_secgroup._get_rule_changes(desired_rules, present_rules), ([], rules_to_create))
|
|
|
|
|
|
|
|
def test__get_rule_changes_delete_rules(self):
|
|
|
|
'''
|
|
|
|
tests a condition where a rule must be deleted
|
|
|
|
'''
|
|
|
|
present_rules = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 22), ('to_port', 22), ('cidr_ip', '0.0.0.0/0')]),
|
|
|
|
OrderedDict([('ip_protocol', 'tcp'), ('from_port', 80), ('to_port', 80), ('cidr_ip', '0.0.0.0/0')])]
|
|
|
|
desired_rules = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 22), ('to_port', 22), ('cidr_ip', '0.0.0.0/0')])]
|
|
|
|
# can also use: rules_to_delete = [rule for rule in present_rules if rule not in desired_rules]
|
|
|
|
rules_to_delete = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 80), ('to_port', 80), ('cidr_ip', '0.0.0.0/0')])]
|
|
|
|
self.assertEqual(boto_secgroup._get_rule_changes(desired_rules, present_rules), (rules_to_delete, []))
|