예제 #1
0
파일: test_mdadm.py 프로젝트: yagnik/salt
    def test_create(self):
        mock = MagicMock(return_value='salt')
        with patch.dict(mdadm.__salt__, {'cmd.run': mock}), \
                patch('salt.utils.which', lambda exe: exe):
            ret = mdadm.create('/dev/md0',
                               5,
                               devices=['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                               test_mode=False,
                               force=True,
                               chunk=256)
            self.assertEqual('salt', ret)

            # Only available in 3.6 and above on py3
            if hasattr(mock, 'assert_called_once'):
                mock.assert_called_once()
            args, kwargs = mock.call_args
            # expected cmd is
            # mdadm -C /dev/md0 -R -v --chunk 256 --force -l 5 -e default -n 3 /dev/sdb1 /dev/sdc1 /dev/sdd1
            # where args between -v and -l could be in any order
            self.assertEqual(len(args), 1)
            self.assertEqual(len(args[0]), 17)
            self.assertEqual(args[0][:5],
                             ['mdadm', '-C', '/dev/md0', '-R', '-v'])
            self.assertEqual(args[0][8:], [
                '-l', '5', '-e', 'default', '-n', '3', '/dev/sdb1',
                '/dev/sdc1', '/dev/sdd1'
            ])
            self.assertEqual(sorted(args[0][5:8]),
                             sorted(['--chunk', '256', '--force']))
            self.assertIn('--chunk 256', ' '.join(args[0][5:8]))
            self.assertEqual(kwargs, {'python_shell': False})
예제 #2
0
파일: mdadm_test.py 프로젝트: s7726/salt
 def test_create_test_mode(self):
     mock = MagicMock()
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create('/dev/md0',
                            5, ['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                            force=True,
                            chunk=256,
                            test_mode=True)
         self.assertEqual(
             'mdadm -C /dev/md0 -v --chunk=256 --force -l 5 -n 3 '
             '/dev/sdb1 /dev/sdc1 /dev/sdd1', ret)
         assert not mock.called, 'test mode failed, cmd.run called'
예제 #3
0
파일: mdadm_test.py 프로젝트: s7726/salt
 def test_create(self):
     mock = MagicMock(return_value='salt')
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create('/dev/md0',
                            5, ['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                            test_mode=False,
                            force=True,
                            chunk=256)
         self.assertEqual('salt', ret)
         mock.assert_called_once_with(
             'mdadm -C /dev/md0 -v --chunk=256 --force -l 5 -n 3 '
             '/dev/sdb1 /dev/sdc1 /dev/sdd1')
예제 #4
0
 def test_create_test_mode(self):
     mock = MagicMock()
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create('/dev/md0',
                            5, ['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                            force=True,
                            chunk=256,
                            test_mode=True)
         self.assertEqual([
             'mdadm', '-C', '/dev/md0', '-v', '--chunk', 256, '--force',
             '-l', 5, '-e', 'default', '-n', 3, '/dev/sdb1', '/dev/sdc1',
             '/dev/sdd1'
         ], ret)
         assert not mock.called, 'test mode failed, cmd.run called'
예제 #5
0
 def test_create_test_mode(self):
     mock = MagicMock()
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create(
                 '/dev/md0', 5,
                 devices=['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                 force=True,
                 chunk=256,
                 test_mode=True
         )
         self.assertEqual('mdadm -C /dev/md0 -R -v --chunk 256 '
                           '--force -l 5 -e default -n 3 '
                           '/dev/sdb1 /dev/sdc1 /dev/sdd1', ret)
         assert not mock.called, 'test mode failed, cmd.run called'
예제 #6
0
 def test_create_test_mode(self):
     mock = MagicMock()
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create(
                 '/dev/md0', 5,
                 devices=['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                 force=True,
                 chunk=256,
                 test_mode=True
         )
         self.assertEqual(sorted('mdadm -C /dev/md0 -R -v --chunk 256 '
                           '--force -l 5 -e default -n 3 '
                           '/dev/sdb1 /dev/sdc1 /dev/sdd1'.split()), sorted(ret.split()))
         assert not mock.called, 'test mode failed, cmd.run called'
예제 #7
0
 def test_create(self):
     mock = MagicMock(return_value='salt')
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create('/dev/md0',
                            5, ['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                            test_mode=False,
                            force=True,
                            chunk=256)
         self.assertEqual('salt', ret)
         mock.assert_called_once_with([
             'mdadm', '-C', '/dev/md0', '-v', '--chunk', 256, '--force',
             '-l', 5, '-e', 'default', '-n', 3, '/dev/sdb1', '/dev/sdc1',
             '/dev/sdd1'
         ],
                                      python_shell=False)
예제 #8
0
 def test_create(self):
     mock = MagicMock(return_value='salt')
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create(
                 '/dev/md0', 5,
                 devices=['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                 test_mode=False,
                 force=True,
                 chunk=256
         )
         self.assertEqual('salt', ret)
         mock.assert_called_once_with(
             ['mdadm', '-C', '/dev/md0', '-R', '-v', '--chunk', '256', '--force',
              '-l', '5', '-e', 'default', '-n', '3', '/dev/sdb1', '/dev/sdc1',
              '/dev/sdd1'], python_shell=False)
예제 #9
0
 def test_create_test_mode(self):
     mock = MagicMock()
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create(
                 '/dev/md0', 5,
                 ['/dev/sdb1',
                  '/dev/sdc1',
                  '/dev/sdd1'],
                 force=True,
                 chunk=256,
                 test_mode=True
         )
         self.assertEqual(['mdadm', '-C', '/dev/md0', '-v', '--chunk', 256,
                           '--force', '-l', 5, '-e', 'default', '-n', 3,
                           '/dev/sdb1', '/dev/sdc1', '/dev/sdd1'], ret)
         assert not mock.called, 'test mode failed, cmd.run called'
예제 #10
0
 def test_create(self):
     mock = MagicMock(return_value='salt')
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create(
                 '/dev/md0', 5,
                 ['/dev/sdb1',
                  '/dev/sdc1',
                  '/dev/sdd1'],
                 test_mode=False,
                 force=True,
                 chunk=256
         )
         self.assertEqual('salt', ret)
         mock.assert_called_once_with(
                 'mdadm -C /dev/md0 -v --chunk=256 --force -l 5 -n 3 '
                 '/dev/sdb1 /dev/sdc1 /dev/sdd1'
         )
예제 #11
0
파일: test_mdadm.py 프로젝트: cldeluna/salt
 def test_create(self):
     mock = MagicMock(return_value='salt')
     with patch.dict(mdadm.__salt__, {'cmd.run': mock}):
         ret = mdadm.create('/dev/md0',
                            5,
                            devices=['/dev/sdb1', '/dev/sdc1', '/dev/sdd1'],
                            test_mode=False,
                            force=True,
                            chunk=256)
         self.assertEqual('salt', ret)
         if six.PY2:
             expected_args = [
                 'mdadm', '-C', '/dev/md0', '-R', '-v', '--chunk', '256',
                 '--force', '-l', '5', '-e', 'default', '-n', '3',
                 '/dev/sdb1', '/dev/sdc1', '/dev/sdd1'
             ]
         else:
             expected_args = [
                 'mdadm', '-C', '/dev/md0', '-R', '-v', '--force',
                 '--chunk', '256', '-l', '5', '-e', 'default', '-n', '3',
                 '/dev/sdb1', '/dev/sdc1', '/dev/sdd1'
             ]
         mock.assert_called_once_with(expected_args, python_shell=False)