Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dvpl 11087 python3.13 #592

Merged
merged 13 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
os:
- ubuntu-latest
python: [ 3.7, 3.9]
python: [ 3.7, 3.9, 3.13]
splunk-version:
- "8.1"
- "8.2"
Expand All @@ -23,8 +23,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Run docker-compose
run: SPLUNK_VERSION=${{matrix.splunk-version}} docker-compose up -d
- name: Run docker compose
run: SPLUNK_VERSION=${{matrix.splunk-version}} docker compose up -d

- name: Setup Python
uses: actions/setup-python@v4
Expand Down
111 changes: 1 addition & 110 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,124 +14,15 @@
# License for the specific language governing permissions and limitations
# under the License.

from setuptools import setup, Command

import os
import sys
from setuptools import setup

import splunklib

failed = False

def run_test_suite():
import unittest

def mark_failed():
global failed
failed = True

class _TrackingTextTestResult(unittest._TextTestResult):
def addError(self, test, err):
unittest._TextTestResult.addError(self, test, err)
mark_failed()

def addFailure(self, test, err):
unittest._TextTestResult.addFailure(self, test, err)
mark_failed()

class TrackingTextTestRunner(unittest.TextTestRunner):
def _makeResult(self):
return _TrackingTextTestResult(
self.stream, self.descriptions, self.verbosity)

original_cwd = os.path.abspath(os.getcwd())
os.chdir('tests')
suite = unittest.defaultTestLoader.discover('.')
runner = TrackingTextTestRunner(verbosity=2)
runner.run(suite)
os.chdir(original_cwd)

return failed


def run_test_suite_with_junit_output():
try:
import unittest2 as unittest
except ImportError:
import unittest
import xmlrunner
original_cwd = os.path.abspath(os.getcwd())
os.chdir('tests')
suite = unittest.defaultTestLoader.discover('.')
xmlrunner.XMLTestRunner(output='../test-reports').run(suite)
os.chdir(original_cwd)


class CoverageCommand(Command):
"""setup.py command to run code coverage of the test suite."""
description = "Create an HTML coverage report from running the full test suite."
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
try:
import coverage
except ImportError:
print("Could not import coverage. Please install it and try again.")
exit(1)
cov = coverage.coverage(source=['splunklib'])
cov.start()
run_test_suite()
cov.stop()
cov.html_report(directory='coverage_report')


class TestCommand(Command):
"""setup.py command to run the whole test suite."""
description = "Run test full test suite."
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
failed = run_test_suite()
if failed:
sys.exit(1)


class JunitXmlTestCommand(Command):
"""setup.py command to run the whole test suite."""
description = "Run test full test suite with JUnit-formatted output."
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
run_test_suite_with_junit_output()


setup(
author="Splunk, Inc.",

author_email="[email protected]",

cmdclass={'coverage': CoverageCommand,
'test': TestCommand,
'testjunit': JunitXmlTestCommand},

description="The Splunk Software Development Kit for Python.",

license="http://www.apache.org/licenses/LICENSE-2.0",
Expand Down
9 changes: 8 additions & 1 deletion splunklib/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ class Context:
:type scheme: "https" or "http"
:param verify: Enable (True) or disable (False) SSL verification for https connections.
:type verify: ``Boolean``
:param self_signed_certificate: Specifies if self signed certificate is used
:type self_signed_certificate: ``Boolean``
:param sharing: The sharing mode for the namespace (the default is "user").
:type sharing: "global", "system", "app", or "user"
:param owner: The owner context of the namespace (optional, the default is "None").
Expand Down Expand Up @@ -526,6 +528,7 @@ def __init__(self, handler=None, **kwargs):
self.bearerToken = kwargs.get("splunkToken", "")
self.autologin = kwargs.get("autologin", False)
self.additional_headers = kwargs.get("headers", [])
self._self_signed_certificate = kwargs.get("self_signed_certificate", True)

# Store any cookies in the self.http._cookies dict
if "cookie" in kwargs and kwargs['cookie'] not in [None, _NoAuthenticationToken]:
Expand Down Expand Up @@ -604,7 +607,11 @@ def connect(self):
"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.scheme == "https":
sock = ssl.wrap_socket(sock)
context = ssl.create_default_context()
context.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1
context.check_hostname = not self._self_signed_certificate
context.verify_mode = ssl.CERT_NONE if self._self_signed_certificate else ssl.CERT_REQUIRED
sock = context.wrap_socket(sock, server_hostname=self.host)
sock.connect((socket.gethostbyname(self.host), self.port))
return sock

Expand Down
1 change: 1 addition & 0 deletions tests/modularinput/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def stream_events(self, inputs, ew):
# Remove paths and line numbers
err = re.sub(r'File "[^"]+', 'File "...', err.getvalue())
err = re.sub(r'line \d+', 'line 123', err)
err = re.sub(r' +~+\^+', '', err)

assert out.getvalue() == ""
assert err == (
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = clean,docs,py37,py39
envlist = clean,docs,py37,py39,313
skipsdist = {env:TOXBUILD:false}

[testenv:pep8]
Expand Down Expand Up @@ -28,8 +28,6 @@ setenv = SPLUNK_HOME=/opt/splunk
allowlist_externals = make
deps = pytest
pytest-cov
xmlrunner
unittest-xml-reporting
python-dotenv

distdir = build
Expand Down
Loading