예제 #1
0
    def test_create_volume(self):
        '''
        Test if it creates a glusterfs volume.
        '''
        mock_run = MagicMock(return_value=xml_command_success)
        with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
            self.assertRaises(
                SaltInvocationError,
                glusterfs.create_volume,
                'newvolume',
                'host1:brick')

            self.assertRaises(
                SaltInvocationError,
                glusterfs.create_volume,
                'newvolume',
                'host1/brick')

            self.assertFalse(mock_run.called)

            mock_start_volume = MagicMock(return_value=True)
            with patch.object(glusterfs, 'start_volume', mock_start_volume):
                # Create, do not start
                self.assertTrue(glusterfs.create_volume('newvolume',
                                                        'host1:/brick'))
                self.assertFalse(mock_start_volume.called)

                # Create and start
                self.assertTrue(glusterfs.create_volume('newvolume',
                                                        'host1:/brick',
                                                        start=True))
                self.assertTrue(mock_start_volume.called)

                mock_start_volume.return_value = False
                # Create and fail start
                self.assertFalse(glusterfs.create_volume('newvolume',
                                                         'host1:/brick',
                                                         start=True))

            mock_run.return_value = xml_command_fail
            self.assertFalse(glusterfs.create_volume('newvolume', 'host1:/brick',
                             True, True, True, 'tcp', True))
예제 #2
0
    def test_create_volume(self):
        '''
        Test if it creates a glusterfs volume.
        '''
        mock_run = MagicMock(return_value=xml_command_success)
        with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
            self.assertRaises(
                SaltInvocationError,
                glusterfs.create_volume,
                'newvolume',
                'host1:brick')

            self.assertRaises(
                SaltInvocationError,
                glusterfs.create_volume,
                'newvolume',
                'host1/brick')

            self.assertFalse(mock_run.called)

            mock_start_volume = MagicMock(return_value=True)
            with patch.object(glusterfs, 'start_volume', mock_start_volume):
                # Create, do not start
                self.assertTrue(glusterfs.create_volume('newvolume',
                                                        'host1:/brick'))
                self.assertFalse(mock_start_volume.called)

                # Create and start
                self.assertTrue(glusterfs.create_volume('newvolume',
                                                        'host1:/brick',
                                                        start=True))
                self.assertTrue(mock_start_volume.called)

                mock_start_volume.return_value = False
                # Create and fail start
                self.assertFalse(glusterfs.create_volume('newvolume',
                                                         'host1:/brick',
                                                         start=True))

            mock_run.return_value = xml_command_fail
            self.assertFalse(glusterfs.create_volume('newvolume', 'host1:/brick',
                             True, True, True, 'tcp', True))
예제 #3
0
    def test_create_volume(self):
        """
        Test if it creates a glusterfs volume.
        """
        mock_run = MagicMock(return_value=xml_command_success)
        with patch.dict(glusterfs.__salt__, {"cmd.run": mock_run}):
            self.assertRaises(SaltInvocationError, glusterfs.create_volume,
                              "newvolume", "host1:brick")

            self.assertRaises(SaltInvocationError, glusterfs.create_volume,
                              "newvolume", "host1/brick")

            self.assertFalse(mock_run.called)

            mock_start_volume = MagicMock(return_value=True)
            with patch.object(glusterfs, "start_volume", mock_start_volume):
                # Create, do not start
                self.assertTrue(
                    glusterfs.create_volume("newvolume", "host1:/brick"))
                self.assertFalse(mock_start_volume.called)

                # Create and start
                self.assertTrue(
                    glusterfs.create_volume("newvolume",
                                            "host1:/brick",
                                            start=True))
                self.assertTrue(mock_start_volume.called)

                mock_start_volume.return_value = False
                # Create and fail start
                self.assertFalse(
                    glusterfs.create_volume("newvolume",
                                            "host1:/brick",
                                            start=True))

            mock_run.return_value = xml_command_fail
            self.assertFalse(
                glusterfs.create_volume("newvolume", "host1:/brick", True,
                                        True, True, "tcp", True))