Пример #1
0
def test_server_exclusion(*args):
    """
    Exclude servers using regular expressions.
    """
    openstackCheck = OpenStackCheck(
        "test",
        {
            'keystone_server_url': 'http://10.0.2.15:5000',
            'ssl_verify': False,
            'exclude_server_ids': common.EXCLUDED_SERVER_IDS,
        },
        instances=instances,
    )

    # Retrieve servers
    openstackCheck.server_details_by_id = copy.deepcopy(
        common.ALL_SERVER_DETAILS)
    i_key = "test_instance"
    server_ids = openstackCheck.get_servers_managed_by_hypervisor(
        i_key, False, False)

    # Assert
    # .. 1 out of 4 server ids filtered
    assert len(server_ids) == 1

    # Ensure the server IDs filtered are the ones expected
    for server_id in server_ids:
        assert server_id in common.FILTERED_SERVER_ID
Пример #2
0
def test_cache_between_runs(self, *args):
    """
    Ensure the cache contains the expected VMs between check runs.
    """

    openstackCheck = OpenStackCheck(
        "test",
        {
            'keystone_server_url': 'http://10.0.2.15:5000',
            'ssl_verify': False,
            'exclude_server_ids': common.EXCLUDED_SERVER_IDS,
        },
        instances=instances,
    )

    # Start off with a list of servers
    openstackCheck.server_details_by_id = copy.deepcopy(
        common.ALL_SERVER_DETAILS)
    i_key = "test_instance"

    # Update the cached list of servers based on what the endpoint returns
    cached_servers = openstackCheck.get_all_servers(i_key, False)

    assert 'server-1' not in cached_servers
    assert 'server_newly_added' in cached_servers
Пример #3
0
    IncompleteConfig,
    IncompleteIdentity,
    KeystoneCatalog,
    OpenStackCheck,
    OpenStackProjectScope,
    OpenStackUnscoped,
)

from . import common

instances = common.MOCK_CONFIG['instances']
instance = common.MOCK_CONFIG['instances'][0]
instance['tags'] = ['optional:tag1']
init_config = common.MOCK_CONFIG['init_config']
openstack_check = OpenStackCheck('openstack',
                                 init_config,
                                 instances=[instance])


class MockHTTPResponse(object):
    def __init__(self, response_dict, headers):
        self.response_dict = response_dict
        self.headers = headers

    def json(self):
        return self.response_dict


MOCK_HTTP_RESPONSE = MockHTTPResponse(
    response_dict=common.EXAMPLE_AUTH_RESPONSE,
    headers={"X-Subject-Token": "fake_token"})