Ejemplo n.º 1
0
    def create_servers(self, rcs, num, wait_for=None):
        """
        Create some number of servers using just Nova, and wait until they
        are active.  This uses the same default server arguments as
        `create_group`.

        :param TestResources rcs: An instance of
            :class:`otter.integration.lib.resources.TestResources`
        :param int num: The number of servers to create.
        :param wait_for: What state to wait for for those servers - by default,
            it waits just for them to be active

        :return: an iterable of server details JSON of the created servers.
        """
        image_id = yield fetch_ubuntu_image_id(rcs, self.pool)
        as_args = create_scaling_group_dict(
            image_ref=image_id,
            flavor_ref=flavor_ref)
        server_args = as_args['launchConfiguration']['args']
        server_args['server']['name'] = "autogenerated-non-as-test-server"

        if wait_for is None:
            wait_for = ContainsDict({'status': Equals("ACTIVE")})

        server_ids = yield gatherResults([
            create_server(rcs, self.pool, server_args) for _ in range(num)])

        self.test_case.addCleanup(delete_servers, server_ids, rcs, self.pool)

        servers = yield wait_for_servers(
            rcs,
            self.pool,
            # The list of active servers' ids has the created server ids
            AfterPreprocessing(
                lambda servers: [s for s in servers if s['id'] in server_ids],
                AllMatch(wait_for)
            )
        )

        returnValue(
            [server for server in servers if server['id'] in server_ids])
Ejemplo n.º 2
0
    def create_servers(self, rcs, num, wait_for=None):
        """
        Create some number of servers using just Nova, and wait until they
        are active.  This uses the same default server arguments as
        `create_group`.

        :param TestResources rcs: An instance of
            :class:`otter.integration.lib.resources.TestResources`
        :param int num: The number of servers to create.
        :param wait_for: What state to wait for for those servers - by default,
            it waits just for them to be active

        :return: an iterable of server details JSON of the created servers.
        """
        image_id = yield fetch_ubuntu_image_id(rcs, self.pool)
        as_args = create_scaling_group_dict(
            image_ref=image_id,
            flavor_ref=flavor_ref)
        server_args = as_args['launchConfiguration']['args']
        server_args['server']['name'] = "autogenerated-non-as-test-server"

        if wait_for is None:
            wait_for = ContainsDict({'status': Equals("ACTIVE")})

        server_ids = yield gatherResults([
            create_server(rcs, self.pool, server_args) for _ in range(num)])

        self.test_case.addCleanup(delete_servers, server_ids, rcs, self.pool)

        servers = yield wait_for_servers(
            rcs,
            self.pool,
            # The list of active servers' ids has the created server ids
            AfterPreprocessing(
                lambda servers: [s for s in servers if s['id'] in server_ids],
                AllMatch(wait_for)
            )
        )

        returnValue(
            [server for server in servers if server['id'] in server_ids])
Ejemplo n.º 3
0
    def start(self, rcs, test):
        """Create a scaling group.

        :param TestResources rcs: A set of OpenStack resources encapsulated
            in a TestResources instance.

        :return: The same instance of TestResources.
        """

        test.addCleanup(self.stop, rcs)

        def record_results(resp):
            rcs.groups.append(resp)
            self.group_id = str(resp["group"]["id"])
            if verbosity > 0:
                print('Created scaling group {0} \n'.format(self.group_id))
                pp.pprint(rcs.groups)
            return rcs

        def send(image_id):
            lc_type = self.group_config["launchConfiguration"]["type"]
            if image_id is not None and lc_type == "launch_server":
                self.group_config = update_in(
                    self.group_config,
                    ["launchConfiguration", "args", "server", "imageRef"],
                    lambda _: image_id)
            d = self.treq.post(
                "%s/groups" % str(rcs.endpoints["otter"]),
                json.dumps(self.group_config),
                headers=headers(str(rcs.token)),
                pool=self.pool)
            d.addCallback(check_success, [201])
            d.addCallback(self.treq.json_content)
            return d.addCallback(record_results)

        # If image_ref is not configured, get it from nova
        if self._image_ref() is None:
            return fetch_ubuntu_image_id(rcs, self.pool).addCallback(send)
        else:
            return send(None)
Ejemplo n.º 4
0
    def start(self, rcs, test):
        """Create a scaling group.

        :param TestResources rcs: A set of OpenStack resources encapsulated
            in a TestResources instance.

        :return: The same instance of TestResources.
        """

        test.addCleanup(self.stop, rcs)

        def record_results(resp):
            rcs.groups.append(resp)
            self.group_id = str(resp["group"]["id"])
            if verbosity > 0:
                print('Created scaling group {0} \n'.format(self.group_id))
                pp.pprint(rcs.groups)
            return rcs

        def send(image_id):
            lc_type = self.group_config["launchConfiguration"]["type"]
            if image_id is not None and lc_type == "launch_server":
                self.group_config = update_in(
                    self.group_config,
                    ["launchConfiguration", "args", "server", "imageRef"],
                    lambda _: image_id)
            d = self.treq.post("%s/groups" % str(rcs.endpoints["otter"]),
                               json.dumps(self.group_config),
                               headers=headers(str(rcs.token)),
                               pool=self.pool)
            d.addCallback(check_success, [201])
            d.addCallback(self.treq.json_content)
            return d.addCallback(record_results)

        # If image_ref is not configured, get it from nova
        if self._image_ref() is None:
            return fetch_ubuntu_image_id(rcs, self.pool).addCallback(send)
        else:
            return send(None)