def test_get_hostname(): hn = Hostname(context_wrap(HOSTNAME)) expected = (HOSTNAME, HOSTNAME_SHORT, 'example.com') result = hostname(hn, None, None) assert result.fqdn == expected[0] assert result.hostname == expected[1] assert result.domain == expected[2] hn = Hostname(context_wrap(HOSTNAME_SHORT)) expected = (HOSTNAME_SHORT, HOSTNAME_SHORT, '') result = hostname(hn, None, None) assert result.fqdn == expected[0] assert result.hostname == expected[1] assert result.domain == expected[2]
def test_hostname(): data = Hostname(context_wrap(HOSTNAME)) assert data.fqdn == "rhel7.example.com" assert data.hostname == "rhel7" assert data.domain == "example.com" assert "{0}".format(data) == "<hostname: rhel7, domain: example.com>" data = Hostname(context_wrap(HOSTNAME_SHORT)) assert data.fqdn == "rhel7" assert data.hostname == "rhel7" assert data.domain == "" data = Hostname(context_wrap("")) assert data.fqdn is None assert data.hostname is None assert data.domain is None
def test_lssap_ascs(): lssap = Lssap(context_wrap(Lssap_ascs_TEST)) hn = hostname(Hostname(context_wrap(HOSTNAME)), None, None) sap = Sap(hn, None, lssap) assert sap['ASCS16'].sid == 'HA2' assert sap.is_netweaver is False assert sap.is_hana is False assert sap.is_ascs is True
def test_doc_examples(): env = { 'saps': Sap(hostname(Hostname(context_wrap(HOSTNAME)), None, None), None, Lssap(context_wrap(Lssap_doc_TEST))) } failed, total = doctest.testmod(sap, globs=env) assert failed == 0
def test_full_multiline_hostname(): data = Hostname(context_wrap(HOSTNAME_FULL_MULTILINE, strip=False)) assert data.fqdn == "rhel7.example.com" assert data.hostname == "rhel7" assert data.domain == "example.com" assert "{0}".format( data ) == "<raw: rhel7.example.com, hostname: rhel7, domain: example.com>"
def test_lssap_hana(): lssap = Lssap(context_wrap(Lssap_hana_TEST)) hn = hostname(Hostname(context_wrap(HOSTNAME)), None, None) sap = Sap(hn, None, lssap) assert 'D50' not in sap assert sap.is_netweaver is False assert sap.is_hana is True assert sap.is_ascs is False
def test_hostname_doc(): env = { 'hostname': Hostname(context_wrap(HOSTNAME_FULL)), 'hostname_def': HostnameDefault(context_wrap(HOSTNAME_SHORT)), 'hostname_s': HostnameShort(context_wrap(HOSTNAME_SHORT)), } failed, total = doctest.testmod(hostname, globs=env) assert failed == 0
def test_all(): lssap = Lssap(context_wrap(Lssap_all_TEST)) hn = hostname(Hostname(context_wrap(HOSTNAME)), None, None) sap = Sap(hn, None, lssap) assert sap['D16'].version == '749, patch 10, changelist 1698137' assert sap['ASCS16'].hostname == 'lu0417' assert sap.is_netweaver is True assert sap.is_hana is True assert sap.is_ascs is True
def test_get_all_hostname(): hn = Hostname(context_wrap(HOSTNAME)) fhn = Facter(context_wrap(FACTS_FQDN)) shn = SystemID(context_wrap(SYSTEMID_PROFILE_NAME)) expected = (HOSTNAME, HOSTNAME_SHORT, 'example.com') result = hostname(hn, fhn, shn) assert result.fqdn == expected[0] assert result.hostname == expected[1] assert result.domain == expected[2]
def test_full_hostname(): data = Hostname(context_wrap(HOSTNAME_FULL)) assert data.fqdn == "rhel7.example.com" assert data.raw == "rhel7.example.com" assert data.hostname == "rhel7" assert data.domain == "example.com" assert "{0}".format( data ) == "<raw: rhel7.example.com, hostname: rhel7, domain: example.com>"
def test_lssap_netweaver(): lssap = Lssap(context_wrap(Lssap_nw_TEST)) hn = hostname(Hostname(context_wrap(HOSTNAME)), None, None) sap = Sap(hn, None, lssap) assert sap['D50'].number == '50' assert 'D16' in sap.local_instances assert 'D51' in sap.all_instances assert 'D51' not in sap.local_instances assert sap.is_netweaver is True assert sap.is_hana is False assert sap.is_ascs is False
def test_hostname_uh(): hostname = Hostname(context_wrap(HOSTNAME)) uname = Uname(context_wrap(UNAME)) hostname_uh = HostnameUH(hostname, None) assert hostname_uh.hostname == HOSTNAME hostname_uh = HostnameUH(None, uname) assert hostname_uh.hostname == "hostone_u.example.com" hostname_uh = HostnameUH(hostname, uname) assert hostname_uh.hostname == HOSTNAME
def test_saphostcrtl_hana(): lssap = Lssap(context_wrap(Lssap_nw_TEST)) inst = SAPHostCtrlInstances(context_wrap(SAPHOSTCTRL_HOSTINSTANCES)) hn = hostname(Hostname(context_wrap(HOSTNAME)), None, None) sap = Sap(hn, inst, lssap) assert 'D50' not in sap assert sap.local_instances == ['HDB88'] assert 'HDB90' in sap.all_instances assert sap['HDB88'].number == '88' assert sap['HDB90'].hostname == 'lu0418' assert sap['HDB90'].version == '749, patch 211, changelist 1754007' assert sap.number('HDB90') == '90' assert sap.sid('HDB88') == 'D89' assert sap.is_netweaver is False assert sap.is_hana is True assert sap.is_ascs is False
def test_saphostcrtl_hana_2(): lssap = Lssap(context_wrap(Lssap_all_TEST)) inst = SAPHostCtrlInstances(context_wrap(SAPHOSTCTRL_HOSTINSTANCES_GOOD)) hn = hostname(Hostname(context_wrap(HOSTNAME1)), None, None) sap = Sap(hn, inst, lssap) assert 'D50' not in sap assert sorted(sap.local_instances) == sorted(['HDB88', 'HDB90', 'SMDA91']) assert sorted(sap.business_instances) == sorted(['HDB88', 'HDB90']) assert sorted(sap.function_instances) == sorted(['SMDA91']) assert 'ASCS52' in sap.all_instances assert sap['HDB88'].number == '88' assert sap['HDB90'].hostname == 'li-ld-1810' assert sap['DVEBMGS09'].version == '749, patch 301, changelist 1779613' assert sap.version('HDB90') == '749, patch 211, changelist 1754007' assert sap.hostname('HDB62') == 'd62dbsrv' assert sap.type('SCS10') == 'SCS' assert sap.is_netweaver is False assert sap.is_hana is True assert sap.is_ascs is False
from insights.core.plugins import make_fail from insights.plugins import insights_heartbeat from insights.parsers.hostname import Hostname from insights.specs import Specs from insights.tests import context_wrap, InputData, run_test NON_MATCHING_HOSTNAME = "some-other-hostname-that-doesnt-match" good = Hostname(context_wrap(insights_heartbeat.HOST)) bad = Hostname(context_wrap(NON_MATCHING_HOSTNAME)) def test_heartbeat(): expected_result = make_fail(insights_heartbeat.ERROR_KEY) assert expected_result == insights_heartbeat.is_insights_heartbeat(good) assert insights_heartbeat.is_insights_heartbeat(bad) is None def test_integration_tests(): comp = insights_heartbeat.is_insights_heartbeat input_data = InputData(name="Match: no kernel") input_data.add(Specs.hostname, insights_heartbeat.HOST) expected = make_fail(insights_heartbeat.ERROR_KEY) run_test(comp, input_data, expected) input_data = InputData(name="No Match: bad hostname") input_data.add(Specs.hostname, NON_MATCHING_HOSTNAME) run_test(comp, input_data, None)
def test_short_multiline_hostname(): data = Hostname(context_wrap(HOSTNAME_SHORT_MULTILINE, strip=False)) assert data.fqdn == "rhel7" assert data.hostname == "rhel7" assert data.domain == ""
def test_empty_hostname(): with pytest.raises(Exception): Hostname(context_wrap(""))
def test_ab(): hn = hostname(Hostname(context_wrap(HOSTNAME)), None, None) with pytest.raises(SkipException) as se: Sap(hn, None, None) assert 'No SAP instance.' in str(se)
def test_hostname_raise(): hn = Hostname(context_wrap("")) with pytest.raises(Exception): hostname(hn, None, None)
def test_short_hostname(): data = Hostname(context_wrap(HOSTNAME_SHORT)) assert data.fqdn == "rhel7" assert data.hostname == "rhel7" assert data.domain == ""