Create new project/user for rally test
[functest.git] / functest / opnfv_tests / openstack / snaps / snaps_test_runner.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
4 #
5 # 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 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 """configuration params to run snaps tests"""
12
13 import logging
14
15 import os_client_config
16 import shade
17 from xtesting.core import unit
18
19 from functest.opnfv_tests.openstack.snaps import snaps_utils
20 from functest.utils import config
21 from functest.utils import functest_utils
22
23
24 class SnapsTestRunner(unit.Suite):
25     # pylint: disable=too-many-instance-attributes
26     """
27     This test executes the SNAPS Python Tests
28     """
29
30     def __init__(self, **kwargs):
31         super(SnapsTestRunner, self).__init__(**kwargs)
32         self.logger = logging.getLogger(__name__)
33         self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
34
35         if 'ext_net_name' in kwargs:
36             self.ext_net_name = kwargs['ext_net_name']
37         else:
38             self.ext_net_name = snaps_utils.get_ext_net_name(self.os_creds)
39
40         self.netconf_override = None
41         if hasattr(config.CONF, 'snaps_network_config'):
42             self.netconf_override = getattr(
43                 config.CONF, 'snaps_network_config')
44
45         self.use_fip = (
46             getattr(config.CONF, 'snaps_use_floating_ips') == 'True')
47         self.use_keystone = (
48             getattr(config.CONF, 'snaps_use_keystone') == 'True')
49
50         self.flavor_metadata = getattr(config.CONF, 'snaps_flavor_extra_specs',
51                                        None)
52         self.logger.info("Using flavor metadata '%s'", self.flavor_metadata)
53
54         self.image_metadata = None
55         if hasattr(config.CONF, 'snaps_images'):
56             self.image_metadata = getattr(config.CONF, 'snaps_images')
57
58     def check_requirements(self):
59         """Skip if OpenStack Rocky or newer."""
60         try:
61             cloud_config = os_client_config.get_config()
62             cloud = shade.OpenStackCloud(cloud_config=cloud_config)
63             if functest_utils.get_nova_version(cloud) > (2, 60):
64                 self.is_skipped = True
65         except Exception:  # pylint: disable=broad-except
66             pass