Debian Codegraph @

neutron_tempest_plugin/bgpvpn/scenario/manager.py

raw
1 # Copyright 2012 OpenStack Foundation
2 # Copyright 2013 IBM Corp.
3 # All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
16
17 from oslo_log import log
18
19 from tempest.common import utils
20 from tempest import config
21 from tempest.lib.common.utils import data_utils
22 from tempest.lib.common.utils import test_utils
23 from tempest.lib import exceptions as lib_exc
24 from tempest.scenario import manager
25
26 CONF = config.CONF
27
28 LOG = log.getLogger(__name__)
29
30
31 class ScenarioTest(manager.NetworkScenarioTest):
32 """Base class for scenario tests. Uses tempest own clients. """
33
34 credentials = ['primary']
35
36
37 class NetworkScenarioTest(ScenarioTest):
38 """Base class for network scenario tests.
39
40 This class provide helpers for network scenario tests, using the neutron
41 API. Helpers from ancestor which use the nova network API are overridden
42 with the neutron API.
43
44 This Class also enforces using Neutron instead of novanetwork.
45 Subclassed tests will be skipped if Neutron is not enabled
46
47 """
48
49 credentials = ['primary', 'admin']
50
51 @classmethod
52 def skip_checks(cls):
53 super(NetworkScenarioTest, cls).skip_checks()
54 if not CONF.service_available.neutron:
55 raise cls.skipException('Neutron not available')
56 if not utils.is_extension_enabled('bgpvpn', 'network'):
57 msg = "Bgpvpn extension not enabled."
58 raise cls.skipException(msg)
59
60 def _check_remote_connectivity(self, source, dest, should_succeed=True,
61 nic=None):
62 """check ping server via source ssh connection
63
64 :param source: RemoteClient: an ssh connection from which to ping
65 :param dest: and IP to ping against
66 :param should_succeed: boolean should ping succeed or not
67 :param nic: specific network interface to ping from
68 :returns: boolean -- should_succeed == ping
69 :returns: ping is false if ping failed
70 """
71 def ping_remote():
72 try:
73 source.ping_host(dest, nic=nic)
74 except lib_exc.SSHExecCommandFailed:
75 LOG.warning('Failed to ping IP: %s via a ssh connection '
76 'from: %s.', dest, source.ssh_client.host)
77 return not should_succeed
78 return should_succeed
79
80 return test_utils.call_until_true(ping_remote,
81 CONF.validation.ping_timeout,
82 1)
83
84 def create_loginable_secgroup_rule(self, security_group_rules_client=None,
85 secgroup=None,
86 security_groups_client=None):
87 """Create loginable security group rule
88
89 This function will create:
90 1. egress and ingress tcp port 22 allow rule in order to allow ssh
91 access for ipv4.
92 2. egress and ingress tcp port 80 allow rule in order to allow http
93 access for ipv4.
94 3. egress and ingress ipv6 icmp allow rule, in order to allow icmpv6.
95 4. egress and ingress ipv4 icmp allow rule, in order to allow icmpv4.
96 """
97
98 if security_group_rules_client is None:
99 security_group_rules_client = self.security_group_rules_client
100 if security_groups_client is None:
101 security_groups_client = self.security_groups_client
102 rules = []
103 rulesets = [
104 dict(
105 # ssh
106 protocol='tcp',
107 port_range_min=22,
108 port_range_max=22,
109 ),
110 dict(
111 # http
112 protocol='tcp',
113 port_range_min=80,
114 port_range_max=80,
115 ),
116 dict(
117 # ping
118 protocol='icmp',
119 ),
120 dict(
121 # ipv6-icmp for ping6
122 protocol='icmp',
123 ethertype='IPv6',
124 )
125 ]
126 sec_group_rules_client = security_group_rules_client
127 for ruleset in rulesets:
128 for r_direction in ['ingress', 'egress']:
129 ruleset['direction'] = r_direction
130 try:
131 sg_rule = self.create_security_group_rule(
132 sec_group_rules_client=sec_group_rules_client,
133 secgroup=secgroup,
134 security_groups_client=security_groups_client,
135 **ruleset)
136 except lib_exc.Conflict as ex:
137 # if rule already exist - skip rule and continue
138 msg = 'Security group rule already exists'
139 if msg not in ex._error_string:
140 raise ex
141 else:
142 self.assertEqual(r_direction, sg_rule['direction'])
143 rules.append(sg_rule)
144
145 return rules
146
147 def _create_router(self, client=None, tenant_id=None,
148 namestart='router-smoke'):
149 if not client:
150 client = self.admin_routers_client
151 if not tenant_id:
152 tenant_id = client.project_id
153 name = data_utils.rand_name(namestart)
154 result = client.create_router(name=name,
155 admin_state_up=True,
156 tenant_id=tenant_id)
157 router = result['router']
158 self.assertEqual(router['name'], name)
159 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
160 client.delete_router,
161 router['id'])
162 return router