1
0

test_boto_vpc.py 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368
  1. # -*- coding: utf-8 -*-
  2. # TODO: Update skipped tests to expect dictionary results from the execution
  3. # module functions.
  4. # Import Python libs
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import os.path
  7. import random
  8. import string
  9. import sys
  10. # pylint: disable=3rd-party-module-not-gated
  11. import pkg_resources
  12. from pkg_resources import DistributionNotFound
  13. import pytest
  14. # Import Salt libs
  15. import salt.config
  16. import salt.loader
  17. import salt.modules.boto_vpc as boto_vpc
  18. from salt.exceptions import CommandExecutionError, SaltInvocationError
  19. # Import 3rd-party libs
  20. from salt.ext import six
  21. # pylint: disable=import-error
  22. from salt.ext.six.moves import range # pylint: disable=redefined-builtin
  23. from salt.modules.boto_vpc import _maybe_set_name_tag, _maybe_set_tags
  24. from salt.utils.versions import LooseVersion
  25. # Import Salt Testing libs
  26. from tests.support.mixins import LoaderModuleMockMixin
  27. from tests.support.mock import MagicMock, patch
  28. from tests.support.runtests import RUNTIME_VARS
  29. from tests.support.unit import TestCase, skipIf
  30. # pylint: enable=3rd-party-module-not-gated
  31. # pylint: disable=no-name-in-module,unused-import
  32. try:
  33. import boto
  34. boto.ENDPOINTS_PATH = os.path.join(
  35. RUNTIME_VARS.TESTS_DIR, "unit/files/endpoints.json"
  36. )
  37. import boto3
  38. from boto.exception import BotoServerError
  39. HAS_BOTO = True
  40. except ImportError:
  41. HAS_BOTO = False
  42. try:
  43. import moto
  44. from moto import mock_ec2_deprecated
  45. HAS_MOTO = True
  46. except ImportError:
  47. HAS_MOTO = False
  48. def mock_ec2_deprecated(self):
  49. """
  50. if the mock_ec2_deprecated function is not available due to import failure
  51. this replaces the decorated function with stub_function.
  52. Allows boto_vpc unit tests to use the @mock_ec2_deprecated decorator
  53. without a "NameError: name 'mock_ec2_deprecated' is not defined" error.
  54. """
  55. def stub_function(self):
  56. pass
  57. return stub_function
  58. # pylint: enable=import-error,no-name-in-module,unused-import
  59. # the boto_vpc module relies on the connect_to_region() method
  60. # which was added in boto 2.8.0
  61. # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12
  62. required_boto_version = "2.8.0"
  63. required_moto_version = "1.0.0"
  64. region = "us-east-1"
  65. access_key = "GKTADJGHEIQSXMKKRBJ08H"
  66. secret_key = "askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs"
  67. conn_parameters = {
  68. "region": region,
  69. "key": access_key,
  70. "keyid": secret_key,
  71. "profile": {},
  72. }
  73. cidr_block = "10.0.0.0/24"
  74. dhcp_options_parameters = {
  75. "domain_name": "example.com",
  76. "domain_name_servers": ["1.2.3.4"],
  77. "ntp_servers": ["5.6.7.8"],
  78. "netbios_name_servers": ["10.0.0.1"],
  79. "netbios_node_type": 2,
  80. }
  81. network_acl_entry_parameters = ("fake", 100, -1, "allow", cidr_block)
  82. dhcp_options_parameters.update(conn_parameters)
  83. def _has_required_boto():
  84. """
  85. Returns True/False boolean depending on if Boto is installed and correct
  86. version.
  87. """
  88. if not HAS_BOTO:
  89. return False
  90. elif LooseVersion(boto.__version__) < LooseVersion(required_boto_version):
  91. return False
  92. else:
  93. return True
  94. def _get_boto_version():
  95. """
  96. Returns the boto version
  97. """
  98. if not HAS_BOTO:
  99. return False
  100. return LooseVersion(boto.__version__)
  101. def _get_moto_version():
  102. """
  103. Returns the moto version
  104. """
  105. try:
  106. return LooseVersion(six.text_type(moto.__version__))
  107. except AttributeError:
  108. try:
  109. return LooseVersion(pkg_resources.get_distribution("moto").version)
  110. except DistributionNotFound:
  111. return False
  112. def _has_required_moto():
  113. """
  114. Returns True/False boolean depending on if Moto is installed and correct
  115. version.
  116. """
  117. if not HAS_MOTO:
  118. return False
  119. else:
  120. if _get_moto_version() < LooseVersion(required_moto_version):
  121. return False
  122. return True
  123. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  124. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  125. @skipIf(
  126. _has_required_boto() is False,
  127. "The boto module must be greater than"
  128. " or equal to version {}. Installed: {}".format(
  129. required_boto_version, _get_boto_version() if HAS_BOTO else "None"
  130. ),
  131. )
  132. @skipIf(
  133. _has_required_moto() is False,
  134. "The moto version must be >= to version {}. Installed: {}".format(
  135. required_moto_version, _get_moto_version() if HAS_MOTO else "None"
  136. ),
  137. )
  138. class BotoVpcTestCaseBase(TestCase, LoaderModuleMockMixin):
  139. conn3 = None
  140. def setup_loader_modules(self):
  141. self.opts = opts = salt.config.DEFAULT_MINION_OPTS.copy()
  142. utils = salt.loader.utils(
  143. opts, whitelist=["boto", "boto3", "args", "systemd", "path", "platform"]
  144. )
  145. return {boto_vpc: {"__utils__": utils}}
  146. # Set up MagicMock to replace the boto3 session
  147. def setUp(self):
  148. super(BotoVpcTestCaseBase, self).setUp()
  149. boto_vpc.__init__(self.opts)
  150. delattr(self, "opts")
  151. # connections keep getting cached from prior tests, can't find the
  152. # correct context object to clear it. So randomize the cache key, to prevent any
  153. # cache hits
  154. conn_parameters["key"] = "".join(
  155. random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
  156. )
  157. self.patcher = patch("boto3.session.Session")
  158. self.addCleanup(self.patcher.stop)
  159. self.addCleanup(delattr, self, "patcher")
  160. mock_session = self.patcher.start()
  161. session_instance = mock_session.return_value
  162. self.conn3 = MagicMock()
  163. self.addCleanup(delattr, self, "conn3")
  164. session_instance.client.return_value = self.conn3
  165. class BotoVpcTestCaseMixin(object):
  166. conn = None
  167. def _create_vpc(self, name=None, tags=None):
  168. """
  169. Helper function to create a test vpc
  170. """
  171. if not self.conn:
  172. self.conn = boto.vpc.connect_to_region(region)
  173. vpc = self.conn.create_vpc(cidr_block)
  174. _maybe_set_name_tag(name, vpc)
  175. _maybe_set_tags(tags, vpc)
  176. return vpc
  177. def _create_subnet(
  178. self,
  179. vpc_id,
  180. cidr_block="10.0.0.0/25",
  181. name=None,
  182. tags=None,
  183. availability_zone=None,
  184. ):
  185. """
  186. Helper function to create a test subnet
  187. """
  188. if not self.conn:
  189. self.conn = boto.vpc.connect_to_region(region)
  190. subnet = self.conn.create_subnet(
  191. vpc_id, cidr_block, availability_zone=availability_zone
  192. )
  193. _maybe_set_name_tag(name, subnet)
  194. _maybe_set_tags(tags, subnet)
  195. return subnet
  196. def _create_internet_gateway(self, vpc_id, name=None, tags=None):
  197. """
  198. Helper function to create a test internet gateway
  199. """
  200. if not self.conn:
  201. self.conn = boto.vpc.connect_to_region(region)
  202. igw = self.conn.create_internet_gateway()
  203. _maybe_set_name_tag(name, igw)
  204. _maybe_set_tags(tags, igw)
  205. return igw
  206. def _create_customer_gateway(self, vpc_id, name=None, tags=None):
  207. """
  208. Helper function to create a test customer gateway
  209. """
  210. if not self.conn:
  211. self.conn = boto.vpc.connect_to_region(region)
  212. gw = self.conn.create_customer_gateway(vpc_id)
  213. _maybe_set_name_tag(name, gw)
  214. _maybe_set_tags(tags, gw)
  215. return gw
  216. def _create_dhcp_options(
  217. self,
  218. domain_name="example.com",
  219. domain_name_servers=None,
  220. ntp_servers=None,
  221. netbios_name_servers=None,
  222. netbios_node_type=2,
  223. ):
  224. """
  225. Helper function to create test dchp options
  226. """
  227. if not netbios_name_servers:
  228. netbios_name_servers = ["10.0.0.1"]
  229. if not ntp_servers:
  230. ntp_servers = ["5.6.7.8"]
  231. if not domain_name_servers:
  232. domain_name_servers = ["1.2.3.4"]
  233. if not self.conn:
  234. self.conn = boto.vpc.connect_to_region(region)
  235. return self.conn.create_dhcp_options(
  236. domain_name=domain_name,
  237. domain_name_servers=domain_name_servers,
  238. ntp_servers=ntp_servers,
  239. netbios_name_servers=netbios_name_servers,
  240. netbios_node_type=netbios_node_type,
  241. )
  242. def _create_network_acl(self, vpc_id):
  243. """
  244. Helper function to create test network acl
  245. """
  246. if not self.conn:
  247. self.conn = boto.vpc.connect_to_region(region)
  248. return self.conn.create_network_acl(vpc_id)
  249. def _create_network_acl_entry(
  250. self,
  251. network_acl_id,
  252. rule_number,
  253. protocol,
  254. rule_action,
  255. cidr_block,
  256. egress=None,
  257. icmp_code=None,
  258. icmp_type=None,
  259. port_range_from=None,
  260. port_range_to=None,
  261. ):
  262. """
  263. Helper function to create test network acl entry
  264. """
  265. if not self.conn:
  266. self.conn = boto.vpc.connect_to_region(region)
  267. return self.conn.create_network_acl_entry(
  268. network_acl_id,
  269. rule_number,
  270. protocol,
  271. rule_action,
  272. cidr_block,
  273. egress=egress,
  274. icmp_code=icmp_code,
  275. icmp_type=icmp_type,
  276. port_range_from=port_range_from,
  277. port_range_to=port_range_to,
  278. )
  279. def _create_route_table(self, vpc_id, name=None, tags=None):
  280. """
  281. Helper function to create a test route table
  282. """
  283. if not self.conn:
  284. self.conn = boto.vpc.connect_to_region(region)
  285. rtbl = self.conn.create_route_table(vpc_id)
  286. _maybe_set_name_tag(name, rtbl)
  287. _maybe_set_tags(tags, rtbl)
  288. return rtbl
  289. @skipIf(
  290. sys.version_info > (3, 6),
  291. "Disabled for 3.7+ pending https://github.com/spulec/moto/issues/1706.",
  292. )
  293. class BotoVpcTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  294. """
  295. TestCase for salt.modules.boto_vpc module
  296. """
  297. @mock_ec2_deprecated
  298. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  299. def test_that_when_checking_if_a_vpc_exists_by_id_and_a_vpc_exists_the_vpc_exists_method_returns_true(
  300. self,
  301. ):
  302. """
  303. Tests checking vpc existence via id when the vpc already exists
  304. """
  305. vpc = self._create_vpc()
  306. vpc_exists_result = boto_vpc.exists(vpc_id=vpc.id, **conn_parameters)
  307. self.assertTrue(vpc_exists_result["exists"])
  308. @mock_ec2_deprecated
  309. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  310. def test_that_when_checking_if_a_vpc_exists_by_id_and_a_vpc_does_not_exist_the_vpc_exists_method_returns_false(
  311. self,
  312. ):
  313. """
  314. Tests checking vpc existence via id when the vpc does not exist
  315. """
  316. self._create_vpc() # Created to ensure that the filters are applied correctly
  317. vpc_exists_result = boto_vpc.exists(vpc_id="fake", **conn_parameters)
  318. self.assertFalse(vpc_exists_result["exists"])
  319. @mock_ec2_deprecated
  320. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  321. def test_that_when_checking_if_a_vpc_exists_by_name_and_a_vpc_exists_the_vpc_exists_method_returns_true(
  322. self,
  323. ):
  324. """
  325. Tests checking vpc existence via name when vpc exists
  326. """
  327. self._create_vpc(name="test")
  328. vpc_exists_result = boto_vpc.exists(name="test", **conn_parameters)
  329. self.assertTrue(vpc_exists_result["exists"])
  330. @mock_ec2_deprecated
  331. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  332. def test_that_when_checking_if_a_vpc_exists_by_name_and_a_vpc_does_not_exist_the_vpc_exists_method_returns_false(
  333. self,
  334. ):
  335. """
  336. Tests checking vpc existence via name when vpc does not exist
  337. """
  338. self._create_vpc() # Created to ensure that the filters are applied correctly
  339. vpc_exists_result = boto_vpc.exists(name="test", **conn_parameters)
  340. self.assertFalse(vpc_exists_result["exists"])
  341. @mock_ec2_deprecated
  342. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  343. def test_that_when_checking_if_a_vpc_exists_by_tags_and_a_vpc_exists_the_vpc_exists_method_returns_true(
  344. self,
  345. ):
  346. """
  347. Tests checking vpc existence via tag when vpc exists
  348. """
  349. self._create_vpc(tags={"test": "testvalue"})
  350. vpc_exists_result = boto_vpc.exists(
  351. tags={"test": "testvalue"}, **conn_parameters
  352. )
  353. self.assertTrue(vpc_exists_result["exists"])
  354. @mock_ec2_deprecated
  355. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  356. def test_that_when_checking_if_a_vpc_exists_by_tags_and_a_vpc_does_not_exist_the_vpc_exists_method_returns_false(
  357. self,
  358. ):
  359. """
  360. Tests checking vpc existence via tag when vpc does not exist
  361. """
  362. self._create_vpc() # Created to ensure that the filters are applied correctly
  363. vpc_exists_result = boto_vpc.exists(
  364. tags={"test": "testvalue"}, **conn_parameters
  365. )
  366. self.assertFalse(vpc_exists_result["exists"])
  367. @mock_ec2_deprecated
  368. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  369. def test_that_when_checking_if_a_vpc_exists_by_cidr_and_a_vpc_exists_the_vpc_exists_method_returns_true(
  370. self,
  371. ):
  372. """
  373. Tests checking vpc existence via cidr when vpc exists
  374. """
  375. self._create_vpc()
  376. vpc_exists_result = boto_vpc.exists(cidr="10.0.0.0/24", **conn_parameters)
  377. self.assertTrue(vpc_exists_result["exists"])
  378. @mock_ec2_deprecated
  379. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  380. def test_that_when_checking_if_a_vpc_exists_by_cidr_and_a_vpc_does_not_exist_the_vpc_exists_method_returns_false(
  381. self,
  382. ):
  383. """
  384. Tests checking vpc existence via cidr when vpc does not exist
  385. """
  386. self._create_vpc() # Created to ensure that the filters are applied correctly
  387. vpc_exists_result = boto_vpc.exists(cidr="10.10.10.10/24", **conn_parameters)
  388. self.assertFalse(vpc_exists_result["exists"])
  389. @mock_ec2_deprecated
  390. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  391. def test_that_when_checking_if_a_vpc_exists_but_providing_no_filters_the_vpc_exists_method_raises_a_salt_invocation_error(
  392. self,
  393. ):
  394. """
  395. Tests checking vpc existence when no filters are provided
  396. """
  397. with self.assertRaisesRegex(
  398. SaltInvocationError,
  399. "At least one of the following "
  400. "must be provided: vpc_id, vpc_name, "
  401. "cidr or tags.",
  402. ):
  403. boto_vpc.exists(**conn_parameters)
  404. @mock_ec2_deprecated
  405. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  406. def test_get_vpc_id_method_when_filtering_by_name(self):
  407. """
  408. Tests getting vpc id when filtering by name
  409. """
  410. vpc = self._create_vpc(name="test")
  411. get_id_result = boto_vpc.get_id(name="test", **conn_parameters)
  412. self.assertEqual(vpc.id, get_id_result["id"])
  413. @mock_ec2_deprecated
  414. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  415. def test_get_vpc_id_method_when_filtering_by_invalid_name(self):
  416. """
  417. Tests getting vpc id when filtering by invalid name
  418. """
  419. self._create_vpc(name="test")
  420. get_id_result = boto_vpc.get_id(name="test_fake", **conn_parameters)
  421. self.assertEqual(get_id_result["id"], None)
  422. @mock_ec2_deprecated
  423. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  424. def test_get_vpc_id_method_when_filtering_by_cidr(self):
  425. """
  426. Tests getting vpc id when filtering by cidr
  427. """
  428. vpc = self._create_vpc()
  429. get_id_result = boto_vpc.get_id(cidr="10.0.0.0/24", **conn_parameters)
  430. self.assertEqual(vpc.id, get_id_result["id"])
  431. @mock_ec2_deprecated
  432. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  433. def test_get_vpc_id_method_when_filtering_by_invalid_cidr(self):
  434. """
  435. Tests getting vpc id when filtering by invalid cidr
  436. """
  437. self._create_vpc()
  438. get_id_result = boto_vpc.get_id(cidr="10.10.10.10/24", **conn_parameters)
  439. self.assertEqual(get_id_result["id"], None)
  440. @mock_ec2_deprecated
  441. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  442. def test_get_vpc_id_method_when_filtering_by_tags(self):
  443. """
  444. Tests getting vpc id when filtering by tags
  445. """
  446. vpc = self._create_vpc(tags={"test": "testvalue"})
  447. get_id_result = boto_vpc.get_id(tags={"test": "testvalue"}, **conn_parameters)
  448. self.assertEqual(vpc.id, get_id_result["id"])
  449. @mock_ec2_deprecated
  450. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  451. def test_get_vpc_id_method_when_filtering_by_invalid_tags(self):
  452. """
  453. Tests getting vpc id when filtering by invalid tags
  454. """
  455. self._create_vpc(tags={"test": "testvalue"})
  456. get_id_result = boto_vpc.get_id(
  457. tags={"test": "fake-testvalue"}, **conn_parameters
  458. )
  459. self.assertEqual(get_id_result["id"], None)
  460. @mock_ec2_deprecated
  461. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  462. def test_get_vpc_id_method_when_not_providing_filters_raises_a_salt_invocation_error(
  463. self,
  464. ):
  465. """
  466. Tests getting vpc id but providing no filters
  467. """
  468. with self.assertRaisesRegex(
  469. SaltInvocationError,
  470. "At least one of the following must be provided: vpc_id, vpc_name, cidr or tags.",
  471. ):
  472. boto_vpc.get_id(**conn_parameters)
  473. @mock_ec2_deprecated
  474. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  475. def test_get_vpc_id_method_when_more_than_one_vpc_is_matched_raises_a_salt_command_execution_error(
  476. self,
  477. ):
  478. """
  479. Tests getting vpc id but providing no filters
  480. """
  481. vpc1 = self._create_vpc(name="vpc-test1")
  482. vpc2 = self._create_vpc(name="vpc-test2")
  483. with self.assertRaisesRegex(
  484. CommandExecutionError, "Found more than one VPC matching the criteria."
  485. ):
  486. boto_vpc.get_id(cidr="10.0.0.0/24", **conn_parameters)
  487. @mock_ec2_deprecated
  488. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  489. def test_that_when_creating_a_vpc_succeeds_the_create_vpc_method_returns_true(self):
  490. """
  491. tests True VPC created.
  492. """
  493. vpc_creation_result = boto_vpc.create(cidr_block, **conn_parameters)
  494. self.assertTrue(vpc_creation_result)
  495. @mock_ec2_deprecated
  496. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  497. def test_that_when_creating_a_vpc_and_specifying_a_vpc_name_succeeds_the_create_vpc_method_returns_true(
  498. self,
  499. ):
  500. """
  501. tests True VPC created.
  502. """
  503. vpc_creation_result = boto_vpc.create(
  504. cidr_block, vpc_name="test", **conn_parameters
  505. )
  506. self.assertTrue(vpc_creation_result)
  507. @mock_ec2_deprecated
  508. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  509. def test_that_when_creating_a_vpc_and_specifying_tags_succeeds_the_create_vpc_method_returns_true(
  510. self,
  511. ):
  512. """
  513. tests True VPC created.
  514. """
  515. vpc_creation_result = boto_vpc.create(
  516. cidr_block, tags={"test": "value"}, **conn_parameters
  517. )
  518. self.assertTrue(vpc_creation_result)
  519. @mock_ec2_deprecated
  520. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  521. def test_that_when_creating_a_vpc_fails_the_create_vpc_method_returns_false(self):
  522. """
  523. tests False VPC not created.
  524. """
  525. with patch(
  526. "moto.ec2.models.VPCBackend.create_vpc",
  527. side_effect=BotoServerError(400, "Mocked error"),
  528. ):
  529. vpc_creation_result = boto_vpc.create(cidr_block, **conn_parameters)
  530. self.assertFalse(vpc_creation_result["created"])
  531. self.assertTrue("error" in vpc_creation_result)
  532. @mock_ec2_deprecated
  533. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  534. def test_that_when_deleting_an_existing_vpc_the_delete_vpc_method_returns_true(
  535. self,
  536. ):
  537. """
  538. Tests deleting an existing vpc
  539. """
  540. vpc = self._create_vpc()
  541. vpc_deletion_result = boto_vpc.delete(vpc.id, **conn_parameters)
  542. self.assertTrue(vpc_deletion_result)
  543. @mock_ec2_deprecated
  544. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  545. def test_that_when_deleting_a_non_existent_vpc_the_delete_vpc_method_returns_false(
  546. self,
  547. ):
  548. """
  549. Tests deleting a non-existent vpc
  550. """
  551. delete_vpc_result = boto_vpc.delete("1234", **conn_parameters)
  552. self.assertFalse(delete_vpc_result["deleted"])
  553. @mock_ec2_deprecated
  554. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  555. def test_that_when_describing_vpc_by_id_it_returns_the_dict_of_properties_returns_true(
  556. self,
  557. ):
  558. """
  559. Tests describing parameters via vpc id if vpc exist
  560. """
  561. # With moto 0.4.25 through 0.4.30, is_default is set to True.
  562. # 0.4.24 and older and 0.4.31 and newer, is_default is False
  563. if LooseVersion("0.4.25") <= _get_moto_version() < LooseVersion("0.4.31"):
  564. is_default = True
  565. else:
  566. is_default = False
  567. vpc = self._create_vpc(name="test", tags={"test": "testvalue"})
  568. describe_vpc = boto_vpc.describe(vpc_id=vpc.id, **conn_parameters)
  569. vpc_properties = dict(
  570. id=vpc.id,
  571. cidr_block=six.text_type(cidr_block),
  572. is_default=is_default,
  573. state="available",
  574. tags={"Name": "test", "test": "testvalue"},
  575. dhcp_options_id="dopt-7a8b9c2d",
  576. region="us-east-1",
  577. instance_tenancy="default",
  578. )
  579. self.assertEqual(describe_vpc, {"vpc": vpc_properties})
  580. @mock_ec2_deprecated
  581. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  582. def test_that_when_describing_vpc_by_id_it_returns_the_dict_of_properties_returns_false(
  583. self,
  584. ):
  585. """
  586. Tests describing parameters via vpc id if vpc does not exist
  587. """
  588. vpc = self._create_vpc(name="test", tags={"test": "testvalue"})
  589. describe_vpc = boto_vpc.describe(vpc_id="vpc-fake", **conn_parameters)
  590. self.assertFalse(describe_vpc["vpc"])
  591. @mock_ec2_deprecated
  592. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  593. def test_that_when_describing_vpc_by_id_on_connection_error_it_returns_error(self):
  594. """
  595. Tests describing parameters failure
  596. """
  597. vpc = self._create_vpc(name="test", tags={"test": "testvalue"})
  598. with patch(
  599. "moto.ec2.models.VPCBackend.get_all_vpcs",
  600. side_effect=BotoServerError(400, "Mocked error"),
  601. ):
  602. describe_result = boto_vpc.describe(vpc_id=vpc.id, **conn_parameters)
  603. self.assertTrue("error" in describe_result)
  604. @mock_ec2_deprecated
  605. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  606. def test_that_when_describing_vpc_but_providing_no_vpc_id_the_describe_method_raises_a_salt_invocation_error(
  607. self,
  608. ):
  609. """
  610. Tests describing vpc without vpc id
  611. """
  612. with self.assertRaisesRegex(
  613. SaltInvocationError, "A valid vpc id or name needs to be specified."
  614. ):
  615. boto_vpc.describe(vpc_id=None, **conn_parameters)
  616. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  617. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  618. @skipIf(
  619. _has_required_boto() is False,
  620. "The boto module must be greater than"
  621. " or equal to version {}. Installed: {}".format(
  622. required_boto_version, _get_boto_version()
  623. ),
  624. )
  625. @skipIf(
  626. _has_required_moto() is False,
  627. "The moto version must be >= to version {0}".format(required_moto_version),
  628. )
  629. @skipIf(
  630. sys.version_info > (3, 6),
  631. "Disabled for 3.7+ pending https://github.com/spulec/moto/issues/1706.",
  632. )
  633. class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  634. @mock_ec2_deprecated
  635. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  636. def test_get_subnet_association_single_subnet(self):
  637. """
  638. tests that given multiple subnet ids in the same VPC that the VPC ID is
  639. returned. The test is valuable because it uses a string as an argument
  640. to subnets as opposed to a list.
  641. """
  642. vpc = self._create_vpc()
  643. subnet = self._create_subnet(vpc.id)
  644. subnet_association = boto_vpc.get_subnet_association(
  645. subnets=subnet.id, **conn_parameters
  646. )
  647. self.assertEqual(vpc.id, subnet_association["vpc_id"])
  648. @mock_ec2_deprecated
  649. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  650. def test_get_subnet_association_multiple_subnets_same_vpc(self):
  651. """
  652. tests that given multiple subnet ids in the same VPC that the VPC ID is
  653. returned.
  654. """
  655. vpc = self._create_vpc()
  656. subnet_a = self._create_subnet(vpc.id, "10.0.0.0/25")
  657. subnet_b = self._create_subnet(vpc.id, "10.0.0.128/25")
  658. subnet_association = boto_vpc.get_subnet_association(
  659. [subnet_a.id, subnet_b.id], **conn_parameters
  660. )
  661. self.assertEqual(vpc.id, subnet_association["vpc_id"])
  662. @mock_ec2_deprecated
  663. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  664. def test_get_subnet_association_multiple_subnets_different_vpc(self):
  665. """
  666. tests that given multiple subnet ids in different VPCs that False is
  667. returned.
  668. """
  669. vpc_a = self._create_vpc()
  670. vpc_b = self.conn.create_vpc(cidr_block)
  671. subnet_a = self._create_subnet(vpc_a.id, "10.0.0.0/24")
  672. subnet_b = self._create_subnet(vpc_b.id, "10.0.0.0/24")
  673. subnet_association = boto_vpc.get_subnet_association(
  674. [subnet_a.id, subnet_b.id], **conn_parameters
  675. )
  676. self.assertEqual(set(subnet_association["vpc_ids"]), set([vpc_a.id, vpc_b.id]))
  677. @mock_ec2_deprecated
  678. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  679. def test_that_when_creating_a_subnet_succeeds_the_create_subnet_method_returns_true(
  680. self,
  681. ):
  682. """
  683. Tests creating a subnet successfully
  684. """
  685. vpc = self._create_vpc()
  686. subnet_creation_result = boto_vpc.create_subnet(
  687. vpc.id, "10.0.0.0/24", **conn_parameters
  688. )
  689. self.assertTrue(subnet_creation_result["created"])
  690. self.assertTrue("id" in subnet_creation_result)
  691. @mock_ec2_deprecated
  692. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  693. def test_that_when_creating_a_subnet_and_specifying_a_name_succeeds_the_create_subnet_method_returns_true(
  694. self,
  695. ):
  696. """
  697. Tests creating a subnet successfully when specifying a name
  698. """
  699. vpc = self._create_vpc()
  700. subnet_creation_result = boto_vpc.create_subnet(
  701. vpc.id, "10.0.0.0/24", subnet_name="test", **conn_parameters
  702. )
  703. self.assertTrue(subnet_creation_result["created"])
  704. @mock_ec2_deprecated
  705. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  706. def test_that_when_creating_a_subnet_and_specifying_tags_succeeds_the_create_subnet_method_returns_true(
  707. self,
  708. ):
  709. """
  710. Tests creating a subnet successfully when specifying a tag
  711. """
  712. vpc = self._create_vpc()
  713. subnet_creation_result = boto_vpc.create_subnet(
  714. vpc.id, "10.0.0.0/24", tags={"test": "testvalue"}, **conn_parameters
  715. )
  716. self.assertTrue(subnet_creation_result["created"])
  717. @mock_ec2_deprecated
  718. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  719. def test_that_when_creating_a_subnet_fails_the_create_subnet_method_returns_error(
  720. self,
  721. ):
  722. """
  723. Tests creating a subnet failure
  724. """
  725. vpc = self._create_vpc()
  726. with patch(
  727. "moto.ec2.models.SubnetBackend.create_subnet",
  728. side_effect=BotoServerError(400, "Mocked error"),
  729. ):
  730. subnet_creation_result = boto_vpc.create_subnet(
  731. vpc.id, "10.0.0.0/24", **conn_parameters
  732. )
  733. self.assertTrue("error" in subnet_creation_result)
  734. @mock_ec2_deprecated
  735. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  736. def test_that_when_deleting_an_existing_subnet_the_delete_subnet_method_returns_true(
  737. self,
  738. ):
  739. """
  740. Tests deleting an existing subnet
  741. """
  742. vpc = self._create_vpc()
  743. subnet = self._create_subnet(vpc.id)
  744. subnet_deletion_result = boto_vpc.delete_subnet(
  745. subnet_id=subnet.id, **conn_parameters
  746. )
  747. self.assertTrue(subnet_deletion_result["deleted"])
  748. @mock_ec2_deprecated
  749. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  750. def test_that_when_deleting_a_non_existent_subnet_the_delete_vpc_method_returns_false(
  751. self,
  752. ):
  753. """
  754. Tests deleting a subnet that doesn't exist
  755. """
  756. delete_subnet_result = boto_vpc.delete_subnet(
  757. subnet_id="1234", **conn_parameters
  758. )
  759. self.assertTrue("error" in delete_subnet_result)
  760. @mock_ec2_deprecated
  761. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  762. def test_that_when_checking_if_a_subnet_exists_by_id_the_subnet_exists_method_returns_true(
  763. self,
  764. ):
  765. """
  766. Tests checking if a subnet exists when it does exist
  767. """
  768. vpc = self._create_vpc()
  769. subnet = self._create_subnet(vpc.id)
  770. subnet_exists_result = boto_vpc.subnet_exists(
  771. subnet_id=subnet.id, **conn_parameters
  772. )
  773. self.assertTrue(subnet_exists_result["exists"])
  774. @mock_ec2_deprecated
  775. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  776. def test_that_when_a_subnet_does_not_exist_the_subnet_exists_method_returns_false(
  777. self,
  778. ):
  779. """
  780. Tests checking if a subnet exists which doesn't exist
  781. """
  782. subnet_exists_result = boto_vpc.subnet_exists("fake", **conn_parameters)
  783. self.assertFalse(subnet_exists_result["exists"])
  784. @mock_ec2_deprecated
  785. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  786. def test_that_when_checking_if_a_subnet_exists_by_name_the_subnet_exists_method_returns_true(
  787. self,
  788. ):
  789. """
  790. Tests checking subnet existence by name
  791. """
  792. vpc = self._create_vpc()
  793. self._create_subnet(vpc.id, name="test")
  794. subnet_exists_result = boto_vpc.subnet_exists(name="test", **conn_parameters)
  795. self.assertTrue(subnet_exists_result["exists"])
  796. @mock_ec2_deprecated
  797. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  798. def test_that_when_checking_if_a_subnet_exists_by_name_the_subnet_does_not_exist_the_subnet_method_returns_false(
  799. self,
  800. ):
  801. """
  802. Tests checking subnet existence by name when it doesn't exist
  803. """
  804. vpc = self._create_vpc()
  805. self._create_subnet(vpc.id)
  806. subnet_exists_result = boto_vpc.subnet_exists(name="test", **conn_parameters)
  807. self.assertFalse(subnet_exists_result["exists"])
  808. @mock_ec2_deprecated
  809. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  810. def test_that_when_checking_if_a_subnet_exists_by_tags_the_subnet_exists_method_returns_true(
  811. self,
  812. ):
  813. """
  814. Tests checking subnet existence by tag
  815. """
  816. vpc = self._create_vpc()
  817. self._create_subnet(vpc.id, tags={"test": "testvalue"})
  818. subnet_exists_result = boto_vpc.subnet_exists(
  819. tags={"test": "testvalue"}, **conn_parameters
  820. )
  821. self.assertTrue(subnet_exists_result["exists"])
  822. @mock_ec2_deprecated
  823. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  824. def test_that_when_checking_if_a_subnet_exists_by_tags_the_subnet_does_not_exist_the_subnet_method_returns_false(
  825. self,
  826. ):
  827. """
  828. Tests checking subnet existence by tag when subnet doesn't exist
  829. """
  830. vpc = self._create_vpc()
  831. self._create_subnet(vpc.id)
  832. subnet_exists_result = boto_vpc.subnet_exists(
  833. tags={"test": "testvalue"}, **conn_parameters
  834. )
  835. self.assertFalse(subnet_exists_result["exists"])
  836. @mock_ec2_deprecated
  837. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  838. def test_that_when_checking_if_a_subnet_exists_but_providing_no_filters_the_subnet_exists_method_raises_a_salt_invocation_error(
  839. self,
  840. ):
  841. """
  842. Tests checking subnet existence without any filters
  843. """
  844. with self.assertRaisesRegex(
  845. SaltInvocationError,
  846. "At least one of the following must be specified: "
  847. "subnet id, cidr, subnet_name, tags, or zones.",
  848. ):
  849. boto_vpc.subnet_exists(**conn_parameters)
  850. @skipIf(True, "Skip these tests while investigating failures")
  851. @mock_ec2_deprecated
  852. def test_that_describe_subnet_by_id_for_existing_subnet_returns_correct_data(self):
  853. """
  854. Tests describing a subnet by id.
  855. """
  856. vpc = self._create_vpc()
  857. subnet = self._create_subnet(vpc.id)
  858. describe_subnet_results = boto_vpc.describe_subnet(
  859. region=region, key=secret_key, keyid=access_key, subnet_id=subnet.id
  860. )
  861. self.assertEqual(
  862. set(describe_subnet_results["subnet"].keys()),
  863. set(["id", "cidr_block", "availability_zone", "tags"]),
  864. )
  865. @mock_ec2_deprecated
  866. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  867. def test_that_describe_subnet_by_id_for_non_existent_subnet_returns_none(self):
  868. """
  869. Tests describing a non-existent subnet by id.
  870. """
  871. self._create_vpc()
  872. describe_subnet_results = boto_vpc.describe_subnet(
  873. region=region, key=secret_key, keyid=access_key, subnet_id="subnet-a1b2c3"
  874. )
  875. self.assertEqual(describe_subnet_results["subnet"], None)
  876. @skipIf(True, "Skip these tests while investigating failures")
  877. @mock_ec2_deprecated
  878. def test_that_describe_subnet_by_name_for_existing_subnet_returns_correct_data(
  879. self,
  880. ):
  881. """
  882. Tests describing a subnet by name.
  883. """
  884. vpc = self._create_vpc()
  885. self._create_subnet(vpc.id, name="test")
  886. describe_subnet_results = boto_vpc.describe_subnet(
  887. region=region, key=secret_key, keyid=access_key, subnet_name="test"
  888. )
  889. self.assertEqual(
  890. set(describe_subnet_results["subnet"].keys()),
  891. set(["id", "cidr_block", "availability_zone", "tags"]),
  892. )
  893. @mock_ec2_deprecated
  894. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  895. def test_that_describe_subnet_by_name_for_non_existent_subnet_returns_none(self):
  896. """
  897. Tests describing a non-existent subnet by id.
  898. """
  899. self._create_vpc()
  900. describe_subnet_results = boto_vpc.describe_subnet(
  901. region=region, key=secret_key, keyid=access_key, subnet_name="test"
  902. )
  903. self.assertEqual(describe_subnet_results["subnet"], None)
  904. @skipIf(True, "Skip these tests while investigating failures")
  905. @mock_ec2_deprecated
  906. def test_that_describe_subnets_by_id_for_existing_subnet_returns_correct_data(self):
  907. """
  908. Tests describing multiple subnets by id.
  909. """
  910. vpc = self._create_vpc()
  911. subnet1 = self._create_subnet(vpc.id)
  912. subnet2 = self._create_subnet(vpc.id)
  913. describe_subnet_results = boto_vpc.describe_subnets(
  914. region=region,
  915. key=secret_key,
  916. keyid=access_key,
  917. subnet_ids=[subnet1.id, subnet2.id],
  918. )
  919. self.assertEqual(len(describe_subnet_results["subnets"]), 2)
  920. self.assertEqual(
  921. set(describe_subnet_results["subnets"][0].keys()),
  922. set(["id", "cidr_block", "availability_zone", "tags"]),
  923. )
  924. @skipIf(True, "Skip these tests while investigating failures")
  925. @mock_ec2_deprecated
  926. def test_that_describe_subnets_by_name_for_existing_subnets_returns_correct_data(
  927. self,
  928. ):
  929. """
  930. Tests describing multiple subnets by id.
  931. """
  932. vpc = self._create_vpc()
  933. self._create_subnet(vpc.id, name="subnet1")
  934. self._create_subnet(vpc.id, name="subnet2")
  935. describe_subnet_results = boto_vpc.describe_subnets(
  936. region=region,
  937. key=secret_key,
  938. keyid=access_key,
  939. subnet_names=["subnet1", "subnet2"],
  940. )
  941. self.assertEqual(len(describe_subnet_results["subnets"]), 2)
  942. self.assertEqual(
  943. set(describe_subnet_results["subnets"][0].keys()),
  944. set(["id", "cidr_block", "availability_zone", "tags"]),
  945. )
  946. @mock_ec2_deprecated
  947. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  948. def test_create_subnet_passes_availability_zone(self):
  949. """
  950. Tests that the availability_zone kwarg is passed on to _create_resource
  951. """
  952. vpc = self._create_vpc()
  953. self._create_subnet(vpc.id, name="subnet1", availability_zone="us-east-1a")
  954. describe_subnet_results = boto_vpc.describe_subnets(
  955. region=region, key=secret_key, keyid=access_key, subnet_names=["subnet1"]
  956. )
  957. self.assertEqual(
  958. describe_subnet_results["subnets"][0]["availability_zone"], "us-east-1a"
  959. )
  960. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  961. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  962. @skipIf(
  963. _has_required_boto() is False,
  964. "The boto module must be greater than"
  965. " or equal to version {}. Installed: {}".format(
  966. required_boto_version, _get_boto_version()
  967. ),
  968. )
  969. @skipIf(
  970. sys.version_info > (3, 6),
  971. "Disabled for 3.7+ pending https://github.com/spulec/moto/issues/1706.",
  972. )
  973. class BotoVpcInternetGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  974. @mock_ec2_deprecated
  975. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  976. def test_that_when_creating_an_internet_gateway_the_create_internet_gateway_method_returns_true(
  977. self,
  978. ):
  979. """
  980. Tests creating an internet gateway successfully (with no vpc id or name)
  981. """
  982. igw_creation_result = boto_vpc.create_internet_gateway(
  983. region=region, key=secret_key, keyid=access_key
  984. )
  985. self.assertTrue(igw_creation_result.get("created"))
  986. @mock_ec2_deprecated
  987. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  988. def test_that_when_creating_an_internet_gateway_with_non_existent_vpc_the_create_internet_gateway_method_returns_an_error(
  989. self,
  990. ):
  991. """
  992. Tests that creating an internet gateway for a non-existent VPC fails.
  993. """
  994. igw_creation_result = boto_vpc.create_internet_gateway(
  995. region=region, key=secret_key, keyid=access_key, vpc_name="non-existent-vpc"
  996. )
  997. self.assertTrue("error" in igw_creation_result)
  998. @mock_ec2_deprecated
  999. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1000. def test_that_when_creating_an_internet_gateway_with_vpc_name_specified_the_create_internet_gateway_method_returns_true(
  1001. self,
  1002. ):
  1003. """
  1004. Tests creating an internet gateway with vpc name specified.
  1005. """
  1006. self._create_vpc(name="test-vpc")
  1007. igw_creation_result = boto_vpc.create_internet_gateway(
  1008. region=region, key=secret_key, keyid=access_key, vpc_name="test-vpc"
  1009. )
  1010. self.assertTrue(igw_creation_result.get("created"))
  1011. @mock_ec2_deprecated
  1012. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1013. def test_that_when_creating_an_internet_gateway_with_vpc_id_specified_the_create_internet_gateway_method_returns_true(
  1014. self,
  1015. ):
  1016. """
  1017. Tests creating an internet gateway with vpc name specified.
  1018. """
  1019. vpc = self._create_vpc()
  1020. igw_creation_result = boto_vpc.create_internet_gateway(
  1021. region=region, key=secret_key, keyid=access_key, vpc_id=vpc.id
  1022. )
  1023. self.assertTrue(igw_creation_result.get("created"))
  1024. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  1025. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  1026. @skipIf(
  1027. _has_required_boto() is False,
  1028. "The boto module must be greater than"
  1029. " or equal to version {}. Installed: {}".format(
  1030. required_boto_version, _get_boto_version()
  1031. ),
  1032. )
  1033. @skipIf(
  1034. sys.version_info > (3, 6),
  1035. "Disabled for 3.7+ pending https://github.com/spulec/moto/issues/1706.",
  1036. )
  1037. class BotoVpcNatGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  1038. @mock_ec2_deprecated
  1039. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1040. def test_that_when_creating_an_nat_gateway_the_create_nat_gateway_method_returns_true(
  1041. self,
  1042. ):
  1043. """
  1044. Tests creating an nat gateway successfully (with subnet_id specified)
  1045. """
  1046. vpc = self._create_vpc()
  1047. subnet = self._create_subnet(
  1048. vpc.id, name="subnet1", availability_zone="us-east-1a"
  1049. )
  1050. ngw_creation_result = boto_vpc.create_nat_gateway(
  1051. subnet_id=subnet.id, region=region, key=secret_key, keyid=access_key
  1052. )
  1053. self.assertTrue(ngw_creation_result.get("created"))
  1054. @mock_ec2_deprecated
  1055. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1056. def test_that_when_creating_an_nat_gateway_with_non_existent_subnet_the_create_nat_gateway_method_returns_an_error(
  1057. self,
  1058. ):
  1059. """
  1060. Tests that creating an nat gateway for a non-existent subnet fails.
  1061. """
  1062. ngw_creation_result = boto_vpc.create_nat_gateway(
  1063. region=region,
  1064. key=secret_key,
  1065. keyid=access_key,
  1066. subnet_name="non-existent-subnet",
  1067. )
  1068. self.assertTrue("error" in ngw_creation_result)
  1069. @mock_ec2_deprecated
  1070. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1071. def test_that_when_creating_an_nat_gateway_with_subnet_name_specified_the_create_nat_gateway_method_returns_true(
  1072. self,
  1073. ):
  1074. """
  1075. Tests creating an nat gateway with subnet name specified.
  1076. """
  1077. vpc = self._create_vpc()
  1078. subnet = self._create_subnet(
  1079. vpc.id, name="test-subnet", availability_zone="us-east-1a"
  1080. )
  1081. ngw_creation_result = boto_vpc.create_nat_gateway(
  1082. region=region, key=secret_key, keyid=access_key, subnet_name="test-subnet"
  1083. )
  1084. self.assertTrue(ngw_creation_result.get("created"))
  1085. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  1086. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  1087. @skipIf(
  1088. _has_required_boto() is False,
  1089. "The boto module must be greater than"
  1090. " or equal to version {}. Installed: {}".format(
  1091. required_boto_version, _get_boto_version()
  1092. ),
  1093. )
  1094. class BotoVpcCustomerGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  1095. @mock_ec2_deprecated
  1096. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1097. def test_that_when_creating_a_customer_gateway_the_create_customer_gateway_method_returns_true(
  1098. self,
  1099. ):
  1100. """
  1101. Tests creating an internet gateway successfully (with no vpc id or name)
  1102. """
  1103. gw_creation_result = boto_vpc.create_customer_gateway(
  1104. "ipsec.1", "10.1.1.1", None
  1105. )
  1106. self.assertTrue(gw_creation_result.get("created"))
  1107. @mock_ec2_deprecated
  1108. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1109. def test_that_when_checking_if_a_subnet_exists_by_id_the_subnet_exists_method_returns_true(
  1110. self,
  1111. ):
  1112. """
  1113. Tests checking if a subnet exists when it does exist
  1114. """
  1115. gw_creation_result = boto_vpc.create_customer_gateway(
  1116. "ipsec.1", "10.1.1.1", None
  1117. )
  1118. gw_exists_result = boto_vpc.customer_gateway_exists(
  1119. customer_gateway_id=gw_creation_result["id"]
  1120. )
  1121. self.assertTrue(gw_exists_result["exists"])
  1122. @mock_ec2_deprecated
  1123. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1124. def test_that_when_a_subnet_does_not_exist_the_subnet_exists_method_returns_false(
  1125. self,
  1126. ):
  1127. """
  1128. Tests checking if a subnet exists which doesn't exist
  1129. """
  1130. gw_exists_result = boto_vpc.customer_gateway_exists("fake")
  1131. self.assertFalse(gw_exists_result["exists"])
  1132. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  1133. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  1134. @skipIf(
  1135. _has_required_boto() is False,
  1136. "The boto module must be greater than"
  1137. " or equal to version {}. Installed: {}".format(
  1138. required_boto_version, _get_boto_version()
  1139. ),
  1140. )
  1141. @skipIf(
  1142. _has_required_moto() is False,
  1143. "The moto version must be >= to version {0}".format(required_moto_version),
  1144. )
  1145. @skipIf(
  1146. sys.version_info > (3, 6),
  1147. "Disabled for 3.7+ pending https://github.com/spulec/moto/issues/1706.",
  1148. )
  1149. class BotoVpcDHCPOptionsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  1150. @mock_ec2_deprecated
  1151. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1152. def test_that_when_creating_dhcp_options_succeeds_the_create_dhcp_options_method_returns_true(
  1153. self,
  1154. ):
  1155. """
  1156. Tests creating dhcp options successfully
  1157. """
  1158. dhcp_options_creation_result = boto_vpc.create_dhcp_options(
  1159. **dhcp_options_parameters
  1160. )
  1161. self.assertTrue(dhcp_options_creation_result["created"])
  1162. @mock_ec2_deprecated
  1163. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1164. def test_that_when_creating_dhcp_options_and_specifying_a_name_succeeds_the_create_dhcp_options_method_returns_true(
  1165. self,
  1166. ):
  1167. """
  1168. Tests creating dchp options with name successfully
  1169. """
  1170. dhcp_options_creation_result = boto_vpc.create_dhcp_options(
  1171. dhcp_options_name="test", **dhcp_options_parameters
  1172. )
  1173. self.assertTrue(dhcp_options_creation_result["created"])
  1174. @mock_ec2_deprecated
  1175. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1176. def test_that_when_creating_dhcp_options_and_specifying_tags_succeeds_the_create_dhcp_options_method_returns_true(
  1177. self,
  1178. ):
  1179. """
  1180. Tests creating dchp options with tag successfully
  1181. """
  1182. dhcp_options_creation_result = boto_vpc.create_dhcp_options(
  1183. tags={"test": "testvalue"}, **dhcp_options_parameters
  1184. )
  1185. self.assertTrue(dhcp_options_creation_result["created"])
  1186. @mock_ec2_deprecated
  1187. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  1188. def test_that_when_creating_dhcp_options_fails_the_create_dhcp_options_method_returns_error(
  1189. self,
  1190. ):
  1191. """
  1192. Tests creating dhcp options failure
  1193. """
  1194. with patch(
  1195. "moto.ec2.models.DHCPOptionsSetBackend.create_dhcp_options",
  1196. side_effect=BotoServerError(400, "Mocked error"),
  1197. ):
  1198. r = dhcp_options_creation_result = boto_vpc.create_dhcp_options(
  1199. **dhcp_options_parameters
  1200. )
  1201. self.assertTrue("error" in r)
  1202. @mock_ec2_deprecated
  1203. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1204. def test_that_when_associating_an_existing_dhcp_options_set_to_an_existing_vpc_the_associate_dhcp_options_method_returns_true(
  1205. self,
  1206. ):
  1207. """
  1208. Tests associating existing dchp options successfully
  1209. """
  1210. vpc = self._create_vpc()
  1211. dhcp_options = self._create_dhcp_options()
  1212. dhcp_options_association_result = boto_vpc.associate_dhcp_options_to_vpc(
  1213. dhcp_options.id, vpc.id, **conn_parameters
  1214. )
  1215. self.assertTrue(dhcp_options_association_result["associated"])
  1216. @mock_ec2_deprecated
  1217. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1218. def test_that_when_associating_a_non_existent_dhcp_options_set_to_an_existing_vpc_the_associate_dhcp_options_method_returns_error(
  1219. self,
  1220. ):
  1221. """
  1222. Tests associating non-existanct dhcp options successfully
  1223. """
  1224. vpc = self._create_vpc()
  1225. dhcp_options_association_result = boto_vpc.associate_dhcp_options_to_vpc(
  1226. "fake", vpc.id, **conn_parameters
  1227. )
  1228. self.assertTrue("error" in dhcp_options_association_result)
  1229. @mock_ec2_deprecated
  1230. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1231. def test_that_when_associating_an_existing_dhcp_options_set_to_a_non_existent_vpc_the_associate_dhcp_options_method_returns_false(
  1232. self,
  1233. ):
  1234. """
  1235. Tests associating existing dhcp options to non-existence vpc
  1236. """
  1237. dhcp_options = self._create_dhcp_options()
  1238. dhcp_options_association_result = boto_vpc.associate_dhcp_options_to_vpc(
  1239. dhcp_options.id, "fake", **conn_parameters
  1240. )
  1241. self.assertTrue("error" in dhcp_options_association_result)
  1242. @mock_ec2_deprecated
  1243. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1244. def test_that_when_creating_dhcp_options_set_to_an_existing_vpc_succeeds_the_associate_new_dhcp_options_method_returns_true(
  1245. self,
  1246. ):
  1247. """
  1248. Tests creation/association of dchp options to an existing vpc successfully
  1249. """
  1250. vpc = self._create_vpc()
  1251. dhcp_creation_result = boto_vpc.create_dhcp_options(
  1252. vpc_id=vpc.id, **dhcp_options_parameters
  1253. )
  1254. self.assertTrue(dhcp_creation_result["created"])
  1255. @mock_ec2_deprecated
  1256. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  1257. def test_that_when_creating_and_associating_dhcp_options_set_to_an_existing_vpc_fails_creating_the_dhcp_options_the_associate_new_dhcp_options_method_raises_exception(
  1258. self,
  1259. ):
  1260. """
  1261. Tests creation failure during creation/association of dchp options to an existing vpc
  1262. """
  1263. vpc = self._create_vpc()
  1264. with patch(
  1265. "moto.ec2.models.DHCPOptionsSetBackend.create_dhcp_options",
  1266. side_effect=BotoServerError(400, "Mocked error"),
  1267. ):
  1268. r = boto_vpc.associate_new_dhcp_options_to_vpc(
  1269. vpc.id, **dhcp_options_parameters
  1270. )
  1271. self.assertTrue("error" in r)
  1272. @mock_ec2_deprecated
  1273. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  1274. def test_that_when_creating_and_associating_dhcp_options_set_to_an_existing_vpc_fails_associating_the_dhcp_options_the_associate_new_dhcp_options_method_raises_exception(
  1275. self,
  1276. ):
  1277. """
  1278. Tests association failure during creation/association of dchp options to existing vpc
  1279. """
  1280. vpc = self._create_vpc()
  1281. with patch(
  1282. "moto.ec2.models.DHCPOptionsSetBackend.associate_dhcp_options",
  1283. side_effect=BotoServerError(400, "Mocked error"),
  1284. ):
  1285. r = boto_vpc.associate_new_dhcp_options_to_vpc(
  1286. vpc.id, **dhcp_options_parameters
  1287. )
  1288. self.assertTrue("error" in r)
  1289. @mock_ec2_deprecated
  1290. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1291. def test_that_when_creating_dhcp_options_set_to_a_non_existent_vpc_the_dhcp_options_the_associate_new_dhcp_options_method_returns_false(
  1292. self,
  1293. ):
  1294. """
  1295. Tests creation/association of dhcp options to non-existent vpc
  1296. """
  1297. r = boto_vpc.create_dhcp_options(vpc_name="fake", **dhcp_options_parameters)
  1298. self.assertTrue("error" in r)
  1299. @mock_ec2_deprecated
  1300. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1301. def test_that_when_dhcp_options_exists_the_dhcp_options_exists_method_returns_true(
  1302. self,
  1303. ):
  1304. """
  1305. Tests existence of dhcp options successfully
  1306. """
  1307. dhcp_options = self._create_dhcp_options()
  1308. dhcp_options_exists_result = boto_vpc.dhcp_options_exists(
  1309. dhcp_options.id, **conn_parameters
  1310. )
  1311. self.assertTrue(dhcp_options_exists_result["exists"])
  1312. @mock_ec2_deprecated
  1313. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1314. def test_that_when_dhcp_options_do_not_exist_the_dhcp_options_exists_method_returns_false(
  1315. self,
  1316. ):
  1317. """
  1318. Tests existence of dhcp options failure
  1319. """
  1320. r = boto_vpc.dhcp_options_exists("fake", **conn_parameters)
  1321. self.assertFalse(r["exists"])
  1322. @mock_ec2_deprecated
  1323. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  1324. def test_that_when_checking_if_dhcp_options_exists_but_providing_no_filters_the_dhcp_options_exists_method_raises_a_salt_invocation_error(
  1325. self,
  1326. ):
  1327. """
  1328. Tests checking dhcp option existence with no filters
  1329. """
  1330. with self.assertRaisesRegex(
  1331. SaltInvocationError,
  1332. "At least one of the following must be provided: id, name, or tags.",
  1333. ):
  1334. boto_vpc.dhcp_options_exists(**conn_parameters)
  1335. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  1336. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  1337. @skipIf(
  1338. _has_required_boto() is False,
  1339. "The boto module must be greater than"
  1340. " or equal to version {}. Installed: {}".format(
  1341. required_boto_version, _get_boto_version()
  1342. ),
  1343. )
  1344. @skipIf(
  1345. sys.version_info > (3, 6),
  1346. "Disabled for 3.7+ pending https://github.com/spulec/moto/issues/1706.",
  1347. )
  1348. class BotoVpcNetworkACLTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  1349. @mock_ec2_deprecated
  1350. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1351. def test_that_when_creating_network_acl_for_an_existing_vpc_the_create_network_acl_method_returns_true(
  1352. self,
  1353. ):
  1354. """
  1355. Tests creation of network acl with existing vpc
  1356. """
  1357. vpc = self._create_vpc()
  1358. network_acl_creation_result = boto_vpc.create_network_acl(
  1359. vpc.id, **conn_parameters
  1360. )
  1361. self.assertTrue(network_acl_creation_result)
  1362. @mock_ec2_deprecated
  1363. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1364. def test_that_when_creating_network_acl_for_an_existing_vpc_and_specifying_a_name_the_create_network_acl_method_returns_true(
  1365. self,
  1366. ):
  1367. """
  1368. Tests creation of network acl via name with an existing vpc
  1369. """
  1370. vpc = self._create_vpc()
  1371. network_acl_creation_result = boto_vpc.create_network_acl(
  1372. vpc.id, network_acl_name="test", **conn_parameters
  1373. )
  1374. self.assertTrue(network_acl_creation_result)
  1375. @mock_ec2_deprecated
  1376. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1377. def test_that_when_creating_network_acl_for_an_existing_vpc_and_specifying_tags_the_create_network_acl_method_returns_true(
  1378. self,
  1379. ):
  1380. """
  1381. Tests creation of network acl via tags with an existing vpc
  1382. """
  1383. vpc = self._create_vpc()
  1384. network_acl_creation_result = boto_vpc.create_network_acl(
  1385. vpc.id, tags={"test": "testvalue"}, **conn_parameters
  1386. )
  1387. self.assertTrue(network_acl_creation_result)
  1388. @mock_ec2_deprecated
  1389. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1390. def test_that_when_creating_network_acl_for_a_non_existent_vpc_the_create_network_acl_method_returns_an_error(
  1391. self,
  1392. ):
  1393. """
  1394. Tests creation of network acl with a non-existent vpc
  1395. """
  1396. network_acl_creation_result = boto_vpc.create_network_acl(
  1397. "fake", **conn_parameters
  1398. )
  1399. self.assertTrue("error" in network_acl_creation_result)
  1400. @mock_ec2_deprecated
  1401. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1402. def test_that_when_creating_network_acl_fails_the_create_network_acl_method_returns_false(
  1403. self,
  1404. ):
  1405. """
  1406. Tests creation of network acl failure
  1407. """
  1408. vpc = self._create_vpc()
  1409. with patch(
  1410. "moto.ec2.models.NetworkACLBackend.create_network_acl",
  1411. side_effect=BotoServerError(400, "Mocked error"),
  1412. ):
  1413. network_acl_creation_result = boto_vpc.create_network_acl(
  1414. vpc.id, **conn_parameters
  1415. )
  1416. self.assertFalse(network_acl_creation_result)
  1417. @mock_ec2_deprecated
  1418. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1419. def test_that_when_deleting_an_existing_network_acl_the_delete_network_acl_method_returns_true(
  1420. self,
  1421. ):
  1422. """
  1423. Tests deletion of existing network acl successfully
  1424. """
  1425. vpc = self._create_vpc()
  1426. network_acl = self._create_network_acl(vpc.id)
  1427. network_acl_deletion_result = boto_vpc.delete_network_acl(
  1428. network_acl.id, **conn_parameters
  1429. )
  1430. self.assertTrue(network_acl_deletion_result)
  1431. @mock_ec2_deprecated
  1432. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1433. def test_that_when_deleting_a_non_existent_network_acl_the_delete_network_acl_method_returns_an_error(
  1434. self,
  1435. ):
  1436. """
  1437. Tests deleting a non-existent network acl
  1438. """
  1439. network_acl_deletion_result = boto_vpc.delete_network_acl(
  1440. "fake", **conn_parameters
  1441. )
  1442. self.assertTrue("error" in network_acl_deletion_result)
  1443. @mock_ec2_deprecated
  1444. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1445. def test_that_when_a_network_acl_exists_the_network_acl_exists_method_returns_true(
  1446. self,
  1447. ):
  1448. """
  1449. Tests existence of network acl
  1450. """
  1451. vpc = self._create_vpc()
  1452. network_acl = self._create_network_acl(vpc.id)
  1453. network_acl_deletion_result = boto_vpc.network_acl_exists(
  1454. network_acl.id, **conn_parameters
  1455. )
  1456. self.assertTrue(network_acl_deletion_result)
  1457. @mock_ec2_deprecated
  1458. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1459. def test_that_when_a_network_acl_does_not_exist_the_network_acl_exists_method_returns_false(
  1460. self,
  1461. ):
  1462. """
  1463. Tests checking network acl does not exist
  1464. """
  1465. network_acl_deletion_result = boto_vpc.network_acl_exists(
  1466. "fake", **conn_parameters
  1467. )
  1468. self.assertFalse(network_acl_deletion_result["exists"])
  1469. @mock_ec2_deprecated
  1470. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  1471. def test_that_when_checking_if_network_acl_exists_but_providing_no_filters_the_network_acl_exists_method_raises_a_salt_invocation_error(
  1472. self,
  1473. ):
  1474. """
  1475. Tests checking existence of network acl with no filters
  1476. """
  1477. with self.assertRaisesRegex(
  1478. SaltInvocationError,
  1479. "At least one of the following must be provided: id, name, or tags.",
  1480. ):
  1481. boto_vpc.dhcp_options_exists(**conn_parameters)
  1482. @mock_ec2_deprecated
  1483. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1484. def test_that_when_creating_a_network_acl_entry_successfully_the_create_network_acl_entry_method_returns_true(
  1485. self,
  1486. ):
  1487. """
  1488. Tests creating network acl successfully
  1489. """
  1490. vpc = self._create_vpc()
  1491. network_acl = self._create_network_acl(vpc.id)
  1492. network_acl_entry_creation_result = boto_vpc.create_network_acl_entry(
  1493. network_acl.id, *network_acl_entry_parameters, **conn_parameters
  1494. )
  1495. self.assertTrue(network_acl_entry_creation_result)
  1496. @mock_ec2_deprecated
  1497. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1498. def test_that_when_creating_a_network_acl_entry_for_a_non_existent_network_acl_the_create_network_acl_entry_method_returns_false(
  1499. self,
  1500. ):
  1501. """
  1502. Tests creating network acl entry for non-existent network acl
  1503. """
  1504. network_acl_entry_creation_result = boto_vpc.create_network_acl_entry(
  1505. *network_acl_entry_parameters, **conn_parameters
  1506. )
  1507. self.assertFalse(network_acl_entry_creation_result)
  1508. @mock_ec2_deprecated
  1509. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1510. def test_that_when_replacing_a_network_acl_entry_successfully_the_replace_network_acl_entry_method_returns_true(
  1511. self,
  1512. ):
  1513. """
  1514. Tests replacing network acl entry successfully
  1515. """
  1516. vpc = self._create_vpc()
  1517. network_acl = self._create_network_acl(vpc.id)
  1518. self._create_network_acl_entry(network_acl.id, *network_acl_entry_parameters)
  1519. network_acl_entry_creation_result = boto_vpc.replace_network_acl_entry(
  1520. network_acl.id, *network_acl_entry_parameters, **conn_parameters
  1521. )
  1522. self.assertTrue(network_acl_entry_creation_result)
  1523. @mock_ec2_deprecated
  1524. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1525. def test_that_when_replacing_a_network_acl_entry_for_a_non_existent_network_acl_the_replace_network_acl_entry_method_returns_false(
  1526. self,
  1527. ):
  1528. """
  1529. Tests replacing a network acl entry for a non-existent network acl
  1530. """
  1531. network_acl_entry_creation_result = boto_vpc.create_network_acl_entry(
  1532. *network_acl_entry_parameters, **conn_parameters
  1533. )
  1534. self.assertFalse(network_acl_entry_creation_result)
  1535. @mock_ec2_deprecated
  1536. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1537. def test_that_when_deleting_an_existing_network_acl_entry_the_delete_network_acl_entry_method_returns_true(
  1538. self,
  1539. ):
  1540. """
  1541. Tests deleting existing network acl entry successfully
  1542. """
  1543. vpc = self._create_vpc()
  1544. network_acl = self._create_network_acl(vpc.id)
  1545. network_acl_entry = self._create_network_acl_entry(
  1546. network_acl.id, *network_acl_entry_parameters
  1547. )
  1548. network_acl_entry_deletion_result = boto_vpc.delete_network_acl_entry(
  1549. network_acl_entry.id, 100, **conn_parameters
  1550. )
  1551. self.assertTrue(network_acl_entry_deletion_result)
  1552. @mock_ec2_deprecated
  1553. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1554. def test_that_when_deleting_a_non_existent_network_acl_entry_the_delete_network_acl_entry_method_returns_false(
  1555. self,
  1556. ):
  1557. """
  1558. Tests deleting a non-existent network acl entry
  1559. """
  1560. network_acl_entry_deletion_result = boto_vpc.delete_network_acl_entry(
  1561. "fake", 100, **conn_parameters
  1562. )
  1563. self.assertFalse(network_acl_entry_deletion_result)
  1564. @mock_ec2_deprecated
  1565. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1566. def test_that_when_associating_an_existing_network_acl_to_an_existing_subnet_the_associate_network_acl_method_returns_true(
  1567. self,
  1568. ):
  1569. """
  1570. Tests association of existing network acl to existing subnet successfully
  1571. """
  1572. vpc = self._create_vpc()
  1573. network_acl = self._create_network_acl(vpc.id)
  1574. subnet = self._create_subnet(vpc.id)
  1575. network_acl_association_result = boto_vpc.associate_network_acl_to_subnet(
  1576. network_acl.id, subnet.id, **conn_parameters
  1577. )
  1578. self.assertTrue(network_acl_association_result)
  1579. @mock_ec2_deprecated
  1580. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1581. def test_that_when_associating_a_non_existent_network_acl_to_an_existing_subnet_the_associate_network_acl_method_returns_an_error(
  1582. self,
  1583. ):
  1584. """
  1585. Tests associating a non-existent network acl to existing subnet failure
  1586. """
  1587. vpc = self._create_vpc()
  1588. subnet = self._create_subnet(vpc.id)
  1589. network_acl_association_result = boto_vpc.associate_network_acl_to_subnet(
  1590. "fake", subnet.id, **conn_parameters
  1591. )
  1592. self.assertTrue("error" in network_acl_association_result)
  1593. @mock_ec2_deprecated
  1594. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1595. def test_that_when_associating_an_existing_network_acl_to_a_non_existent_subnet_the_associate_network_acl_method_returns_false(
  1596. self,
  1597. ):
  1598. """
  1599. Tests associating an existing network acl to a non-existent subnet
  1600. """
  1601. vpc = self._create_vpc()
  1602. network_acl = self._create_network_acl(vpc.id)
  1603. network_acl_association_result = boto_vpc.associate_network_acl_to_subnet(
  1604. network_acl.id, "fake", **conn_parameters
  1605. )
  1606. self.assertFalse(network_acl_association_result)
  1607. @mock_ec2_deprecated
  1608. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1609. def test_that_when_creating_and_associating_a_network_acl_to_a_subnet_succeeds_the_associate_new_network_acl_to_subnet_method_returns_true(
  1610. self,
  1611. ):
  1612. """
  1613. Tests creating/associating a network acl to a subnet to a new network
  1614. """
  1615. vpc = self._create_vpc()
  1616. subnet = self._create_subnet(vpc.id)
  1617. network_acl_creation_and_association_result = boto_vpc.associate_new_network_acl_to_subnet(
  1618. vpc.id, subnet.id, **conn_parameters
  1619. )
  1620. self.assertTrue(network_acl_creation_and_association_result)
  1621. @mock_ec2_deprecated
  1622. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1623. def test_that_when_creating_and_associating_a_network_acl_to_a_subnet_and_specifying_a_name_succeeds_the_associate_new_network_acl_to_subnet_method_returns_true(
  1624. self,
  1625. ):
  1626. """
  1627. Tests creation/association of a network acl to subnet via name successfully
  1628. """
  1629. vpc = self._create_vpc()
  1630. subnet = self._create_subnet(vpc.id)
  1631. network_acl_creation_and_association_result = boto_vpc.associate_new_network_acl_to_subnet(
  1632. vpc.id, subnet.id, network_acl_name="test", **conn_parameters
  1633. )
  1634. self.assertTrue(network_acl_creation_and_association_result)
  1635. @mock_ec2_deprecated
  1636. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1637. def test_that_when_creating_and_associating_a_network_acl_to_a_subnet_and_specifying_tags_succeeds_the_associate_new_network_acl_to_subnet_method_returns_true(
  1638. self,
  1639. ):
  1640. """
  1641. Tests creating/association of a network acl to a subnet via tag successfully
  1642. """
  1643. vpc = self._create_vpc()
  1644. subnet = self._create_subnet(vpc.id)
  1645. network_acl_creation_and_association_result = boto_vpc.associate_new_network_acl_to_subnet(
  1646. vpc.id, subnet.id, tags={"test": "testvalue"}, **conn_parameters
  1647. )
  1648. self.assertTrue(network_acl_creation_and_association_result)
  1649. @mock_ec2_deprecated
  1650. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1651. def test_that_when_creating_and_associating_a_network_acl_to_a_non_existent_subnet_the_associate_new_network_acl_to_subnet_method_returns_false(
  1652. self,
  1653. ):
  1654. """
  1655. Tests creation/association of a network acl to a non-existent vpc
  1656. """
  1657. vpc = self._create_vpc()
  1658. network_acl_creation_and_association_result = boto_vpc.associate_new_network_acl_to_subnet(
  1659. vpc.id, "fake", **conn_parameters
  1660. )
  1661. self.assertFalse(network_acl_creation_and_association_result)
  1662. @mock_ec2_deprecated
  1663. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1664. def test_that_when_creating_a_network_acl_to_a_non_existent_vpc_the_associate_new_network_acl_to_subnet_method_returns_an_error(
  1665. self,
  1666. ):
  1667. """
  1668. Tests creation/association of network acl to a non-existent subnet
  1669. """
  1670. vpc = self._create_vpc()
  1671. subnet = self._create_subnet(vpc.id)
  1672. network_acl_creation_result = boto_vpc.create_network_acl(
  1673. vpc_name="fake", subnet_id=subnet.id, **conn_parameters
  1674. )
  1675. self.assertTrue("error" in network_acl_creation_result)
  1676. @mock_ec2_deprecated
  1677. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1678. def test_that_when_disassociating_network_acl_succeeds_the_disassociate_network_acl_method_should_return_true(
  1679. self,
  1680. ):
  1681. """
  1682. Tests disassociation of network acl success
  1683. """
  1684. vpc = self._create_vpc()
  1685. subnet = self._create_subnet(vpc.id)
  1686. dhcp_disassociate_result = boto_vpc.disassociate_network_acl(
  1687. subnet.id, vpc_id=vpc.id, **conn_parameters
  1688. )
  1689. self.assertTrue(dhcp_disassociate_result)
  1690. @mock_ec2_deprecated
  1691. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1692. def test_that_when_disassociating_network_acl_for_a_non_existent_vpc_the_disassociate_network_acl_method_should_return_false(
  1693. self,
  1694. ):
  1695. """
  1696. Tests disassociation of network acl from non-existent vpc
  1697. """
  1698. vpc = self._create_vpc()
  1699. subnet = self._create_subnet(vpc.id)
  1700. dhcp_disassociate_result = boto_vpc.disassociate_network_acl(
  1701. subnet.id, vpc_id="fake", **conn_parameters
  1702. )
  1703. self.assertFalse(dhcp_disassociate_result)
  1704. @mock_ec2_deprecated
  1705. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1706. def test_that_when_disassociating_network_acl_for_a_non_existent_subnet_the_disassociate_network_acl_method_should_return_false(
  1707. self,
  1708. ):
  1709. """
  1710. Tests disassociation of network acl from non-existent subnet
  1711. """
  1712. vpc = self._create_vpc()
  1713. dhcp_disassociate_result = boto_vpc.disassociate_network_acl(
  1714. "fake", vpc_id=vpc.id, **conn_parameters
  1715. )
  1716. self.assertFalse(dhcp_disassociate_result)
  1717. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  1718. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  1719. @skipIf(
  1720. _has_required_boto() is False,
  1721. "The boto module must be greater than"
  1722. " or equal to version {}. Installed: {}".format(
  1723. required_boto_version, _get_boto_version()
  1724. ),
  1725. )
  1726. class BotoVpcRouteTablesTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  1727. @mock_ec2_deprecated
  1728. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1729. def test_that_when_creating_a_route_table_succeeds_the_create_route_table_method_returns_true(
  1730. self,
  1731. ):
  1732. """
  1733. Tests creating route table successfully
  1734. """
  1735. vpc = self._create_vpc()
  1736. route_table_creation_result = boto_vpc.create_route_table(
  1737. vpc.id, **conn_parameters
  1738. )
  1739. self.assertTrue(route_table_creation_result)
  1740. @mock_ec2_deprecated
  1741. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1742. def test_that_when_creating_a_route_table_on_a_non_existent_vpc_the_create_route_table_method_returns_false(
  1743. self,
  1744. ):
  1745. """
  1746. Tests creating route table on a non-existent vpc
  1747. """
  1748. route_table_creation_result = boto_vpc.create_route_table(
  1749. "fake", **conn_parameters
  1750. )
  1751. self.assertTrue(route_table_creation_result)
  1752. @mock_ec2_deprecated
  1753. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1754. def test_that_when_deleting_a_route_table_succeeds_the_delete_route_table_method_returns_true(
  1755. self,
  1756. ):
  1757. """
  1758. Tests deleting route table successfully
  1759. """
  1760. vpc = self._create_vpc()
  1761. route_table = self._create_route_table(vpc.id)
  1762. route_table_deletion_result = boto_vpc.delete_route_table(
  1763. route_table.id, **conn_parameters
  1764. )
  1765. self.assertTrue(route_table_deletion_result)
  1766. @mock_ec2_deprecated
  1767. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1768. def test_that_when_deleting_a_non_existent_route_table_the_delete_route_table_method_returns_false(
  1769. self,
  1770. ):
  1771. """
  1772. Tests deleting non-existent route table
  1773. """
  1774. route_table_deletion_result = boto_vpc.delete_route_table(
  1775. "fake", **conn_parameters
  1776. )
  1777. self.assertFalse(route_table_deletion_result)
  1778. @mock_ec2_deprecated
  1779. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1780. def test_that_when_route_table_exists_the_route_table_exists_method_returns_true(
  1781. self,
  1782. ):
  1783. """
  1784. Tests existence of route table success
  1785. """
  1786. vpc = self._create_vpc()
  1787. route_table = self._create_route_table(vpc.id)
  1788. route_table_existence_result = boto_vpc.route_table_exists(
  1789. route_table.id, **conn_parameters
  1790. )
  1791. self.assertTrue(route_table_existence_result)
  1792. @mock_ec2_deprecated
  1793. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1794. def test_that_when_route_table_does_not_exist_the_route_table_exists_method_returns_false(
  1795. self,
  1796. ):
  1797. """
  1798. Tests existence of route table failure
  1799. """
  1800. route_table_existence_result = boto_vpc.route_table_exists(
  1801. "fake", **conn_parameters
  1802. )
  1803. self.assertFalse(route_table_existence_result)
  1804. @mock_ec2_deprecated
  1805. @skipIf(True, "Disabled pending https://github.com/spulec/moto/issues/493")
  1806. def test_that_when_checking_if_a_route_table_exists_but_providing_no_filters_the_route_table_exists_method_raises_a_salt_invocation_error(
  1807. self,
  1808. ):
  1809. """
  1810. Tests checking route table without filters
  1811. """
  1812. with self.assertRaisesRegex(
  1813. SaltInvocationError,
  1814. "At least one of the following must be provided: id, name, or tags.",
  1815. ):
  1816. boto_vpc.dhcp_options_exists(**conn_parameters)
  1817. @mock_ec2_deprecated
  1818. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1819. def test_that_when_associating_a_route_table_succeeds_the_associate_route_table_method_should_return_the_association_id(
  1820. self,
  1821. ):
  1822. """
  1823. Tests associating route table successfully
  1824. """
  1825. vpc = self._create_vpc()
  1826. subnet = self._create_subnet(vpc.id)
  1827. route_table = self._create_route_table(vpc.id)
  1828. association_id = boto_vpc.associate_route_table(
  1829. route_table.id, subnet.id, **conn_parameters
  1830. )
  1831. self.assertTrue(association_id)
  1832. @mock_ec2_deprecated
  1833. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1834. def test_that_when_associating_a_route_table_with_a_non_existent_route_table_the_associate_route_table_method_should_return_false(
  1835. self,
  1836. ):
  1837. """
  1838. Tests associating of route table to non-existent route table
  1839. """
  1840. vpc = self._create_vpc()
  1841. subnet = self._create_subnet(vpc.id)
  1842. association_id = boto_vpc.associate_route_table(
  1843. "fake", subnet.id, **conn_parameters
  1844. )
  1845. self.assertFalse(association_id)
  1846. @mock_ec2_deprecated
  1847. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1848. def test_that_when_associating_a_route_table_with_a_non_existent_subnet_the_associate_route_table_method_should_return_false(
  1849. self,
  1850. ):
  1851. """
  1852. Tests associating of route table with non-existent subnet
  1853. """
  1854. vpc = self._create_vpc()
  1855. route_table = self._create_route_table(vpc.id)
  1856. association_id = boto_vpc.associate_route_table(
  1857. route_table.id, "fake", **conn_parameters
  1858. )
  1859. self.assertFalse(association_id)
  1860. @mock_ec2_deprecated
  1861. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1862. def test_that_when_disassociating_a_route_table_succeeds_the_disassociate_route_table_method_should_return_true(
  1863. self,
  1864. ):
  1865. """
  1866. Tests disassociation of a route
  1867. """
  1868. vpc = self._create_vpc()
  1869. subnet = self._create_subnet(vpc.id)
  1870. route_table = self._create_route_table(vpc.id)
  1871. association_id = self._associate_route_table(route_table.id, subnet.id)
  1872. dhcp_disassociate_result = boto_vpc.disassociate_route_table(
  1873. association_id, **conn_parameters
  1874. )
  1875. self.assertTrue(dhcp_disassociate_result)
  1876. @mock_ec2_deprecated
  1877. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1878. def test_that_when_creating_a_route_succeeds_the_create_route_method_should_return_true(
  1879. self,
  1880. ):
  1881. """
  1882. Tests successful creation of a route
  1883. """
  1884. vpc = self._create_vpc()
  1885. route_table = self._create_route_table(vpc.id)
  1886. route_creation_result = boto_vpc.create_route(
  1887. route_table.id, cidr_block, **conn_parameters
  1888. )
  1889. self.assertTrue(route_creation_result)
  1890. @mock_ec2_deprecated
  1891. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1892. def test_that_when_creating_a_route_with_a_non_existent_route_table_the_create_route_method_should_return_false(
  1893. self,
  1894. ):
  1895. """
  1896. Tests creation of route on non-existent route table
  1897. """
  1898. route_creation_result = boto_vpc.create_route(
  1899. "fake", cidr_block, **conn_parameters
  1900. )
  1901. self.assertFalse(route_creation_result)
  1902. @mock_ec2_deprecated
  1903. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1904. def test_that_when_deleting_a_route_succeeds_the_delete_route_method_should_return_true(
  1905. self,
  1906. ):
  1907. """
  1908. Tests deleting route from route table
  1909. """
  1910. vpc = self._create_vpc()
  1911. route_table = self._create_route_table(vpc.id)
  1912. route_deletion_result = boto_vpc.delete_route(
  1913. route_table.id, cidr_block, **conn_parameters
  1914. )
  1915. self.assertTrue(route_deletion_result)
  1916. @mock_ec2_deprecated
  1917. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1918. def test_that_when_deleting_a_route_with_a_non_existent_route_table_the_delete_route_method_should_return_false(
  1919. self,
  1920. ):
  1921. """
  1922. Tests deleting route from a non-existent route table
  1923. """
  1924. route_deletion_result = boto_vpc.delete_route(
  1925. "fake", cidr_block, **conn_parameters
  1926. )
  1927. self.assertFalse(route_deletion_result)
  1928. @mock_ec2_deprecated
  1929. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1930. def test_that_when_replacing_a_route_succeeds_the_replace_route_method_should_return_true(
  1931. self,
  1932. ):
  1933. """
  1934. Tests replacing route successfully
  1935. """
  1936. vpc = self._create_vpc()
  1937. route_table = self._create_route_table(vpc.id)
  1938. route_replacing_result = boto_vpc.replace_route(
  1939. route_table.id, cidr_block, **conn_parameters
  1940. )
  1941. self.assertTrue(route_replacing_result)
  1942. @mock_ec2_deprecated
  1943. @skipIf(True, "Moto has not implemented this feature. Skipping for now.")
  1944. def test_that_when_replacing_a_route_with_a_non_existent_route_table_the_replace_route_method_should_return_false(
  1945. self,
  1946. ):
  1947. """
  1948. Tests replacing a route when the route table doesn't exist
  1949. """
  1950. route_replacing_result = boto_vpc.replace_route(
  1951. "fake", cidr_block, **conn_parameters
  1952. )
  1953. self.assertFalse(route_replacing_result)
  1954. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  1955. @skipIf(HAS_MOTO is False, "The moto module must be installed.")
  1956. @skipIf(
  1957. _has_required_boto() is False,
  1958. "The boto module must be greater than"
  1959. " or equal to version {}. Installed: {}".format(
  1960. required_boto_version, _get_boto_version()
  1961. ),
  1962. )
  1963. @skipIf(
  1964. _has_required_moto() is False,
  1965. "The moto version must be >= to version {0}".format(required_moto_version),
  1966. )
  1967. @skipIf(
  1968. sys.version_info > (3, 6),
  1969. "Disabled for 3.7+ pending https://github.com/spulec/moto/issues/1706.",
  1970. )
  1971. class BotoVpcPeeringConnectionsTest(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
  1972. @mock_ec2_deprecated
  1973. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1974. def test_request_vpc_peering_connection(self):
  1975. """
  1976. Run with 2 vpc ids and returns a message
  1977. """
  1978. my_vpc = self._create_vpc()
  1979. other_vpc = self._create_vpc()
  1980. self.assertTrue(
  1981. "msg"
  1982. in boto_vpc.request_vpc_peering_connection(
  1983. name="my_peering",
  1984. requester_vpc_id=my_vpc.id,
  1985. peer_vpc_id=other_vpc.id,
  1986. **conn_parameters
  1987. )
  1988. )
  1989. @mock_ec2_deprecated
  1990. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  1991. def test_raises_error_if_both_vpc_name_and_vpc_id_are_specified(self):
  1992. """
  1993. Must specify only one
  1994. """
  1995. my_vpc = self._create_vpc()
  1996. other_vpc = self._create_vpc()
  1997. with self.assertRaises(SaltInvocationError):
  1998. boto_vpc.request_vpc_peering_connection(
  1999. name="my_peering",
  2000. requester_vpc_id=my_vpc.id,
  2001. requester_vpc_name="foobar",
  2002. peer_vpc_id=other_vpc.id,
  2003. **conn_parameters
  2004. )
  2005. boto_vpc.request_vpc_peering_connection(
  2006. name="my_peering",
  2007. requester_vpc_name="my_peering",
  2008. peer_vpc_id=other_vpc.id,
  2009. **conn_parameters
  2010. )