def initialize(self, config=None, request=None, **kwargs): """Return an initialized Ansible Host Manager instance.""" ansible_cfg = dict() # merge command-line configuration options if config is not None: ansible_cfg.update(self._load_ansible_config(config)) # merge pytest request configuration options if request is not None: ansible_cfg.update(self._load_request_config(request)) # merge in provided kwargs ansible_cfg.update(kwargs) return get_host_manager(**ansible_cfg)
def test_connection_failure_v2(): from pytest_ansible.host_manager import get_host_manager from pytest_ansible.errors import AnsibleConnectionFailure hosts = get_host_manager(inventory='unknown.example.com,', connection='smart') with pytest.raises(AnsibleConnectionFailure) as exc_info: hosts.all.ping() # Assert message assert exc_info.value.message == "Host unreachable" # Assert contacted assert exc_info.value.contacted == {} # Assert dark assert 'unknown.example.com' in exc_info.value.dark # Assert unreachable assert 'unreachable' in exc_info.value.dark['unknown.example.com'], exc_info.value.dark.keys() assert exc_info.value.dark['unknown.example.com']['unreachable'] # Assert msg assert 'msg' in exc_info.value.dark['unknown.example.com'] assert 'Failed to connect to the host via ssh' in exc_info.value.dark['unknown.example.com']['msg']
def test_connection_failure_v2(): from pytest_ansible.host_manager import get_host_manager from pytest_ansible.errors import AnsibleConnectionFailure hosts = get_host_manager(inventory='unknown.example.com,', connection='smart') with pytest.raises(AnsibleConnectionFailure) as exc_info: hosts.all.ping() # Assert message assert exc_info.value.message == "Host unreachable" # Assert contacted assert exc_info.value.contacted == {} # Assert dark assert 'unknown.example.com' in exc_info.value.dark # Assert unreachable assert 'unreachable' in exc_info.value.dark['unknown.example.com'], exc_info.value.dark.keys() assert exc_info.value.dark['unknown.example.com']['unreachable'] # Assert msg assert 'msg' in exc_info.value.dark['unknown.example.com'] assert 'Failed to connect to the host via ssh' in exc_info.value.dark['unknown.example.com']['msg']
def test_connection_failure_v1(): from pytest_ansible.host_manager import get_host_manager from pytest_ansible.errors import AnsibleConnectionFailure hosts = get_host_manager(inventory='unknown.example.com,', connection='smart') with pytest.raises(AnsibleConnectionFailure) as exc_info: hosts.all.ping() # Assert message assert exc_info.value.message == "Host unreachable" # Assert contacted assert exc_info.value.contacted == {} # Assert dark assert 'unknown.example.com' in exc_info.value.dark # Assert unreachable assert 'failed' in exc_info.value.dark['unknown.example.com'] assert exc_info.value.dark['unknown.example.com']['failed'] # Assert msg assert 'msg' in exc_info.value.dark['unknown.example.com'] assert exc_info.value.dark['unknown.example.com']['msg'].startswith(u'SSH Error: ssh: Could not resolve hostname' ' unknown.example.com:')
def test_connection_failure_v1(): from pytest_ansible.host_manager import get_host_manager from pytest_ansible.errors import AnsibleConnectionFailure hosts = get_host_manager(inventory='unknown.example.com,', connection='smart') with pytest.raises(AnsibleConnectionFailure) as exc_info: hosts.all.ping() # Assert message assert exc_info.value.message == "Host unreachable" # Assert contacted assert exc_info.value.contacted == {} # Assert dark assert 'unknown.example.com' in exc_info.value.dark # Assert unreachable assert 'failed' in exc_info.value.dark['unknown.example.com'] assert exc_info.value.dark['unknown.example.com']['failed'] # Assert msg assert 'msg' in exc_info.value.dark['unknown.example.com'] assert exc_info.value.dark['unknown.example.com']['msg'].startswith(u'SSH Error: ssh: Could not resolve hostname' ' unknown.example.com:')
def hosts(): from pytest_ansible.host_manager import get_host_manager return get_host_manager(inventory=','.join(ALL_HOSTS), connection='local')