diff --git a/salt/modules/boto_vpc.py b/salt/modules/boto_vpc.py index 71dea66995..4ccaa99f9e 100644 --- a/salt/modules/boto_vpc.py +++ b/salt/modules/boto_vpc.py @@ -691,6 +691,23 @@ def create_route_table(vpc_id, route_table_name=None, tags=None, region=None, ke return False +def delete_route_table(route_table_id, region=None, key=None, keyid=None, profile=None): + conn = _get_conn(region, key, keyid, profile) + if not conn: + return False + + try: + if conn.delete_route_table(route_table_id): + log.info('Route table with id {0} was deleted'.format(route_table_id)) + return True + else: + log.warning('Route table with id {0} was not deleted'.format(route_table_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 a0a0d839ce..6e0247ecc3 100644 --- a/tests/unit/modules/boto_vpc_test.py +++ b/tests/unit/modules/boto_vpc_test.py @@ -124,6 +124,12 @@ class BotoVpcTestCaseBase(TestCase): icmp_code=icmp_code, icmp_type=icmp_type, port_range_from=port_range_from, port_range_to=port_range_to) + def _create_route_table(self, vpc_id): + if not self.conn: + self.conn = boto.vpc.connect_to_region(region) + + return self.conn.create_route_table(vpc_id) + @skipIf(NO_MOCK, NO_MOCK_REASON) @skipIf(HAS_BOTO is False, 'The boto module must be installed.') @@ -707,6 +713,22 @@ class BotoVpcRoutingTablesTestCase(BotoVpcTestCaseBase): self.assertTrue(route_table_creation_result) + @mock_ec2 + @expectedNotImplementedFailure + def test_when_deleting_a_route_table_succeeds_the_delete_route_table_method_returns_true(self): + vpc = self._create_vpc() + route_table = self._create_route_table(vpc.id) + + route_table_deletion_result = boto_vpc.delete_route_table(route_table.id) + + self.assertTrue(route_table_deletion_result) + + @mock_ec2 + @expectedNotImplementedFailure + def test_when_deleting_a_non_existent_route_table_the_delete_route_table_method_returns_false(self): + route_table_deletion_result = boto_vpc.delete_route_table('fake') + + self.assertFalse(route_table_deletion_result) if __name__ == '__main__': from integration import run_tests