def test_dmiresult_equal_to_8(self): """Test that socket count is set to dmicode dep when equal to 8.""" eight_dmi_result = '\tSocket Designation: CPU #000\r\n\t' \ 'Status: Populated, Enabled\r\n ' \ '\tSocket Designation: CPU #001\r\n\t' \ 'Status: Populated, Enabled\r\n ' \ '\tSocket Designation: CPU #002\r\n\t' \ 'Status: Populated, Enabled\r\n' \ '\tSocket Designation: CPU #003\r\n\t' \ 'Status: Populated, Disabled\r\n' \ '\tSocket Designation: CPU #004\r\n\t' \ 'Status: Populated, Enabled\r\n' \ '\tSocket Designation: CPU #005\r\n\t' \ 'Status: Populated, Disabled\r\n' \ '\tSocket Designation: CPU #006\r\n\t' \ 'Status: Populated, Enabled\r\n' \ '\tSocket Designation: CPU #007\r\n\t' \ 'Status: Populated, Enabled\r\n' dependencies = { 'internal_cpu_socket_count_dmi': ansible_result(eight_dmi_result), 'internal_cpu_socket_count_cpuinfo': ansible_result('9'), 'cpu_count': '3' } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 8)
def test_no_processing(self): """Test a key that doesn't need to be processed.""" self.assertEqual( process.process(self.scan_task, {}, NOT_A_KEY, ansible_result(process.NO_DATA), HOST), ansible_result(process.NO_DATA))
def test_sudo_case(self): """Sudo found internal_xen_guest fact.""" self.assertEqual( virt.ProcessVirtXenGuest.process(ansible_result('\r\n1\r\n'), {}), True) self.assertEqual( virt.ProcessVirtXenGuest.process(ansible_result('\r\n0\r\n'), {}), False)
def test_sudo_case(self): """Sudo found internal_kvm_found fact.""" self.assertEqual( virt.ProcessVirtKvmFound.process(ansible_result('\r\nY\r\n'), {}), True) self.assertEqual( virt.ProcessVirtKvmFound.process(ansible_result('\r\nN\r\n'), {}), False)
def test_success_case(self): """Found internal_xen_privcmd_found fact.""" self.assertEqual( virt.ProcessVirtXenPrivcmdFound.process(ansible_result('Y\r\n'), {}), True) self.assertEqual( virt.ProcessVirtXenPrivcmdFound.process(ansible_result('N\r\n'), {}), False)
def test_sudo_case(self): """Sudo found internal_cpu_model_name_kvm fact.""" self.assertEqual( virt.ProcessVirtCpuModelNameKvm.process( ansible_result('\r\nY\r\n'), {}), True) self.assertEqual( virt.ProcessVirtCpuModelNameKvm.process( ansible_result('\r\nN\r\n'), {}), False)
def test_cpu_count_greater_than_8(self): """Test that the sc is set to cpuinfo even if greater thatn 8.""" dependencies = { 'internal_cpu_socket_count_dmi': ansible_result('10'), 'internal_cpu_socket_count_cpuinfo': ansible_result('9'), 'cpu_count': '12' } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 12)
def test_cpuinfo_equal_to_8(self): """Test that socket count is set to cpuinfo dep when equal to 8.""" dependencies = { 'internal_cpu_socket_count_dmi': ansible_result('10'), 'internal_cpu_socket_count_cpuinfo': ansible_result('8'), 'cpu_count': '3' } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 8)
def test_dmiresult_greater_than_8(self): """Test that cpu count is used when other deps greater than 8.""" dependencies = { 'internal_cpu_socket_count_dmi': ansible_result('9'), 'internal_cpu_socket_count_cpuinfo': ansible_result('9'), 'cpu_count': '3' } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 3)
def test_dmiresult_cpuinfo_failed_tasks(self): """Test the sc is the same as cpu count when the deps raise errors.""" dependencies = { 'internal_cpu_socket_count_dmi': ansible_result('Failed', 1), 'internal_cpu_socket_count_cpuinfo': ansible_result('Failed', 1), 'cpu_count': '4' } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 4)
def test_dmiresult_contains_nonint_characters(self): """Test that we use cpuinfo cmd if dmi cmd can't be changed to int.""" dependencies = { 'internal_cpu_socket_count_dmi': ansible_result('Permission Denied.'), 'internal_cpu_socket_count_cpuinfo': ansible_result('2') } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 2)
def test_cpuinfo_failed_return_none(self): """Test that none is returned if everything else fails.""" dependencies = { 'internal_cpu_socket_count_dmi': ansible_result('Permission Denied.'), 'internal_cpu_socket_count_cpuinfo': ansible_result('Failure') } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), None)
def test_cpuinfo_failed_value_error(self): """Test that cpu count is used when other deps rasie value errors.""" dependencies = { 'internal_cpu_socket_count_dmi': ansible_result('Permission Denied.'), 'internal_cpu_socket_count_cpuinfo': ansible_result('Failure'), 'cpu_count': '1' } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 1)
def test_dmiresult_cpuinfo_fails(self): """Test that we use cpu count when dmi and cpuinfo cmds fail.""" dependencies = { 'internal_cpu_socket_count_dmi': ansible_result('Permission Denied.'), 'internal_cpu_socket_count_cpuinfo': ansible_result(''), 'cpu_count': '4' } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 4)
def test_dmiresult_contains_no_enabled_sockets(self): """Test that we use cpuinfo cmd if dmi cmd finds 0 sockets.""" no_dmi_result = '\tSocket Designation: CPU #000\r\n\t' \ 'Status: Unpopulated\r\n ' \ '\tSocket Designation: CPU #001\r\n\t' \ 'Status: Unpopulated\r\n' dependencies = { 'internal_cpu_socket_count_dmi': ansible_result(no_dmi_result), 'internal_cpu_socket_count_cpuinfo': ansible_result('2') } self.assertEqual( cpu.ProcessCpuSocketCount.process('QPC_FORCE_POST_PROCESS', dependencies), 2)
def test_invalid_uuid_case(self): """Test dmi_system_uuid too long.""" # stdout_lines looks like ['a', 'b', 'c'] dependencies = { 'internal_dmi_system_uuid': ansible_result('%s\nb\nc' % ('a' * 37)) } self.assertEqual( dmi.ProcessDmiSystemUuid.process('QPC_FORCE_POST_PROCESS', dependencies), '') # stdout_lines looks like ['', 'b'] dependencies['internal_dmi_system_uuid'] = \ ansible_result('\n%s\n' % ('b' * 37)) self.assertEqual( dmi.ProcessDmiSystemUuid.process('QPC_FORCE_POST_PROCESS', dependencies), '')
def test_task_errored(self): """Test a task that errored on the remote machine.""" self.assertEqual( process.process(self.scan_task, {}, TEST_KEY, ansible_result('error!', rc=1), HOST), process.NO_DATA)
def test_processor_errored(self): """Test a task where the processor itself errors.""" self.assertEqual( process.process(self.scan_task, {}, PROCESSOR_ERROR_KEY, ansible_result(''), HOST), process.NO_DATA)
def test_eap(self): """'fuse' found.""" for processor in self.processors: self.assertEqual( processor.process( ansible_result(' foo\n fuse bar\n baz fuse')), ['fuse bar'])
def test_success_case(self): """Found yum_enabled_repolist.""" input_data = '!jb-eap-7-for-rhel-7-server-rpms/7Server/x86_64 ' \ 'JBoss Enterprise Applicat 886\n' \ '!rhel-7-server-rpms/7Server/x86_64 ' \ 'Red Hat Enterprise Linux 17,664\n' \ '!rhel7-cdn-internal/7Server/x86_64 ' \ 'RHEL 7 - x86_64 17,471\n' \ '!rhel7-cdn-internal-extras/7Server/x86_64 ' \ 'RHEL 7 - x86_64 679\n' \ '!rhel7-cdn-internal-optional/7Server/x86_64 ' \ 'RHEL 7 - x86_64 12,921' expected = [{ 'repo': '!jb-eap-7-for-rhel-7-server-rpms/7Server/x86_64', 'name': 'JBoss Enterprise Applicat' }, { 'repo': '!rhel-7-server-rpms/7Server/x86_64', 'name': 'Red Hat Enterprise Linux' }, { 'repo': '!rhel7-cdn-internal/7Server/x86_64', 'name': 'RHEL 7 - x86_64' }, { 'repo': '!rhel7-cdn-internal-extras/7Server/x86_64', 'name': 'RHEL 7 - x86_64' }, { 'repo': '!rhel7-cdn-internal-optional/7Server/x86_64', 'name': 'RHEL 7 - x86_64' }] self.assertEqual( yum.ProcessEnableYumRepolist.process(ansible_result(input_data)), expected)
def test_success_case(self): """Return the correct (directory, version string) pairs.""" self.assertEqual( set( brms.ProcessFindBRMSKieApiVer.process( ansible_result(self.ansible_stdout))), self.expected)
def test_no_pems_found(self): """Return empty string if it is given.""" in_line = '' expected = '' self.assertEqual( redhat_packages.ProcessRedHatPackagesCerts.process( ansible_result(in_line)), expected)
def test_single_pem(self): """Return stdout with no trailing ;.""" in_line = '69.pem;' expected = '69.pem' self.assertEqual( redhat_packages.ProcessRedHatPackagesCerts.process( ansible_result(in_line)), expected)
def test_no_jboss(self): """No 'jboss' or 'eap' found.""" for processor in self.processors: self.assertEqual( # Blank line in input to check that processor will skip it. processor.process(ansible_result('foo\nbar\n\nbaz')), [])
def test_eap(self): """'eap' found.""" for processor in self.processors: self.assertEqual( processor.process( ansible_result(' foo\n eap bar\n baz eap')), ['eap bar'])
def test_success_case(self): """Return stdout_lines in case of success.""" in_line = 'redhat-620133; redhat-630187\n' self.assertEqual( fuse.ProcessFindJbossCXFJar.process( ansible_result(in_line)), ['redhat-620133', 'redhat-630187'])
def test_success_case(self): """Valid system purpose json.""" input_data = """ { "_version": "1", "role": "server", "addons": [ "ibm" ], "service_level_agreement": "self-support", "usage_type": "dev" } """ expected = { '_version': '1', 'role': 'server', 'addons': ['ibm'], 'service_level_agreement': 'self-support', 'usage_type': 'dev' } self.assertEqual( system_purpose.ProcessSystemPurpose.process( ansible_result(input_data)), expected)
def test_not_found(self): """Did not find candidates.""" self.assertEqual( brms.ProcessKieSearchCandidates.process('QPC_FORCE_POST_PROCESS', { 'internal_jboss_brms_kie_server_candidates': ansible_result('') }), [])
def test_success_case(self): """Found subman_consumed.""" self.assertEqual( subman.ProcessSubmanConsumed.process( ansible_result('subnameA - 1\nsubnameB - 2\nsubnameC - 3')), [{'name': 'subnameA', 'entitlement_id': '1'}, {'name': 'subnameB', 'entitlement_id': '2'}, {'name': 'subnameC', 'entitlement_id': '3'}])
def test_success(self): """Found candidates.""" self.assertEqual( brms.ProcessKieSearchCandidates.process( 'QPC_FORCE_POST_PROCESS', { 'internal_jboss_brms_kie_server_candidates': ansible_result('a\nb\nc') }), ['a', 'b', 'c'])