Skip to content

Commit

Permalink
Remove support for python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dosas committed Dec 10, 2024
1 parent a557d2d commit fb8dbf8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion salt/minion_auth/srv/salt/_runners/foreman_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def salt_config():
"""
Read the foreman configuratoin from FOREMAN_CONFIG
"""
with open(FOREMAN_CONFIG, 'r') as config_file:
with open(FOREMAN_CONFIG) as config_file:
config = yaml.safe_load(config_file.read())
return config

Expand Down
27 changes: 9 additions & 18 deletions salt/report_upload/srv/salt/_runners/foreman_report_upload.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
# -*- coding: utf-8 -*-
'''
Uploads reports from the Salt job cache to Foreman
'''
from __future__ import absolute_import, print_function, unicode_literals
from builtins import str

LAST_UPLOADED = '/etc/salt/last_uploaded'
FOREMAN_CONFIG = '/etc/salt/foreman.yaml'
LOCK_FILE = '/var/lock/salt-report-upload.lock'
from http.client import HTTPConnection, HTTPSConnection

try:
from http.client import HTTPConnection, HTTPSConnection
except ImportError:
from httplib import HTTPConnection, HTTPSConnection

import io
import ssl
import json
import yaml
import os
import base64

# Import python libs
import logging

LAST_UPLOADED = '/etc/salt/last_uploaded'
FOREMAN_CONFIG = '/etc/salt/foreman.yaml'
LOCK_FILE = '/var/lock/salt-report-upload.lock'

log = logging.getLogger(__name__)


def salt_config():
with open(FOREMAN_CONFIG, 'r') as f:
with open(FOREMAN_CONFIG) as f:
config = yaml.safe_load(f.read())
return config


def write_last_uploaded(last_uploaded):
with io.open(LAST_UPLOADED, 'w+') as f:
with open(LAST_UPLOADED, 'w+') as f:
f.write(str(last_uploaded))


Expand Down Expand Up @@ -64,7 +55,7 @@ def upload(report):

if response.status == 200:
write_last_uploaded(report['job']['job_id'])
info_msg = 'Success {0}: {1}'.format(report['job']['job_id'], response.read())
info_msg = 'Success {}: {}'.format(report['job']['job_id'], response.read())
log.info(info_msg)
else:
log.error("Unable to upload job - aborting report upload")
Expand Down Expand Up @@ -103,7 +94,7 @@ def get_lock():
if os.path.isfile(LOCK_FILE):
raise Exception("Unable to obtain lock.")
else:
io.open(LOCK_FILE, 'w+').close()
open(LOCK_FILE, 'w+').close()


def release_lock():
Expand Down

0 comments on commit fb8dbf8

Please sign in to comment.