Пример #1
0
 def test_get_sysctl_openbsd_kern(self):
     module = MagicMock()
     module.get_bin_path.return_value = '/sbin/sysctl'
     module.run_command.return_value = (0, OPENBSD_SYSCTL_KERN_PARTIAL, '')
     sysctl = get_sysctl(module, ['kern'])
     module.run_command.assert_called_once_with(['/sbin/sysctl', 'kern'])
     self.assertEqual(
         len(sysctl),
         len([
             l for l in OPENBSD_SYSCTL_KERN_PARTIAL.splitlines()
             if l.startswith('kern')
         ]))
     self.assertEqual(sysctl['kern.ostype'], 'OpenBSD')  # first line
     self.assertEqual(sysctl['kern.maxproc'], '1310')  # random line
     self.assertEqual(sysctl['kern.posix1version'], '200809')  # last line
     # multiline
     self.assertEqual(
         sysctl['kern.version'],
         'OpenBSD 6.7 (GENERIC) #179: Thu May  7 11:02:37 MDT 2020\n    '
         '[email protected]:/usr/src/sys/arch/amd64/compile/GENERIC'
     )
     # more symbols/spaces in value
     self.assertEqual(
         sysctl['kern.clockrate'],
         'tick = 10000, tickadj = 40, hz = 100, profhz = 100, stathz = 100')
Пример #2
0
    def populate(self, collected_facts=None):
        hardware_facts = {}
        self.sysctl = get_sysctl(self.module, ['hw', 'kern'])

        # TODO: change name
        cpu_facts = self.get_processor_facts()
        memory_facts = self.get_memory_facts()
        device_facts = self.get_device_facts()
        dmi_facts = self.get_dmi_facts()
        uptime_facts = self.get_uptime_facts()

        mount_facts = {}
        try:
            mount_facts = self.get_mount_facts()
        except timeout.TimeoutError:
            pass

        hardware_facts.update(cpu_facts)
        hardware_facts.update(memory_facts)
        hardware_facts.update(dmi_facts)
        hardware_facts.update(device_facts)
        hardware_facts.update(mount_facts)
        hardware_facts.update(uptime_facts)

        return hardware_facts
Пример #3
0
 def test_get_sysctl_command_error(self):
     module = MagicMock()
     module.get_bin_path.return_value = '/usr/sbin/sysctl'
     for err in (IOError, OSError):
         module.reset_mock()
         module.run_command.side_effect = err('foo')
         sysctl = get_sysctl(module, ['hw'])
         module.warn.assert_called_once_with('Unable to read sysctl: foo')
         self.assertEqual(sysctl, {})
Пример #4
0
 def test_get_sysctl_mixed_invalid_output(self):
     module = MagicMock()
     module.get_bin_path.return_value = '/sbin/sysctl'
     module.run_command.return_value = (0, GOOD_BAD_SYSCTL, '')
     sysctl = get_sysctl(module, ['hw'])
     module.run_command.assert_called_once_with(['/sbin/sysctl', 'hw'])
     bad_lines = ['bad.output.here', 'and.bad.output.here']
     for call in module.warn.call_args_list:
         self.assertIn('Unable to split sysctl line', call[0][0])
     self.assertEqual(module.warn.call_count, 2)
     self.assertEqual(sysctl, {'hw.smt': '0'})
Пример #5
0
 def test_get_sysctl_all_invalid_output(self):
     module = MagicMock()
     module.get_bin_path.return_value = '/sbin/sysctl'
     module.run_command.return_value = (0, BAD_SYSCTL, '')
     sysctl = get_sysctl(module, ['hw'])
     module.run_command.assert_called_once_with(['/sbin/sysctl', 'hw'])
     lines = [l for l in BAD_SYSCTL.splitlines() if l]
     for call in module.warn.call_args_list:
         self.assertIn('Unable to split sysctl line', call[0][0])
     self.assertEqual(module.warn.call_count, len(lines))
     self.assertEqual(sysctl, {})
Пример #6
0
    def populate(self, collected_facts=None):
        hardware_facts = {}

        self.sysctl = get_sysctl(self.module, ['hw', 'machdep', 'kern'])
        mac_facts = self.get_mac_facts()
        cpu_facts = self.get_cpu_facts()
        memory_facts = self.get_memory_facts()

        hardware_facts.update(mac_facts)
        hardware_facts.update(cpu_facts)
        hardware_facts.update(memory_facts)

        return hardware_facts
Пример #7
0
 def test_get_sysctl_macos_vm(self):
     module = MagicMock()
     module.get_bin_path.return_value = '/usr/sbin/sysctl'
     module.run_command.return_value = (0, MACOS_SYSCTL_VM_PARTIAL, '')
     sysctl = get_sysctl(module, ['vm'])
     module.run_command.assert_called_once_with(['/usr/sbin/sysctl', 'vm'])
     self.assertEqual(
         len(sysctl),
         len([l for l in MACOS_SYSCTL_VM_PARTIAL.splitlines() if l]))
     self.assertEqual(sysctl['vm.loadavg'], '{ 1.28 1.18 1.13 }')
     self.assertEqual(
         sysctl['vm.swapusage'],
         'total = 2048.00M  used = 1017.50M  free = 1030.50M  (encrypted)')
Пример #8
0
    def populate(self, collected_facts=None):
        hardware_facts = {}

        self.sysctl = get_sysctl(self.module, ['hw', 'machdep', 'kern'])
        mac_facts = self.get_mac_facts()
        cpu_facts = self.get_cpu_facts()
        memory_facts = self.get_memory_facts()

        hardware_facts.update(mac_facts)
        hardware_facts.update(cpu_facts)
        hardware_facts.update(memory_facts)

        return hardware_facts
Пример #9
0
 def test_get_sysctl_linux_vm(self):
     module = MagicMock()
     module.get_bin_path.return_value = '/usr/sbin/sysctl'
     module.run_command.return_value = (0, LINUX_SYSCTL_VM_PARTIAL, '')
     sysctl = get_sysctl(module, ['vm'])
     module.run_command.assert_called_once_with(['/usr/sbin/sysctl', 'vm'])
     self.assertEqual(
         len(sysctl),
         len([l for l in LINUX_SYSCTL_VM_PARTIAL.splitlines() if l]))
     self.assertEqual(sysctl['vm.dirty_background_ratio'], '10')
     self.assertEqual(sysctl['vm.laptop_mode'], '0')
     self.assertEqual(sysctl['vm.min_slab_ratio'], '5')
     # tabs
     self.assertEqual(sysctl['vm.lowmem_reserve_ratio'], '256\t256\t32\t0')
Пример #10
0
 def test_get_sysctl_openbsd_hw(self):
     expected_lines = [l for l in OPENBSD_SYSCTL_HW.splitlines() if l]
     module = MagicMock()
     module.get_bin_path.return_value = '/sbin/sysctl'
     module.run_command.return_value = (0, OPENBSD_SYSCTL_HW, '')
     sysctl = get_sysctl(module, ['hw'])
     module.run_command.assert_called_once_with(['/sbin/sysctl', 'hw'])
     self.assertEqual(len(sysctl), len(expected_lines))
     self.assertEqual(sysctl['hw.machine'], 'amd64')  # first line
     self.assertEqual(sysctl['hw.smt'], '0')  # random line
     self.assertEqual(sysctl['hw.ncpuonline'], '1')  # last line
     # weird chars in value
     self.assertEqual(sysctl['hw.disknames'],
                      'cd0:,sd0:9e1bd96cb20ab429,fd0:')
     # more symbols/spaces in value
     self.assertEqual(sysctl['hw.product'],
                      'Standard PC (i440FX + PIIX, 1996)')
Пример #11
0
    def populate(self, collected_facts=None):
        hardware_facts = {}
        self.sysctl = get_sysctl(self.module, ['hw'])

        hardware_facts.update(self.get_processor_facts())
        hardware_facts.update(self.get_memory_facts())
        hardware_facts.update(self.get_device_facts())
        hardware_facts.update(self.get_dmi_facts())
        hardware_facts.update(self.get_uptime_facts())

        # storage devices notorioslly prone to hang/block so they are under a timeout
        try:
            hardware_facts.update(self.get_mount_facts())
        except timeout.TimeoutError:
            pass

        return hardware_facts
Пример #12
0
    def populate(self, collected_facts=None):
        hardware_facts = {}
        self.sysctl = get_sysctl(self.module, ['machdep'])
        cpu_facts = self.get_cpu_facts()
        memory_facts = self.get_memory_facts()

        mount_facts = {}
        try:
            mount_facts = self.get_mount_facts()
        except TimeoutError:
            pass

        dmi_facts = self.get_dmi_facts()

        hardware_facts.update(cpu_facts)
        hardware_facts.update(memory_facts)
        hardware_facts.update(mount_facts)
        hardware_facts.update(dmi_facts)

        return hardware_facts
Пример #13
0
    def populate(self, collected_facts=None):
        hardware_facts = {}
        self.sysctl = get_sysctl(self.module, ['machdep'])
        cpu_facts = self.get_cpu_facts()
        memory_facts = self.get_memory_facts()

        mount_facts = {}
        try:
            mount_facts = self.get_mount_facts()
        except TimeoutError:
            pass

        dmi_facts = self.get_dmi_facts()

        hardware_facts.update(cpu_facts)
        hardware_facts.update(memory_facts)
        hardware_facts.update(mount_facts)
        hardware_facts.update(dmi_facts)

        return hardware_facts
Пример #14
0
    def populate(self, collected_facts=None):
        hardware_facts = {}
        self.sysctl = get_sysctl(self.module, ['hw'])

        # TODO: change name
        cpu_facts = self.get_processor_facts()
        memory_facts = self.get_memory_facts()
        device_facts = self.get_device_facts()
        dmi_facts = self.get_dmi_facts()

        mount_facts = {}
        try:
            mount_facts = self.get_mount_facts()
        except timeout.TimeoutError:
            pass

        hardware_facts.update(cpu_facts)
        hardware_facts.update(memory_facts)
        hardware_facts.update(dmi_facts)
        hardware_facts.update(device_facts)
        hardware_facts.update(mount_facts)

        return hardware_facts
Пример #15
0
 def test_get_sysctl_nonzero_rc(self):
     module = MagicMock()
     module.get_bin_path.return_value = '/usr/sbin/sysctl'
     module.run_command.return_value = (1, '', '')
     sysctl = get_sysctl(module, ['hw'])
     self.assertEqual(sysctl, {})