Allow getting service via any endpoint
[functest.git] / functest / opnfv_tests / openstack / api / connection_check.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2018 Orange and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 """Verify the connection to OpenStack Services"""
11
12 import logging
13 import time
14
15 import os_client_config
16 import shade
17 from xtesting.core import testcase
18
19 from functest.utils import functest_utils
20
21
22 class ConnectionCheck(testcase.TestCase):
23     """Perform simplest queries"""
24     __logger = logging.getLogger(__name__)
25
26     func_list = [
27         "get_network_extensions", "list_aggregates", "list_domains",
28         "list_endpoints", "list_floating_ip_pools", "list_floating_ips",
29         "list_hypervisors", "list_keypairs", "list_networks", "list_ports",
30         "list_role_assignments", "list_roles", "list_routers", "list_servers",
31         "list_subnets"]
32
33     def __init__(self, **kwargs):
34         if "case_name" not in kwargs:
35             kwargs["case_name"] = 'connection_check'
36         super(ConnectionCheck, self).__init__(**kwargs)
37         try:
38             cloud_config = os_client_config.get_config()
39             self.cloud = shade.OpenStackCloud(cloud_config=cloud_config)
40         except Exception:  # pylint: disable=broad-except
41             self.cloud = None
42
43     def run(self, **kwargs):
44         # pylint: disable=protected-access
45         """Run all read operations to check connections"""
46         status = testcase.TestCase.EX_RUN_ERROR
47         try:
48             assert self.cloud
49             self.start_time = time.time()
50             self.__logger.debug(
51                 "list_services: %s", functest_utils.list_services(self.cloud))
52             for func in self.func_list:
53                 self.__logger.debug(
54                     "%s: %s", func, getattr(self.cloud, func)())
55             data = self.cloud._network_client.get("/service-providers.json")
56             self.__logger.debug(
57                 "list_service_providers: %s",
58                 self.cloud._get_and_munchify('service_providers', data))
59             functest_utils.get_openstack_version(self.cloud)
60             self.result = 100
61             status = testcase.TestCase.EX_OK
62         except Exception:  # pylint: disable=broad-except
63             self.__logger.exception('Cannot run %s', self.case_name)
64         finally:
65             self.stop_time = time.time()
66         return status