def list_router_interfaces(self, uuid): uri = '%s/ports?device_id=%s' % (self.uri_prefix, uuid) resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def delete_software_config(self, conf_id): """Deletes a specific software configuration.""" url = 'software_configs/%s' % str(conf_id) resp, _ = self.delete(url) self.expected_success(204, resp.status) return service_client.ResponseBody(resp)
def disassociate_all_qos(self, qos_id): """Disassociate the specified QoS with all associations.""" url = "qos-specs/%s/disassociate_all" % str(qos_id) resp, body = self.get(url) self.expected_success(202, resp.status) return service_client.ResponseBody(resp, body)
def create_test_server(clients, validatable=False, validation_resources=None, tenant_network=None, wait_until=None, volume_backed=False, **kwargs): """Common wrapper utility returning a test server. This method is a common wrapper returning a test server that can be pingable or sshable. :param clients: Client manager which provides OpenStack Tempest clients. :param validatable: Whether the server will be pingable or sshable. :param validation_resources: Resources created for the connection to the server. Include a keypair, a security group and an IP. :param tenant_network: Tenant network to be used for creating a server. :param wait_until: Server status to wait for the server to reach after its creation. :param volume_backed: Whether the instance is volume backed or not. :returns: a tuple """ # TODO(jlanoux) add support of wait_until PINGABLE/SSHABLE name = kwargs.pop('name', data_utils.rand_name(__name__ + "-instance")) flavor = kwargs.pop('flavor', CONF.compute.flavor_ref) image_id = kwargs.pop('image_id', CONF.compute.image_ref) kwargs = fixed_network.set_networks_kwarg( tenant_network, kwargs) or {} multiple_create_request = (max(kwargs.get('min_count', 0), kwargs.get('max_count', 0)) > 1) if CONF.validation.run_validation and validatable: # As a first implementation, multiple pingable or sshable servers will # not be supported if multiple_create_request: msg = ("Multiple pingable or sshable servers not supported at " "this stage.") raise ValueError(msg) if 'security_groups' in kwargs: kwargs['security_groups'].append( {'name': validation_resources['security_group']['name']}) else: try: kwargs['security_groups'] = [ {'name': validation_resources['security_group']['name']}] except KeyError: LOG.debug("No security group provided.") if 'key_name' not in kwargs: try: kwargs['key_name'] = validation_resources['keypair']['name'] except KeyError: LOG.debug("No key provided.") if CONF.validation.connect_method == 'floating': if wait_until is None: wait_until = 'ACTIVE' if volume_backed: volume_name = data_utils.rand_name('volume') volumes_client = clients.volumes_v2_client if CONF.volume_feature_enabled.api_v1: volumes_client = clients.volumes_client volume = volumes_client.create_volume( display_name=volume_name, imageRef=image_id) volumes_client.wait_for_volume_status(volume['volume']['id'], 'available') bd_map_v2 = [{ 'uuid': volume['volume']['id'], 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': True}] kwargs['block_device_mapping_v2'] = bd_map_v2 # Since this is boot from volume an image does not need # to be specified. image_id = '' body = clients.servers_client.create_server(name=name, imageRef=image_id, flavorRef=flavor, **kwargs) # handle the case of multiple servers servers = [] if multiple_create_request: # Get servers created which name match with name param. body_servers = clients.servers_client.list_servers() servers = \ [s for s in body_servers['servers'] if s['name'].startswith(name)] else: body = service_client.ResponseBody(body.response, body['server']) servers = [body] # The name of the method to associate a floating IP to as server is too # long for PEP8 compliance so: assoc = clients.compute_floating_ips_client.associate_floating_ip_to_server if wait_until: for server in servers: try: waiters.wait_for_server_status( clients.servers_client, server['id'], wait_until) # Multiple validatable servers are not supported for now. Their # creation will fail with the condition above (l.58). if CONF.validation.run_validation and validatable: if CONF.validation.connect_method == 'floating': assoc(floating_ip=validation_resources[ 'floating_ip']['ip'], server_id=servers[0]['id']) except Exception: with excutils.save_and_reraise_exception(): if ('preserve_server_on_error' not in kwargs or kwargs['preserve_server_on_error'] is False): for server in servers: try: clients.servers_client.delete_server( server['id']) except Exception: LOG.exception('Deleting server %s failed' % server['id']) return body, servers
def delete_stack(self, stack_identifier): """Deletes the specified Stack.""" resp, _ = self.delete("stacks/%s" % str(stack_identifier)) self.expected_success(204, resp.status) return service_client.ResponseBody(resp)
def remove_image_member(self, image_id, member_id): url = 'v2/images/%s/members/%s' % (image_id, member_id) resp, _ = self.delete(url) self.expected_success(204, resp.status) return service_client.ResponseBody(resp)
def deactivate_image(self, image_id): url = 'v2/images/%s/actions/deactivate' % image_id resp, body = self.post(url, None) self.expected_success(204, resp.status) return service_client.ResponseBody(resp, body)
def list_networks_hosted_by_one_dhcp_agent(self, agent_id): uri = '%s/agents/%s/dhcp-networks' % (self.uri_prefix, agent_id) resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def remove_network_from_dhcp_agent(self, agent_id, network_id): uri = '%s/agents/%s/dhcp-networks/%s' % (self.uri_prefix, agent_id, network_id) resp, body = self.delete(uri) self.expected_success(204, resp.status) return service_client.ResponseBody(resp, body)
def remove_router_from_l3_agent(self, agent_id, router_id): uri = '%s/agents/%s/l3-routers/%s' % (self.uri_prefix, agent_id, router_id) resp, body = self.delete(uri) self.expected_success(204, resp.status) return service_client.ResponseBody(resp, body)
def list_dhcp_agent_hosting_network(self, network_id): uri = '%s/networks/%s/dhcp-agents' % (self.uri_prefix, network_id) resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def list_l3_agents_hosting_router(self, router_id): uri = '%s/routers/%s/l3-agents' % (self.uri_prefix, router_id) resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def list_routers_on_l3_agent(self, agent_id): uri = '%s/agents/%s/l3-routers' % (self.uri_prefix, agent_id) resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def list_pools_hosted_by_one_lbaas_agent(self, agent_id): uri = '%s/agents/%s/loadbalancer-pools' % (self.uri_prefix, agent_id) resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def list_image_members(self, image_id): url = 'v2/images/%s/members' % image_id resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def list_lb_pool_stats(self, pool_id): uri = '%s/lb/pools/%s/stats' % (self.uri_prefix, pool_id) resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def show_image_member(self, image_id, member_id): url = 'v2/images/%s/members/%s' % (image_id, member_id) resp, body = self.get(url) self.expected_success(200, resp.status) return service_client.ResponseBody(resp, json.loads(body))
def delete_snapshot(self, snapshot_id): """Delete Snapshot.""" resp, body = self.delete("snapshots/%s" % str(snapshot_id)) self.expected_success(202, resp.status) return service_client.ResponseBody(resp, body)
def show_schema(self, schema): url = 'v2/schemas/%s' % schema resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBody(resp, body)
def reset_snapshot_status(self, snapshot_id, status): """Reset the specified snapshot's status.""" post_body = json.dumps({'os-reset_status': {"status": status}}) resp, body = self.post('snapshots/%s/action' % snapshot_id, post_body) self.expected_success(202, resp.status) return service_client.ResponseBody(resp, body)
def delete_region(self, region_id): """Delete region.""" resp, body = self.delete('regions/%s' % region_id) self.expected_success(204, resp.status) return service_client.ResponseBody(resp, body)
def delete_snapshot_metadata_item(self, snapshot_id, id): """Delete metadata item for the snapshot.""" url = "snapshots/%s/metadata/%s" % (str(snapshot_id), str(id)) resp, body = self.delete(url) self.expected_success(200, resp.status) return service_client.ResponseBody(resp, body)
def show_limits(self): resp, body = self.get("limits") body = json.loads(body) self.validate_response(schema.get_limit, resp, body) return service_client.ResponseBody(resp, body['limits'])
def force_delete_snapshot(self, snapshot_id): """Force Delete Snapshot.""" post_body = json.dumps({'os-force_delete': {}}) resp, body = self.post('snapshots/%s/action' % snapshot_id, post_body) self.expected_success(202, resp.status) return service_client.ResponseBody(resp, body)
def show_resource_type_template(self, resource_type_name): """Return the template of a resource type.""" url = 'resource_types/%s/template' % resource_type_name resp, body = self.get(url) self.expected_success(200, resp.status) return service_client.ResponseBody(resp, json.loads(body))
def add_image_tag(self, image_id, tag): url = 'v2/images/%s/tags/%s' % (image_id, tag) resp, body = self.put(url, body=None) self.expected_success(204, resp.status) return service_client.ResponseBody(resp, body)
def delete_software_deploy(self, deploy_id): """Deletes a specific software deployment.""" url = 'software_deployments/%s' % str(deploy_id) resp, _ = self.delete(url) self.expected_success(204, resp.status) return service_client.ResponseBody(resp)
def delete_image_tag(self, image_id, tag): url = 'v2/images/%s/tags/%s' % (image_id, tag) resp, _ = self.delete(url) self.expected_success(204, resp.status) return service_client.ResponseBody(resp)
def delete_qos(self, qos_id, force=False): """Delete the specified QoS specification.""" resp, body = self.delete("qos-specs/%s?force=%s" % (str(qos_id), force)) self.expected_success(202, resp.status) return service_client.ResponseBody(resp, body)
def reset_quotas(self, tenant_id): uri = '%s/quotas/%s' % (self.uri_prefix, tenant_id) resp, body = self.delete(uri) self.expected_success(204, resp.status) return service_client.ResponseBody(resp, body)