summaryrefslogtreecommitdiff
path: root/kuryr_tempest_plugin/tests/scenario/test_cross_ping.py
blob: 5687df281cb4e63db4a7c098a42b34ed7e35c892 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright 2017 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import testtools

from oslo_log import log as logging
from tempest import config
from tempest.lib import decorators
from tempest.lib import exceptions
from tempest.lib.common.utils import data_utils

from kuryr_tempest_plugin.tests.scenario import base

LOG = logging.getLogger(__name__)
CONF = config.CONF


class TestCrossPingScenario(base.BaseKuryrScenarioTest):

    @classmethod
    def skip_checks(cls):
        super(TestCrossPingScenario, cls).skip_checks()
        if not CONF.network_feature_enabled.floating_ips:
            raise cls.skipException("Floating ips are not available")

    @decorators.idempotent_id('bddf5441-1244-449d-a125-b5fddfb1a1a8')
    def test_vm_pod_ping(self):
        keypair = self.create_keypair()
        security_groups = [
            {'name': self._create_security_group()['name']}
        ]
        server = self.create_server(name=data_utils.rand_name(prefix='kuryr'),
                                    key_name=keypair['name'],
                                    security_groups=security_groups)
        fip = self.create_floating_ip(server)

        pod_name, pod = self.create_pod()
        self.addCleanup(self.delete_pod, pod_name, pod)
        pod_fip = self.assign_fip_to_pod(pod_name)

        ssh_client = self.get_remote_client(fip['floating_ip_address'],
                                            private_key=keypair['private_key'])
        cmd = ("ping -c1 -w1 %s &> /dev/null; echo $?" %
               pod_fip['floatingip']['floating_ip_address'])

        try:
            result = ssh_client.exec_command(cmd)
            if result:
                msg = ('Failed while trying to ping. Could not ping '
                       'from host "%s" to "%s".' % (
                           fip['floating_ip_address'],
                           pod_fip['floatingip']['floating_ip_address']))
            self.assertEqual('0', result.rstrip('\n'))
        except exceptions.SSHExecCommandFailed:
            LOG.error("Couldn't ping server")