示例#1
0
    def test_cloud_distro_refresh(
            self,
            mock_distro_refresh,
            mock_get_host_key,
            mock_terminate_instance,
            mock_get_ssh_client,
            mock_start_instance,
            mock_set_image_id,
            mock_set_instance_ip
    ):
        """Test exception raised when invalid test item provided."""
        mock_distro_refresh.return_value = 'Refreshed!'
        mock_get_host_key.return_value = b'04820482'
        mock_terminate_instance.return_value = None
        mock_get_ssh_client.return_value = None
        mock_start_instance.return_value = None
        mock_set_image_id.return_value = None
        mock_set_instance_ip.return_value = None
        self.kwargs['running_instance_id'] = 'fakeinstance'
        self.kwargs['test_files'] = ['test_refresh']
        self.kwargs['cleanup'] = True

        cloud = IpaCloud(**self.kwargs)
        cloud.ssh_private_key_file = 'tests/data/ida_test'
        cloud.ssh_user = '******'

        status, results = cloud.test_image()
        assert status == 0
        assert mock_distro_refresh.call_count == 1
        self.kwargs['cleanup'] = None
示例#2
0
    def test_cloud_break_if_test_failure(
        self,
        mock_run_test,
        mock_get_host_key,
        mock_get_ssh_client,
        mock_start_instance,
        mock_set_image_id,
        mock_set_instance_ip
    ):
        """Test exception raised when invalid test item provided."""
        mock_run_test.return_value = 1
        mock_get_host_key.return_value = b'04820482'
        mock_get_ssh_client.return_value = None
        mock_start_instance.return_value = None
        mock_set_image_id.return_value = None
        mock_set_instance_ip.return_value = None
        self.kwargs['running_instance_id'] = 'fakeinstance'
        self.kwargs['early_exit'] = True

        cloud = IpaCloud(**self.kwargs)
        cloud.ssh_private_key_file = 'tests/data/ida_test'
        cloud.ssh_user = '******'

        status, results = cloud.test_image()
        assert status == 1
        assert mock_run_test.call_count == 1
示例#3
0
    def test_cloud_bad_connect_soft_reboot(
        self,
        mock_soft_reboot,
        mock_get_host_key,
        mock_get_ssh_client,
        mock_start_instance,
        mock_set_image_id,
        mock_set_instance_ip
    ):
        """Test exception when connection not established after hard reboot."""
        mock_soft_reboot.return_value = None
        mock_get_host_key.return_value = b'04820482'
        mock_get_ssh_client.side_effect = [
            None,
            None,
            IpaSSHException('ERROR!')
        ]
        mock_start_instance.return_value = None
        mock_set_image_id.return_value = None
        mock_set_instance_ip.return_value = None
        self.kwargs['running_instance_id'] = 'fakeinstance'
        self.kwargs['test_files'] = ['test_soft_reboot']

        cloud = IpaCloud(**self.kwargs)
        cloud.ssh_private_key_file = 'tests/data/ida_test'
        cloud.ssh_user = '******'
        cloud.logger = MagicMock()

        cloud.test_image()
        cloud.logger.error.assert_called_once_with(
            'Unable to connect to instance after soft reboot: ERROR!'
        )
        cloud.logger.error.reset_mock()

        assert mock_get_ssh_client.call_count > 0
        assert mock_soft_reboot.call_count == 1

        mock_soft_reboot.reset_mock()
        cloud.results_dir = self.results_dir.name

        mock_get_ssh_client.side_effect = [None, None, Exception('ERROR!')]

        cloud.test_image()
        cloud.logger.error.assert_called_once_with(
            'Instance failed soft reboot: ERROR!'
        )

        assert mock_get_ssh_client.call_count > 0
        assert mock_soft_reboot.call_count == 1
        mock_soft_reboot.reset_mock()
示例#4
0
    def test_cloud_get_ssh_client(self, mock_get_ssh_client):
        """Test get ssh client method."""
        cloud = IpaCloud(*args, **self.kwargs)

        cloud.instance_ip = '127.0.0.1'
        cloud.ssh_user = '******'
        cloud.ssh_private_key_file = 'tests/data/ida_test'

        client = MagicMock()
        mock_get_ssh_client.return_value = client

        val = cloud._get_ssh_client()
        assert val == client
        assert mock_get_ssh_client.call_count == 1

        ipa_utils.clear_cache()