Esempio n. 1
0
    def create_test_server(cls, **kwargs):
        """Wrapper utility that returns a test server."""
        name = data_utils.rand_name(cls.__name__ + "-instance")
        if "name" in kwargs:
            name = kwargs.pop("name")
        flavor = kwargs.get("flavor", cls.flavor_ref)
        image_id = kwargs.get("image_id", cls.image_ref)

        resp, body = cls.servers_client.create_server(name, image_id, flavor, **kwargs)

        # handle the case of multiple servers
        servers = [body]
        if "min_count" in kwargs or "max_count" in kwargs:
            # Get servers created which name match with name param.
            r, b = cls.servers_client.list_servers()
            servers = [s for s in b["servers"] if s["name"].startswith(name)]

        if "wait_until" in kwargs:
            for server in servers:
                try:
                    cls.servers_client.wait_for_server_status(server["id"], kwargs["wait_until"])
                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:
                                    cls.servers_client.delete_server(server["id"])
                                except Exception:
                                    pass

        cls.servers.extend(servers)

        return resp, body
Esempio n. 2
0
    def create_test_server(cls, **kwargs):
        """Wrapper utility that returns a test server."""
        name = data_utils.rand_name(cls.__name__ + "-instance")
        if 'name' in kwargs:
            name = kwargs.pop('name')
        flavor = kwargs.get('flavor', cls.flavor_ref)
        image_id = kwargs.get('image_id', cls.image_ref)
        if 'networks' not in kwargs and cls.fixed_network_name:
            response, body = cls.network_client.list_networks()
            #self.assertEqual('200', response['status'])
            networks = body['networks']
            # If several networks found, set the NetID on which to connect the
            # server to avoid the following error "Multiple possible netwo
            # found, use a Network ID to be more specific."
            # See Tempest #1297660
            if len(networks) > 1:
                 for network in networks:
                   if network['name'] == cls.fixed_network_name:
                      kwargs['networks'] = [{'uuid': str(network['id'])}]
                      break
                 if 'networks' not in kwargs: 
                    # Randomly choose a network from the available networks
                     net = random.choice(networks)
                     kwargs['networks'] = [{'uuid': str(net['id'])}]
                     msg = ("The network on which the NIC of the server must "
                           "be connected can not be found :  "
                           "fixed_network_name=%s. Starting instance with "
                           "random network.") % cls.fixed_network_name
                     LOG.info(msg)
                                                     
        resp, body = cls.servers_client.create_server(
            name, image_id, flavor, **kwargs)

        # handle the case of multiple servers
        servers = [body]
        if 'min_count' in kwargs or 'max_count' in kwargs:
            # Get servers created which name match with name param.
            r, b = cls.servers_client.list_servers()
            servers = [s for s in b['servers'] if s['name'].startswith(name)]

        if 'wait_until' in kwargs:
            for server in servers:
                try:
                    cls.servers_client.wait_for_server_status(
                        server['id'], kwargs['wait_until'])
                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:
                                    cls.servers_client.delete_server(
                                        server['id'])
                                except Exception:
                                    pass

        cls.servers.extend(servers)

        return resp, body
Esempio n. 3
0
def remove_path_on_error(path):
    """Protect code that wants to operate on PATH atomically.
    Any exception will cause PATH to be removed.

    :param path: File to work with
    """
    try:
        yield
    except Exception:
        with excutils.save_and_reraise_exception():
            delete_if_exists(path)
Esempio n. 4
0
def remove_path_on_error(path):
    """Protect code that wants to operate on PATH atomically.
    Any exception will cause PATH to be removed.

    :param path: File to work with
    """
    try:
        yield
    except Exception:
        with excutils.save_and_reraise_exception():
            delete_if_exists(path)
Esempio n. 5
0
    def create_test_server(cls, **kwargs):
        """Wrapper utility that returns a test server."""
        name = data_utils.rand_name(cls.__name__ + "-instance")
        if 'name' in kwargs:
            name = kwargs.pop('name')
        flavor = kwargs.get('flavor', cls.flavor_ref)
        image_id = kwargs.get('image_id', cls.image_ref)

        resp, body = cls.servers_client.create_server(name, image_id, flavor,
                                                      **kwargs)

        # handle the case of multiple servers
        servers = [body]
        if 'min_count' in kwargs or 'max_count' in kwargs:
            # Get servers created which name match with name param.
            r, b = cls.servers_client.list_servers()
            servers = [s for s in b['servers'] if s['name'].startswith(name)]

        if 'wait_until' in kwargs:
            for server in servers:
                try:
                    cls.servers_client.wait_for_server_status(
                        server['id'], kwargs['wait_until'])
                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:
                                    cls.servers_client.delete_server(
                                        server['id'])
                                except Exception:
                                    pass

        cls.servers.extend(servers)

        return resp, body
Esempio n. 6
0
    def create_test_server(cls, **kwargs):
        """Wrapper utility that returns a test server."""
        name = data_utils.rand_name(cls.__name__ + "-instance")
        if 'name' in kwargs:
            name = kwargs.pop('name')
        flavor = kwargs.get('flavor', cls.flavor_ref)
        image_id = kwargs.get('image_id', cls.image_ref)

        resp, body = cls.servers_client.create_server(
            name, image_id, flavor, **kwargs)

        # handle the case of multiple servers
        servers = [body]
        if 'min_count' in kwargs or 'max_count' in kwargs:
            # Get servers created which name match with name param.
            r, b = cls.servers_client.list_servers()
            servers = [s for s in b['servers'] if s['name'].startswith(name)]

        if 'wait_until' in kwargs:
            for server in servers:
                try:
                    cls.servers_client.wait_for_server_status(
                        server['id'], kwargs['wait_until'])
                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:
                                    cls.servers_client.delete_server(
                                        server['id'])
                                except Exception:
                                    pass

        cls.servers.extend(servers)

        return resp, body