def test_add_volume_bricks(self):
        '''
        Test if it add brick(s) to an existing volume
        '''
        mock = MagicMock(return_value='does not exist')
        with patch.object(glusterfs, 'status', mock):
            self.assertEqual(
                glusterfs.add_volume_bricks('Newvolume1', ['bricks']),
                'does not exist')

        mock = MagicMock(return_value='is not started')
        with patch.object(glusterfs, 'status', mock):
            self.assertEqual(
                glusterfs.add_volume_bricks('Newvolume1', ['bricks']),
                'is not started')

        ret = '1 bricks successfully added to the volume Newvolume1'
        mock = MagicMock(return_value={'bricks': {}, 'healers': {}, 'nfs': {}})
        with patch.object(glusterfs, 'status', mock):
            mock = MagicMock(return_value='creation success')
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
                self.assertEqual(
                    glusterfs.add_volume_bricks('Newvolume1', ['bricks']), ret)

            mock = MagicMock(return_value='')
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
                self.assertEqual(
                    glusterfs.add_volume_bricks('Newvolume1', ['bricks']), '')

                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1', []),
                                 'Bricks already in volume Newvolume1')
Ejemplo n.º 2
0
    def test_add_volume_bricks(self):
        '''
        Test if it add brick(s) to an existing volume
        '''
        mock = MagicMock(return_value='does not exist')
        with patch.object(glusterfs, 'status', mock):
            self.assertEqual(glusterfs.add_volume_bricks('Newvolume1',
                                                         ['bricks']),
                             'does not exist')

        mock = MagicMock(return_value='is not started')
        with patch.object(glusterfs, 'status', mock):
            self.assertEqual(glusterfs.add_volume_bricks('Newvolume1',
                                                         ['bricks']),
                             'is not started')

        ret = '1 bricks successfully added to the volume Newvolume1'
        mock = MagicMock(return_value={'bricks': {}, 'healers': {}, 'nfs': {}})
        with patch.object(glusterfs, 'status', mock):
            mock = MagicMock(return_value='creation success')
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1',
                                                             ['bricks']), ret)

            mock = MagicMock(return_value='')
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1',
                                                             ['bricks']), '')

                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1', []),
                                 'Bricks already in volume Newvolume1')
Ejemplo n.º 3
0
    def test_add_volume_bricks(self):
        '''
        Test if it add brick(s) to an existing volume
        '''
        mock_info = MagicMock(return_value={
            'Newvolume1': {
                'status': '1',
                'bricks': {
                    'brick1': {'path': 'host:/path1'},
                    'brick2': {'path': 'host:/path2'}
                }
            }
        })
        with patch.object(glusterfs, 'info', mock_info):
            mock_run = MagicMock(return_value=xml_command_success)
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
                # Volume does not exist
                self.assertFalse(glusterfs.add_volume_bricks('nonExisting',
                                                             ['bricks']))
                # Brick already exists
                self.assertTrue(glusterfs.add_volume_bricks('Newvolume1',
                                                       ['host:/path2']))
                # Already existing brick as a string
                self.assertTrue(glusterfs.add_volume_bricks('Newvolume1',
                                                            'host:/path2'))
                self.assertFalse(mock_run.called)
                # A new brick:
                self.assertTrue(glusterfs.add_volume_bricks('Newvolume1',
                                                            ['host:/new1']))
                self.assertTrue(mock_run.called)

                # Gluster call fails
                mock_run.return_value = xml_command_fail
                self.assertFalse(glusterfs.add_volume_bricks('Newvolume1',
                                                             ['new:/path']))
Ejemplo n.º 4
0
    def test_add_volume_bricks(self):
        '''
        Test if it add brick(s) to an existing volume
        '''
        # volume does not exist
        mock = MagicMock(return_value=xml_command_fail)
        with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
            self.assertRaises(
                CommandExecutionError, glusterfs.add_volume_bricks, 'Newvolume1', ['bricks'])

        ret = '1 bricks successfully added to the volume Newvolume1'
        # volume does exist
        mock = MagicMock(return_value={'bricks': {}})
        with patch.object(glusterfs, 'info', mock):
            mock = MagicMock(return_value=xml_command_success)
            # ... and the added brick does not exist
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1',
                                                             ['bricks']), ret)

        mock = MagicMock(
            return_value={'bricks': {'brick1': {'path': 'bricks'}}})
        with patch.object(glusterfs, 'info', mock):
            # ... and the added brick does exist
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
                # As a list
                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1', ['bricks']),
                                 'Bricks already in volume Newvolume1')
                # As a string
                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1', 'bricks'),
                                 'Bricks already in volume Newvolume1')
                # And empty list
                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1', []),
                                 'Bricks already in volume Newvolume1')
Ejemplo n.º 5
0
    def test_add_volume_bricks(self):
        '''
        Test if it add brick(s) to an existing volume
        '''
        mock_info = MagicMock(return_value={
            'Newvolume1': {
                'status': '1',
                'bricks': {
                    'brick1': {'path': 'host:/path1'},
                    'brick2': {'path': 'host:/path2'}
                }
            }
        })
        with patch.object(glusterfs, 'info', mock_info):
            mock_run = MagicMock(return_value=xml_command_success)
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
                # Volume does not exist
                self.assertFalse(glusterfs.add_volume_bricks('nonExisting',
                                                             ['bricks']))
                # Brick already exists
                self.assertTrue(glusterfs.add_volume_bricks('Newvolume1',
                                                       ['host:/path2']))
                # Already existing brick as a string
                self.assertTrue(glusterfs.add_volume_bricks('Newvolume1',
                                                            'host:/path2'))
                self.assertFalse(mock_run.called)
                # A new brick:
                self.assertTrue(glusterfs.add_volume_bricks('Newvolume1',
                                                            ['host:/new1']))
                self.assertTrue(mock_run.called)

                # Gluster call fails
                mock_run.return_value = xml_command_fail
                self.assertFalse(glusterfs.add_volume_bricks('Newvolume1',
                                                             ['new:/path']))
Ejemplo n.º 6
0
    def test_add_volume_bricks(self):
        '''
        Test if it add brick(s) to an existing volume
        '''
        # volume does not exist
        mock = MagicMock(return_value=xml_command_fail)
        with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
            self.assertRaises(CommandExecutionError,
                              glusterfs.add_volume_bricks, 'Newvolume1',
                              ['bricks'])

        ret = '1 bricks successfully added to the volume Newvolume1'
        # volume does exist
        mock = MagicMock(return_value={'Newvolume1': {'bricks': {}}})
        with patch.object(glusterfs, 'info', mock):
            mock = MagicMock(return_value=xml_command_success)
            # ... and the added brick does not exist
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
                self.assertEqual(
                    glusterfs.add_volume_bricks('Newvolume1', ['bricks']), ret)

        mock = MagicMock(return_value={
            'Newvolume1': {
                'bricks': {
                    'brick1': {
                        'path': 'bricks'
                    }
                }
            }
        })
        with patch.object(glusterfs, 'info', mock):
            # ... and the added brick does exist
            with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
                # As a list
                self.assertEqual(
                    glusterfs.add_volume_bricks('Newvolume1', ['bricks']),
                    'Bricks already in volume Newvolume1')
                # As a string
                self.assertEqual(
                    glusterfs.add_volume_bricks('Newvolume1', 'bricks'),
                    'Bricks already in volume Newvolume1')
                # And empty list
                self.assertEqual(glusterfs.add_volume_bricks('Newvolume1', []),
                                 'Bricks already in volume Newvolume1')
Ejemplo n.º 7
0
    def test_add_volume_bricks(self):
        """
        Test if it add brick(s) to an existing volume
        """
        mock_info = MagicMock(
            return_value={
                "Newvolume1": {
                    "status": "1",
                    "bricks": {
                        "brick1": {
                            "path": "host:/path1"
                        },
                        "brick2": {
                            "path": "host:/path2"
                        },
                    },
                }
            })
        with patch.object(glusterfs, "info", mock_info):
            mock_run = MagicMock(return_value=xml_command_success)
            with patch.dict(glusterfs.__salt__, {"cmd.run": mock_run}):
                # Volume does not exist
                self.assertFalse(
                    glusterfs.add_volume_bricks("nonExisting", ["bricks"]))
                # Brick already exists
                self.assertTrue(
                    glusterfs.add_volume_bricks("Newvolume1", ["host:/path2"]))
                # Already existing brick as a string
                self.assertTrue(
                    glusterfs.add_volume_bricks("Newvolume1", "host:/path2"))
                self.assertFalse(mock_run.called)
                # A new brick:
                self.assertTrue(
                    glusterfs.add_volume_bricks("Newvolume1", ["host:/new1"]))
                self.assertTrue(mock_run.called)

                # Gluster call fails
                mock_run.return_value = xml_command_fail
                self.assertFalse(
                    glusterfs.add_volume_bricks("Newvolume1", ["new:/path"]))