Пример #1
0
    def test_2_hmcs(self, capsys):
        """
        Check out the HMCs specified in the HMC credentials file.
        Skip HMCs that cannot be contacted.
        """

        cpc_items = self.hmc_creds.get_cpc_items()

        if cpc_items is None:
            info(capsys, "HMC credentials file not found: %r - Skipping the "
                 "checking of HMCs", self.hmc_creds.filepath)
            return

        rt_config = zhmcclient.RetryTimeoutConfig(
            connect_timeout=10,
            connect_retries=1,
        )

        # Check HMCs and their CPCs
        for cpc_name in cpc_items:

            cpc_item = cpc_items[cpc_name]

            hmc_host = cpc_item['hmc_host']

            info(capsys, "Checking HMC %r for CPC %r", (hmc_host, cpc_name))

            session = zhmcclient.Session(
                hmc_host, cpc_item['hmc_userid'], cpc_item['hmc_password'],
                retry_timeout_config=rt_config)

            client = zhmcclient.Client(session)

            try:
                session.logon()
            except zhmcclient.ConnectionError as exc:
                info(capsys, "Skipping HMC %r for CPC %r: %s",
                     (hmc_host, cpc_name, exc))
                continue

            cpcs = client.cpcs.list()
            cpc_names = [cpc.name for cpc in cpcs]
            if cpc_name not in cpc_names:
                raise AssertionError(
                    "CPC {!r} not found in HMC {!r}.\n"
                    "Existing CPCs: {!r}".
                    format(cpc_name, hmc_host, cpc_names))

            session.logoff()
Пример #2
0
import zhmcclient
import zhmcclient_mock

# Logger names by log component
LOGGER_NAMES = {
    'all': '',  # root logger
    'api': zhmcclient.API_LOGGER_NAME,
    'hmc': zhmcclient.HMC_LOGGER_NAME,
}

DEFAULT_LOG = 'all=warning'

DEFAULT_RT_CONFIG = zhmcclient.RetryTimeoutConfig(
    connect_timeout=10,
    connect_retries=1,
    operation_timeout=300,
    status_timeout=60,
)


def assert_resources(resources, exp_resources, prop_names):
    """
    Assert that a list of resource objects is equal to an expected list of
    resource objects (or faked resource objects).

    This is done by comparing:
    - The resource URIs, making sure that the two lists have matching URIs.
    - The specified list of property names.

    Parameters:
    'exporter': (EXPORTER_LOGGER_NAME, logging.INFO),
}
VALID_LOG_COMPONENTS = LOGGER_NAMES.keys()

VALID_LOG_DESTINATIONS = ['stderr']
VALID_LOG_DESTINATIONS_DISPLAY = VALID_LOG_DESTINATIONS + ['FILE']

# Sleep time in seconds when retrying metrics retrieval
RETRY_SLEEP_TIME = 10

# Retry / timeout configuration for zhmcclient (used at the socket level)
RETRY_TIMEOUT_CONFIG = zhmcclient.RetryTimeoutConfig(
    connect_timeout=10,
    connect_retries=2,
    read_timeout=120,
    read_retries=2,
    max_redirects=zhmcclient.DEFAULT_MAX_REDIRECTS,
    operation_timeout=zhmcclient.DEFAULT_OPERATION_TIMEOUT,
    status_timeout=zhmcclient.DEFAULT_STATUS_TIMEOUT,
    name_uri_cache_timetolive=zhmcclient.DEFAULT_NAME_URI_CACHE_TIMETOLIVE,
)


class YAMLInfoNotFoundError(Exception):
    """A custom error that is raised when something that was expected in a
    YAML cannot be found.
    """
    pass


class ConnectionError(Exception):
    # pylint: disable=redefined-builtin