3 # Copyright (c) 2015 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 """Some common utils wrapping snaps functions """
12 from functest.utils import constants
13 from functest.utils import env
15 from snaps.openstack.tests import openstack_tests
16 from snaps.openstack.utils import neutron_utils, nova_utils
19 def get_ext_net_name(os_creds):
21 Returns the configured external network name or
22 the first retrieved external network name
23 :param: os_creds: an instance of snaps OSCreds object
26 neutron = neutron_utils.neutron_client(os_creds)
27 ext_nets = neutron_utils.get_external_networks(neutron)
28 if env.get('EXTERNAL_NETWORK'):
29 extnet_config = env.get('EXTERNAL_NETWORK')
30 for ext_net in ext_nets:
31 if ext_net.name == extnet_config:
33 return ext_nets[0].name if ext_nets else ""
36 def get_active_compute_cnt(os_creds):
38 Returns the number of active compute servers
39 :param: os_creds: an instance of snaps OSCreds object
40 :return: the number of active compute servers
42 nova = nova_utils.nova_client(os_creds)
43 computes = nova_utils.get_availability_zone_hosts(nova, zone_name='nova')
47 def get_credentials(proxy_settings_str=None, ssh_proxy_cmd=None):
49 Returns snaps OSCreds object instance
50 :param: proxy_settings_str: proxy settings string <host>:<port>
51 :param: ssh_proxy_cmd: the SSH proxy command for the environment
52 :return: an instance of snaps OSCreds object
55 if hasattr(constants.CONST, 'snaps_os_creds_override'):
56 creds_override = getattr(constants.CONST, 'snaps_os_creds_override')
57 os_creds = openstack_tests.get_credentials(
58 os_env_file=constants.ENV_FILE, proxy_settings_str=proxy_settings_str,
59 ssh_proxy_cmd=ssh_proxy_cmd, overrides=creds_override)