summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils
diff options
context:
space:
mode:
Diffstat (limited to 'snaps/openstack/utils')
-rw-r--r--snaps/openstack/utils/cinder_utils.py9
-rw-r--r--snaps/openstack/utils/glance_utils.py9
-rw-r--r--snaps/openstack/utils/heat_utils.py6
-rw-r--r--snaps/openstack/utils/keystone_utils.py19
-rw-r--r--snaps/openstack/utils/launch_utils.py30
-rw-r--r--snaps/openstack/utils/magnum_utils.py9
-rw-r--r--snaps/openstack/utils/neutron_utils.py7
-rw-r--r--snaps/openstack/utils/nova_utils.py8
-rw-r--r--snaps/openstack/utils/tests/cinder_utils_tests.py28
-rw-r--r--snaps/openstack/utils/tests/glance_utils_tests.py7
-rw-r--r--snaps/openstack/utils/tests/heat_utils_tests.py84
-rw-r--r--snaps/openstack/utils/tests/keystone_utils_tests.py11
-rw-r--r--snaps/openstack/utils/tests/magnum_utils_tests.py8
-rw-r--r--snaps/openstack/utils/tests/neutron_utils_tests.py52
-rw-r--r--snaps/openstack/utils/tests/nova_utils_tests.py55
-rw-r--r--snaps/openstack/utils/tests/settings_utils_tests.py19
16 files changed, 256 insertions, 105 deletions
diff --git a/snaps/openstack/utils/cinder_utils.py b/snaps/openstack/utils/cinder_utils.py
index 246245e..61abe22 100644
--- a/snaps/openstack/utils/cinder_utils.py
+++ b/snaps/openstack/utils/cinder_utils.py
@@ -33,13 +33,18 @@ Utilities for basic neutron API calls
"""
-def cinder_client(os_creds):
+def cinder_client(os_creds, session=None):
"""
Creates and returns a cinder client object
+ :param os_creds: the credentials for connecting to the OpenStack remote API
+ :param session: the keystone session object (optional)
:return: the cinder client
"""
+ if not session:
+ session = keystone_utils.keystone_session(os_creds)
+
return Client(version=os_creds.volume_api_version,
- session=keystone_utils.keystone_session(os_creds),
+ session=session,
region_name=os_creds.region_name)
diff --git a/snaps/openstack/utils/glance_utils.py b/snaps/openstack/utils/glance_utils.py
index a127ad3..db20f2f 100644
--- a/snaps/openstack/utils/glance_utils.py
+++ b/snaps/openstack/utils/glance_utils.py
@@ -34,13 +34,18 @@ Utilities for basic neutron API calls
"""
-def glance_client(os_creds):
+def glance_client(os_creds, session=None):
"""
Creates and returns a glance client object
+ :param os_creds: the credentials for connecting to the OpenStack remote API
+ :param session: the keystone session object (optional)
:return: the glance client
"""
+ if not session:
+ session = keystone_utils.keystone_session(os_creds)
+
return Client(version=os_creds.image_api_version,
- session=keystone_utils.keystone_session(os_creds),
+ session=session,
region_name=os_creds.region_name)
diff --git a/snaps/openstack/utils/heat_utils.py b/snaps/openstack/utils/heat_utils.py
index d42eefa..3d62fdf 100644
--- a/snaps/openstack/utils/heat_utils.py
+++ b/snaps/openstack/utils/heat_utils.py
@@ -32,15 +32,17 @@ __author__ = 'spisarski'
logger = logging.getLogger('heat_utils')
-def heat_client(os_creds):
+def heat_client(os_creds, session=None):
"""
Retrieves the Heat client
:param os_creds: the OpenStack credentials
:return: the client
"""
logger.debug('Retrieving Heat Client')
+ if not session:
+ session = keystone_utils.keystone_session(os_creds)
return Client(os_creds.heat_api_version,
- session=keystone_utils.keystone_session(os_creds),
+ session=session,
region_name=os_creds.region_name)
diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py
index 263f823..52c86d8 100644
--- a/snaps/openstack/utils/keystone_utils.py
+++ b/snaps/openstack/utils/keystone_utils.py
@@ -14,6 +14,7 @@
# limitations under the License.
import logging
+import keystoneauth1
from keystoneclient.client import Client
from keystoneauth1.identity import v3, v2
from keystoneauth1 import session
@@ -78,15 +79,29 @@ def keystone_session(os_creds):
verify=os_creds.cacert)
-def keystone_client(os_creds):
+def close_session(session):
+ """
+ Closes a keystone session
+ :param session: a session.Session object
+ """
+ if isinstance(session, keystoneauth1.session.Session):
+ session.session.close()
+
+
+def keystone_client(os_creds, session=None):
"""
Returns the keystone client
:param os_creds: the OpenStack credentials (OSCreds) object
+ :param session: the keystone session object (optional)
:return: the client
"""
+
+ if not session:
+ session = keystone_session(os_creds)
+
return Client(
version=os_creds.identity_api_version,
- session=keystone_session(os_creds),
+ session=session,
interface=os_creds.interface,
region_name=os_creds.region_name)
diff --git a/snaps/openstack/utils/launch_utils.py b/snaps/openstack/utils/launch_utils.py
index 1899ef6..fd78bd2 100644
--- a/snaps/openstack/utils/launch_utils.py
+++ b/snaps/openstack/utils/launch_utils.py
@@ -48,7 +48,7 @@ from snaps.openstack.create_user import OpenStackUser
from snaps.openstack.create_volume import OpenStackVolume
from snaps.openstack.create_volume_type import OpenStackVolumeType
from snaps.openstack.os_credentials import OSCreds, ProxySettings
-from snaps.openstack.utils import deploy_utils, neutron_utils
+from snaps.openstack.utils import deploy_utils, neutron_utils, keystone_utils
from snaps.provisioning import ansible_utils
logger = logging.getLogger('lanuch_utils')
@@ -713,18 +713,22 @@ def __get_router_variable_value(var_config_values, routers_dict, os_creds):
if router_creator:
if 'external_fixed_ip' == var_config_values.get('attr'):
- neutron = neutron_utils.neutron_client(os_creds)
- ext_nets = neutron_utils.get_external_networks(neutron)
-
- subnet_name = var_config_values.get('subnet_name')
-
- for ext_net in ext_nets:
- for subnet in ext_net.subnets:
- if subnet_name == subnet.name:
- router = router_creator.get_router()
- for fixed_ips in router.external_fixed_ips:
- if subnet.id == fixed_ips['subnet_id']:
- return fixed_ips['ip_address']
+ session = keystone_utils.keystone_session(os_creds)
+ neutron = neutron_utils.neutron_client(os_creds, session)
+ try:
+ ext_nets = neutron_utils.get_external_networks(neutron)
+
+ subnet_name = var_config_values.get('subnet_name')
+
+ for ext_net in ext_nets:
+ for subnet in ext_net.subnets:
+ if subnet_name == subnet.name:
+ router = router_creator.get_router()
+ for fixed_ips in router.external_fixed_ips:
+ if subnet.id == fixed_ips['subnet_id']:
+ return fixed_ips['ip_address']
+ finally:
+ keystone_utils.close_session(session)
def __get_vm_port_variable_value(var_config_values, vm_dict):
diff --git a/snaps/openstack/utils/magnum_utils.py b/snaps/openstack/utils/magnum_utils.py
index 96ba6d1..1f39cfe 100644
--- a/snaps/openstack/utils/magnum_utils.py
+++ b/snaps/openstack/utils/magnum_utils.py
@@ -24,15 +24,18 @@ __author__ = 'spisarski'
logger = logging.getLogger('magnum_utils')
-def magnum_client(os_creds):
+def magnum_client(os_creds, session=None):
"""
Retrieves the Magnum client
:param os_creds: the OpenStack credentialsf
+ :param session: the keystone session object (optional)
:return: the client
"""
logger.debug('Retrieving Magnum Client')
- return Client(str(os_creds.magnum_api_version),
- session=keystone_utils.keystone_session(os_creds))
+ if not session:
+ session = keystone_utils.keystone_session(os_creds)
+
+ return Client(str(os_creds.magnum_api_version), session=session)
def get_cluster_template(magnum, template_config=None, template_name=None):
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py
index 8685d14..03e24f5 100644
--- a/snaps/openstack/utils/neutron_utils.py
+++ b/snaps/openstack/utils/neutron_utils.py
@@ -33,15 +33,18 @@ Utilities for basic neutron API calls
"""
-def neutron_client(os_creds):
+def neutron_client(os_creds, session=None):
"""
Instantiates and returns a client for communications with OpenStack's
Neutron server
:param os_creds: the credentials for connecting to the OpenStack remote API
+ :param session: the keystone session object (optional)
:return: the client object
"""
+ if not session:
+ session = keystone_utils.keystone_session(os_creds)
return Client(api_version=os_creds.network_api_version,
- session=keystone_utils.keystone_session(os_creds),
+ session=session,
region_name=os_creds.region_name)
diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py
index faa2d75..38460c5 100644
--- a/snaps/openstack/utils/nova_utils.py
+++ b/snaps/openstack/utils/nova_utils.py
@@ -42,16 +42,20 @@ Utilities for basic OpenStack Nova API calls
"""
-def nova_client(os_creds):
+def nova_client(os_creds, session=None):
"""
Instantiates and returns a client for communications with OpenStack's Nova
server
:param os_creds: The connection credentials to the OpenStack API
+ :param session: the keystone session object (optional)
:return: the client object
"""
logger.debug('Retrieving Nova Client')
+ if not session:
+ session = keystone_utils.keystone_session(os_creds)
+
return Client(os_creds.compute_api_version,
- session=keystone_utils.keystone_session(os_creds),
+ session=session,
region_name=os_creds.region_name)
diff --git a/snaps/openstack/utils/tests/cinder_utils_tests.py b/snaps/openstack/utils/tests/cinder_utils_tests.py
index 3004c0f..073d574 100644
--- a/snaps/openstack/utils/tests/cinder_utils_tests.py
+++ b/snaps/openstack/utils/tests/cinder_utils_tests.py
@@ -43,7 +43,7 @@ class CinderSmokeTests(OSComponentTestCase):
"""
Tests to ensure that the proper credentials can connect.
"""
- cinder = cinder_utils.cinder_client(self.os_creds)
+ cinder = cinder_utils.cinder_client(self.os_creds, self.os_session)
volumes = cinder.volumes.list()
self.assertIsNotNone(volumes)
self.assertTrue(isinstance(volumes, list))
@@ -74,8 +74,10 @@ class CinderUtilsVolumeTests(OSComponentTestCase):
guid = uuid.uuid4()
self.volume_name = self.__class__.__name__ + '-' + str(guid)
self.volume = None
- self.cinder = cinder_utils.cinder_client(self.os_creds)
- self.keystone = keystone_utils.keystone_client(self.os_creds)
+ self.cinder = cinder_utils.cinder_client(
+ self.os_creds, self.os_session)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -186,7 +188,8 @@ class CinderUtilsQoSTests(OSComponentTestCase):
self.qos_name = self.__class__.__name__ + '-' + str(guid)
self.specs = {'foo': 'bar '}
self.qos = None
- self.cinder = cinder_utils.cinder_client(self.os_creds)
+ self.cinder = cinder_utils.cinder_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -198,6 +201,8 @@ class CinderUtilsQoSTests(OSComponentTestCase):
except NotFound:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_qos_both(self):
"""
Tests the cinder_utils.create_qos()
@@ -283,7 +288,8 @@ class CinderUtilsSimpleVolumeTypeTests(OSComponentTestCase):
volume_type_name = self.__class__.__name__ + '-' + str(guid)
self.volume_type_settings = VolumeTypeConfig(name=volume_type_name)
self.volume_type = None
- self.cinder = cinder_utils.cinder_client(self.os_creds)
+ self.cinder = cinder_utils.cinder_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -295,6 +301,8 @@ class CinderUtilsSimpleVolumeTypeTests(OSComponentTestCase):
except NotFound:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_simple_volume_type(self):
"""
Tests the cinder_utils.create_volume_type(), get_volume_type(), and
@@ -351,7 +359,8 @@ class CinderUtilsAddEncryptionTests(OSComponentTestCase):
self.encryption_name = self.__class__.__name__ + '-' + str(guid)
self.encryption = None
- self.cinder = cinder_utils.cinder_client(self.os_creds)
+ self.cinder = cinder_utils.cinder_client(
+ self.os_creds, self.os_session)
volume_type_name = self.__class__.__name__ + '-' + str(guid) + '-type'
self.volume_type = cinder_utils.create_volume_type(
@@ -374,6 +383,8 @@ class CinderUtilsAddEncryptionTests(OSComponentTestCase):
except NotFound:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_simple_encryption(self):
"""
Tests the cinder_utils.create_volume_encryption(),
@@ -468,7 +479,8 @@ class CinderUtilsVolumeTypeCompleteTests(OSComponentTestCase):
self.qos_name = self.__class__.__name__ + '-' + str(guid) + '-qos'
self.vol_type_name = self.__class__.__name__ + '-' + str(guid)
self.specs = {'foo': 'bar'}
- self.cinder = cinder_utils.cinder_client(self.os_creds)
+ self.cinder = cinder_utils.cinder_client(
+ self.os_creds, self.os_session)
qos_settings = QoSConfig(
name=self.qos_name, specs=self.specs, consumer=Consumer.both)
self.qos = cinder_utils.create_qos(self.cinder, qos_settings)
@@ -496,6 +508,8 @@ class CinderUtilsVolumeTypeCompleteTests(OSComponentTestCase):
except NotFound:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_with_encryption(self):
"""
Tests the cinder_utils.create_volume_type() where encryption has been
diff --git a/snaps/openstack/utils/tests/glance_utils_tests.py b/snaps/openstack/utils/tests/glance_utils_tests.py
index e61b795..e761ed8 100644
--- a/snaps/openstack/utils/tests/glance_utils_tests.py
+++ b/snaps/openstack/utils/tests/glance_utils_tests.py
@@ -39,7 +39,7 @@ class GlanceSmokeTests(OSComponentTestCase):
"""
Tests to ensure that the proper credentials can connect.
"""
- glance = glance_utils.glance_client(self.os_creds)
+ glance = glance_utils.glance_client(self.os_creds, self.os_session)
image = glance_utils.get_image(glance, image_name='foo')
self.assertIsNone(image)
@@ -69,7 +69,8 @@ class GlanceUtilsTests(OSComponentTestCase):
guid = uuid.uuid4()
self.image_name = self.__class__.__name__ + '-' + str(guid)
self.image = None
- self.glance = glance_utils.glance_client(self.os_creds)
+ self.glance = glance_utils.glance_client(
+ self.os_creds, self.os_session)
if self.image_metadata:
self.glance_test_meta = self.image_metadata.get('glance_tests')
else:
@@ -89,6 +90,8 @@ class GlanceUtilsTests(OSComponentTestCase):
if os.path.exists(self.tmp_dir) and os.path.isdir(self.tmp_dir):
shutil.rmtree(self.tmp_dir)
+ super(self.__class__, self).__clean__()
+
def test_create_image_minimal_url(self):
"""
Tests the glance_utils.create_image() function with a URL unless the
diff --git a/snaps/openstack/utils/tests/heat_utils_tests.py b/snaps/openstack/utils/tests/heat_utils_tests.py
index cad3fc2..081736a 100644
--- a/snaps/openstack/utils/tests/heat_utils_tests.py
+++ b/snaps/openstack/utils/tests/heat_utils_tests.py
@@ -47,7 +47,7 @@ class HeatSmokeTests(OSComponentTestCase):
"""
Tests to ensure that the proper credentials can connect.
"""
- heat = heat_utils.heat_client(self.os_creds)
+ heat = heat_utils.heat_client(self.os_creds, self.os_session)
# This should not throw an exception
stacks = heat.stacks.list()
@@ -115,7 +115,8 @@ class HeatUtilsCreateSimpleStackTests(OSComponentTestCase):
env_values=env_values)
self.stack1 = None
self.stack2 = None
- self.heat_client = heat_utils.heat_client(self.os_creds)
+ self.heat_client = heat_utils.heat_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -145,6 +146,8 @@ class HeatUtilsCreateSimpleStackTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_stack(self):
"""
Tests the creation of an OpenStack Heat stack1 that does not exist.
@@ -174,7 +177,7 @@ class HeatUtilsCreateSimpleStackTests(OSComponentTestCase):
self.assertTrue(stack_active(self.heat_client, self.stack1))
- neutron = neutron_utils.neutron_client(self.os_creds)
+ neutron = neutron_utils.neutron_client(self.os_creds, self.os_session)
networks = heat_utils.get_stack_networks(
self.heat_client, neutron, self.stack1)
self.assertIsNotNone(networks)
@@ -185,8 +188,9 @@ class HeatUtilsCreateSimpleStackTests(OSComponentTestCase):
self.assertEqual(1, len(subnets))
self.assertEqual(self.subnet_name, subnets[0].name)
- nova = nova_utils.nova_client(self.os_creds)
- keystone = keystone_utils.keystone_client(self.os_creds)
+ nova = nova_utils.nova_client(self.os_creds, self.os_session)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
servers = heat_utils.get_stack_servers(
self.heat_client, nova, neutron, keystone, self.stack1,
self.os_creds.project_name)
@@ -277,7 +281,8 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase):
stack_settings = StackConfig(
name=stack_name, template_path=heat_tmplt_path,
env_values=env_values)
- self.heat_client = heat_utils.heat_client(self.os_creds)
+ self.heat_client = heat_utils.heat_client(
+ self.os_creds, self.os_session)
self.stack = heat_utils.create_stack(self.heat_client, stack_settings)
self.assertTrue(stack_active(self.heat_client, self.stack))
@@ -309,10 +314,15 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase):
time.sleep(3)
if not is_deleted:
- nova = nova_utils.nova_client(self.os_creds)
- keystone = keystone_utils.keystone_client(self.os_creds)
- neutron = neutron_utils.neutron_client(self.os_creds)
- glance = glance_utils.glance_client(self.os_creds)
+ nova = nova_utils.nova_client(
+ self.os_creds, self.os_session)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
+ neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+ glance = glance_utils.glance_client(
+ self.os_creds, self.os_session)
+
servers = heat_utils.get_stack_servers(
self.heat_client, nova, neutron, keystone, self.stack,
self.os_creds.project_name)
@@ -359,6 +369,8 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase):
os.chmod(expanded_path, 0o755)
os.remove(expanded_path)
+ super(self.__class__, self).__clean__()
+
def test_get_settings_from_stack(self):
"""
Tests that a heat template with floating IPs and can have the proper
@@ -372,7 +384,7 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase):
self.assertIsNotNone(options)
self.assertEqual(1, len(options))
- neutron = neutron_utils.neutron_client(self.os_creds)
+ neutron = neutron_utils.neutron_client(self.os_creds, self.os_session)
networks = heat_utils.get_stack_networks(
self.heat_client, neutron, self.stack)
self.assertIsNotNone(networks)
@@ -384,9 +396,10 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase):
self.assertIsNotNone(network_settings)
self.assertEqual(self.network_name, network_settings.name)
- nova = nova_utils.nova_client(self.os_creds)
- glance = glance_utils.glance_client(self.os_creds)
- keystone = keystone_utils.keystone_client(self.os_creds)
+ nova = nova_utils.nova_client(self.os_creds, self.os_session)
+ glance = glance_utils.glance_client(self.os_creds, self.os_session)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
servers = heat_utils.get_stack_servers(
self.heat_client, nova, neutron, keystone, self.stack,
self.os_creds.project_name)
@@ -458,8 +471,10 @@ class HeatUtilsRouterTests(OSComponentTestCase):
name=stack_name, template_path=heat_tmplt_path,
env_values=env_values)
self.stack = None
- self.heat_client = heat_utils.heat_client(self.os_creds)
- self.neutron = neutron_utils.neutron_client(self.os_creds)
+ self.heat_client = heat_utils.heat_client(
+ self.os_creds, self.os_session)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -471,6 +486,8 @@ class HeatUtilsRouterTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_router_with_stack(self):
"""
Tests the creation of an OpenStack router with Heat and the retrieval
@@ -504,7 +521,8 @@ class HeatUtilsRouterTests(OSComponentTestCase):
router = routers[0]
self.assertEqual(self.router_name, router.name)
- keystone = keystone_utils.keystone_client(self.os_creds)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
ext_net = neutron_utils.get_network(
self.neutron, keystone, network_name=self.ext_net_name)
self.assertEqual(ext_net.id, router.external_network_id)
@@ -534,8 +552,10 @@ class HeatUtilsVolumeTests(OSComponentTestCase):
name=stack_name, template_path=heat_tmplt_path,
env_values=env_values)
self.stack = None
- self.heat_client = heat_utils.heat_client(self.os_creds)
- self.cinder = cinder_utils.cinder_client(self.os_creds)
+ self.heat_client = heat_utils.heat_client(
+ self.os_creds, self.os_session)
+ self.cinder = cinder_utils.cinder_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -547,6 +567,8 @@ class HeatUtilsVolumeTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_vol_with_stack(self):
"""
Tests the creation of an OpenStack volume with Heat.
@@ -614,8 +636,10 @@ class HeatUtilsFlavorTests(OSComponentTestCase):
self.stack_settings = StackConfig(
name=stack_name, template_path=heat_tmplt_path)
self.stack = None
- self.heat_client = heat_utils.heat_client(self.os_creds)
- self.nova = nova_utils.nova_client(self.os_creds)
+ self.heat_client = heat_utils.heat_client(
+ self.os_creds, self.os_session)
+ self.nova = nova_utils.nova_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -627,6 +651,8 @@ class HeatUtilsFlavorTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_flavor_with_stack(self):
"""
Tests the creation of an OpenStack volume with Heat.
@@ -673,8 +699,10 @@ class HeatUtilsKeypairTests(OSComponentTestCase):
name=stack_name, template_path=heat_tmplt_path,
env_values=env_values)
self.stack = None
- self.heat_client = heat_utils.heat_client(self.os_creds)
- self.nova = nova_utils.nova_client(self.os_creds)
+ self.heat_client = heat_utils.heat_client(
+ self.os_creds, self.os_session)
+ self.nova = nova_utils.nova_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -686,6 +714,8 @@ class HeatUtilsKeypairTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_keypair_with_stack(self):
"""
Tests the creation of an OpenStack keypair with Heat.
@@ -736,8 +766,10 @@ class HeatUtilsSecurityGroupTests(OSComponentTestCase):
name=stack_name, template_path=heat_tmplt_path,
env_values=env_values)
self.stack = None
- self.heat_client = heat_utils.heat_client(self.os_creds)
- self.neutron = neutron_utils.neutron_client(self.os_creds)
+ self.heat_client = heat_utils.heat_client(
+ self.os_creds, self.os_session)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -749,6 +781,8 @@ class HeatUtilsSecurityGroupTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_security_group_with_stack(self):
"""
Tests the creation of an OpenStack SecurityGroup with Heat.
diff --git a/snaps/openstack/utils/tests/keystone_utils_tests.py b/snaps/openstack/utils/tests/keystone_utils_tests.py
index 7ce7a61..cc3a8ad 100644
--- a/snaps/openstack/utils/tests/keystone_utils_tests.py
+++ b/snaps/openstack/utils/tests/keystone_utils_tests.py
@@ -31,7 +31,8 @@ class KeystoneSmokeTests(OSComponentTestCase):
"""
Tests to ensure that the proper credentials can connect.
"""
- keystone = keystone_utils.keystone_client(self.os_creds)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
users = keystone.users.list()
self.assertIsNotNone(users)
@@ -66,14 +67,16 @@ class KeystoneUtilsTests(OSComponentTestCase):
self.project_name = self.guid + '-projName'
self.project = None
self.role = None
- self.keystone = keystone_utils.keystone_client(self.os_creds)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
Cleans the remote OpenStack objects
"""
if self.project:
- neutron = neutron_utils.neutron_client(self.os_creds)
+ neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
default_sec_grp = neutron_utils.get_security_group(
neutron, self.keystone, sec_grp_name='default',
project_name=self.os_creds.project_name)
@@ -92,6 +95,8 @@ class KeystoneUtilsTests(OSComponentTestCase):
if self.role:
keystone_utils.delete_role(self.keystone, self.role)
+ super(self.__class__, self).__clean__()
+
def test_create_user_minimal(self):
"""
Tests the keystone_utils.create_user() function
diff --git a/snaps/openstack/utils/tests/magnum_utils_tests.py b/snaps/openstack/utils/tests/magnum_utils_tests.py
index f841c48..d87d97a 100644
--- a/snaps/openstack/utils/tests/magnum_utils_tests.py
+++ b/snaps/openstack/utils/tests/magnum_utils_tests.py
@@ -44,7 +44,8 @@ class MagnumSmokeTests(OSComponentTestCase):
"""
Tests to ensure that the proper credentials can connect.
"""
- magnum = magnum_utils.magnum_client(self.os_creds)
+ magnum = magnum_utils.magnum_client(
+ self.os_creds, self.os_session)
# This should not throw an exception
self.assertIsNotNone(magnum.clusters.list())
@@ -70,7 +71,8 @@ class MagnumUtilsClusterTypeTests(OSComponentTestCase):
def setUp(self):
self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
self.cluster_type_name = self.guid + '-cluster-type'
- self.magnum = magnum_utils.magnum_client(self.os_creds)
+ self.magnum = magnum_utils.magnum_client(
+ self.os_creds, self.os_session)
metadata = self.image_metadata
if not metadata:
@@ -130,6 +132,8 @@ class MagnumUtilsClusterTypeTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_cluster_template_simple(self):
config = ClusterTemplateConfig(
name=self.cluster_type_name,
diff --git a/snaps/openstack/utils/tests/neutron_utils_tests.py b/snaps/openstack/utils/tests/neutron_utils_tests.py
index 2583a96..cd293ca 100644
--- a/snaps/openstack/utils/tests/neutron_utils_tests.py
+++ b/snaps/openstack/utils/tests/neutron_utils_tests.py
@@ -41,7 +41,7 @@ class NeutronSmokeTests(OSComponentTestCase):
"""
Tests to ensure that the proper credentials can connect.
"""
- neutron = neutron_utils.neutron_client(self.os_creds)
+ neutron = neutron_utils.neutron_client(self.os_creds, self.os_session)
networks = neutron.list_networks()
@@ -70,7 +70,7 @@ class NeutronSmokeTests(OSComponentTestCase):
configured self.ext_net_name is contained within the returned list
:return:
"""
- neutron = neutron_utils.neutron_client(self.os_creds)
+ neutron = neutron_utils.neutron_client(self.os_creds, self.os_session)
ext_networks = neutron_utils.get_external_networks(neutron)
found = False
for network in ext_networks:
@@ -88,8 +88,10 @@ class NeutronUtilsNetworkTests(OSComponentTestCase):
def setUp(self):
guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
self.port_name = str(guid) + '-port'
- self.neutron = neutron_utils.neutron_client(self.os_creds)
- self.keystone = keystone_utils.keystone_client(self.os_creds)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
self.network = None
self.net_config = openstack_tests.get_pub_net_config(
net_name=guid + '-pub-net')
@@ -101,6 +103,8 @@ class NeutronUtilsNetworkTests(OSComponentTestCase):
if self.network:
neutron_utils.delete_network(self.neutron, self.network)
+ super(self.__class__, self).__clean__()
+
def test_create_network(self):
"""
Tests the neutron_utils.create_network() function
@@ -145,8 +149,10 @@ class NeutronUtilsSubnetTests(OSComponentTestCase):
def setUp(self):
guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
self.port_name = str(guid) + '-port'
- self.neutron = neutron_utils.neutron_client(self.os_creds)
- self.keystone = keystone_utils.keystone_client(self.os_creds)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
self.network = None
self.net_config = openstack_tests.get_pub_net_config(
net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet',
@@ -162,6 +168,8 @@ class NeutronUtilsSubnetTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_subnet(self):
"""
Tests the neutron_utils.create_network() function
@@ -264,7 +272,8 @@ class NeutronUtilsIPv6Tests(OSComponentTestCase):
def setUp(self):
self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
- self.neutron = neutron_utils.neutron_client(self.os_creds)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
self.network = None
def tearDown(self):
@@ -277,6 +286,8 @@ class NeutronUtilsIPv6Tests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_network_slaac(self):
"""
Tests the neutron_utils.create_network() with an IPv6 subnet where DHCP
@@ -497,8 +508,10 @@ class NeutronUtilsRouterTests(OSComponentTestCase):
def setUp(self):
guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
self.port_name = str(guid) + '-port'
- self.neutron = neutron_utils.neutron_client(self.os_creds)
- self.keystone = keystone_utils.keystone_client(self.os_creds)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
self.network = None
self.port = None
self.router = None
@@ -533,6 +546,8 @@ class NeutronUtilsRouterTests(OSComponentTestCase):
if self.network:
neutron_utils.delete_network(self.neutron, self.network)
+ super(self.__class__, self).__clean__()
+
def test_create_router_simple(self):
"""
Tests the neutron_utils.create_router()
@@ -856,8 +871,10 @@ class NeutronUtilsSecurityGroupTests(OSComponentTestCase):
self.security_groups = list()
self.security_group_rules = list()
- self.neutron = neutron_utils.neutron_client(self.os_creds)
- self.keystone = keystone_utils.keystone_client(self.os_creds)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -873,6 +890,8 @@ class NeutronUtilsSecurityGroupTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_delete_simple_sec_grp(self):
"""
Tests the neutron_utils.create_security_group() function
@@ -944,7 +963,8 @@ class NeutronUtilsSecurityGroupTests(OSComponentTestCase):
for free_rule in free_rules:
self.security_group_rules.append(free_rule)
- keystone = keystone_utils.keystone_client(self.os_creds)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
self.security_group_rules.append(
neutron_utils.create_security_group_rule(
self.neutron, keystone, sec_grp_settings.rule_settings[0],
@@ -1001,8 +1021,10 @@ class NeutronUtilsFloatingIpTests(OSComponentTestCase):
Instantiates the CreateImage object that is responsible for downloading
and creating an OS image file within OpenStack
"""
- self.neutron = neutron_utils.neutron_client(self.os_creds)
- self.keystone = keystone_utils.keystone_client(self.os_creds)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
self.floating_ip = None
def tearDown(self):
@@ -1016,6 +1038,8 @@ class NeutronUtilsFloatingIpTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_floating_ips(self):
"""
Tests the creation of a floating IP
diff --git a/snaps/openstack/utils/tests/nova_utils_tests.py b/snaps/openstack/utils/tests/nova_utils_tests.py
index 910684c..f5df865 100644
--- a/snaps/openstack/utils/tests/nova_utils_tests.py
+++ b/snaps/openstack/utils/tests/nova_utils_tests.py
@@ -49,7 +49,7 @@ class NovaSmokeTests(OSComponentTestCase):
"""
Tests to ensure that the proper credentials can connect.
"""
- nova = nova_utils.nova_client(self.os_creds)
+ nova = nova_utils.nova_client(self.os_creds, self.os_session)
# This should not throw an exception
nova.flavors.list()
@@ -58,7 +58,7 @@ class NovaSmokeTests(OSComponentTestCase):
"""
Tests to ensure that get_hypervisors() function works.
"""
- nova = nova_utils.nova_client(self.os_creds)
+ nova = nova_utils.nova_client(self.os_creds, self.os_session)
hosts = nova_utils.get_hypervisor_hosts(nova)
# This should not throw an exception
@@ -95,7 +95,7 @@ class NovaUtilsKeypairTests(OSComponentTestCase):
self.priv_key_file_path = 'tmp/' + guid
self.pub_key_file_path = self.priv_key_file_path + '.pub'
- self.nova = nova_utils.nova_client(self.os_creds)
+ self.nova = nova_utils.nova_client(self.os_creds, self.os_session)
self.keys = nova_utils.create_keys()
self.public_key = nova_utils.public_key_openssh(self.keys)
self.keypair_name = guid
@@ -123,6 +123,8 @@ class NovaUtilsKeypairTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_keypair(self):
"""
Tests the creation of an OpenStack keypair that does not exist.
@@ -176,7 +178,7 @@ class NovaUtilsFlavorTests(OSComponentTestCase):
self.flavor_settings = FlavorConfig(
name=guid + '-name', flavor_id=guid + '-id', ram=1, disk=1,
vcpus=1, ephemeral=1, swap=2, rxtx_factor=3.0, is_public=False)
- self.nova = nova_utils.nova_client(self.os_creds)
+ self.nova = nova_utils.nova_client(self.os_creds, self.os_session)
self.flavor = None
def tearDown(self):
@@ -189,6 +191,8 @@ class NovaUtilsFlavorTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_flavor(self):
"""
Tests the creation of an OpenStack keypair that does not exist.
@@ -242,10 +246,14 @@ class NovaUtilsInstanceTests(OSComponentTestCase):
guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
- self.nova = nova_utils.nova_client(self.os_creds)
- self.keystone = keystone_utils.keystone_client(self.os_creds)
- self.neutron = neutron_utils.neutron_client(self.os_creds)
- self.glance = glance_utils.glance_client(self.os_creds)
+ self.nova = nova_utils.nova_client(
+ self.os_creds, self.os_session)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+ self.glance = glance_utils.glance_client(
+ self.os_creds, self.os_session)
self.image_creator = None
self.network_creator = None
@@ -316,6 +324,8 @@ class NovaUtilsInstanceTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_create_instance(self):
"""
Tests the nova_utils.create_server() method
@@ -363,8 +373,9 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase):
guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
- self.nova = nova_utils.nova_client(self.os_creds)
- self.cinder = cinder_utils.cinder_client(self.os_creds)
+ self.nova = nova_utils.nova_client(self.os_creds, self.os_session)
+ self.cinder = cinder_utils.cinder_client(
+ self.os_creds, self.os_session)
self.image_creator = None
self.network_creator = None
@@ -442,6 +453,8 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_add_remove_volume(self):
"""
Tests the nova_utils.attach_volume() and detach_volume functions with
@@ -453,8 +466,10 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase):
self.assertEqual(0, len(self.volume_creator.get_volume().attachments))
# Attach volume to VM
- neutron = neutron_utils.neutron_client(self.os_creds)
- keystone = keystone_utils.keystone_client(self.os_creds)
+ neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
self.assertIsNotNone(nova_utils.attach_volume(
self.nova, neutron, keystone, self.instance_creator.get_vm_inst(),
self.volume_creator.get_volume(), self.os_creds.project_name))
@@ -476,7 +491,8 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase):
self.assertTrue(attached)
self.assertIsNotNone(vol_attach)
- keystone = keystone_utils.keystone_client(self.os_creds)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
vm_attach = nova_utils.get_server_object_by_id(
self.nova, neutron, keystone,
self.instance_creator.get_vm_inst().id, self.os_creds.project_name)
@@ -528,8 +544,9 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase):
self.assertEqual(0, len(self.volume_creator.get_volume().attachments))
# Attach volume to VM
- neutron = neutron_utils.neutron_client(self.os_creds)
- keystone = keystone_utils.keystone_client(self.os_creds)
+ neutron = neutron_utils.neutron_client(self.os_creds, self.os_session)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
with self.assertRaises(NovaException):
nova_utils.attach_volume(
self.nova, neutron, keystone,
@@ -548,14 +565,16 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase):
self.assertEqual(0, len(self.volume_creator.get_volume().attachments))
# Attach volume to VM
- neutron = neutron_utils.neutron_client(self.os_creds)
- keystone = keystone_utils.keystone_client(self.os_creds)
+ neutron = neutron_utils.neutron_client(self.os_creds, self.os_session)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
nova_utils.attach_volume(
self.nova, neutron, keystone, self.instance_creator.get_vm_inst(),
self.volume_creator.get_volume(), self.os_creds.project_name)
# Check VmInst for attachment
- keystone = keystone_utils.keystone_client(self.os_creds)
+ keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
latest_vm = nova_utils.get_server_object_by_id(
self.nova, neutron, keystone,
self.instance_creator.get_vm_inst().id, self.os_creds.project_name)
diff --git a/snaps/openstack/utils/tests/settings_utils_tests.py b/snaps/openstack/utils/tests/settings_utils_tests.py
index 7dc59b5..14af990 100644
--- a/snaps/openstack/utils/tests/settings_utils_tests.py
+++ b/snaps/openstack/utils/tests/settings_utils_tests.py
@@ -58,7 +58,8 @@ class SettingsUtilsNetworkingTests(OSComponentTestCase):
self.network_name = guid + '-net'
self.subnet_name = guid + '-subnet'
self.net_creator = None
- self.neutron = neutron_utils.neutron_client(self.os_creds)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
def tearDown(self):
"""
@@ -70,6 +71,8 @@ class SettingsUtilsNetworkingTests(OSComponentTestCase):
except:
pass
+ super(self.__class__, self).__clean__()
+
def test_derive_net_settings_no_subnet(self):
"""
Validates the utility function settings_utils#create_network_config
@@ -154,10 +157,14 @@ class SettingsUtilsVmInstTests(OSComponentTestCase):
Instantiates the CreateImage object that is responsible for downloading
and creating an OS image file within OpenStack
"""
- self.nova = nova_utils.nova_client(self.os_creds)
- self.keystone = keystone_utils.keystone_client(self.os_creds)
- self.glance = glance_utils.glance_client(self.os_creds)
- self.neutron = neutron_utils.neutron_client(self.os_creds)
+ self.nova = nova_utils.nova_client(
+ self.os_creds, self.os_session)
+ self.keystone = keystone_utils.keystone_client(
+ self.os_creds, self.os_session)
+ self.glance = glance_utils.glance_client(
+ self.os_creds, self.os_session)
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
self.keypair_priv_filepath = 'tmp/' + guid
@@ -315,7 +322,7 @@ class SettingsUtilsVmInstTests(OSComponentTestCase):
if os.path.isfile(self.test_file_local_path):
os.remove(self.test_file_local_path)
- # super(self.__class__, self).__clean__()
+ super(self.__class__, self).__clean__()
def test_derive_vm_inst_config(self):
"""