Пример #1
0
    def test_apply_(self):
        '''
        Test to seed a location (disk image, directory, or block device)
        with the minion config, approve the minion's key, and/or install
        salt-minion.
        '''
        mock = MagicMock(side_effect=[False, {'type': 'type',
                                              'target': 'target'},
                                      {'type': 'type', 'target': 'target'},
                                      {'type': 'type', 'target': 'target'}])
        with patch.dict(seed.__salt__, {'file.stats': mock}):
            self.assertEqual(seed.apply_('path'), 'path does not exist')

            with patch.object(seed, '_mount', return_value=False):
                self.assertEqual(seed.apply_('path'),
                                 'target could not be mounted')

            with patch.object(seed, '_mount', return_value=True):
                with patch.object(os.path, 'join', return_value='A'):
                    with patch.object(os, 'makedirs',
                                      MagicMock(side_effect=OSError('f'))):
                        with patch.object(os.path, 'isdir',
                                          return_value=False):
                            self.assertRaises(OSError, seed.apply_, 'p')

                    with patch.object(os, 'makedirs', MagicMock()):
                        with patch.object(seed, 'mkconfig', return_value='A'):
                            with patch.object(seed, '_check_install',
                                              return_value=False):
                                with patch.object(seed, '_umount',
                                                  return_value=None):
                                    self.assertFalse(seed.apply_('path',
                                                                 install=False))
Пример #2
0
    def test_apply_(self):
        '''
        Test to seed a location (disk image, directory, or block device)
        with the minion config, approve the minion's key, and/or install
        salt-minion.
        '''
        mock = MagicMock(side_effect=[False, {'type': 'type',
                                              'target': 'target'},
                                      {'type': 'type', 'target': 'target'},
                                      {'type': 'type', 'target': 'target'}])
        with patch.dict(seed.__salt__, {'file.stats': mock}):
            self.assertEqual(seed.apply_('path'), 'path does not exist')

            with patch.object(seed, '_mount', return_value=False):
                self.assertEqual(seed.apply_('path'),
                                 'target could not be mounted')

            with patch.object(seed, '_mount', return_value=True):
                with patch.object(os.path, 'join', return_value='A'):
                    with patch.object(os, 'makedirs',
                                      MagicMock(side_effect=OSError('f'))):
                        with patch.object(os.path, 'isdir',
                                          return_value=False):
                            self.assertRaises(OSError, seed.apply_, 'p')

                    with patch.object(os, 'makedirs', MagicMock()):
                        with patch.object(seed, 'mkconfig', return_value='A'):
                            with patch.object(seed, '_check_install',
                                              return_value=False):
                                with patch.object(seed, '_umount',
                                                  return_value=None):
                                    self.assertFalse(seed.apply_('path',
                                                                 install=False))
Пример #3
0
    def test_apply_(self):
        """
        Test to seed a location (disk image, directory, or block device)
        with the minion config, approve the minion's key, and/or install
        salt-minion.
        """
        mock = MagicMock(side_effect=[
            False,
            {
                "type": "type",
                "target": "target"
            },
            {
                "type": "type",
                "target": "target"
            },
            {
                "type": "type",
                "target": "target"
            },
        ])
        with patch.dict(seed.__salt__, {"file.stats": mock}):
            self.assertEqual(seed.apply_("path"), "path does not exist")

            with patch.object(seed, "_mount", return_value=False):
                self.assertEqual(seed.apply_("path"),
                                 "target could not be mounted")

            with patch.object(seed, "_mount", return_value="/mountpoint"):
                with patch.object(os.path, "join", return_value="A"):
                    with patch.object(os, "makedirs",
                                      MagicMock(side_effect=OSError("f"))):
                        with patch.object(os.path, "isdir",
                                          return_value=False):
                            self.assertRaises(OSError, seed.apply_, "p")

                    with patch.object(os, "makedirs", MagicMock()):
                        with patch.object(seed, "mkconfig", return_value="A"):
                            with patch.object(seed,
                                              "_check_install",
                                              return_value=False):
                                with patch.object(
                                        seed, "_umount",
                                        return_value=None) as umount_mock:
                                    self.assertFalse(
                                        seed.apply_("path", install=False))
                                    umount_mock.assert_called_once_with(
                                        "/mountpoint", "target", "type")