diff options
author | spisarski <s.pisarski@cablelabs.com> | 2018-03-09 14:42:34 -0700 |
---|---|---|
committer | spisarski <s.pisarski@cablelabs.com> | 2018-03-12 08:28:45 -0600 |
commit | 9e9e09590cce321f55996c1a31370ffdf28251b0 (patch) | |
tree | a0e031d0365604f4a299ad8f748fe10d09a75a8a | |
parent | fb0ab37c323717ca10ac3f3bda24ae390635495e (diff) |
Closing keystone sessions after done with them.
By not closing all of the keystone sessions being created when
running all of the tests, this may be the root cause to the IOError
occasionally being observed:
IOError: [Errno 24] Too many open files
JIRA: SNAPS-285
Change-Id: I7fc7ab0c6cdd02f1ae32bb3ae4f121cb465d5693
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
50 files changed, 617 insertions, 331 deletions
diff --git a/snaps/config/network.py b/snaps/config/network.py index 5f18c6b..8148c61 100644 --- a/snaps/config/network.py +++ b/snaps/config/network.py @@ -98,11 +98,15 @@ class NetworkConfig(object): return self.project_id else: if self.project_name: - keystone = keystone_utils.keystone_client(os_creds) - project = keystone_utils.get_project( - keystone=keystone, project_name=self.project_name) - if project: - return project.id + session = keystone_utils.keystone_session(os_creds) + keystone = keystone_utils.keystone_client(os_creds, session) + try: + project = keystone_utils.get_project( + keystone=keystone, project_name=self.project_name) + if project: + return project.id + finally: + keystone_utils.close_session(session) return None @@ -255,9 +259,13 @@ class SubnetConfig(object): if self.name: out['name'] = self.name if self.project_name: - keystone = keystone_utils.keystone_client(os_creds) - project = keystone_utils.get_project( - keystone=keystone, project_name=self.project_name) + session = keystone_utils.keystone_session(os_creds) + keystone = keystone_utils.keystone_client(os_creds, session) + try: + project = keystone_utils.get_project( + keystone=keystone, project_name=self.project_name) + finally: + keystone_utils.close_session(session) project_id = None if project: project_id = project.id @@ -441,10 +449,15 @@ class PortConfig(object): out = dict() - keystone = keystone_utils.keystone_client(os_creds) - network = neutron_utils.get_network( - neutron, keystone, network_name=self.network_name, - project_name=self.project_name) + session = keystone_utils.keystone_session(os_creds) + keystone = keystone_utils.keystone_client(os_creds, session) + try: + network = neutron_utils.get_network( + neutron, keystone, network_name=self.network_name, + project_name=self.project_name) + finally: + keystone_utils.close_session(session) + if not network: raise PortConfigError( 'Cannot locate network with name - ' + self.network_name diff --git a/snaps/config/router.py b/snaps/config/router.py index f5bbbf0..6b03ad2 100644 --- a/snaps/config/router.py +++ b/snaps/config/router.py @@ -78,31 +78,34 @@ class RouterConfig(object): out = dict() ext_gw = dict() - keystone = keystone_utils.keystone_client(os_creds) - - if self.name: - out['name'] = self.name - if self.project_name: - project = keystone_utils.get_project( - keystone=keystone, project_name=self.project_name) - if project: - out['tenant_id'] = project.id - else: - raise RouterConfigError( - 'Could not find project ID for project named - ' + - self.project_name) - if self.admin_state_up is not None: - out['admin_state_up'] = self.admin_state_up - if self.external_gateway: - ext_net = neutron_utils.get_network( - neutron, keystone, network_name=self.external_gateway) - if ext_net: - ext_gw['network_id'] = ext_net.id - out['external_gateway_info'] = ext_gw - else: - raise RouterConfigError( - 'Could not find the external network named - ' + - self.external_gateway) + session = keystone_utils.keystone_session(os_creds) + keystone = keystone_utils.keystone_client(os_creds, session) + try: + if self.name: + out['name'] = self.name + if self.project_name: + project = keystone_utils.get_project( + keystone=keystone, project_name=self.project_name) + if project: + out['tenant_id'] = project.id + else: + raise RouterConfigError( + 'Could not find project ID for project named - ' + + self.project_name) + if self.admin_state_up is not None: + out['admin_state_up'] = self.admin_state_up + if self.external_gateway: + ext_net = neutron_utils.get_network( + neutron, keystone, network_name=self.external_gateway) + if ext_net: + ext_gw['network_id'] = ext_net.id + out['external_gateway_info'] = ext_gw + else: + raise RouterConfigError( + 'Could not find the external network named - ' + + self.external_gateway) + finally: + keystone_utils.close_session(session) return {'router': out} diff --git a/snaps/domain/network.py b/snaps/domain/network.py index aabec21..a028e2b 100644 --- a/snaps/domain/network.py +++ b/snaps/domain/network.py @@ -46,7 +46,6 @@ class Network: self.admin_state_up == other.admin_state_up and self.shared == other.shared and self.external == other.external and - self.type == other.type and self.subnets == other.subnets) diff --git a/snaps/openstack/cluster_template.py b/snaps/openstack/cluster_template.py index c4ba76d..f6c7aa2 100644 --- a/snaps/openstack/cluster_template.py +++ b/snaps/openstack/cluster_template.py @@ -85,6 +85,8 @@ class OpenStackClusterTemplate(OpenStackMagnumObject): self.__cluster_template = None + super(self.__class__, self).clean() + def get_cluster_template(self): """ Returns the domain Volume object as it was populated when create() was diff --git a/snaps/openstack/create_flavor.py b/snaps/openstack/create_flavor.py index 65b9059..48b3e7c 100644 --- a/snaps/openstack/create_flavor.py +++ b/snaps/openstack/create_flavor.py @@ -87,6 +87,8 @@ class OpenStackFlavor(OpenStackComputeObject): self.__flavor = None + super(self.__class__, self).clean() + def get_flavor(self): """ Returns the OpenStack flavor object diff --git a/snaps/openstack/create_image.py b/snaps/openstack/create_image.py index a5520e3..1a8aa12 100644 --- a/snaps/openstack/create_image.py +++ b/snaps/openstack/create_image.py @@ -54,7 +54,10 @@ class OpenStackImage(OpenStackCloudObject): Loads the existing Image :return: The Image domain object or None """ - self.__glance = glance_utils.glance_client(self._os_creds) + super(self.__class__, self).initialize() + + self.__glance = glance_utils.glance_client( + self._os_creds, self._os_session) self.__image = glance_utils.get_image( self.__glance, image_settings=self.image_settings) @@ -145,6 +148,11 @@ class OpenStackImage(OpenStackCloudObject): self.__kernel_image = None self.__ramdisk_image = None + if self.__glance: + self.__glance.http_client.session.session.close() + + super(self.__class__, self).clean() + def get_image(self): """ Returns the domain Image object as it was populated when create() was diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py index a964723..45666d5 100644 --- a/snaps/openstack/create_instance.py +++ b/snaps/openstack/create_instance.py @@ -73,8 +73,14 @@ class OpenStackVmInstance(OpenStackComputeObject): """ super(self.__class__, self).initialize() - 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.__cinder = cinder_utils.cinder_client( + self._os_creds, self._os_session) + self.__glance = glance_utils.glance_client( + self._os_creds, self._os_session) self.__ports = self.__query_ports(self.instance_settings.port_settings) self.__lookup_existing_vm_by_name() @@ -134,9 +140,8 @@ class OpenStackVmInstance(OpenStackComputeObject): active, error, or timeout waiting. Floating IPs will be assigned after active when block=True """ - glance = glance_utils.glance_client(self._os_creds) self.__vm = nova_utils.create_server( - self._nova, self.__keystone, self.__neutron, glance, + self._nova, self.__keystone, self.__neutron, self.__glance, self.instance_settings, self.image_settings, self._os_creds.project_name, self.keypair_settings) logger.info('Created instance with name - %s', @@ -162,9 +167,8 @@ class OpenStackVmInstance(OpenStackComputeObject): if self.instance_settings.volume_names: for volume_name in self.instance_settings.volume_names: - cinder = cinder_utils.cinder_client(self._os_creds) volume = cinder_utils.get_volume( - cinder, self.__keystone, volume_name=volume_name, + self.__cinder, self.__keystone, volume_name=volume_name, project_name=self._os_creds.project_name) if volume and self.vm_active(block=True): @@ -271,9 +275,8 @@ class OpenStackVmInstance(OpenStackComputeObject): if self.__vm: # Detach Volume for volume_rec in self.__vm.volume_ids: - cinder = cinder_utils.cinder_client(self._os_creds) volume = cinder_utils.get_volume_by_id( - cinder, volume_rec['id']) + self.__cinder, volume_rec['id']) if volume: vm = nova_utils.detach_volume( self._nova, self.__neutron, self.__keystone, self.__vm, @@ -310,6 +313,8 @@ class OpenStackVmInstance(OpenStackComputeObject): 'VM not deleted within the timeout period of %s ' 'seconds', self.instance_settings.vm_delete_timeout) + super(self.__class__, self).clean() + def __query_ports(self, port_settings): """ Returns the previously configured ports or an empty list if none @@ -795,16 +800,21 @@ def generate_creator(os_creds, vm_inst, image_config, project_name, :param keypair_config: the associated KeypairConfig object (optional) :return: an initialized OpenStackVmInstance object """ - nova = nova_utils.nova_client(os_creds) - keystone = keystone_utils.keystone_client(os_creds) - neutron = neutron_utils.neutron_client(os_creds) - derived_inst_config = settings_utils.create_vm_inst_config( - nova, keystone, neutron, vm_inst, project_name) - - derived_inst_creator = OpenStackVmInstance( - os_creds, derived_inst_config, image_config, keypair_config) - derived_inst_creator.initialize() - return derived_inst_creator + session = keystone_utils.keystone_session(os_creds) + nova = nova_utils.nova_client(os_creds, session) + keystone = keystone_utils.keystone_client(os_creds, session) + neutron = neutron_utils.neutron_client(os_creds, session) + + try: + derived_inst_config = settings_utils.create_vm_inst_config( + nova, keystone, neutron, vm_inst, project_name) + + derived_inst_creator = OpenStackVmInstance( + os_creds, derived_inst_config, image_config, keypair_config) + derived_inst_creator.initialize() + return derived_inst_creator + finally: + keystone_utils.close_session(session) class VmInstanceSettings(VmInstanceConfig): diff --git a/snaps/openstack/create_keypairs.py b/snaps/openstack/create_keypairs.py index a181a7b..b037c3f 100644 --- a/snaps/openstack/create_keypairs.py +++ b/snaps/openstack/create_keypairs.py @@ -133,6 +133,8 @@ class OpenStackKeypair(OpenStackComputeObject): os.remove(expanded_path) logger.info('Deleted private key file [%s]', expanded_path) + super(self.__class__, self).clean() + def get_keypair(self): """ Returns the OpenStack keypair object diff --git a/snaps/openstack/create_network.py b/snaps/openstack/create_network.py index 3d50eb5..13c9667 100644 --- a/snaps/openstack/create_network.py +++ b/snaps/openstack/create_network.py @@ -19,7 +19,7 @@ from neutronclient.common.exceptions import NetworkNotFoundClient, Unauthorized from snaps.config.network import NetworkConfig, SubnetConfig, PortConfig from snaps.openstack.openstack_creator import OpenStackNetworkObject -from snaps.openstack.utils import neutron_utils, keystone_utils +from snaps.openstack.utils import neutron_utils __author__ = 'spisarski' @@ -52,9 +52,8 @@ class OpenStackNetwork(OpenStackNetworkObject): super(self.__class__, self).initialize() try: - keystone = keystone_utils.keystone_client(self._os_creds) self.__network = neutron_utils.get_network( - self._neutron, keystone, + self._neutron, self._keystone, network_settings=self.network_settings, project_name=self._os_creds.project_name) except Unauthorized as e: @@ -83,12 +82,13 @@ class OpenStackNetwork(OpenStackNetworkObject): """ Removes and deletes all items created in reverse order. """ - if self.__network: - try: - neutron_utils.delete_network(self._neutron, self.__network) - except NetworkNotFoundClient: - pass - self.__network = None + try: + neutron_utils.delete_network(self._neutron, self.__network) + except NetworkNotFoundClient: + pass + self.__network = None + + super(self.__class__, self).clean() def get_network(self): """ diff --git a/snaps/openstack/create_project.py b/snaps/openstack/create_project.py index e871118..c20fe5e 100644 --- a/snaps/openstack/create_project.py +++ b/snaps/openstack/create_project.py @@ -83,16 +83,20 @@ class OpenStackProject(OpenStackIdentityObject): """ if self.__project: # Delete security group 'default' if exists - neutron = neutron_utils.neutron_client(self._os_creds) - default_sec_grp = neutron_utils.get_security_group( - neutron, self._keystone, sec_grp_name='default', - project_name=self.__project.name) - if default_sec_grp: - try: - neutron_utils.delete_security_group( - neutron, default_sec_grp) - except: - pass + neutron = neutron_utils.neutron_client( + self._os_creds, self._os_session) + try: + default_sec_grp = neutron_utils.get_security_group( + neutron, self._keystone, sec_grp_name='default', + project_name=self.__project.name) + if default_sec_grp: + try: + neutron_utils.delete_security_group( + neutron, default_sec_grp) + except: + pass + finally: + neutron.httpclient.session.session.close() # Delete Project try: @@ -114,6 +118,8 @@ class OpenStackProject(OpenStackIdentityObject): if role: keystone_utils.delete_role(self._keystone, role) + super(self.__class__, self).clean() + def get_project(self): """ Returns the OpenStack project object populated on create() @@ -142,32 +148,48 @@ class OpenStackProject(OpenStackIdentityObject): Returns the compute quotas as an instance of the ComputeQuotas class :return: """ - nova = nova_utils.nova_client(self._os_creds) - return nova_utils.get_compute_quotas(nova, self.__project.id) + nova = nova_utils.nova_client(self._os_creds, self._os_session) + + try: + return nova_utils.get_compute_quotas(nova, self.__project.id) + finally: + nova.client.session.session.close() def get_network_quotas(self): """ Returns the network quotas as an instance of the NetworkQuotas class :return: """ - neutron = neutron_utils.neutron_client(self._os_creds) - return neutron_utils.get_network_quotas(neutron, self.__project.id) + neutron = neutron_utils.neutron_client( + self._os_creds, self._os_session) + try: + return neutron_utils.get_network_quotas(neutron, self.__project.id) + finally: + neutron.httpclient.session.session.close() def update_compute_quotas(self, compute_quotas): """ Updates the compute quotas for this project :param compute_quotas: a ComputeQuotas object. """ - nova = nova_utils.nova_client(self._os_creds) - nova_utils.update_quotas(nova, self.__project.id, compute_quotas) + nova = nova_utils.nova_client(self._os_creds, self._os_session) + try: + nova_utils.update_quotas(nova, self.__project.id, compute_quotas) + finally: + nova.client.session.session.close() def update_network_quotas(self, network_quotas): """ Updates the network quotas for this project :param network_quotas: a NetworkQuotas object. """ - neutron = neutron_utils.neutron_client(self._os_creds) - neutron_utils.update_quotas(neutron, self.__project.id, network_quotas) + neutron = neutron_utils.neutron_client( + self._os_creds, self._os_session) + try: + neutron_utils.update_quotas( + neutron, self.__project.id, network_quotas) + finally: + neutron.httpclient.session.session.close() class ProjectSettings(ProjectConfig): @@ -181,4 +203,4 @@ class ProjectSettings(ProjectConfig): from warnings import warn warn('Use snaps.config.project.ProjectConfig instead', DeprecationWarning) - super(self.__class__, self).__init__(**kwargs)
\ No newline at end of file + super(self.__class__, self).__init__(**kwargs) diff --git a/snaps/openstack/create_qos.py b/snaps/openstack/create_qos.py index 44e35a3..7764a57 100644 --- a/snaps/openstack/create_qos.py +++ b/snaps/openstack/create_qos.py @@ -90,6 +90,8 @@ class OpenStackQoS(OpenStackVolumeObject): self.__qos = None + super(self.__class__, self).clean() + def get_qos(self): """ Returns the domain QoS object as it was populated when create() was diff --git a/snaps/openstack/create_router.py b/snaps/openstack/create_router.py index 50c0b28..4395059 100644 --- a/snaps/openstack/create_router.py +++ b/snaps/openstack/create_router.py @@ -43,8 +43,6 @@ class OpenStackRouter(OpenStackNetworkObject): if not router_settings: raise RouterCreationError('router_settings is required') - self.__keystone = None - self.router_settings = router_settings # Attributes instantiated on create() @@ -63,11 +61,9 @@ class OpenStackRouter(OpenStackNetworkObject): """ super(self.__class__, self).initialize() - self.__keystone = keystone_utils.keystone_client(self._os_creds) - try: self.__router = neutron_utils.get_router( - self._neutron, self.__keystone, + self._neutron, self._keystone, router_settings=self.router_settings, project_name=self._os_creds.project_name) except Unauthorized as e: @@ -86,7 +82,7 @@ class OpenStackRouter(OpenStackNetworkObject): for port_setting in self.router_settings.port_settings: port = neutron_utils.get_port( - self._neutron, self.__keystone, port_settings=port_setting, + self._neutron, self._keystone, port_settings=port_setting, project_name=self._os_creds.project_name) if port: self.__ports.append(port) @@ -121,7 +117,7 @@ class OpenStackRouter(OpenStackNetworkObject): for port_setting in self.router_settings.port_settings: port = neutron_utils.get_port( - self._neutron, self.__keystone, port_settings=port_setting, + self._neutron, self._keystone, port_settings=port_setting, project_name=self._os_creds.project_name) logger.info( 'Retrieved port %s for router - %s', port_setting.name, @@ -184,6 +180,8 @@ class OpenStackRouter(OpenStackNetworkObject): pass self.__router = None + super(self.__class__, self).clean() + def get_router(self): """ Returns the OpenStack router object diff --git a/snaps/openstack/create_security_group.py b/snaps/openstack/create_security_group.py index eecf789..490f419 100644 --- a/snaps/openstack/create_security_group.py +++ b/snaps/openstack/create_security_group.py @@ -20,7 +20,6 @@ from neutronclient.common.exceptions import NotFound, Conflict from snaps.config.security_group import ( SecurityGroupConfig, SecurityGroupRuleConfig) from snaps.openstack.openstack_creator import OpenStackNetworkObject -from snaps.openstack.utils import keystone_utils from snaps.openstack.utils import neutron_utils __author__ = 'spisarski' @@ -56,9 +55,9 @@ class OpenStackSecurityGroup(OpenStackNetworkObject): """ super(self.__class__, self).initialize() - keystone = keystone_utils.keystone_client(self._os_creds) self.__security_group = neutron_utils.get_security_group( - self._neutron, keystone, sec_grp_settings=self.sec_grp_settings, + self._neutron, self._keystone, + sec_grp_settings=self.sec_grp_settings, project_name=self._os_creds.project_name) if self.__security_group: # Populate rules @@ -86,9 +85,8 @@ class OpenStackSecurityGroup(OpenStackNetworkObject): logger.info( 'Creating security group %s...' % self.sec_grp_settings.name) - keystone = keystone_utils.keystone_client(self._os_creds) self.__security_group = neutron_utils.create_security_group( - self._neutron, keystone, self.sec_grp_settings) + self._neutron, self._keystone, self.sec_grp_settings) # Get the rules added for free auto_rules = neutron_utils.get_rules_by_security_group( @@ -104,7 +102,7 @@ class OpenStackSecurityGroup(OpenStackNetworkObject): for sec_grp_rule_setting in self.sec_grp_settings.rule_settings: try: custom_rule = neutron_utils.create_security_group_rule( - self._neutron, keystone, sec_grp_rule_setting, + self._neutron, self._keystone, sec_grp_rule_setting, self._os_creds.project_name) self.__rules[sec_grp_rule_setting] = custom_rule except Conflict as e: @@ -161,6 +159,8 @@ class OpenStackSecurityGroup(OpenStackNetworkObject): self.__security_group = None + super(self.__class__, self).clean() + def get_security_group(self): """ Returns the OpenStack security group object @@ -181,9 +181,9 @@ class OpenStackSecurityGroup(OpenStackNetworkObject): :param rule_setting: the rule configuration """ rule_setting.sec_grp_name = self.sec_grp_settings.name - keystone = keystone_utils.keystone_client(self._os_creds) new_rule = neutron_utils.create_security_group_rule( - self._neutron, keystone, rule_setting, self._os_creds.project_name) + self._neutron, self._keystone, rule_setting, + self._os_creds.project_name) self.__rules[rule_setting] = new_rule self.sec_grp_settings.rule_settings.append(rule_setting) diff --git a/snaps/openstack/create_stack.py b/snaps/openstack/create_stack.py index aff10b7..12ce602 100644 --- a/snaps/openstack/create_stack.py +++ b/snaps/openstack/create_stack.py @@ -29,7 +29,7 @@ from snaps.openstack.create_volume import OpenStackVolume from snaps.openstack.create_volume_type import OpenStackVolumeType from snaps.openstack.openstack_creator import OpenStackCloudObject from snaps.openstack.utils import ( - nova_utils, settings_utils, glance_utils, cinder_utils, keystone_utils) + nova_utils, settings_utils, glance_utils, cinder_utils) from snaps.openstack.create_network import OpenStackNetwork from snaps.openstack.utils import heat_utils, neutron_utils @@ -73,12 +73,28 @@ class OpenStackHeatStack(OpenStackCloudObject, object): self.__stack = None self.__heat_cli = None + self.__neutron = None + self.__nova = None + self.__glance = None + self.__cinder = None + def initialize(self): """ Loads the existing heat stack :return: The Stack domain object or None """ - self.__heat_cli = heat_utils.heat_client(self._os_creds) + super(self.__class__, self).initialize() + + self.__neutron = neutron_utils.neutron_client( + self._os_creds, self._os_session) + self.__nova = nova_utils.nova_client(self._os_creds, self._os_session) + self.__glance = glance_utils.glance_client( + self._os_creds, self._os_session) + self.__cinder = cinder_utils.cinder_client( + self._os_creds, self._os_session) + + self.__heat_cli = heat_utils.heat_client( + self._os_creds, self._os_session) self.__stack = heat_utils.get_stack( self.__heat_cli, stack_settings=self.stack_settings) if self.__stack: @@ -152,6 +168,13 @@ class OpenStackHeatStack(OpenStackCloudObject, object): self.__stack = None + self.__neutron.httpclient.session.session.close() + self.__nova.client.session.session.close() + self.__glance.http_client.session.session.close() + self.__cinder.client.session.session.close() + + super(self.__class__, self).clean() + def get_stack(self): """ Returns the domain Stack object as it was populated when create() was @@ -219,15 +242,13 @@ class OpenStackHeatStack(OpenStackCloudObject, object): :return: list() of OpenStackNetwork objects """ - neutron = neutron_utils.neutron_client(self._os_creds) - out = list() stack_networks = heat_utils.get_stack_networks( - self.__heat_cli, neutron, self.__stack) + self.__heat_cli, self.__neutron, self.__stack) for stack_network in stack_networks: net_settings = settings_utils.create_network_config( - neutron, stack_network) + self.__neutron, stack_network) net_creator = OpenStackNetwork(self._os_creds, net_settings) out.append(net_creator) net_creator.initialize() @@ -241,15 +262,13 @@ class OpenStackHeatStack(OpenStackCloudObject, object): :return: list() of OpenStackNetwork objects """ - neutron = neutron_utils.neutron_client(self._os_creds) - out = list() stack_security_groups = heat_utils.get_stack_security_groups( - self.__heat_cli, neutron, self.__stack) + self.__heat_cli, self.__neutron, self.__stack) for stack_security_group in stack_security_groups: settings = settings_utils.create_security_group_config( - neutron, stack_security_group) + self.__neutron, stack_security_group) creator = OpenStackSecurityGroup(self._os_creds, settings) out.append(creator) creator.initialize() @@ -263,15 +282,13 @@ class OpenStackHeatStack(OpenStackCloudObject, object): :return: list() of OpenStackRouter objects """ - neutron = neutron_utils.neutron_client(self._os_creds) - out = list() stack_routers = heat_utils.get_stack_routers( - self.__heat_cli, neutron, self.__stack) + self.__heat_cli, self.__neutron, self.__stack) for routers in stack_routers: settings = settings_utils.create_router_config( - neutron, routers) + self.__neutron, routers) creator = OpenStackRouter(self._os_creds, settings) out.append(creator) creator.initialize() @@ -287,21 +304,16 @@ class OpenStackHeatStack(OpenStackCloudObject, object): out = list() - nova = nova_utils.nova_client(self._os_creds) - keystone = keystone_utils.keystone_client(self._os_creds) - neutron = neutron_utils.neutron_client(self._os_creds) stack_servers = heat_utils.get_stack_servers( - self.__heat_cli, nova, neutron, keystone, self.__stack, - self._os_creds.project_name) - - glance = glance_utils.glance_client(self._os_creds) + self.__heat_cli, self.__nova, self.__neutron, self._keystone, + self.__stack, self._os_creds.project_name) for stack_server in stack_servers: vm_inst_settings = settings_utils.create_vm_inst_config( - nova, keystone, neutron, stack_server, + self.__nova, self._keystone, self.__neutron, stack_server, self._os_creds.project_name) image_settings = settings_utils.determine_image_config( - glance, stack_server, self.image_settings) + self.__glance, stack_server, self.image_settings) keypair_settings = settings_utils.determine_keypair_config( self.__heat_cli, self.__stack, stack_server, keypair_settings=self.keypair_settings, @@ -322,10 +334,8 @@ class OpenStackHeatStack(OpenStackCloudObject, object): """ out = list() - cinder = cinder_utils.cinder_client(self._os_creds) - volumes = heat_utils.get_stack_volumes( - self.__heat_cli, cinder, self.__stack) + self.__heat_cli, self.__cinder, self.__stack) for volume in volumes: settings = settings_utils.create_volume_config(volume) @@ -348,10 +358,8 @@ class OpenStackHeatStack(OpenStackCloudObject, object): """ out = list() - cinder = cinder_utils.cinder_client(self._os_creds) - vol_types = heat_utils.get_stack_volume_types( - self.__heat_cli, cinder, self.__stack) + self.__heat_cli, self.__cinder, self.__stack) for volume in vol_types: settings = settings_utils.create_volume_type_config(volume) @@ -375,10 +383,9 @@ class OpenStackHeatStack(OpenStackCloudObject, object): """ out = list() - nova = nova_utils.nova_client(self._os_creds) keypairs = heat_utils.get_stack_keypairs( - self.__heat_cli, nova, self.__stack) + self.__heat_cli, self.__nova, self.__stack) for keypair in keypairs: settings = settings_utils.create_keypair_config( @@ -403,10 +410,9 @@ class OpenStackHeatStack(OpenStackCloudObject, object): """ out = list() - nova = nova_utils.nova_client(self._os_creds) flavors = heat_utils.get_stack_flavors( - self.__heat_cli, nova, self.__stack) + self.__heat_cli, self.__nova, self.__stack) for flavor in flavors: settings = settings_utils.create_flavor_config(flavor) diff --git a/snaps/openstack/create_user.py b/snaps/openstack/create_user.py index aefebe4..b187f4e 100644 --- a/snaps/openstack/create_user.py +++ b/snaps/openstack/create_user.py @@ -77,6 +77,8 @@ class OpenStackUser(OpenStackIdentityObject): pass self.__user = None + super(self.__class__, self).clean() + def get_user(self): """ Returns the OpenStack user object populated in create() diff --git a/snaps/openstack/create_volume.py b/snaps/openstack/create_volume.py index 656df80..b35cd89 100644 --- a/snaps/openstack/create_volume.py +++ b/snaps/openstack/create_volume.py @@ -20,7 +20,7 @@ from cinderclient.exceptions import NotFound from snaps.config.volume import VolumeConfig from snaps.openstack.openstack_creator import OpenStackVolumeObject -from snaps.openstack.utils import cinder_utils, keystone_utils +from snaps.openstack.utils import cinder_utils __author__ = 'spisarski' @@ -51,7 +51,6 @@ class OpenStackVolume(OpenStackVolumeObject): self.volume_settings = volume_settings self.__volume = None - self.__keystone = None def initialize(self): """ @@ -60,9 +59,8 @@ class OpenStackVolume(OpenStackVolumeObject): """ super(self.__class__, self).initialize() - self.__keystone = keystone_utils.keystone_client(self._os_creds) self.__volume = cinder_utils.get_volume( - self._cinder, self.__keystone, + self._cinder, self._keystone, volume_settings=self.volume_settings, project_name=self._os_creds.project_name) return self.__volume @@ -77,7 +75,7 @@ class OpenStackVolume(OpenStackVolumeObject): if not self.__volume: self.__volume = cinder_utils.create_volume( - self._cinder, self.__keystone, self.volume_settings) + self._cinder, self._keystone, self.volume_settings) logger.info( 'Created volume with name - %s', self.volume_settings.name) @@ -128,6 +126,8 @@ class OpenStackVolume(OpenStackVolumeObject): self.__volume = None + super(self.__class__, self).clean() + def get_volume(self): """ Returns the domain Volume object as it was populated when create() was diff --git a/snaps/openstack/create_volume_type.py b/snaps/openstack/create_volume_type.py index a7198d8..9a45561 100644 --- a/snaps/openstack/create_volume_type.py +++ b/snaps/openstack/create_volume_type.py @@ -87,6 +87,8 @@ class OpenStackVolumeType(OpenStackVolumeObject): self.__volume_type = None + super(self.__class__, self).clean() + def get_volume_type(self): """ Returns the domain Volume object as it was populated when create() was diff --git a/snaps/openstack/openstack_creator.py b/snaps/openstack/openstack_creator.py index cf741f3..9bd099b 100644 --- a/snaps/openstack/openstack_creator.py +++ b/snaps/openstack/openstack_creator.py @@ -30,15 +30,20 @@ class OpenStackCloudObject(CloudObject): :param os_creds: the OpenStack credentials object """ self._os_creds = os_creds + self._os_session = None + self._keystone = None def initialize(self): - raise NotImplementedError('Do not override abstract method') + self._os_session = keystone_utils.keystone_session(self._os_creds) + self._keystone = keystone_utils.keystone_client( + self._os_creds, session=self._os_session) def create(self): raise NotImplementedError('Do not override abstract method') def clean(self): - raise NotImplementedError('Do not override abstract method') + if self._os_session: + keystone_utils.close_session(self._os_session) class OpenStackComputeObject(OpenStackCloudObject): @@ -55,14 +60,12 @@ class OpenStackComputeObject(OpenStackCloudObject): self._nova = None def initialize(self): - self._nova = nova_utils.nova_client(self._os_creds) + super(OpenStackComputeObject, self).initialize() + self._nova = nova_utils.nova_client(self._os_creds, self._os_session) def create(self): raise NotImplementedError('Do not override abstract method') - def clean(self): - raise NotImplementedError('Do not override abstract method') - class OpenStackNetworkObject(OpenStackCloudObject): """ @@ -78,14 +81,13 @@ class OpenStackNetworkObject(OpenStackCloudObject): self._neutron = None def initialize(self): - self._neutron = neutron_utils.neutron_client(self._os_creds) + super(OpenStackNetworkObject, self).initialize() + self._neutron = neutron_utils.neutron_client( + self._os_creds, self._os_session) def create(self): raise NotImplementedError('Do not override abstract method') - def clean(self): - raise NotImplementedError('Do not override abstract method') - class OpenStackIdentityObject(OpenStackCloudObject): """ @@ -98,17 +100,13 @@ class OpenStackIdentityObject(OpenStackCloudObject): :param os_creds: the OpenStack credentials object """ super(OpenStackIdentityObject, self).__init__(os_creds) - self._keystone = None def initialize(self): - self._keystone = keystone_utils.keystone_client(self._os_creds) + super(OpenStackIdentityObject, self).initialize() def create(self): raise NotImplementedError('Do not override abstract method') - def clean(self): - raise NotImplementedError('Do not override abstract method') - class OpenStackVolumeObject(OpenStackCloudObject): """ @@ -124,14 +122,13 @@ class OpenStackVolumeObject(OpenStackCloudObject): self._cinder = None def initialize(self): - self._cinder = cinder_utils.cinder_client(self._os_creds) + super(OpenStackVolumeObject, self).initialize() + self._cinder = cinder_utils.cinder_client( + self._os_creds, self._os_session) def create(self): raise NotImplementedError('Do not override abstract method') - def clean(self): - raise NotImplementedError('Do not override abstract method') - class OpenStackMagnumObject(OpenStackCloudObject): """ @@ -147,10 +144,9 @@ class OpenStackMagnumObject(OpenStackCloudObject): self._magnum = None def initialize(self): - self._magnum = magnum_utils.magnum_client(self._os_creds) + super(OpenStackMagnumObject, self).initialize() + self._magnum = magnum_utils.magnum_client( + self._os_creds, self._os_session) def create(self): raise NotImplementedError('Do not override abstract method') - - def clean(self): - raise NotImplementedError('Do not override abstract method') diff --git a/snaps/openstack/tests/cluster_template_tests.py b/snaps/openstack/tests/cluster_template_tests.py index 355467d..b08f260 100644 --- a/snaps/openstack/tests/cluster_template_tests.py +++ b/snaps/openstack/tests/cluster_template_tests.py @@ -54,7 +54,8 @@ class CreateClusterTemplateTests(OSIntegrationTestCase): 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: diff --git a/snaps/openstack/tests/create_flavor_tests.py b/snaps/openstack/tests/create_flavor_tests.py index f84355d..453509b 100644 --- a/snaps/openstack/tests/create_flavor_tests.py +++ b/snaps/openstack/tests/create_flavor_tests.py @@ -274,7 +274,7 @@ class CreateFlavorTests(OSComponentTestCase): guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.flavor_name = guid + 'name' - self.nova = nova_utils.nova_client(self.os_creds) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) # Initialize for cleanup self.flavor_creator = None @@ -286,6 +286,8 @@ class CreateFlavorTests(OSComponentTestCase): if self.flavor_creator: self.flavor_creator.clean() + super(self.__class__, self).__clean__() + def test_create_flavor(self): """ Tests the creation of an OpenStack flavor. diff --git a/snaps/openstack/tests/create_image_tests.py b/snaps/openstack/tests/create_image_tests.py index 9965f87..ae59a67 100644 --- a/snaps/openstack/tests/create_image_tests.py +++ b/snaps/openstack/tests/create_image_tests.py @@ -265,7 +265,8 @@ class CreateImageSuccessTests(OSIntegrationTestCase): guid = uuid.uuid4() self.image_name = self.__class__.__name__ + '-' + str(guid) - self.glance = glance_utils.glance_client(self.os_creds) + self.glance = glance_utils.glance_client( + self.os_creds, self.os_session) self.image_creator = None if self.image_metadata and 'glance_tests' in self.image_metadata: @@ -379,8 +380,8 @@ class CreateImageSuccessTests(OSIntegrationTestCase): clean() does not raise an Exception. """ # Create Image - self.image_creator = create_image.OpenStackImage(self.os_creds, - self.image_settings) + self.image_creator = create_image.OpenStackImage( + self.os_creds, self.image_settings) created_image = self.image_creator.create() self.assertIsNotNone(created_image) @@ -562,7 +563,8 @@ class CreateMultiPartImageTests(OSIntegrationTestCase): guid = uuid.uuid4() self.image_creators = list() self.image_name = self.__class__.__name__ + '-' + str(guid) - self.glance = glance_utils.glance_client(self.os_creds) + self.glance = glance_utils.glance_client( + self.os_creds, self.os_session) self.tmp_dir = 'tmp/' + str(guid) if not os.path.exists(self.tmp_dir): diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py index 12ae10b..6005f98 100644 --- a/snaps/openstack/tests/create_instance_tests.py +++ b/snaps/openstack/tests/create_instance_tests.py @@ -50,6 +50,7 @@ from snaps.openstack.tests.os_source_file_test import ( OSIntegrationTestCase, OSComponentTestCase) from snaps.openstack.utils import nova_utils, keystone_utils, neutron_utils from snaps.openstack.utils.nova_utils import RebootType +from snaps.openstack.utils import nova_utils, settings_utils, neutron_utils __author__ = 'spisarski' @@ -293,7 +294,7 @@ class SimpleHealthCheck(OSIntegrationTestCase): """ super(self.__class__, self).__start__() - self.nova = nova_utils.nova_client(self.os_creds) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.vm_inst_name = guid + '-inst' self.port_1_name = guid + 'port-1' @@ -512,9 +513,10 @@ class CreateInstanceSimpleTests(OSIntegrationTestCase): self.image_creator.image_settings) vm_inst = self.inst_creator.create(block=True) - self.assertIsNotNone(nova_utils.get_server( + vm_inst_get = nova_utils.get_server( self.nova, self.neutron, self.keystone, - vm_inst_settings=instance_settings)) + vm_inst_settings=instance_settings) + self.assertEqual(vm_inst, vm_inst_get) self.assertIsNotNone(self.inst_creator.get_vm_inst().availability_zone) self.assertIsNone(self.inst_creator.get_vm_inst().compute_host) @@ -590,7 +592,7 @@ class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): """ super(self.__class__, self).__start__() - self.nova = nova_utils.nova_client(self.os_creds) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.keypair_priv_filepath = 'tmp/' + guid self.keypair_pub_filepath = self.keypair_priv_filepath + '.pub' @@ -1016,7 +1018,7 @@ class CreateInstanceIPv6NetworkTests(OSIntegrationTestCase): """ super(self.__class__, self).__start__() - self.nova = nova_utils.nova_client(self.os_creds) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.keypair_priv_filepath = 'tmp/' + self.guid self.keypair_pub_filepath = self.keypair_priv_filepath + '.pub' @@ -1621,7 +1623,8 @@ class CreateInstanceOnComputeHost(OSIntegrationTestCase): Tests the creation of OpenStack VM instances to each compute node. """ from snaps.openstack.utils import nova_utils - nova = nova_utils.nova_client(self.admin_os_creds) + nova = nova_utils.nova_client( + self.admin_os_creds, self.admin_os_session) zone_hosts = nova_utils.get_availability_zone_hosts(nova) # Create Instance on each server/zone @@ -1675,7 +1678,7 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.vm_inst_name = self.guid + '-inst' - self.nova = nova_utils.nova_client(self.os_creds) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) os_image_settings = openstack_tests.cirros_image_settings( name=self.guid + '-image', image_metadata=self.image_metadata) @@ -2006,7 +2009,7 @@ class CreateInstanceFromThreePartImage(OSIntegrationTestCase): guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.image_name = guid self.vm_inst_name = guid + '-inst' - self.nova = nova_utils.nova_client(self.os_creds) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) net_config = openstack_tests.get_priv_net_config( net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet', @@ -2216,6 +2219,8 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): if os.path.exists(self.tmpDir) and os.path.isdir(self.tmpDir): shutil.rmtree(self.tmpDir) + super(self.__class__, self).__clean__() + def test_inst_from_file_image_simple_flat(self): """ Creates a VM instance from a locally sourced file image using simply @@ -2636,7 +2641,7 @@ class CreateInstanceTwoNetTests(OSIntegrationTestCase): self.ip1 = '10.200.201.5' self.ip2 = '10.200.202.5' - self.nova = nova_utils.nova_client(self.os_creds) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) # Initialize for tearDown() self.image_creator = None @@ -2858,8 +2863,10 @@ class CreateInstanceVolumeTests(OSIntegrationTestCase): guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.vm_inst_name = guid + '-inst' - self.nova = nova_utils.nova_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.neutron = neutron_utils.neutron_client( + self.os_creds, self.os_session) os_image_settings = openstack_tests.cirros_image_settings( name=guid + '-image', image_metadata=self.image_metadata) diff --git a/snaps/openstack/tests/create_keypairs_tests.py b/snaps/openstack/tests/create_keypairs_tests.py index 63e0bcc..44214d0 100644 --- a/snaps/openstack/tests/create_keypairs_tests.py +++ b/snaps/openstack/tests/create_keypairs_tests.py @@ -200,7 +200,7 @@ class CreateKeypairsTests(OSIntegrationTestCase): guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.priv_file_path = 'tmp/' + guid self.pub_file_path = self.priv_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.keypair_name = guid self.keypair_creator = None @@ -370,7 +370,7 @@ class CreateKeypairsCleanupTests(OSIntegrationTestCase): guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.priv_file_path = 'tmp/' + guid self.pub_file_path = self.priv_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.keypair_name = guid self.keypair_creator = None diff --git a/snaps/openstack/tests/create_network_tests.py b/snaps/openstack/tests/create_network_tests.py index a863a05..d326889 100644 --- a/snaps/openstack/tests/create_network_tests.py +++ b/snaps/openstack/tests/create_network_tests.py @@ -369,7 +369,8 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): router_name=guid + '-pub-router', external_net=self.ext_net_name, netconf_override=self.netconf_override) - self.neutron = neutron_utils.neutron_client(self.os_creds) + self.neutron = neutron_utils.neutron_client( + self.os_creds, self.os_session) # Initialize for cleanup self.net_creator = None @@ -576,7 +577,8 @@ class CreateNetworkGatewayTests(OSIntegrationTestCase): 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.ip_prfx = '10.1.0.' @@ -708,7 +710,8 @@ class CreateNetworkIPv6Tests(OSIntegrationTestCase): super(self.__class__, self).__start__() 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) # Initialize for cleanup self.net_creator = None @@ -811,8 +814,10 @@ class CreateNetworkTypeTests(OSComponentTestCase): self.net_config = openstack_tests.get_pub_net_config( net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet') - 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) # Initialize for cleanup self.net_creator = None @@ -824,6 +829,8 @@ class CreateNetworkTypeTests(OSComponentTestCase): if self.net_creator: self.net_creator.clean() + super(self.__class__, self).__clean__() + def test_create_network_type_vlan(self): """ Tests the creation of an OpenStack network of type vlan. @@ -954,7 +961,8 @@ class CreateMultipleNetworkTests(OSIntegrationTestCase): self.net_config = openstack_tests.get_pub_net_config( net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet') - self.neutron = neutron_utils.neutron_client(self.os_creds) + self.neutron = neutron_utils.neutron_client( + self.os_creds, self.os_session) # Initialize for cleanup self.admin_net_creator = None diff --git a/snaps/openstack/tests/create_project_tests.py b/snaps/openstack/tests/create_project_tests.py index 2c10311..41e58fc 100644 --- a/snaps/openstack/tests/create_project_tests.py +++ b/snaps/openstack/tests/create_project_tests.py @@ -99,7 +99,8 @@ class CreateProjectSuccessTests(OSComponentTestCase): name=guid + '-name', domain=self.os_creds.project_domain_name) - self.keystone = keystone_utils.keystone_client(self.os_creds) + self.keystone = keystone_utils.keystone_client( + self.os_creds, self.os_session) # Initialize for cleanup self.project_creator = None @@ -111,6 +112,8 @@ class CreateProjectSuccessTests(OSComponentTestCase): if self.project_creator: self.project_creator.clean() + super(self.__class__, self).__clean__() + def test_create_project_bad_domain(self): """ Tests the creation of an OpenStack project with an invalid domain @@ -214,12 +217,12 @@ class CreateProjectSuccessTests(OSComponentTestCase): self.assertEqual(update_network_quotas, self.project_creator.get_network_quotas()) - nova = nova_utils.nova_client(self.os_creds) + nova = nova_utils.nova_client(self.os_creds, self.os_session) new_compute_quotas = nova_utils.get_compute_quotas( nova, self.project_creator.get_project().id) self.assertEqual(update_compute_quotas, new_compute_quotas) - neutron = neutron_utils.neutron_client(self.os_creds) + neutron = neutron_utils.neutron_client(self.os_creds, self.os_session) new_network_quotas = neutron_utils.get_network_quotas( neutron, self.project_creator.get_project().id) self.assertEqual(update_network_quotas, new_network_quotas) @@ -241,7 +244,8 @@ class CreateProjectUserTests(OSComponentTestCase): name=self.guid + '-name', domain=self.os_creds.project_domain_name) - self.keystone = keystone_utils.keystone_client(self.os_creds) + self.keystone = keystone_utils.keystone_client( + self.os_creds, self.os_session) # Initialize for cleanup self.project_creator = None @@ -262,6 +266,8 @@ class CreateProjectUserTests(OSComponentTestCase): if self.project_creator: self.project_creator.clean() + super(self.__class__, self).__clean__() + def test_create_project_sec_grp_one_user(self): """ Tests the creation of an OpenStack object to a project with a new users diff --git a/snaps/openstack/tests/create_qos_tests.py b/snaps/openstack/tests/create_qos_tests.py index 1d7fbd0..b3d7979 100644 --- a/snaps/openstack/tests/create_qos_tests.py +++ b/snaps/openstack/tests/create_qos_tests.py @@ -126,7 +126,8 @@ class CreateQoSTests(OSIntegrationTestCase): name=self.__class__.__name__ + '-' + str(guid), consumer=Consumer.both) - self.cinder = cinder_utils.cinder_client(self.admin_os_creds) + self.cinder = cinder_utils.cinder_client( + self.admin_os_creds, self.admin_os_session) self.qos_creator = create_qos.OpenStackQoS( self.admin_os_creds, qos_settings) diff --git a/snaps/openstack/tests/create_router_tests.py b/snaps/openstack/tests/create_router_tests.py index d605916..439d9e3 100644 --- a/snaps/openstack/tests/create_router_tests.py +++ b/snaps/openstack/tests/create_router_tests.py @@ -130,7 +130,8 @@ class CreateRouterSuccessTests(OSIntegrationTestCase): self.router_creator = None self.network_creator1 = None self.network_creator2 = 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): """ @@ -515,7 +516,8 @@ class CreateMultipleRouterTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.admin_router_creator = None self.proj_router_creator = None - self.neutron = neutron_utils.neutron_client(self.os_creds) + self.neutron = neutron_utils.neutron_client( + self.os_creds, self.os_session) network_settings = NetworkConfig( name=self.guid + '-pub-net', shared=True, @@ -623,7 +625,8 @@ class CreateRouterSecurityGroupTests(OSIntegrationTestCase): self.os_creds, SecurityGroupConfig(name=self.guid + '-sec_grp')) self.sec_grp_creator.create() - self.neutron = neutron_utils.neutron_client(self.os_creds) + self.neutron = neutron_utils.neutron_client( + self.os_creds, self.os_session) def tearDown(self): """ diff --git a/snaps/openstack/tests/create_security_group_tests.py b/snaps/openstack/tests/create_security_group_tests.py index 6f0fdec..dc632b7 100644 --- a/snaps/openstack/tests/create_security_group_tests.py +++ b/snaps/openstack/tests/create_security_group_tests.py @@ -210,7 +210,8 @@ class CreateSecurityGroupTests(OSIntegrationTestCase): guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.sec_grp_name = guid + 'name' - self.neutron = neutron_utils.neutron_client(self.os_creds) + self.neutron = neutron_utils.neutron_client( + self.os_creds, self.os_session) # Initialize for cleanup self.sec_grp_creator = None @@ -697,7 +698,8 @@ class CreateMultipleSecurityGroupTests(OSIntegrationTestCase): guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.sec_grp_name = guid + 'name' - self.neutron = neutron_utils.neutron_client(self.os_creds) + self.neutron = neutron_utils.neutron_client( + self.os_creds, self.os_session) # Initialize for cleanup self.admin_sec_grp_config = SecurityGroupConfig( diff --git a/snaps/openstack/tests/create_stack_tests.py b/snaps/openstack/tests/create_stack_tests.py index ad8ac31..f728211 100644 --- a/snaps/openstack/tests/create_stack_tests.py +++ b/snaps/openstack/tests/create_stack_tests.py @@ -139,7 +139,7 @@ class CreateStackSuccessTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) self.stack_creator = None self.image_creator = OpenStackImage( @@ -351,8 +351,10 @@ class CreateStackSuccessTests(OSIntegrationTestCase): # Need to use 'admin' creds as heat creates objects under it's own # project/tenant - 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) net_by_name = neutron_utils.get_network( neutron, keystone, network_name=net_creators[0].get_network().name) self.assertEqual(net_creators[0].get_network(), net_by_name) @@ -389,9 +391,9 @@ class CreateStackSuccessTests(OSIntegrationTestCase): self.assertEqual(self.vm_inst_name, vm_inst_creators[0].get_vm_inst().name) - nova = nova_utils.nova_client(self.os_creds) - neutron = neutron_utils.neutron_client(self.os_creds) - keystone = keystone_utils.keystone_client(self.os_creds) + nova = nova_utils.nova_client(self.os_creds, self.os_session) + neutron = neutron_utils.neutron_client(self.os_creds, self.os_session) + keystone = keystone_utils.keystone_client(self.os_creds, self.os_session) vm_inst_by_name = nova_utils.get_server( nova, neutron, keystone, server_name=vm_inst_creators[0].get_vm_inst().name) @@ -414,7 +416,7 @@ class CreateStackFloatingIpTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) self.stack_creator = None self.image_creator = OpenStackImage( @@ -521,7 +523,7 @@ class CreateStackNestedResourceTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) self.stack_creator = None self.image_creator = OpenStackImage( @@ -632,8 +634,9 @@ class CreateStackRouterTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) - self.neutron = neutron_utils.neutron_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) + self.neutron = neutron_utils.neutron_client( + self.os_creds, self.os_session) self.stack_creator = None self.net_name = self.guid + '-net' @@ -702,7 +705,7 @@ class CreateStackVolumeTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) self.stack_creator = None self.volume_name = self.guid + '-volume' @@ -796,7 +799,7 @@ class CreateStackFlavorTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) self.stack_creator = None self.heat_tmplt_path = pkg_resources.resource_filename( @@ -855,8 +858,8 @@ class CreateStackKeypairTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) - self.nova = nova_utils.nova_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) self.stack_creator = None self.keypair_name = self.guid + '-kp' @@ -939,8 +942,8 @@ class CreateStackSecurityGroupTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) - self.nova = nova_utils.nova_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) self.stack_creator = None self.security_group_name = self.guid + '-sec-grp' @@ -1034,6 +1037,7 @@ class CreateStackNegativeTests(OSIntegrationTestCase): def tearDown(self): if self.stack_creator: self.stack_creator.clean() + super(self.__class__, self).__clean__() def test_missing_dependencies(self): @@ -1073,7 +1077,7 @@ class CreateStackFailureTests(OSIntegrationTestCase): self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) - self.heat_cli = heat_utils.heat_client(self.os_creds) + self.heat_cli = heat_utils.heat_client(self.os_creds, self.os_session) self.stack_creator = None self.tmp_file = file_utils.save_string_to_file( diff --git a/snaps/openstack/tests/create_user_tests.py b/snaps/openstack/tests/create_user_tests.py index d3eb4a6..718d5a3 100644 --- a/snaps/openstack/tests/create_user_tests.py +++ b/snaps/openstack/tests/create_user_tests.py @@ -109,7 +109,7 @@ class CreateUserSuccessTests(OSComponentTestCase): roles={'admin': self.os_creds.project_name}, domain_name=self.os_creds.user_domain_name) - self.keystone = keystone_utils.keystone_client(self.os_creds) + self.keystone = keystone_utils.keystone_client(self.os_creds, self.os_session) # Initialize for cleanup self.user_creator = None @@ -121,6 +121,8 @@ class CreateUserSuccessTests(OSComponentTestCase): if self.user_creator: self.user_creator.clean() + super(self.__class__, self).__clean__() + def test_create_user(self): """ Tests the creation of an OpenStack user. diff --git a/snaps/openstack/tests/create_volume_tests.py b/snaps/openstack/tests/create_volume_tests.py index cf90b6e..4392245 100644 --- a/snaps/openstack/tests/create_volume_tests.py +++ b/snaps/openstack/tests/create_volume_tests.py @@ -129,8 +129,10 @@ class CreateSimpleVolumeSuccessTests(OSIntegrationTestCase): self.volume_settings = VolumeConfig( name=self.__class__.__name__ + '-' + str(guid)) - 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) self.volume_creator = None def tearDown(self): @@ -223,7 +225,8 @@ class CreateSimpleVolumeFailureTests(OSIntegrationTestCase): super(self.__class__, self).__start__() self.guid = uuid.uuid4() - self.cinder = cinder_utils.cinder_client(self.os_creds) + self.cinder = cinder_utils.cinder_client( + self.os_creds, self.os_session) self.volume_creator = None def tearDown(self): @@ -353,7 +356,8 @@ class CreateVolumeWithImageTests(OSIntegrationTestCase): def setUp(self): super(self.__class__, self).__start__() - self.cinder = cinder_utils.cinder_client(self.os_creds) + self.cinder = cinder_utils.cinder_client( + self.os_creds, self.os_session) guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.volume_name = guid + '-vol' @@ -465,12 +469,14 @@ class CreateVolMultipleCredsTests(OSIntegrationTestCase): admin_vol = self.volume_creators[0].create(block=True) self.assertIsNotNone(admin_vol) - admin_key = keystone_utils.keystone_client(self.admin_os_creds) + admin_key = keystone_utils.keystone_client( + self.admin_os_creds, self.admin_os_session) admin_proj = keystone_utils.get_project( admin_key, project_name=self.admin_os_creds.project_name) self.assertEqual(admin_vol.project_id, admin_proj.id) - admin_cinder = cinder_utils.cinder_client(self.admin_os_creds) + admin_cinder = cinder_utils.cinder_client( + self.admin_os_creds, self.admin_os_session) admin_vol_get = cinder_utils.get_volume( admin_cinder, admin_key, volume_name=vol_name, project_name=self.admin_os_creds.project_name) @@ -484,8 +490,10 @@ class CreateVolMultipleCredsTests(OSIntegrationTestCase): self.assertNotEqual(admin_vol, proj_vol) - proj_key = keystone_utils.keystone_client(self.os_creds) - proj_cinder = cinder_utils.cinder_client(self.os_creds) + proj_key = keystone_utils.keystone_client( + self.os_creds, self.os_session) + proj_cinder = cinder_utils.cinder_client( + self.os_creds, self.os_session) proj_vol_get = cinder_utils.get_volume( proj_cinder, proj_key, volume_name=vol_name, project_name=self.os_creds.project_name) diff --git a/snaps/openstack/tests/create_volume_type_tests.py b/snaps/openstack/tests/create_volume_type_tests.py index 5e78ee9..b797274 100644 --- a/snaps/openstack/tests/create_volume_type_tests.py +++ b/snaps/openstack/tests/create_volume_type_tests.py @@ -127,7 +127,8 @@ class CreateSimpleVolumeTypeSuccessTests(OSIntegrationTestCase): self.volume_type_settings = VolumeTypeConfig( name=self.__class__.__name__ + '-' + str(guid)) - self.cinder = cinder_utils.cinder_client(self.admin_os_creds) + self.cinder = cinder_utils.cinder_client( + self.admin_os_creds, self.admin_os_session) self.volume_type_creator = OpenStackVolumeType( self.admin_os_creds, self.volume_type_settings) @@ -211,7 +212,8 @@ class CreateVolumeTypeComplexTests(OSIntegrationTestCase): def setUp(self): super(self.__class__, self).__start__() - self.cinder = cinder_utils.cinder_client(self.admin_os_creds) + self.cinder = cinder_utils.cinder_client( + self.admin_os_creds, self.admin_os_session) guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) diff --git a/snaps/openstack/tests/os_source_file_test.py b/snaps/openstack/tests/os_source_file_test.py index b361ea8..51b9400 100644 --- a/snaps/openstack/tests/os_source_file_test.py +++ b/snaps/openstack/tests/os_source_file_test.py @@ -53,6 +53,7 @@ class OSComponentTestCase(unittest.TestCase): self.os_creds = openstack_tests.get_credentials( dev_os_env_file=dev_os_env_file) + self.os_session = keystone_utils.keystone_session(self.os_creds) self.ext_net_name = ext_net_name if not self.ext_net_name and file_utils.file_exists(dev_os_env_file): @@ -76,6 +77,14 @@ class OSComponentTestCase(unittest.TestCase): return suite + def __clean__(self): + """ + Cleans up keystone session. + """ + if self.os_session: + keystone_utils.close_session(self.os_session) + + class OSIntegrationTestCase(OSComponentTestCase): def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None, @@ -144,9 +153,13 @@ class OSIntegrationTestCase(OSComponentTestCase): self.project_creator = None self.user_creator = None self.admin_os_creds = self.os_creds + self.admin_os_session = self.os_session + keystone_utils.keystone_session( + self.admin_os_creds) if self.use_keystone: - self.keystone = keystone_utils.keystone_client(self.admin_os_creds) + self.keystone = keystone_utils.keystone_client( + self.admin_os_creds, self.admin_os_session) guid = self.__class__.__name__ + '-' + str(uuid.uuid4())[:-19] project_name = guid + '-proj' self.project_creator = deploy_utils.create_project( @@ -168,6 +181,7 @@ class OSIntegrationTestCase(OSComponentTestCase): self.os_creds = self.user_creator.get_os_creds( self.project_creator.project_settings.name) + self.os_session = keystone_utils.keystone_session(self.os_creds) # add user to project self.project_creator.assoc_user(self.user_creator.get_user()) @@ -184,3 +198,9 @@ class OSIntegrationTestCase(OSComponentTestCase): if self.user_creator: self.user_creator.clean() + + if self.admin_os_session: + keystone_utils.close_session(self.admin_os_session) + + super(OSIntegrationTestCase, self).__clean__() + 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): """ diff --git a/snaps/provisioning/tests/ansible_utils_tests.py b/snaps/provisioning/tests/ansible_utils_tests.py index 851dd64..14fe8e9 100644 --- a/snaps/provisioning/tests/ansible_utils_tests.py +++ b/snaps/provisioning/tests/ansible_utils_tests.py @@ -58,7 +58,7 @@ class AnsibleProvisioningTests(OSIntegrationTestCase): """ super(self.__class__, self).__start__() - self.nova = nova_utils.nova_client(self.os_creds) + self.nova = nova_utils.nova_client(self.os_creds, self.os_session) guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.keypair_priv_filepath = 'tmp/' + guid |