From 40230406fb98c8476499f466c72a3488f0db862b Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 29 Sep 2014 19:32:35 +0300 Subject: [PATCH] Added the ability to disassociate a route table. --- salt/modules/boto_vpc.py | 19 +++++++++++++++++++ tests/unit/modules/boto_vpc_test.py | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/salt/modules/boto_vpc.py b/salt/modules/boto_vpc.py index 35ec97beff..a632fab00c 100644 --- a/salt/modules/boto_vpc.py +++ b/salt/modules/boto_vpc.py @@ -739,6 +739,25 @@ def route_table_exists(route_table_id, region=None, key=None, keyid=None, profil return False +def disassociate_route_table(association_id, region=None, key=None, keyid=None, profile=None): + conn = _get_conn(region, key, keyid, profile) + if not conn: + return False + + try: + if conn.disassociate_route_table(association_id): + log.info('Route table with association id {0} has been disassociated.'.format(association_id)) + + return True + else: + log.warning('Route table with association id {0} has not been disassociated.'.format(association_id)) + + return False + except boto.exception.BotoServerError as e: + log.error(e) + return False + + def _get_conn(region, key, keyid, profile): ''' Get a boto connection to vpc. diff --git a/tests/unit/modules/boto_vpc_test.py b/tests/unit/modules/boto_vpc_test.py index 41ab7646ef..131982f43b 100644 --- a/tests/unit/modules/boto_vpc_test.py +++ b/tests/unit/modules/boto_vpc_test.py @@ -726,7 +726,7 @@ class BotoVpcNetworkACLTestCase(BotoVpcTestCaseBase): @skipIf(_has_required_boto() is False, 'The boto module must be greater than' ' or equal to version {0}' .format(required_boto_version)) -class BotoVpcRoutingTablesTestCase(BotoVpcTestCaseBase): +class BotoVpcRouteTablesTestCase(BotoVpcTestCaseBase): @mock_ec2 @expectedNotImplementedFailure def test_when_creating_a_route_table_succeeds_the_create_route_table_method_returns_true(self): @@ -776,6 +776,19 @@ class BotoVpcRoutingTablesTestCase(BotoVpcTestCaseBase): route_table_existence_result = boto_vpc.route_table_exists('fake', **conn_parameters) self.assertFalse(route_table_existence_result) + + @mock_ec2 + @expectedNotImplementedFailure + def test_when_disassociating_route_table_succeeds_the_disassociate_route_table_method_should_return_true(self): + vpc = self._create_vpc() + subnet = self._create_subnet(vpc.id) + route_table = self._create_route_table(vpc.id) + + association_id = self._associate_route_table(route_table.id, subnet.id) + + dhcp_disassociate_result = boto_vpc.disassociate_route_table(association_id, **conn_parameters) + + self.assertTrue(dhcp_disassociate_result) if __name__ == '__main__':