summaryrefslogtreecommitdiffstats
path: root/functest/opnfv_tests/openstack/api/connection_check.py
blob: adca30ee9e24afb43e6b0bfe1c7e3e94cbe05c7c (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
67
68
#!/usr/bin/env python

# Copyright (c) 2018 Orange and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0

"""Verify the connection to OpenStack Services"""

import logging
import time

import os_client_config
import shade
from xtesting.core import testcase

from functest.utils import functest_utils


class ConnectionCheck(testcase.TestCase):
    """Perform simplest queries"""
    __logger = logging.getLogger(__name__)

    func_list = [
        "get_network_extensions", "list_aggregates", "list_domains",
        "list_endpoints", "list_floating_ip_pools", "list_floating_ips",
        "list_hypervisors", "list_keypairs", "list_networks", "list_ports",
        "list_role_assignments", "list_roles", "list_routers", "list_servers",
        "list_subnets"]

    def __init__(self, **kwargs):
        if "case_name" not in kwargs:
            kwargs["case_name"] = 'connection_check'
        super(ConnectionCheck, self).__init__(**kwargs)
        self.output_log_name = 'functest.log'
        self.output_debug_log_name = 'functest.debug.log'
        try:
            cloud_config = os_client_config.get_config()
            self.cloud = shade.OpenStackCloud(cloud_config=cloud_config)
        except Exception:  # pylint: disable=broad-except
            self.cloud = None

    def run(self, **kwargs):
        # pylint: disable=protected-access
        """Run all read operations to check connections"""
        status = testcase.TestCase.EX_RUN_ERROR
        try:
            assert self.cloud
            self.start_time = time.time()
            self.__logger.debug(
                "list_services: %s", functest_utils.list_services(self.cloud))
            for func in self.func_list:
                self.__logger.debug(
                    "%s: %s", func, getattr(self.cloud, func)())
            data = self.cloud._network_client.get("/service-providers.json")
            self.__logger.debug(
                "list_service_providers: %s",
                self.cloud._get_and_munchify('service_providers', data))
            functest_utils.get_openstack_version(self.cloud)
            self.result = 100
            status = testcase.TestCase.EX_OK
        except Exception:  # pylint: disable=broad-except
            self.__logger.exception('Cannot run %s', self.case_name)
        finally:
            self.stop_time = time.time()
        return status