Generate xunit reports (rally and tempest)
[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
20 class ConnectionCheck(testcase.TestCase):
21     """Perform simplest queries"""
22     __logger = logging.getLogger(__name__)
23
24     def __init__(self, **kwargs):
25         if "case_name" not in kwargs:
26             kwargs["case_name"] = 'connection_check'
27         super(ConnectionCheck, self).__init__(**kwargs)
28         try:
29             cloud_config = os_client_config.get_config()
30             self.cloud = shade.OpenStackCloud(cloud_config=cloud_config)
31         except Exception:  # pylint: disable=broad-except
32             self.cloud = None
33
34     def run(self, **kwargs):
35         # pylint: disable=protected-access
36         """Run all read operations to check connections"""
37         status = testcase.TestCase.EX_RUN_ERROR
38         try:
39             assert self.cloud
40             self.start_time = time.time()
41             for func in ["get_network_extensions",
42                          "list_aggregates", "list_domains", "list_endpoints",
43                          "list_floating_ip_pools", "list_floating_ips",
44                          "list_hypervisors", "list_keypairs", "list_networks",
45                          "list_ports", "list_role_assignments", "list_roles",
46                          "list_routers", "list_servers", "list_services",
47                          "list_subnets"]:
48                 self.__logger.debug(
49                     "%s: %s", func, getattr(self.cloud, func)())
50             data = self.cloud._network_client.get("/service-providers.json")
51             self.__logger.debug(
52                 "list_service_providers: %s",
53                 self.cloud._get_and_munchify('service_providers', data))
54             self.result = 100
55             status = testcase.TestCase.EX_OK
56         except Exception:  # pylint: disable=broad-except
57             self.__logger.exception('Cannot run %s', self.case_name)
58         finally:
59             self.stop_time = time.time()
60         return status