From 6a6049a1b5edc93fd42cb60b4be6b095c11819e5 Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Tue, 11 Oct 2016 15:07:38 +0300 Subject: [PATCH] skip vpn tests if vpnaas is not in network features list Change-Id: Ie6e779e58917c375b150949a0151cbb907466cba --- api/test_customer_gateways.py | 1 + api/test_tags.py | 2 ++ api/test_vpn_connections.py | 1 + api/test_vpn_gateways.py | 1 + base.py | 21 +++++++++++++++++++++ config.py | 1 + scenario/test_vpn.py | 1 + 7 files changed, 28 insertions(+) diff --git a/api/test_customer_gateways.py b/api/test_customer_gateways.py index 41ee24a..8d1a735 100644 --- a/api/test_customer_gateways.py +++ b/api/test_customer_gateways.py @@ -31,6 +31,7 @@ class CustomerGatewayTest(base.EC2TestCase): super(CustomerGatewayTest, cls).setUpClass() if not base.TesterStateHolder().get_vpc_enabled(): raise cls.skipException('VPC is disabled') + base.check_network_feature_enabled('vpnaas') def test_create_delete_customer_gateway(self): data = self.client.create_customer_gateway( diff --git a/api/test_tags.py b/api/test_tags.py index 8645fc1..2733684 100644 --- a/api/test_tags.py +++ b/api/test_tags.py @@ -441,6 +441,7 @@ class TagTest(base.EC2TestCase): self._test_tag_resource(cgw_id, 'customer-gateway', describe_func) @base.skip_without_vpc() + @base.skip_without_network_feature('vpnaas') def test_tag_vpn_gateway(self): data = self.client.create_vpn_gateway(Type='ipsec.1') vgw_id = data['VpnGateway']['VpnGatewayId'] @@ -456,6 +457,7 @@ class TagTest(base.EC2TestCase): self._test_tag_resource(vgw_id, 'vpn-gateway', describe_func) @base.skip_without_vpc() + @base.skip_without_network_feature('vpnaas') def test_tag_vpn_connection(self): data = self.client.create_customer_gateway( Type='ipsec.1', PublicIp='198.51.100.77', BgpAsn=65000) diff --git a/api/test_vpn_connections.py b/api/test_vpn_connections.py index 105a827..e4d2fbc 100644 --- a/api/test_vpn_connections.py +++ b/api/test_vpn_connections.py @@ -35,6 +35,7 @@ class VpnConnectionTest(base.EC2TestCase): super(VpnConnectionTest, cls).setUpClass() if not base.TesterStateHolder().get_vpc_enabled(): raise cls.skipException('VPC is disabled') + base.check_network_feature_enabled('vpnaas') data = cls.client.create_customer_gateway( Type='ipsec.1', PublicIp=cls.CUSTOMER_GATEWAY_IP, BgpAsn=65000) diff --git a/api/test_vpn_gateways.py b/api/test_vpn_gateways.py index b92a859..148ef32 100644 --- a/api/test_vpn_gateways.py +++ b/api/test_vpn_gateways.py @@ -32,6 +32,7 @@ class VpnGatewayTest(base.EC2TestCase): super(VpnGatewayTest, cls).setUpClass() if not base.TesterStateHolder().get_vpc_enabled(): raise cls.skipException('VPC is disabled') + base.check_network_feature_enabled('vpnaas') data = cls.client.create_vpc(CidrBlock=cls.VPC_CIDR) cls.vpc_id = data['Vpc']['VpcId'] diff --git a/base.py b/base.py index 33db487..5db3bab 100644 --- a/base.py +++ b/base.py @@ -241,6 +241,27 @@ def skip_without_vpc(*args, **kwargs): return decorator +def check_network_feature_enabled(ext_name): + if hasattr(CONF, 'network_feature_enabled'): + ext_list = CONF.network_feature_enabled.api_extensions + else: + ext_list = ['all'] + if 'all' not in ext_list and ext_name not in ext_list: + msg = ("Skipped network test as %s is not available" % ext_name) + raise testtools.TestCase.skipException(msg) + + +def skip_without_network_feature(ext_name, *args, **kwargs): + """A decorator useful to skip tests without specified network extension.""" + def decorator(f): + @functools.wraps(f) + def wrapper(self, *func_args, **func_kwargs): + check_network_feature_enabled(ext_name) + return f(self, *func_args, **func_kwargs) + return wrapper + return decorator + + class EC2TestCase(base.BaseTestCase): """Recommended to use as base class for boto related test.""" diff --git a/config.py b/config.py index a57f5fe..925feab 100644 --- a/config.py +++ b/config.py @@ -39,6 +39,7 @@ class ConfigPrivate(object): if config_opts.aws_group.name in cfg.CONF: self.aws = cfg.CONF.aws self.service_available = cfg.CONF.service_available + self.network_feature_enabled = cfg.CONF['network-feature-enabled'] return # Environment variables override defaults... diff --git a/scenario/test_vpn.py b/scenario/test_vpn.py index 362daf6..7b0268d 100644 --- a/scenario/test_vpn.py +++ b/scenario/test_vpn.py @@ -46,6 +46,7 @@ class VpnTest(scenario_base.BaseScenarioTest): super(VpnTest, cls).setUpClass() if not base.TesterStateHolder().get_vpc_enabled(): raise cls.skipException('VPC is disabled') + base.check_network_feature_enabled('vpnaas') def test_vpn_routing(self): vpc_id, _subnet_id = self.create_vpc_and_subnet('10.42.0.0/20')