def test_server_helper_methods(self, mock_ris, mock_osclients, mock_rally_utils, mock_sleep): def _is_ready(resource): return resource.status == "ACTIVE" mock_ris.return_value = _is_ready get_from_mgr = butils.get_from_manager() fc = fakes.FakeClients() mock_osclients.Clients.return_value = fc fake_nova = fakes.FakeNovaClient() fc.get_nova_client = lambda: fake_nova fsm = fakes.FakeServerManager(fake_nova.images) fake_server = fsm.create("s1", "i1", 1) fsm.create = lambda name, iid, fid, **kwargs: fake_server fake_nova.servers = fsm fake_image_id = fsm.create_image(fake_server, 'img') fake_image = fsm.images.get(fake_image_id) fsm.create_image = lambda svr, name: fake_image.id temp_keys = ["username", "password", "tenant_name", "uri"] users_endpoints = [dict(zip(temp_keys, temp_keys))] utils.NovaScenario._clients = butils.\ create_openstack_clients(users_endpoints, temp_keys)[0] utils.utils = mock_rally_utils utils.bench_utils.get_from_manager = lambda: get_from_mgr utils.NovaScenario._boot_server("s1", "i1", 1) utils.NovaScenario._create_image(fake_server) utils.NovaScenario._suspend_server(fake_server) utils.NovaScenario._delete_server(fake_server) expected = [ mock.call.wait_for(fake_server, is_ready=_is_ready, update_resource=butils.get_from_manager(), check_interval=3, timeout=600), mock.call.wait_for(fake_image, is_ready=_is_ready, update_resource=butils.get_from_manager(), check_interval=3, timeout=600), mock.call.wait_for(fake_server, is_ready=_is_ready, update_resource=butils.get_from_manager(), check_interval=3, timeout=600), mock.call.wait_for(fake_server, is_ready=butils.is_none, update_resource=butils.get_from_manager(), check_interval=3, timeout=600) ] self.assertEqual(expected, mock_rally_utils.mock_calls)
def _create_snapshot(self, volume_id, force=False, **kwargs): """Create one snapshot. Returns when the snapshot is actually created and is in the "Available" state. :param volume_id: volume uuid for creating snapshot :param force: flag to indicate whether to snapshot a volume even if it's attached to an instance :param kwargs: Other optional parameters to initialize the volume :returns: Created snapshot object """ kwargs["display_name"] = kwargs.get("display_name", self._generate_random_name()) kwargs["force"] = force snapshot = self.clients("cinder").volume_snapshots.create( volume_id, **kwargs) time.sleep(CONF.benchmark.cinder_volume_create_prepoll_delay) snapshot = bench_utils.wait_for( snapshot, is_ready=bench_utils.resource_is("available"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.cinder_volume_create_timeout, check_interval=CONF.benchmark.cinder_volume_create_poll_interval) return snapshot
def _create_volume(self, size, **kwargs): """Create one volume. Returns when the volume is actually created and is in the "Available" state. :param size: int be size of volume in GB, or dictionary, must contain two values: min - minimum size volumes will be created as; max - maximum size volumes will be created as. :param kwargs: Other optional parameters to initialize the volume :returns: Created volume object """ kwargs["display_name"] = kwargs.get("display_name", self._generate_random_name()) if isinstance(size, dict): size = random.randint(size["min"], size["max"]) volume = self.clients("cinder").volumes.create(size, **kwargs) # NOTE(msdubov): It is reasonable to wait 5 secs before starting to # check whether the volume is ready => less API calls. time.sleep(CONF.benchmark.cinder_volume_create_prepoll_delay) volume = bench_utils.wait_for( volume, is_ready=bench_utils.resource_is("available"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.cinder_volume_create_timeout, check_interval=CONF.benchmark.cinder_volume_create_poll_interval, ) return volume
def _boot_server(self, server_name, image_id, flavor_id, **kwargs): """Boots one server. Returns when the server is actually booted and is in the "Active" state. :param server_name: String used to name the server :param image_id: ID of the image to be used for server creation :param flavor_id: ID of the flavor to be used for server creation :param **kwargs: Other optional parameters to initialize the server :returns: Created server object """ if 'security_groups' not in kwargs: kwargs['security_groups'] = [secgroup.SSH_GROUP_NAME] else: if secgroup.SSH_GROUP_NAME not in kwargs['security_groups']: kwargs['security_groups'].append(secgroup.SSH_GROUP_NAME) server = self.clients("nova").servers.create(server_name, image_id, flavor_id, **kwargs) time.sleep(CONF.benchmark.nova_server_boot_prepoll_delay) server = bench_utils.wait_for( server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_boot_timeout, check_interval=CONF.benchmark.nova_server_boot_poll_interval ) return server
def test_get_from_manager_in_deleted_state(self): get_from_manager = utils.get_from_manager() manager = fakes.FakeManager() resource = fakes.FakeResource(manager=manager, status="DELETED") manager._cache(resource) self.assertRaises(exceptions.GetResourceNotFound, get_from_manager, resource)
def _boot_server(cls, server_name, image_id, flavor_id, **kwargs): """Boots one server. Returns when the server is actually booted and is in the "Active" state. :param server_name: String used to name the server :param image_id: ID of the image to be used for server creation :param flavor_id: ID of the flavor to be used for server creation :param **kwargs: Other optional parameters to initialize the server :returns: Created server object """ if 'security_groups' not in kwargs: kwargs['security_groups'] = ['rally_open'] else: if 'rally_open' not in kwargs['security_groups']: kwargs['security_groups'].append('rally_open') server = cls.clients("nova").servers.create( server_name, image_id, flavor_id, **kwargs) # NOTE(msdubov): It is reasonable to wait 5 secs before starting to # check whether the server is ready => less API calls. time.sleep(5) server = utils.wait_for(server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=600, check_interval=3) return server
def _create_volume(self, size, **kwargs): """create one volume. Returns when the volume is actually created and is in the "Available" state. :param size: int be size of volume in GB :param **kwargs: Other optional parameters to initialize the volume :returns: Created volume object """ kwargs["display_name"] = kwargs.get("display_name", self._generate_random_name()) volume = self.clients("cinder").volumes.create(size, **kwargs) # NOTE(msdubov): It is reasonable to wait 5 secs before starting to # check whether the volume is ready => less API calls. time.sleep(CONF.benchmark.cinder_volume_create_prepoll_delay) volume = bench_utils.wait_for( volume, is_ready=bench_utils.resource_is("available"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.cinder_volume_create_timeout, check_interval=CONF.benchmark.cinder_volume_create_poll_interval ) return volume
def test_get_from_manager_in_error_state(self): get_from_manager = utils.get_from_manager() manager = fakes.FakeManager() resource = fakes.FakeResource(manager=manager, status="ERROR") manager._cache(resource) self.assertRaises(exceptions.GetResourceFailure, get_from_manager, resource)
def _update_stack(self, stack, template, parameters=None, files=None, environment=None): """Update an existing stack :param stack: stack that need to be updated :param template: Updated template :param parameters: template parameters for stack update :param files: additional files used in template :param environment: stack environment definition :returns: object of updated stack """ kw = { "stack_name": stack.stack_name, "disable_rollback": True, "parameters": parameters or {}, "template": template, "files": files or {}, "environment": environment or {} } self.clients("heat").stacks.update(stack.id, **kw) time.sleep(CONF.benchmark.heat_stack_update_prepoll_delay) stack = bench_utils.wait_for( stack, is_ready=bench_utils.resource_is("UPDATE_COMPLETE"), update_resource=bench_utils.get_from_manager(["UPDATE_FAILED"]), timeout=CONF.benchmark.heat_stack_update_timeout, check_interval=CONF.benchmark.heat_stack_update_poll_interval) return stack
def _create_image(self, image_name, container_format, image_url, disk_format, **kwargs): """Create a new image. :param image_name: String used to name the image :param container_format: Container format of image. Acceptable formats: ami, ari, aki, bare, and ovf. :param image_url: URL for download image :param disk_format: Disk format of image. Acceptable formats: ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, and iso. :param **kwargs: optional parameters to create image returns: object of image """ image = self.clients("glance").images.create( name=image_name, copy_from=image_url, container_format=container_format, disk_format=disk_format, **kwargs) time.sleep(CONF.benchmark.glance_image_create_prepoll_delay) image = bench_utils.wait_for( image, is_ready=bench_utils.resource_is("active"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.glance_image_create_timeout, check_interval=CONF.benchmark.glance_image_create_poll_interval) return image
def _live_migrate(self, server, target_host, block_migration=False, disk_over_commit=False, skip_host_check=False): """Run live migration of the given server. :param server: Server object :param target_host: Specifies the target compute node to migrate :param block_migration: Specifies the migration type :param disk_over_commit: Specifies whether to overcommit migrated instance or not :param skip_host_check: Specifies whether to verify the targeted host availability """ server_admin = self.admin_clients("nova").servers.get(server.id) host_pre_migrate = getattr(server_admin, "OS-EXT-SRV-ATTR:host") server_admin.live_migrate(target_host, block_migration=block_migration, disk_over_commit=disk_over_commit) bench_utils.wait_for( server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_live_migrate_timeout, check_interval=( CONF.benchmark.nova_server_live_migrate_poll_interval) ) server_admin = self.admin_clients("nova").servers.get(server.id) if (host_pre_migrate == getattr(server_admin, "OS-EXT-SRV-ATTR:host") and not skip_host_check): raise exceptions.LiveMigrateException( "Migration complete but instance did not change host: %s" % host_pre_migrate)
def _update_stack(self, stack, template=None): """Update an existing stack :param stack: stack that need to be updated :param template: Updated template :returns: object of updated stack """ template = template or self.default_template kw = { "stack_name": stack.stack_name, "disable_rollback": True, "parameters": {}, "template": template, "files": {}, "environment": {} } self.clients("heat").stacks.update(stack.id, **kw) time.sleep(CONF.benchmark.heat_stack_update_prepoll_delay) stack = bench_utils.wait_for( stack, is_ready=bench_utils.resource_is("UPDATE_COMPLETE"), update_resource=bench_utils.get_from_manager(["UPDATE_FAILED"]), timeout=CONF.benchmark.heat_stack_update_timeout, check_interval=CONF.benchmark.heat_stack_update_poll_interval) return stack
def _create_share(self, share_proto, size=1, **kwargs): """Create a share. :param share_proto: share protocol for new share, available values are NFS, CIFS, GlusterFS and HDFS. :param size: size of a share in GB :param snapshot_id: ID of the snapshot :param name: name of new share :param description: description of a share :param metadata: optional metadata to set on share creation :param share_network: either instance of ShareNetwork or str with ID :param share_type: either instance of ShareType or str with ID :param is_public: defines whether to set share as public or not. :returns: instance of :class:`Share` """ if not kwargs.get("name"): kwargs["name"] = self._generate_random_name() share = self.clients("manila").shares.create(share_proto, size, **kwargs) time.sleep(CONF.benchmark.manila_share_create_prepoll_delay) share = bench_utils.wait_for( share, is_ready=bench_utils.resource_is("available"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.manila_share_create_timeout, check_interval=CONF.benchmark.manila_share_create_poll_interval, ) return share
def _create_stack(self, template=None): """Create a new stack. :param template: optional parameter. Template with stack description. :returns: object of stack """ stack_name = self._generate_random_name() template = template or self.default_template kw = { "stack_name": stack_name, "disable_rollback": True, "parameters": {}, "template": template, "files": {}, "environment": {} } # heat client returns body instead manager object, so we should # get manager object using stack_id stack_id = self.clients("heat").stacks.create(**kw)["stack"]["id"] stack = self.clients("heat").stacks.get(stack_id) time.sleep(CONF.benchmark.heat_stack_create_prepoll_delay) stack = bench_utils.wait_for( stack, is_ready=bench_utils.resource_is("CREATE_COMPLETE"), update_resource=bench_utils.get_from_manager(["CREATE_FAILED"]), timeout=CONF.benchmark.heat_stack_create_timeout, check_interval=CONF.benchmark.heat_stack_create_poll_interval) return stack
def _migrate(self, server, skip_host_check=False): """Run migration of the given server. :param server: Server object :param skip_host_check: Specifies whether to verify the targeted host availability """ server_admin = self.admin_clients("nova").servers.get(server.id) host_pre_migrate = getattr(server_admin, "OS-EXT-SRV-ATTR:host") server_admin.migrate() bench_utils.wait_for( server, is_ready=bench_utils.resource_is("VERIFY_RESIZE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_migrate_timeout, check_interval=( CONF.benchmark.nova_server_migrate_poll_interval) ) if not skip_host_check: server_admin = self.admin_clients("nova").servers.get(server.id) host_after_migrate = getattr(server_admin, "OS-EXT-SRV-ATTR:host") if host_pre_migrate == host_after_migrate: raise exceptions.MigrateException( "Migration complete but instance did not change host: %s" % host_pre_migrate)
def _boot_server(self, server_name, image_id, flavor_id, **kwargs): """Boots one server. Returns when the server is actually booted and is in the "Active" state. :param server_name: String used to name the server :param image_id: ID of the image to be used for server creation :param flavor_id: ID of the flavor to be used for server creation :param **kwargs: Other optional parameters to initialize the server :returns: Created server object """ allow_ssh_secgroup = self.context().get("allow_ssh") if allow_ssh_secgroup: if 'security_groups' not in kwargs: kwargs['security_groups'] = [allow_ssh_secgroup] elif allow_ssh_secgroup not in kwargs['security_groups']: kwargs['security_groups'].append(allow_ssh_secgroup) server = self.clients("nova").servers.create(server_name, image_id, flavor_id, **kwargs) time.sleep(CONF.benchmark.nova_server_boot_prepoll_delay) server = bench_utils.wait_for( server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_boot_timeout, check_interval=CONF.benchmark.nova_server_boot_poll_interval) return server
def _create_snapshot(self, volume_id, force=False, **kwargs): """Create one snapshot. Returns when the snapshot is actually created and is in the "Available" state. :param volume_id: volume uuid for creating snapshot :param force: flag to indicate whether to snapshot a volume even if it's attached to an instance :param kwargs: Other optional parameters to initialize the volume :returns: Created snapshot object """ kwargs["display_name"] = kwargs.get("display_name", self._generate_random_name()) kwargs["force"] = force snapshot = self.clients("cinder").volume_snapshots.create(volume_id, **kwargs) time.sleep(CONF.benchmark.cinder_volume_create_prepoll_delay) snapshot = bench_utils.wait_for( snapshot, is_ready=bench_utils.resource_is("available"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.cinder_volume_create_timeout, check_interval=CONF.benchmark.cinder_volume_create_poll_interval ) return snapshot
def _create_share(self, share_proto, size=1, **kwargs): """Create a share. :param share_proto: share protocol for new share, available values are NFS, CIFS, GlusterFS and HDFS. :param size: size of a share in GB :param snapshot_id: ID of the snapshot :param name: name of new share :param description: description of a share :param metadata: optional metadata to set on share creation :param share_network: either instance of ShareNetwork or str with ID :param share_type: either instance of ShareType or str with ID :param is_public: defines whether to set share as public or not. :returns: instance of :class:`Share` """ if (self.context and self.context.get("tenant", {}).get("share_networks", []) and not kwargs.get("share_network")): kwargs["share_network"] = next(self.context.get("tenant", {}).get( "sn_iterator")) if not kwargs.get("name"): kwargs["name"] = self._generate_random_name() share = self.clients("manila").shares.create( share_proto, size, **kwargs) time.sleep(CONF.benchmark.manila_share_create_prepoll_delay) share = bench_utils.wait_for( share, is_ready=bench_utils.resource_is("available"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.manila_share_create_timeout, check_interval=CONF.benchmark.manila_share_create_poll_interval, ) return share
def _create_stack(self, stack_name, template=None): """Create a new stack. :param stack_name: string. Name for created stack. :param template: optional parameter. Template with stack description. returns: object of stack """ template = template or self.default_template kw = { "stack_name": stack_name, "disable_rollback": True, "parameters": {}, "template": template, "files": {}, "environment": {} } # heat client returns body instead manager object, so we should # get manager object using stack_id stack_id = self.clients("heat").stacks.create(**kw)["stack"]["id"] stack = self.clients("heat").stacks.get(stack_id) time.sleep(CONF.benchmark.heat_stack_create_prepoll_delay) stack = bench_utils.wait_for( stack, is_ready=heat_resource_is("CREATE_COMPLETE"), update_resource=bench_utils.get_from_manager(["CREATE_FAILED"]), timeout=CONF.benchmark.heat_stack_create_timeout, check_interval=CONF.benchmark.heat_stack_create_poll_interval) return stack
def _resize(self, server, flavor): server.resize(flavor) bench_utils.wait_for( server, is_ready=bench_utils.resource_is("VERIFY_RESIZE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_resize_timeout, check_interval=CONF.benchmark.nova_server_resize_poll_interval)
def _delete_floating_ip(self, floating_ip): """Delete (deallocate) a floating ip for a tenant :param floating_ip: The floating ip address to delete. """ self.clients("nova").floating_ips.delete(floating_ip) bench_utils.wait_for_delete( floating_ip, update_resource=bench_utils.get_from_manager())
def _wait_finish_of_deploy(self, environment): bench_utils.wait_for( environment, is_ready=bench_utils.resource_is("READY"), update_resource=bench_utils.get_from_manager(), timeout=1200.0, check_interval=5.0 )
def _resize_revert(self, server): server.revert_resize() bench_utils.wait_for( server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_resize_revert_timeout, check_interval=( CONF.benchmark.nova_server_resize_revert_poll_interval))
def _resize_confirm(self, server, status="ACTIVE"): server.confirm_resize() bench_utils.wait_for( server, is_ready=bench_utils.resource_is(status), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_resize_confirm_timeout, check_interval=( CONF.benchmark.nova_server_resize_confirm_poll_interval))
def _do_server_reboot(self, server, reboottype): server.reboot(reboot_type=reboottype) time.sleep(CONF.benchmark.nova_server_reboot_prepoll_delay) bench_utils.wait_for( server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_reboot_timeout, check_interval=CONF.benchmark.nova_server_reboot_poll_interval )
def _resize(self, server, flavor): server.resize(flavor) bench_utils.wait_for( server, is_ready=bench_utils.resource_is("VERIFY_RESIZE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_resize_timeout, check_interval=CONF.benchmark.nova_server_resize_poll_interval )
def _create_image(self, container_format, image_location, disk_format, name=None, prefix=None, length=None, **kwargs): """Create a new image. :param container_format: container format of image. Acceptable formats: ami, ari, aki, bare, and ovf :param image_location: image file location :param disk_format: disk format of image. Acceptable formats: ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, and iso :param name: string used to name the image :param prefix: prefix of generated image name if name not specified ignore if name specified :param length: length of autometic generated part in image name ignore if name specified :param kwargs: optional parameters to create image :returns: image object """ name = name or self._generate_random_name(prefix, length) kw = { "name": name, "container_format": container_format, "disk_format": disk_format, } kw.update(kwargs) try: if os.path.isfile(image_location): kw["data"] = open(image_location) else: kw["copy_from"] = image_location image = self.clients("glance").images.create(**kw) time.sleep(CONF.benchmark.glance_image_create_prepoll_delay) image = bench_utils.wait_for( image, is_ready=bench_utils.resource_is("active"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.glance_image_create_timeout, check_interval=CONF.benchmark.glance_image_create_poll_interval ) finally: if "data" in kw: kw["data"].close() return image
def _detach_volume(self, server, volume): server_id = server.id volume_id = volume.id self.clients("nova").volumes.delete_server_volume(server_id, volume_id) bench_utils.wait_for( volume, is_ready=bench_utils.resource_is("available"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_detach_volume_timeout, check_interval=CONF.benchmark.nova_detach_volume_poll_interval)
def _resize_confirm(self, server): server.confirm_resize() bench_utils.wait_for( server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_resize_confirm_timeout, check_interval=( CONF.benchmark.nova_server_resize_confirm_poll_interval) )
def _delete_floating_ip(self, floating_ip): """Delete (deallocate) a floating ip for a tenant :param floating_ip: The floating ip address to delete. """ self.clients("nova").floating_ips.delete(floating_ip) bench_utils.wait_for_delete( floating_ip, update_resource=bench_utils.get_from_manager() )
def _resize_revert(self, server, status="ACTIVE"): server.revert_resize() bench_utils.wait_for( server, is_ready=bench_utils.resource_is(status), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_resize_revert_timeout, check_interval=( CONF.benchmark.nova_server_resize_revert_poll_interval) )
def _delete_share_network(self, share_network): """Delete share network. :param share_network: instance of :class:`ShareNetwork`. """ share_network.delete() bench_utils.wait_for_delete( share_network, update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.manila_share_delete_timeout, check_interval=CONF.benchmark.manila_share_delete_poll_interval)
def test_get_from_manager_http_exception(self): get_from_manager = utils.get_from_manager() manager = mock.MagicMock() resource = fakes.FakeResource(manager=manager, status="ERROR") class HTTPException(Exception): pass manager.get = mock.MagicMock(side_effect=HTTPException) self.assertRaises(exceptions.GetResourceFailure, get_from_manager, resource)
def _delete_volume(cls, volume): """Delete the given volume. Returns when the volume is actually deleted. :param volume: volume object """ volume.delete() utils.wait_for(volume, is_ready=bench_utils.is_none, update_resource=bench_utils.get_from_manager(), timeout=600, check_interval=2)
def test_get_from_manager_not_found(self): get_from_manager = utils.get_from_manager() manager = mock.MagicMock() resource = fakes.FakeResource(manager=manager, status="ERROR") class NotFoundException(Exception): http_status = 404 manager.get = mock.MagicMock(side_effect=NotFoundException) self.assertRaises(exceptions.GetResourceFailure, get_from_manager, resource)
def _delete_server(cls, server): """Deletes the given server. Returns when the server is actually deleted. :param server: Server object """ server.delete() utils.wait_for(server, is_ready=bench_utils.is_none, update_resource=bench_utils.get_from_manager(), timeout=600, check_interval=3)
def _delete_image(cls, image): """Deletes the given image. Returns when the image is actually deleted. :param image: Image object """ image.delete() utils.wait_for(image, is_ready=bench_utils.resource_is("DELETED"), update_resource=bench_utils.get_from_manager(), timeout=600, check_interval=3)
def _delete_security_service(self, security_service): """Delete security service. :param security_service: instance of :class:`SecurityService`. """ security_service.delete() bench_utils.wait_for_delete( security_service, update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.manila_share_delete_timeout, check_interval=CONF.benchmark.manila_share_delete_poll_interval)
def _delete_share(self, share): """Delete the given share. :param share: :class:`Share` """ share.delete() error_statuses = ("error_deleting", ) bench_utils.wait_for_delete( share, update_resource=bench_utils.get_from_manager(error_statuses), timeout=CONF.benchmark.manila_share_delete_timeout, check_interval=CONF.benchmark.manila_share_delete_poll_interval)
def _stop_server(cls, server): """Stop the given server. Issues a stop on the given server and waits for the server to become SHUTOFF. :param server: The server to stop. """ server.stop() utils.wait_for(server, is_ready=bench_utils.resource_is("SHUTOFF"), update_resource=bench_utils.get_from_manager(), timeout=600, check_interval=2)
def _boot_server(self, server_name, image_id, flavor_id, auto_assign_nic=False, **kwargs): """Boots one server. Returns when the server is actually booted and is in the "Active" state. If multiple networks are present, the first network found that isn't associated with a floating IP pool is used. :param server_name: String used to name the server :param image_id: ID of the image to be used for server creation :param flavor_id: ID of the flavor to be used for server creation :param auto_assign_nic: Boolean for whether or not to assign NICs :param **kwargs: Other optional parameters to initialize the server :returns: Created server object """ allow_ssh_secgroup = self.context().get("allow_ssh") if allow_ssh_secgroup: if 'security_groups' not in kwargs: kwargs['security_groups'] = [allow_ssh_secgroup] elif allow_ssh_secgroup not in kwargs['security_groups']: kwargs['security_groups'].append(allow_ssh_secgroup) nics = kwargs.get('nics', False) if auto_assign_nic and nics is False: nets = self.clients("nova").networks.list() fip_pool = [ pool.name for pool in self.clients("nova").floating_ip_pools.list() ] for net in nets: if net.label not in fip_pool: kwargs['nics'] = [{'net-id': net.id}] break server = self.clients("nova").servers.create(server_name, image_id, flavor_id, **kwargs) time.sleep(CONF.benchmark.nova_server_boot_prepoll_delay) server = bench_utils.wait_for( server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_boot_timeout, check_interval=CONF.benchmark.nova_server_boot_poll_interval) return server
def _detach_volume(self, server, volume): server_id = server.id volume_id = volume.id self.clients("nova").volumes.delete_server_volume(server_id, volume_id) bench_utils.wait_for( volume, is_ready=bench_utils.resource_is("available"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_detach_volume_timeout, check_interval=CONF.benchmark.nova_detach_volume_poll_interval )
def _attach_volume(self, server, volume, device=None): server_id = server.id volume_id = volume.id self.clients("nova").volumes.create_server_volume( server_id, volume_id, device) bench_utils.wait_for( volume, is_ready=bench_utils.resource_is("in-use"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_resize_revert_timeout, check_interval=( CONF.benchmark.nova_server_resize_revert_poll_interval))
def _boot_server(self, image_id, flavor_id, auto_assign_nic=False, name=None, **kwargs): """Boot a server. Returns when the server is actually booted and in "ACTIVE" state. If multiple networks are present, the first network found that isn't associated with a floating IP pool is used. :param image_id: int, image ID for server creation :param flavor_id: int, flavor ID for server creation :param auto_assign_nic: bool, whether or not to auto assign NICs :param name: str, server name :param kwargs: other optional parameters to initialize the server :returns: nova Server instance """ server_name = name or self._generate_random_name() secgroup = self.context.get("user", {}).get("secgroup") if secgroup: if "security_groups" not in kwargs: kwargs["security_groups"] = [secgroup["name"]] elif secgroup["name"] not in kwargs["security_groups"]: kwargs["security_groups"].append(secgroup["name"]) if auto_assign_nic and not kwargs.get("nics", False): nets = [ net["id"] for net in self.context.get("tenant", {}).get("networks", []) ] if nets: # NOTE(amaretskiy): Balance servers among networks: # divmod(iteration % tenants_num, nets_num)[1] net_idx = divmod((self.context["iteration"] % self.context["config"]["users"]["tenants"]), len(nets))[1] kwargs["nics"] = [{"net-id": nets[net_idx]}] server = self.clients("nova").servers.create(server_name, image_id, flavor_id, **kwargs) time.sleep(CONF.benchmark.nova_server_boot_prepoll_delay) server = bench_utils.wait_for( server, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_boot_timeout, check_interval=CONF.benchmark.nova_server_boot_poll_interval) return server
def _suspend_stack(self, stack): """Suspend given stack. :param stack: stack that needs to be suspended """ self.clients("heat").actions.suspend(stack.id) bench_utils.wait_for( stack, is_ready=bench_utils.resource_is("SUSPEND_COMPLETE"), update_resource=bench_utils.get_from_manager(["SUSPEND_FAILED"]), timeout=CONF.benchmark.heat_stack_suspend_timeout, check_interval=CONF.benchmark.heat_stack_suspend_poll_interval)
def _delete_stack(self, stack): """Delete given stack. Returns when the stack is actually deleted. :param stack: stack object """ stack.delete() bench_utils.wait_for_delete( stack, update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.heat_stack_delete_timeout, check_interval=CONF.benchmark.heat_stack_delete_poll_interval)
def _resume_stack(self, stack): """Resume given stack. :param stack: stack that needs to be resumed """ self.clients("heat").actions.resume(stack.id) bench_utils.wait_for( stack, is_ready=bench_utils.resource_is("RESUME_COMPLETE"), update_resource=bench_utils.get_from_manager(["RESUME_FAILED"]), timeout=CONF.benchmark.heat_stack_resume_timeout, check_interval=CONF.benchmark.heat_stack_resume_poll_interval)
def _deploy_environment(self, environment, session): """Deploy environment. :param environment: Environment instance :param session: Session instance """ self.clients("murano").sessions.deploy(environment.id, session.id) bench_utils.wait_for( environment, is_ready=bench_utils.resource_is("READY"), update_resource=bench_utils.get_from_manager(["DEPLOY FAILURE"]), timeout=CONF.benchmark.deploy_environment_timeout, check_interval=CONF.benchmark.deploy_environment_check_interval)
def _delete_environment(self, environment): """Delete given environment. Return when the environment is actually deleted. :param environment: Environment instance """ self.clients("murano").environments.delete(environment.id) bench_utils.wait_for_delete( environment, update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.delete_environment_timeout, check_interval=CONF.benchmark.delete_environment_check_interval)
def _delete_volume(self, volume): """Delete the given volume. Returns when the volume is actually deleted. :param volume: volume object """ volume.delete() bench_utils.wait_for_delete( volume, update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.cinder_volume_delete_timeout, check_interval=CONF.benchmark.cinder_volume_delete_poll_interval)