diff options
author | jose.lausuch <jose.lausuch@ericsson.com> | 2016-07-13 12:07:21 +0200 |
---|---|---|
committer | Jose Lausuch <jose.lausuch@ericsson.com> | 2016-07-14 11:10:47 +0000 |
commit | addc7f7318147c29de474813b00ae40882ca9662 (patch) | |
tree | 6fd60f2dcd2a50c811851ebb9ff7dbeb6b4d3f81 /utils | |
parent | 57d44d445189755d84dfb4abd50082900cb8811f (diff) |
Use common way to get the openstack clients
Instead of repeating the code in all the scripts and
importing the openstack libraries, the clients shall
be given by openstack utils, which is its purpose
JIRA: FUNCTEST-163
Change-Id: I1ccc05a3af44ee1ab5938ea9e4e01dbe55f4816d
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/openstack_clean.py | 33 | ||||
-rwxr-xr-x | utils/openstack_snapshot.py | 26 | ||||
-rw-r--r-- | utils/openstack_utils.py | 10 |
3 files changed, 21 insertions, 48 deletions
diff --git a/utils/openstack_clean.py b/utils/openstack_clean.py index 3eb39a26..c266eeb3 100755 --- a/utils/openstack_clean.py +++ b/utils/openstack_clean.py @@ -20,17 +20,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -""" logging configuration """ - import time - -from cinderclient import client as cinderclient import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils -from keystoneclient.v2_0 import client as keystoneclient -from neutronclient.v2_0 import client as neutronclient -from novaclient import client as novaclient import yaml @@ -41,7 +34,7 @@ OS_SNAPSHOT_FILE = ft_utils.get_parameter_from_yaml( def separator(): - logger.info("-------------------------------------------") + logger.debug("-------------------------------------------") def remove_instances(nova_client, default_instances): @@ -360,9 +353,12 @@ def remove_tenants(keystone_client, default_tenants): def main(): - logger.info("+++++++++++++++++++++++++++++++") logger.info("Cleaning OpenStack resources...") - logger.info("+++++++++++++++++++++++++++++++") + + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + keystone_client = os_utils.get_keystone_client() + cinder_client = os_utils.get_cinder_client() try: with open(OS_SNAPSHOT_FILE) as f: @@ -382,23 +378,6 @@ def main(): default_users = snapshot_yaml.get('users') default_tenants = snapshot_yaml.get('tenants') - creds_nova = os_utils.get_credentials("nova") - nova_client = novaclient.Client('2', **creds_nova) - - creds_neutron = os_utils.get_credentials("neutron") - neutron_client = neutronclient.Client(**creds_neutron) - - creds_keystone = os_utils.get_credentials("keystone") - keystone_client = keystoneclient.Client(**creds_keystone) - - creds_cinder = os_utils.get_credentials("cinder") - # cinder_client = cinderclient.Client(**creds_cinder) - cinder_client = cinderclient.Client('1', creds_cinder['username'], - creds_cinder['api_key'], - creds_cinder['project_id'], - creds_cinder['auth_url'], - service_type="volume") - if not os_utils.check_credentials(): logger.error("Please source the openrc credentials and run " "the script again.") diff --git a/utils/openstack_snapshot.py b/utils/openstack_snapshot.py index 704ef505..058f9ded 100755 --- a/utils/openstack_snapshot.py +++ b/utils/openstack_snapshot.py @@ -20,17 +20,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -""" logging configuration """ - import os - -from cinderclient import client as cinderclient import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils -from keystoneclient.v2_0 import client as keystoneclient -from neutronclient.v2_0 import client as neutronclient -from novaclient import client as novaclient import yaml @@ -143,21 +136,12 @@ def get_tenants(keystone_client): def main(): - creds_nova = os_utils.get_credentials("nova") - nova_client = novaclient.Client('2', **creds_nova) - - creds_neutron = os_utils.get_credentials("neutron") - neutron_client = neutronclient.Client(**creds_neutron) - - creds_keystone = os_utils.get_credentials("keystone") - keystone_client = keystoneclient.Client(**creds_keystone) + logger.info("Generating OpenStack snapshot...") - creds_cinder = os_utils.get_credentials("cinder") - cinder_client = cinderclient.Client('1', creds_cinder['username'], - creds_cinder['api_key'], - creds_cinder['project_id'], - creds_cinder['auth_url'], - service_type="volume") + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + keystone_client = os_utils.get_keystone_client() + cinder_client = os_utils.get_cinder_client() if not os_utils.check_credentials(): logger.error("Please source the openrc credentials and run the" + diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py index 2103c7fe..2af12e55 100644 --- a/utils/openstack_utils.py +++ b/utils/openstack_utils.py @@ -14,6 +14,7 @@ import subprocess import sys import time +from cinderclient import client as cinderclient from glanceclient import client as glanceclient from keystoneclient.v2_0 import client as keystoneclient from neutronclient.v2_0 import client as neutronclient @@ -103,6 +104,15 @@ def get_nova_client(): return novaclient.Client('2', **creds_nova) +def get_cinder_client(): + creds_cinder = get_credentials("cinder") + return cinderclient.Client('2', creds_cinder['username'], + creds_cinder['api_key'], + creds_cinder['project_id'], + creds_cinder['auth_url'], + service_type="volume") + + def get_neutron_client(): creds_neutron = get_credentials("neutron") return neutronclient.Client(**creds_neutron) |