Exemplo n.º 1
0
    def identifier_to_node_uuid(cls, rest_client, node_id_name_or_ip):
        # These will raise appropriate exceptions on failure, so it's safe to
        # assume that otherwise accessing the 'uuid' key is safe.
        if CurieUtil.is_ipv4_address(node_id_name_or_ip):
            return rest_client.hosts_get(host_ip=node_id_name_or_ip)["uuid"]
        elif CurieUtil.is_uuid(node_id_name_or_ip):
            try:
                return rest_client.hosts_get(
                    host_id=node_id_name_or_ip)["uuid"]
            except Exception:
                log.debug("Failed to lookup node via UUID '%s'",
                          node_id_name_or_ip)

        # The provided node identifier is not an IPv4 address or a UUID. It may
        # be either an unresolved hostname or a Prism name. Try Prism name first
        # to avoid potential overhead in name resolution.
        try:
            return rest_client.hosts_get(host_name=node_id_name_or_ip)["uuid"]
        except Exception:
            log.debug("Failed to lookup node via Prism name '%s'",
                      node_id_name_or_ip)

        try:
            ip = CurieUtil.resolve_hostname(node_id_name_or_ip)
        except Exception:
            raise CurieException(
                CurieError.kInvalidParameter,
                "Unable to resolve IP address for '%s'" % node_id_name_or_ip)

        # Allow this to raise it's own exception on failure, as there are no
        # further methods to which we can fall back.
        return rest_client.hosts_get(host_ip=ip)["uuid"]
Exemplo n.º 2
0
 def wait_for_vms_accessible(vms, timeout_secs):
     """
 Wait until all the specified VMs are accessible to run guest OS commands.
 Raises CurieTestException if this takes longer than 'timeout_secs'.
 """
     t1 = time.time()
     t2 = -1
     for xx, vm in enumerate(vms):
         log.info("Waiting for VM %d/%d (%s) to become accessible", xx + 1,
                  len(vms), vm.vm_name())
         if t2 >= 0:
             wait_for_timeout_secs = timeout_secs - (t2 - t1)
         else:
             wait_for_timeout_secs = timeout_secs
         if wait_for_timeout_secs < 0:
             error_msg = "Timeout waiting for VMs to become accessible"
             raise CurieTestException(error_msg)
         if vm.vm_ip() is None:
             error_msg = "IP address not set on Vm object %s" % vm.vm_name()
             raise CurieTestException(error_msg)
         if not CurieUtil.is_ipv4_address(vm.vm_ip()):
             error_msg = "Non-IPv4 address %s on VM %s" % (vm.vm_ip(),
                                                           vm.vm_name())
             raise CurieTestException(error_msg)
         msg = "waiting for VM %s (%s) to become accessible" % \
           (vm.vm_name(), vm.vm_ip())
         if not CurieUtil.wait_for(vm.is_accessible, msg,
                                   wait_for_timeout_secs):
             error_msg = "Timeout waiting for VMs to become accessible"
             raise CurieTestException(error_msg)
         log.info("VM %d/%d (%s) is accessible", xx + 1, len(vms),
                  vm.vm_name())
         t2 = time.time()
Exemplo n.º 3
0
    def __init__(self, cluster, node_id, node_index):
        super(VsphereNode, self).__init__(cluster, node_id, node_index)

        # vCenter node IDs are either IPv4 addresses or hostnames.
        if CurieUtil.is_ipv4_address(node_id):
            self._node_ip = node_id
        else:
            self._node_ip = CurieUtil.resolve_hostname(node_id)
Exemplo n.º 4
0
    def test_slice_with_string_empty_slice(self):
        for ii in range(len(self.sequence)):
            sliced = CurieUtil.slice_with_string(self.sequence,
                                                 "%d:%d" % (ii, ii))
            self.assertEqual(sliced.values(), [])
            self.assertEqual(sliced.keys(), [])

        # Consistency with python built-in slice behavior allowing empty
        # out-of-bounds slices.
        out_of_bounds = len(self.sequence) + 10
        sliced = CurieUtil.slice_with_string(
            self.sequence, "%d:%d" % (out_of_bounds, out_of_bounds))
        self.assertEqual(sliced.values(), [])
        self.assertEqual(sliced.keys(), [])
Exemplo n.º 5
0
    def prereq_runtime_cluster_is_ready_fix(cluster):
        """
    Attempts to ready cluster.

    Raises:
      CurieTestException on failure.
    """
        if not ScenarioUtil.prereq_dependency_has_oob_data(cluster.metadata()):
            raise CurieTestException(
                "Cannot attempt fix without OoB data for cluster")

        unready_nodes = cluster.get_unready_nodes()
        power_on_nodes = []
        for node in unready_nodes:
            if not node.is_powered_on():
                log.info("Powering on node '%s'", node.node_id())
                node.power_on()
                power_on_nodes.append(node)

        if power_on_nodes and not CurieUtil.wait_for(
                lambda: not cluster.get_powered_off_nodes(power_on_nodes,
                                                          sync_with_oob=True),
                "all nodes to be powered on",
                timeout_secs=1200,
                poll_secs=5):
            raise CurieTestException("Timed out waiting for nodes to power on")
        log.info("All nodes are now powered on")

        to_power_on_cvms = []
        for cvm in [vm for vm in cluster.vms() if vm.is_cvm()]:
            if not cvm.is_powered_on():
                to_power_on_cvms.append(cvm)
        log.info("Powering on CVMs: %s",
                 ", ".join([cvm.vm_name() for cvm in to_power_on_cvms]))
        try:
            cluster.power_on_vms(to_power_on_cvms)
        except Exception as exc:
            raise CurieTestException("Failed to power on CVMs: %s" % exc)
        log.info("Powered on all CVMs")

        if not CurieUtil.wait_for(partial(
                ScenarioUtil.prereq_runtime_cluster_is_ready, cluster),
                                  "all nodes to be ready",
                                  timeout_secs=1200,
                                  poll_secs=5):
            raise CurieTestException(
                "Timed out waiting for cluster to be ready")
        log.info("Cluster is now in a ready state")
Exemplo n.º 6
0
  def wait_for(self, func, msg, timeout_secs, poll_secs=None):
    """
    Invoke 'func' every 'poll_secs' seconds until the boolean-ness of the
    returned value is True, in which case we return that value. If
    'timeout_secs' seconds have elapsed, raises an exception. Otherwise, if the
    test is marked to stop, raises a ScenarioStoppedError.

    Args:
      func (callable): Callable to poll.
      msg (str): Readable description of the action.
      timeout_secs (int): Maximum amount of time to wait for func to complete.
      poll_secs (int): Polling interval in seconds. None uses default polling
        interval.

    Raises:
      CurieTestException:
        If 'func' does not evaluate to True within 'timeout_secs' seconds.
      ScenarioStoppedError:
        If the scenario is stopped before wait_for returns.
    """
    return_values = CurieUtil.wait_for_any([func, self.should_stop], msg,
                                            timeout_secs, poll_secs=poll_secs)
    if return_values is None:
      raise ScenarioTimeoutError("Timed out waiting for %s within %d seconds" %
                                 (msg, timeout_secs))
    # Return value of func.
    elif return_values[0]:
      return return_values[0]
    # Return value of self.should_stop.
    elif return_values[1]:
      raise ScenarioStoppedError("Stopped waiting for %s because %s is "
                                 "stopping" % (msg, self))
    else:
      raise RuntimeError("Expected one or more return values to evaluate as "
                         "True: %r" % return_values)
Exemplo n.º 7
0
    def prereq_runtime_node_power_fix(cluster):
        """
    Attempt to boot any powered off nodes in 'cluster'. Block until all nodes
    are powered.

    NB: Powered on will not guarantee that the node is ready. There are further
    vendor-specific prereqs which will verify required services, etc.

    Raises:
      CurieTestException on error or timeout.
    """
        to_power_on_nodes = [
            node for node in cluster.nodes() if not node.is_powered_on()
        ]

        log.info("Attempting to power on the following nodes: %s",
                 ", ".join([node.node_id() for node in to_power_on_nodes]))
        for node in to_power_on_nodes:
            node.power_on()

        def nodes_powered_on():
            for node in to_power_on_nodes:
                if not node.is_powered_on():
                    return False
            return True

        if not CurieUtil.wait_for(
                nodes_powered_on, "nodes to be powered on", 600, poll_secs=5):
            raise CurieTestException("Unable to power on nodes prior to test")
Exemplo n.º 8
0
def _decrypt_field(self, field, key=None):
    """
  Decrypts 'field' via CurieUtil.decrypt_aes256_cfb.

  If provided, 'key' is used, otherwise, if previously set, class-level
  encryption key returned by 'self.get_encryption_key' will be used.

  Args:
    field (str): Name of protobuf field to be decrypted.
    key (str|None): Optional. Encryption key to use, assumed to be a
      SHA-256 digest.

  Raises:
    AttributeError on invalid or non-encrypted 'field'.
    ValueError if no encryption key is provided.
  """
    key = key if key else self.get_encryption_key()
    if not self.is_encrypted_field(field):
        raise AttributeError("Field '%s' is not an encrypted field" % field)

    # TODO (jklein): Disable this transition behavior once all components are
    # in sync.
    if key is None:
        # For transition period, if 'key' is not set, assume field is still
        # plaintext.
        return getattr(self, field)
    #   raise ValueError("Encryption key cannot be None")

    return CurieUtil.decrypt_aes256_cfb(getattr(self, field), key)
Exemplo n.º 9
0
    def power_off(self, sync_management_state=True):
        """
    Powers off the node using out-of-band management interface specified in the
    cluster's metadata.

    Args:
      sync_management_state (bool): If true, wait until the management software
      detects the power state is off. This is True by default in order to
      prevent other management server methods that require power to be on from
      failing unexpectedly.

    Raises:
      CurieTestException if no suitable metadata exists, CurieException on
      all other errors.
    """
        log.debug("Powering off node '%s'", self._node_id)
        if not self.power_management_util.power_off():
            raise CurieException(
                CurieError.kInternalError,
                "Failed to power off node '%s'" % self._node_id)
        # If 'sync_management_state', wait until the management server state is
        # synced with the hardware's state.
        if sync_management_state:
            timeout_secs = 40 * 60
            powered_off = CurieUtil.wait_for(
                lambda: not self.is_powered_on_soft(sync_with_oob=True),
                "management server power state to sync to off for node: %s" %
                self.node_id(),
                timeout_secs,
                poll_secs=5)
            if not powered_off:
                raise CurieException(
                    CurieError.kInternalError,
                    "Failed to sync management server power state after 300s")
Exemplo n.º 10
0
    def __init__(self, cluster, node_id, node_index, node_properties):
        super(HyperVNode, self).__init__(cluster, node_id, node_index)

        self.power_state = node_properties["power_state"]
        self.__fqdn = node_properties["fqdn"]
        self.__overall_state = node_properties["overall_state"]
        ips = node_properties["ips"]

        if not ips:
            raise CurieException("Received empty node ip list in response")

        # vCenter node IDs are either IPv4 addresses or hostnames.
        if CurieUtil.is_ipv4_address(ips[0]):
            self._node_ip = ips[0]
        else:
            self._node_ip = CurieUtil.resolve_hostname(ips[0])
Exemplo n.º 11
0
 def _run(self):
   node = self.scenario.cluster.nodes()[self.node_index]
   address = node.metadata().node_out_of_band_management_info.ip_address
   if not CurieUtil.ping_ip(address):
     raise CurieTestException(
       cause=
       "Out-of-band power management for node '%d' with address '%s' did not "
       "respond to a network ping." % (node.node_index(), address),
       impact=
       "There is no network connectivity to '%s'." % address,
       corrective_action=
       "Please troubleshoot network connectivity to the power management "
       "controller with address '%s'." % address
     )
   try:
     node.power_management_util.get_chassis_status()
   except Exception:
     raise CurieTestException(
       cause=
       "Command failure occurred on the out-of-band power management for "
       "node '%d' with address '%s'." % (node.node_index(), address),
       impact=
       "There is network connectivity to '%s', but power management commands "
       "are failing." % address,
       corrective_action=
       "Please check the configured username and password for the power "
       "management controller with address '%s'. Please also ensure that "
       "'IPMI over LAN' is enabled for the power management controller, and "
       "that network connections to '%s' on UDP port 623 are allowed." %
       (address, address)
     )
Exemplo n.º 12
0
    def sync_power_state_for_nodes(self, nodes, timeout_secs=(40 * 60)):
        """See 'Cluster.sync_power_state_for_nodes' for documentation."""
        log.info("Synchronizing power state for nodes '%s'",
                 ", ".join([node.node_id() for node in nodes]))
        with self._open_vcenter_connection() as vcenter:
            vim_cluster = self._lookup_vim_cluster(vcenter)
            node_power_state_map = self.get_power_state_for_nodes(nodes)
            oob_powered_on, oob_powered_off = \
                self.__verify_mgmt_oob_power_states_match(nodes,
                                                          node_power_state_map)

            def _done_syncing_nodes():
                node_power_state_map = self.get_power_state_for_nodes(nodes)
                oob_powered_on, oob_powered_off = \
                  self.__verify_mgmt_oob_power_states_match(nodes,
                                                            node_power_state_map)
                to_sync_curie_nodes = oob_powered_on + oob_powered_off
                if not to_sync_curie_nodes:
                    return True
                # Reconnect might fail, as hosts may be powered off, but this may
                # force vCenter to refresh their power states.
                to_sync_vim_hosts = vcenter.lookup_hosts(
                    vim_cluster,
                    [node.node_id() for node in to_sync_curie_nodes])
                vcenter.reconnect_hosts(to_sync_vim_hosts)
                return False

            # Ignore the boolean returned by 'wait_for'. Whether or not this
            # succeeds, we want to refresh the values for 'oob_powered_on',
            # 'oob_powered_off' to provide more detailed logging.
            CurieUtil.wait_for(_done_syncing_nodes,
                               "vCenter to sync state for mismatched hosts",
                               timeout_secs=timeout_secs,
                               poll_secs=5)

            node_power_state_map = self.get_power_state_for_nodes(nodes)
            oob_powered_on, oob_powered_off = \
                self.__verify_mgmt_oob_power_states_match(nodes,
                                                          node_power_state_map)
            unsynced_curie_nodes = oob_powered_on + oob_powered_off

            if unsynced_curie_nodes:
                raise CurieTestException(
                    "Unable to sync vCenter power states for %s" % ", ".join(
                        [node.node_id() for node in unsynced_curie_nodes]))

            return node_power_state_map
Exemplo n.º 13
0
 def validate_host_connectivity(cluster_pb):
   cluster_cls = get_cluster_class(cluster_pb)
   cluster = cluster_cls(cluster_pb)
   for node in cluster.nodes():
     if not CurieUtil.ping_ip(node.node_ip()):
       raise CurieException(CurieError.kInternalError,
                             "Host %s - %s not reachable." %
                             (node.node_id(), node.node_ip()))
Exemplo n.º 14
0
 def verify(self):
     # NB: This must reference metadata and *not* the actual 'CurieNode'
     # instances to avoid blocking queries to Prism on AHV.
     node_vec = self.scenario.cluster.metadata().cluster_nodes
     try:
         CurieUtil.slice_with_string(node_vec, self.nodes_slice_str)
     except IndexError:
         raise CurieTestException(
             cause="Node slice '%s' is out of bounds." %
             self.nodes_slice_str,
             impact=
             "The scenario '%s' can not be used with cluster '%s' because the %s "
             "step refers to one or more nodes by an index that is either larger "
             "or smaller than the number of nodes in the cluster (%d)." %
             (self.scenario.display_name, self.scenario.cluster.name(),
              self.name, len(node_vec)),
             corrective_action=
             "Please retry the scenario using a cluster with a compatible number "
             "of nodes. If you are the author of the scenario, please check the "
             "syntax of the %s step to make it compatible with clusters of this "
             "size." % self.name)
     except ValueError as exc:
         raise CurieTestException(
             cause="Syntax error for node slice '%s': %s" %
             (self.nodes_slice_str, exc),
             impact="The scenario '%s' can not be used." %
             self.scenario.display_name,
             corrective_action=
             "Please check the syntax of the %s step. Python-flavored slice "
             "strings are accepted. Additionally, several slice strings can be "
             "combined using commas. The word 'all' can be used to refer to all "
             "nodes, and the letter 'n' can refer to the number of nodes in the "
             "cluster. Arithmetic operations are also supported using the +, -, *, "
             "and / operators. For example, the following strings are valid:\n"
             "  '0'  # The first node.\n"
             "  '0, 1'  # The first two nodes.\n"
             "  '0:2'  # The first two nodes.\n"
             "  '0:2, n-2:n'  # The first two nodes and the last two nodes.\n"
             "  ':2, n-2:'  # The first two nodes and the last two nodes.\n"
             "  ':n/2'  # The first half of the nodes.\n"
             "  'n/2:'  # The last half of the nodes.\n"
             "  'all'  # All nodes." % self.name)
Exemplo n.º 15
0
 def _run(self):
   node = self.scenario.cluster.nodes()[self.node_index]
   if not CurieUtil.ping_ip(node.node_ip()):
     raise CurieTestException(
       cause=
       "Hypervisor for node '%s' with address %s did not respond to a "
       "network ping." % (node, node.node_ip()),
       impact=
       "There is no network connectivity to %s." % node.node_ip(),
       corrective_action=
       "Please troubleshoot network connectivity to the hypervisor for node "
       "'%s' with address %s." % (node, node.node_ip())
     )
Exemplo n.º 16
0
  def _update_cluster_version_info_vcenter(cluster_pb):
    """
    See 'DiscoveryUtil.update_cluster_version_info' for info.
    """
    mgmt_info = cluster_pb.cluster_management_server_info.vcenter_info
    hyp_info = cluster_pb.cluster_hypervisor_info.esx_info

    with VsphereVcenter.from_proto(mgmt_info) as vcenter:
      vim_dc = vcenter.lookup_datacenter(mgmt_info.vcenter_datacenter_name)
      vim_cluster = vcenter.lookup_cluster(vim_dc,
                                           mgmt_info.vcenter_cluster_name)
      if vim_cluster is None:
        raise CurieException(CurieError.kInvalidParameter,
                              "Cluster not found in specified vCenter")

      esx_version_pairs = vcenter.get_esx_versions(vim_cluster)
      hyp_info.version.extend(pair[0] for pair in esx_version_pairs)
      hyp_info.build.extend(pair[1] for pair in esx_version_pairs)

      mgmt_info.vcenter_version, mgmt_info.vcenter_build = \
          vcenter.get_vcenter_version_info()

      if cluster_pb.cluster_software_info.HasField("nutanix_info"):
        cvms = [vim_vm for vim_vm in vcenter.lookup_vms(vim_cluster)
                if vcenter.vim_vm_is_nutanix_cvm(vim_vm)]
        if not cvms:
          raise CurieException(
            CurieError.kInvalidParameter,
            "Unable to locate any CVMs on cluster. Is this a Nutanix cluster?")
        for cvm in cvms:
          ip = get_optional_vim_attr(cvm.guest, "ipAddress")
          if ip and CurieUtil.is_ipv4_address(ip):
            break
        else:
          raise CurieException(
            CurieError.kInvalidParameter,
            "Unable to locate any CVMs with IPv4 addresses on cluster")

        software_info = cluster_pb.cluster_software_info.nutanix_info
        cli = NutanixRestApiClient(
          ip,
          software_info.decrypt_field("prism_user"),
          software_info.decrypt_field("prism_password"))
        DiscoveryUtil._update_cluster_version_info_nos(cli, cluster_pb)
Exemplo n.º 17
0
 def transfer_to(self,
                 local_path,
                 remote_path,
                 timeout_secs,
                 recursive=False):
   """
   Transfer 'local_path' to 'remote_path' on _host. 'timeout_secs' specifies a
   timeout on the transfer. 'recursive' specifies whether the transfer is
   recursive or not. Returns True on success, else False on failure or a
   timeout.
   """
   if recursive:
     opts = self.__base_scp_opts + " -r"
   else:
     opts = self.__base_scp_opts
   cmd = "scp %s %s '%s@%s:%s'" % \
     (opts, local_path, self.__user, self.__host, remote_path)
   log.debug("Transferring %s to %s:%s to using %s",
             local_path, self.__host, remote_path, cmd)
   status, _, _ = CurieUtil.timed_command(cmd, timeout_secs)
   return status == 0
Exemplo n.º 18
0
def get_nodes(scenario, slice_string):
    """Get a list of CurieClusterNodes for a given node index slice string.

  Args:
    scenario (Scenario): Scenario that owns the node.
    slice_string (str): String containing indices of the desired nodes.

  Returns:
    (list): CurieClusterNodes in an order matching that specified by
      'slice_string' .

  Raises:
    CurieTestException:
      If slice_string is out of bounds.
  """
    nodes = scenario.cluster.nodes()
    try:
        return CurieUtil.slice_with_string(nodes, slice_string).values()
    except IndexError as err:
        raise CurieTestException(
            "Node slice is out of bounds (cluster contains %d nodes): %s" %
            (len(nodes), err))
Exemplo n.º 19
0
 def wait_for_cmd(self,
                  cmd_id,
                  timeout_secs,
                  poll_secs=30,
                  desired_state=CmdStatus.kSucceeded):
     """
 Wait up to 'timeout_secs' for the command with ID 'cmd_id' to reach the
 state 'desired_state'. Returns a CmdStatus protobuf for the command on
 success, else raises CurieTestException if either a timeout occurs or the
 command has reached a terminal state that is different from the desired
 state.
 """
     cmd_status = CurieUtil.wait_for(
         lambda: self.check_cmd(cmd_id, desired_state),
         "command %s" % cmd_id,
         timeout_secs,
         poll_secs=poll_secs)
     if cmd_status is not None:
         return cmd_status
     else:
         raise CurieTestException("Timeout waiting for command '%s'" %
                                  cmd_id)
Exemplo n.º 20
0
  def validate_oob_config(cluster_pb):
    """
    Validates provided out-of-band management config in 'cluster_pb'.

    Args:
      cluster_pb (curie_server_state_pb2.CurieSettings.Cluster): Populated
        cluster proto whose data to validate.

    Raises: CurieException on any error encountered.
    """
    for node in cluster_pb.cluster_nodes:
      if (node.node_out_of_band_management_info.interface_type
          == node.NodeOutOfBandManagementInfo.kNone):
        continue

      if not CurieUtil.ping_ip(
        node.node_out_of_band_management_info.ip_address):
        raise CurieException(CurieError.kInternalError,
          "Out-of-band management at '%s' is unreachable" %
          node.node_out_of_band_management_info.ip_address)

      oob_util = get_power_management_util(
        node.node_out_of_band_management_info)
      try:
        oob_util.get_chassis_status()
      except CurieException as exc:
        # Not all OoB implementations will explicitly distinguish an
        # authentication error. Tailor error message appropriately.
        if exc.error_code == CurieError.kOobAuthenticationError:
          raise CurieException(
            error_code=exc.error_code,
            error_msg="Out-of-band management authentication failed for node"
                      " %s" % node.id)
        else:
          raise CurieException(
            error_code=exc.error_code,
            error_msg="Failed to query out-of-band management for node %s. "
                      "Please re-enter credentials" % node.id)
Exemplo n.º 21
0
  def __execute_command(self, cmd):
    """
    Executes 'cmd' via ipmitool 'self.__ipmitool_abspath' using '__flags'.

    Returns:
      (tuple): (rv, stdout, stderr)

    Raises:
      CurieException on bad input or failure to execute the command.
    """
    if isinstance(cmd, basestring):
      cmd = cmd.split(" ")

    if not isinstance(cmd, list):
      raise CurieException(
        CurieError.kInternalError,
        "'cmd' must be of type list or str, not '%s'" % cmd.__class__.__name__)

    generated_cmd = []
    map(generated_cmd.extend,
        [[self.__ipmitool_abspath], self.__get_flag_list(redacted=False), cmd])

    redacted_cmd = []
    map(redacted_cmd.extend,
        [[self.__ipmitool_abspath], self.__get_flag_list(redacted=True), cmd])

    log.info("Executing IPMI command:\n\t'%s'", " ".join(redacted_cmd))
    rv, stdout, stderr = CurieUtil.timed_command(
      " ".join(generated_cmd), timeout_secs=60,
      formatted_cmd=" ".join(redacted_cmd))

    cmd_output = "rv=%s\nstdout=%s\nstderr=%s" % (rv, stdout, stderr)
    if rv < 0:
      raise CurieException(
        CurieError.kInternalError,
        "Failed to execute command: '%s': %s" % (redacted_cmd, cmd_output))
    log.debug(cmd_output)
    return (rv, stdout, stderr)
Exemplo n.º 22
0
 def test_slice_with_n_end(self):
     sliced = CurieUtil.slice_with_string(self.sequence, "1:(n/2)+1")
     self.assertEqual(sliced.values(), ["item_1", "item_2", "item_3"])
     self.assertEqual(sliced.keys(), [1, 2, 3])
Exemplo n.º 23
0
 def test_slice_with_string_single_index_out_of_bounds_max(self):
     with self.assertRaises(IndexError):
         CurieUtil.slice_with_string(self.sequence, "0, 6")
Exemplo n.º 24
0
 def test_slice_with_string_single_index_max(self):
     sliced = CurieUtil.slice_with_string(self.sequence, "5")
     self.assertEqual(sliced.values(), ["item_5"])
     self.assertEqual(sliced.keys(), [5])
Exemplo n.º 25
0
 def test_slice_with_string_negative_range_converted_to_positive(self):
     sliced = CurieUtil.slice_with_string(self.sequence, ":-3")
     self.assertEqual(sliced.values(), ["item_0", "item_1", "item_2"])
     self.assertEqual(sliced.keys(), [0, 1, 2])
Exemplo n.º 26
0
 def test_slice_with_string_negative_indices_converted_to_positive(self):
     sliced = CurieUtil.slice_with_string(self.sequence, "-1, -2")
     self.assertEqual(sliced.values(), ["item_5", "item_4"])
     self.assertEqual(sliced.keys(), [5, 4])
Exemplo n.º 27
0
 def test_slice_with_string_three_indices_mixed_order(self):
     sliced = CurieUtil.slice_with_string(self.sequence, "4, 1, 3")
     self.assertEqual(sliced.values(), ["item_4", "item_1", "item_3"])
     self.assertEqual(sliced.keys(), [4, 1, 3])
Exemplo n.º 28
0
 def test_slice_with_string_mixed_range_reverse(self):
     sliced = CurieUtil.slice_with_string(self.sequence, "4, 1:3")
     self.assertEqual(sliced.values(), ["item_4", "item_1", "item_2"])
     self.assertEqual(sliced.keys(), [4, 1, 2])
Exemplo n.º 29
0
    Returns:
      (bool) True on success, else False.
    """
    success = True
    try:
      self.send_racadm_command("serveraction powerup")
    except CurieException:
      log.exception("Power On failed")
      success = False

    if async or not success:
      return success

    return CurieUtil.wait_for(
      self.is_powered_on,
      "IPMI at '%s' to report node powered on" % self.host,
      timeout_secs=600,
      poll_secs=5)

  def power_off(self, async=False):
    """
    Powers off node associated with iDRAC at 'self.host'.

    Args:
      async (bool): Optional. If True, return immediately after command
        succeeds, don't block until power state has changed to off.

    Returns:
      (bool) True on success, else False.
    """
    success = True
Exemplo n.º 30
0
 def test_slice_with_string_single_range_max(self):
     sliced = CurieUtil.slice_with_string(self.sequence, ":6")
     self.assertEqual(sliced.values(), self.sequence)
     self.assertEqual(sliced.keys(), range(6))