Пример #1
0
 def test_core_virtual(self):
     '''
     test virtual grain with cmd virt-what
     '''
     virt = 'kvm'
     with patch.object(salt.utils.platform, 'is_windows',
                       MagicMock(return_value=False)):
         with patch.object(salt.utils.path, 'which',
                           MagicMock(return_value=True)):
             with patch.dict(
                     core.__salt__,
                 {
                     'cmd.run_all':
                     MagicMock(return_value={
                         'pid': 78,
                         'retcode': 0,
                         'stderr': '',
                         'stdout': virt
                     })
                 }):
                 osdata = {
                     'kernel': 'test',
                 }
                 ret = core._virtual(osdata)
                 self.assertEqual(ret['virtual'], virt)
Пример #2
0
    def test_core_virtual_unicode(self, mock_file, mock_dir):
        '''
        test virtual grain with unicode character in product_name file
        '''
        def path_side_effect(path):
            if path == '/sys/devices/virtual/dmi/id/product_name':
                return True
            return False

        virt = 'kvm'
        mock_file.side_effect = path_side_effect
        mock_dir.side_effect = path_side_effect
        with patch.object(salt.utils.platform, 'is_windows',
                          MagicMock(return_value=False)):
            with patch.object(salt.utils.path, 'which',
                              MagicMock(return_value=True)):
                with patch.dict(
                        core.__salt__,
                    {
                        'cmd.run_all':
                        MagicMock(return_value={
                            'pid': 78,
                            'retcode': 0,
                            'stderr': '',
                            'stdout': virt
                        })
                    }):
                    with patch('salt.utils.files.fopen',
                               mock_open(read_data='嗨')):
                        osdata = {
                            'kernel': 'Linux',
                        }
                        ret = core._virtual(osdata)
                        self.assertEqual(ret['virtual'], virt)
Пример #3
0
 def test_xen_virtual(self):
     '''
     Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
     '''
     with patch.object(os.path, 'isfile', MagicMock(return_value=False)):
         with patch.dict(core.__salt__, {'cmd.run': MagicMock(return_value='')}), \
             patch.object(os.path,
                          'isfile',
                          MagicMock(side_effect=lambda x: True if x == '/sys/bus/xen/drivers/xenconsole' else False)):
             log.debug('Testing Xen')
             self.assertEqual(
                 core._virtual({
                     'kernel': 'Linux'
                 }).get('virtual_subtype'), 'Xen PV DomU')
Пример #4
0
 def test_docker_virtual(self):
     '''
     Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
     '''
     with patch.object(os.path, 'isdir', MagicMock(return_value=False)):
         with patch.object(os.path,
                           'isfile',
                           MagicMock(side_effect=lambda x: True if x == '/proc/1/cgroup' else False)):
             for cgroup_substr in (':/system.slice/docker', ':/docker/',
                                    ':/docker-ce/'):
                 cgroup_data = \
                     '10:memory{0}a_long_sha256sum'.format(cgroup_substr)
                 log.debug(
                     'Testing Docker cgroup substring \'%s\'', cgroup_substr)
                 with patch('salt.utils.files.fopen', mock_open(read_data=cgroup_data)):
                     with patch.dict(core.__salt__, {'cmd.run_all': MagicMock()}):
                         self.assertEqual(
                             core._virtual({'kernel': 'Linux'}).get('virtual_subtype'),
                             'Docker'
                         )