Use atomic_move rather than writing in place in redhat_subscription (#27132)

* Use atomic_move rather than writing in place in redhat_subscription and redhat utils

* Change status to curated

* Put curated in the proper field

* Add RETURN doc section

* Disable yum plugins when unregistering

* Change back to community supported

* Alphabetize imports
pull/27184/head
Sam Doran 7 years ago committed by GitHub
parent e8a396be16
commit 1c40631382

@ -28,6 +28,8 @@
import os
import re
import shutil
import tempfile
import types
from ansible.module_utils.six.moves import configparser
@ -59,16 +61,22 @@ class RegistrationBase(object):
def update_plugin_conf(self, plugin, enabled=True):
plugin_conf = '/etc/yum/pluginconf.d/%s.conf' % plugin
if os.path.isfile(plugin_conf):
tmpfd, tmpfile = tempfile.mkstemp()
shutil.copy2(plugin_conf, tmpfile)
cfg = configparser.ConfigParser()
cfg.read([plugin_conf])
cfg.read([tmpfile])
if enabled:
cfg.set('main', 'enabled', 1)
else:
cfg.set('main', 'enabled', 0)
fd = open(plugin_conf, 'w+')
fd = open(tmpfile, 'w+')
cfg.write(fd)
fd.close()
self.module.atomic_move(tmpfile, plugin_conf)
def subscribe(self, **kwargs):
raise NotImplementedError("Must be implemented by a sub-class")
@ -190,6 +198,8 @@ class Rhsm(RegistrationBase):
'''
args = ['subscription-manager', 'unregister']
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
self.update_plugin_conf('rhnplugin', False)
self.update_plugin_conf('subscription-manager', False)
def subscribe(self, regexp):
'''

@ -15,9 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
ANSIBLE_METADATA = {
'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = '''
@ -196,8 +198,20 @@ EXAMPLES = '''
autosubscribe: yes
'''
RETURN = '''
subscribed_pool_ids:
description: List of pool IDs to which system is now subscribed
returned: success
type: complex
contains: {
"8a85f9815ab905d3015ab928c7005de4": "1"
}
'''
import os
import re
import shutil
import tempfile
import types
from ansible.module_utils.basic import AnsibleModule
@ -234,16 +248,22 @@ class RegistrationBase(object):
def update_plugin_conf(self, plugin, enabled=True):
plugin_conf = '/etc/yum/pluginconf.d/%s.conf' % plugin
if os.path.isfile(plugin_conf):
tmpfd, tmpfile = tempfile.mkstemp()
shutil.copy2(plugin_conf, tmpfile)
cfg = configparser.ConfigParser()
cfg.read([plugin_conf])
cfg.read([tmpfile])
if enabled:
cfg.set('main', 'enabled', 1)
else:
cfg.set('main', 'enabled', 0)
fd = open(plugin_conf, 'rwa+')
fd = open(tmpfile, 'w+')
cfg.write(fd)
fd.close()
self.module.atomic_move(tmpfile, plugin_conf)
def subscribe(self, **kwargs):
raise NotImplementedError("Must be implemented by a sub-class")
@ -392,6 +412,8 @@ class Rhsm(RegistrationBase):
'''
args = [SUBMAN_CMD, 'unregister']
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
self.update_plugin_conf('rhnplugin', False)
self.update_plugin_conf('subscription-manager', False)
def subscribe(self, regexp):
'''
@ -538,6 +560,7 @@ class RhsmPools(object):
"""
This class is used for manipulating pools subscriptions with RHSM
"""
def __init__(self, module, consumed=False):
self.module = module
self.products = self._load_product_list(consumed)

@ -17,9 +17,11 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'core'}
ANSIBLE_METADATA = {
'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = '''
@ -133,10 +135,14 @@ EXAMPLES = '''
channels: rhel-x86_64-server-6-foo-1,rhel-x86_64-server-6-bar-1
'''
RETURN = '''
# Default return values
'''
import os
import sys
import xmlrpclib
import urlparse
import xmlrpclib
# Attempt to import rhn client tools
sys.path.insert(0, '/usr/share/rhn')

Loading…
Cancel
Save