Beispiel #1
0
    def _stack_webhook(self, stack, output_key):
        """POST to the URL given in the output value identified by output_key.

        This can be used to scale stacks up and down, for instance.

        :param stack: stack to call a webhook on
        :param output_key: The name of the output to get the URL from
        :raises InvalidConfigException: if the output key is not found
        """
        url = None
        for output in stack.outputs:
            if output["output_key"] == output_key:
                url = output["output_value"]
                break
        else:
            raise exceptions.InvalidConfigException(
                "No output key %(key)s found in stack %(id)s" % {
                    "key": output_key,
                    "id": stack.id
                })

        platform_params = self.context["env"]["spec"]["existing@openstack"]
        verify = (platform_params["https_cacert"]
                  if not platform_params["https_insecure"] else False)
        with atomic.ActionTimer(self, "heat.%s_webhook" % output_key):
            requests.post(url, verify=verify).raise_for_status()
Beispiel #2
0
    def run(self, image, flavor, force_delete=False, actions=None, **kwargs):
        """Boot a server and run specified actions against it.

        Actions should be passed into the actions parameter. Available actions
        are 'hard_reboot', 'soft_reboot', 'stop_start', 'rescue_unrescue',
        'pause_unpause', 'suspend_resume', 'lock_unlock' and 'shelve_unshelve'.
        Delete server after all actions were completed.

        :param image: image to be used to boot an instance
        :param flavor: flavor to be used to boot an instance
        :param force_delete: True if force_delete should be used
        :param actions: list of action dictionaries, where each action
                        dictionary speicifes an action to be performed
                        in the following format:
                        {"action_name": <no_of_iterations>}
        :param kwargs: Optional additional arguments for server creation
        """
        action_builder = self._bind_actions()
        actions = actions or []
        try:
            action_builder.validate(actions)
        except jsonschema.exceptions.ValidationError as error:
            raise rally_exceptions.InvalidConfigException(
                "Invalid server actions configuration \'%(actions)s\' due to: "
                "%(error)s" % {"actions": str(actions), "error": str(error)})
        server = self._boot_server(image, flavor, **kwargs)
        for action in action_builder.build_actions(actions, server):
            action()
        self._delete_server(server, force=force_delete)
Beispiel #3
0
    def _create_lports(self,
                       lswitch,
                       lport_create_args=[],
                       lport_amount=1,
                       lport_ip_shift=1):
        LOG.info("create %d lports on lswitch %s" % \
                            (lport_amount, lswitch["name"]))

        self.RESOURCE_NAME_FORMAT = "lport_XXXXXX_XXXXXX"

        batch = lport_create_args.get("batch", lport_amount)
        port_security = lport_create_args.get("port_security", True)

        LOG.info("Create lports method: %s" % self.install_method)
        install_method = self.install_method

        network_cidr = lswitch.get("cidr", None)
        ip_addrs = None
        if network_cidr:
            end_ip = network_cidr.ip + lport_amount + lport_ip_shift
            if not end_ip in network_cidr:
                message = _(
                    "Network %s's size is not big enough for %d lports.")
                raise exceptions.InvalidConfigException(
                    message % (network_cidr, lport_amount))

            ip_addrs = netaddr.iter_iprange(network_cidr.ip + lport_ip_shift,
                                            network_cidr.last)

        ovn_nbctl = self.controller_client("ovn-nbctl")
        ovn_nbctl.set_sandbox("controller-sandbox", install_method)
        ovn_nbctl.enable_batch_mode()

        base_mac = [i[:2] for i in self.task["uuid"].split('-')]
        base_mac[0] = str(hex(int(base_mac[0], 16) & 254))
        base_mac[3:] = ['00'] * 3

        flush_count = batch
        lports = []
        for i in range(lport_amount):
            name = self.generate_random_name()
            lport = ovn_nbctl.lswitch_port_add(lswitch["name"], name)

            ip = str(ip_addrs.next()) if ip_addrs else ""
            mac = utils.get_random_mac(base_mac)

            ovn_nbctl.lport_set_addresses(name, [mac, ip])
            if port_security:
                ovn_nbctl.lport_set_port_security(name, mac)

            lports.append(lport)

            flush_count -= 1
            if flush_count < 1:
                ovn_nbctl.flush()
                flush_count = batch

        ovn_nbctl.flush()  # ensure all commands be run
        ovn_nbctl.enable_batch_mode(False)
        return lports
Beispiel #4
0
 def validate(self):
     super(LxcEngine, self).validate()
     if "start_lxc_network" not in self.config:
         return
     lxc_net = netaddr.IPNetwork(self.config["start_lxc_network"])
     num_containers = self.config["containers_per_host"]
     if lxc_net.size - 3 < num_containers:
         message = _("Network size is not enough for %d hosts.")
         raise exceptions.InvalidConfigException(message % num_containers)
Beispiel #5
0
    def _bind_ports_and_wait(self, lports, sandboxes, port_bind_args):
        port_bind_args = port_bind_args or {}
        wait_up = port_bind_args.get("wait_up", False)
        # "wait_sync" takes effect only if wait_up is True.
        # By default we wait for all HVs catching up with the change.
        wait_sync = port_bind_args.get("wait_sync", "hv")
        if wait_sync.lower() not in ['hv', 'sb', 'none']:
            raise exceptions.InvalidConfigException(
                _("Unknown value for wait_sync: %s. "
                  "Only 'hv', 'sb' and 'none' are allowed.") % wait_sync)

        LOG.info("Bind lports method: %s" % self.install_method)

        self._bind_ports(lports, sandboxes, port_bind_args)
        if wait_up:
            self._wait_up_port(lports, wait_sync)
Beispiel #6
0
    def _bind_ports(self, lports, sandboxes, port_bind_args):
        port_bind_args = port_bind_args or {}
        wait_up = port_bind_args.get("wait_up", False)
        # "wait_sync" takes effect only if wait_up is True.
        # By default we wait for all HVs catching up with the change.
        wait_sync = port_bind_args.get("wait_sync", "hv")
        if wait_sync.lower() not in ['hv', 'sb', 'none']:
            raise exceptions.InvalidConfigException(_(
                "Unknown value for wait_sync: %s. "
                "Only 'hv', 'sb' and 'none' are allowed.") % wait_sync)

        sandbox_num = len(sandboxes)
        lport_num = len(lports)
        lport_per_sandbox = (lport_num + sandbox_num - 1) / sandbox_num

        LOG.info("Bind lports method: %s" % self.install_method)
        install_method = self.install_method

        j = 0
        for i in range(0, len(lports), lport_per_sandbox):
            lport_slice = lports[i:i+lport_per_sandbox]

            sandbox = sandboxes[j]["name"]
            farm = sandboxes[j]["farm"]
            ovs_vsctl = self.farm_clients(farm, "ovs-vsctl")
            ovs_vsctl.set_sandbox(sandbox, install_method)
            ovs_vsctl.enable_batch_mode()
            for lport in lport_slice:
                port_name = lport["name"]

                LOG.info("bind %s to %s on %s" % (port_name, sandbox, farm))

                ovs_vsctl.add_port('br-int', port_name)
                ovs_vsctl.db_set('Interface', port_name,
                                 ('external_ids', {"iface-id":port_name,
                                                   "iface-status":"active"}),
                                 ('admin_state', 'up'))
            ovs_vsctl.flush()
            j += 1

        if wait_up:
            self._wait_up_port(lports, wait_sync, install_method)
Beispiel #7
0
 def boot_and_bounce_server(self, image_id, flavor_id, **kwargs):
     """Tests booting a server then performing stop/start or hard/soft
     reboot a number of times.
     """
     action_builder = self._bind_actions()
     actions = kwargs.get('actions', [])
     try:
         action_builder.validate(actions)
     except jsonschema.exceptions.ValidationError as error:
         raise rally_exceptions.InvalidConfigException(
             "Invalid server actions configuration \'%(actions)s\' due to: "
             "%(error)s" % {
                 'actions': str(actions),
                 'error': str(error)
             })
     server = self._boot_server(self._generate_random_name(16), image_id,
                                flavor_id, **kwargs)
     for action in action_builder.build_actions(actions, server):
         action()
     self._delete_server(server)
Beispiel #8
0
    def _stack_webhook(self, stack, output_key):
        """POST to the URL given in the output value identified by output_key.

        This can be used to scale stacks up and down, for instance.

        :param stack: stack to call a webhook on
        :param output_key: The name of the output to get the URL from
        :raises InvalidConfigException: if the output key is not found
        """
        url = None
        for output in stack.outputs:
            if output["output_key"] == output_key:
                url = output["output_value"]
                break
        else:
            raise exceptions.InvalidConfigException(
                "No output key %(key)s found in stack %(id)s" %
                {"key": output_key, "id": stack.id})

        with atomic.ActionTimer(self, "heat.%s_webhook" % output_key):
            requests.post(url).raise_for_status()
Beispiel #9
0
    def boot_and_bounce_server(self, image, flavor, **kwargs):
        """Test booting a server with further performing specified actions.

        Actions should be passed into kwargs. Available actions are
        'hard_reboot', 'soft_reboot', 'stop_start' and 'rescue_unrescue'.
        Delete server after all actions.
        """
        action_builder = self._bind_actions()
        actions = kwargs.get('actions', [])
        try:
            action_builder.validate(actions)
        except jsonschema.exceptions.ValidationError as error:
            raise rally_exceptions.InvalidConfigException(
                "Invalid server actions configuration \'%(actions)s\' due to: "
                "%(error)s" % {
                    'actions': str(actions),
                    'error': str(error)
                })
        server = self._boot_server(self._generate_random_name(), image, flavor,
                                   **kwargs)
        for action in action_builder.build_actions(actions, server):
            action()
        self._delete_server(server)
Beispiel #10
0
    def _do_create_address_set_addr(self,
                                    address_set_id,
                                    addresses_per_address_set=1,
                                    addresses_start_cidr='10.0.0.0/8',
                                    addresses_create_bulk=False,
                                    addresses_create_batch=1):

        addr_cidr = netaddr.IPNetwork(addresses_start_cidr)
        end_ip = addr_cidr.ip + addresses_per_address_set
        if not end_ip in addr_cidr:
            message = _(
                "Address CIDR %s's size is not big enough for %d addresses.")
            raise exceptions.InvalidConfigException(
                message % (addresses_start_cidr, addresses_per_address_set))

        addrs_list = []
        for ip in netaddr.iter_iprange(addr_cidr.ip + 1, end_ip):
            addrs_list.append({'addr': {'address': str(ip)}})

        for addrs in common_utils.chunks(addrs_list, addresses_create_batch):
            if addresses_create_bulk:
                self._create_address_set_addr_bulk(address_set_id, addrs)
            else:
                self._create_address_set_addrs(address_set_id, addrs)
Beispiel #11
0
    def _create_sandbox(self, sandbox_create_args):
        """
        :param sandbox_create_args from task config file
        """

        print("create sandbox")

        amount = sandbox_create_args.get("amount", 1)
        batch = sandbox_create_args.get("batch", 1)

        farm = sandbox_create_args.get("farm")
        controller_ip = self.context["controller"]["ip"]

        start_cidr = sandbox_create_args.get("start_cidr")
        net_dev = sandbox_create_args.get("net_dev", "eth0")
        tag = sandbox_create_args.get("tag", "")

        LOG.info("-------> Create sandbox  method: %s" % self.install_method)
        install_method = self.install_method

        if controller_ip == None:
            raise exceptions.NoSuchConfigField(name="controller_ip")

        sandbox_cidr = netaddr.IPNetwork(start_cidr)
        end_ip = sandbox_cidr.ip + amount
        if not end_ip in sandbox_cidr:
            message = _(
                "Network %s's size is not big enough for %d sandboxes.")
            raise exceptions.InvalidConfigException(message %
                                                    (start_cidr, amount))

        sandbox_hosts = netaddr.iter_iprange(sandbox_cidr.ip,
                                             sandbox_cidr.last)

        ssh = self.farm_clients(farm)

        sandboxes = {}
        batch_left = min(batch, amount)
        i = 0
        while i < amount:

            i += batch_left
            host_ip_list = []
            while batch_left > 0:
                host_ip_list.append(str(sandbox_hosts.next()))
                batch_left -= 1

            cmds = []
            for host_ip in host_ip_list:
                cmd = "./ovs-sandbox.sh --ovn --controller-ip %s \
                             --host-ip %s/%d --device %s"                                                          % \
                         (controller_ip, host_ip, sandbox_cidr.prefixlen,
                                net_dev)
                cmds.append(cmd)

                sandboxes["sandbox-%s" % host_ip] = tag

            if install_method == "docker":
                print "Do not run ssh; sandbox installed by ansible-docker"
            elif install_method == "physical":
                print "Do not run ssh; sandbox installed on physical test bed"
            elif install_method == "sandbox":
                self._do_create_sandbox(ssh, cmds)
            else:
                print "Invalid install method for controller"
                exit(1)

            batch_left = min(batch, amount - i)
            if batch_left <= 0:
                break

        self._add_sandbox_resource(farm, sandboxes)

        return sandboxes