Пример #1
0
    def test_collect_vm_info(self, mock_get_ssh_client):
        """Test collect_vm_info method. """
        distro = MagicMock()
        client = MagicMock()
        distro.get_vm_info.return_value = \
            'Failed to collect VM info: Does not exist.'
        mock_get_ssh_client.return_value = client

        cloud = IpaCloud(*args, **self.kwargs)
        cloud.distro = distro
        cloud.log_file = 'fake_file.name'
        cloud.logger = MagicMock()

        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            file_handle = mock_open.return_value.__enter__.return_value

            cloud._collect_vm_info()

            file_handle.write.assert_has_calls([
                call('\n'),
                call('Failed to collect VM info: Does not exist.')
            ])

        cloud.logger.info.assert_called_once_with(
            'Collecting basic info about VM')
        assert mock_get_ssh_client.call_count == 1
Пример #2
0
    def test_cloud_run_tests(
        self,
        mock_pytest,
        mock_merge_results,
        mock_ipa_utils
    ):
        """Test run tests method."""
        mock_pytest.return_value = 0
        mock_merge_results.return_value = None

        cloud = IpaCloud(**self.kwargs)

        cloud.log_file = 'fake_file.name'
        cloud.terminate = True
        cloud.results['info'] = {
            'platform': 'ec2',
            'region': 'us-west-1'
        }

        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            _ = mock_open.return_value.__enter__.return_value

            out = cloud._run_test(
                ['tests/data/tests/test_image.py'],
                'test.ssh'
            )

        assert out == 0
        assert mock_pytest.call_count == 1
        assert mock_merge_results.call_count == 1
Пример #3
0
    def test_cloud_execute_ssh_command(self, mock_exec_cmd):
        client = MagicMock()
        mock_exec_cmd.return_value = 'command executed successfully!'

        cloud = IpaCloud(*args, **self.kwargs)
        cloud.log_file = 'fake_file.name'

        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            file_handle = mock_open.return_value.__enter__.return_value

            cloud.execute_ssh_command(client, 'python test.py')

            file_handle.write.assert_has_calls(
                [call('\n'),
                 call('command executed successfully!')])
Пример #4
0
    def test_cloud_install_package(self):
        client = MagicMock()
        distro = MagicMock()
        distro.install_package.return_value = 'package install successful!'

        cloud = IpaCloud(*args, **self.kwargs)
        cloud.log_file = 'fake_file.name'
        cloud.distro = distro

        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            file_handle = mock_open.return_value.__enter__.return_value

            cloud.install_package(client, 'python')

            file_handle.write.assert_has_calls(
                [call('\n'), call('package install successful!')])
Пример #5
0
    def test_cloud_extract_archive(self, mock_extract_archive):
        client = MagicMock()

        mock_extract_archive.return_value = 'archive extracted successfully!'

        cloud = IpaCloud(*args, **self.kwargs)
        cloud.log_file = 'fake_file.name'

        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            file_handle = mock_open.return_value.__enter__.return_value

            cloud.extract_archive(client, 'archive.tar.xz')

            file_handle.write.assert_has_calls(
                [call('\n'),
                 call('archive extracted successfully!')])

        mock_extract_archive.assert_called_once_with(client, 'archive.tar.xz',
                                                     None)