Skip to content

Commit

Permalink
Added upgrade script for PKIListener
Browse files Browse the repository at this point in the history
An upgrade script has been added to ensure that the
PKIListener exists in server.xml.

https://bugzilla.redhat.com/show_bug.cgi?id=1655808
  • Loading branch information
edewata committed Apr 23, 2019
1 parent 5b72ce1 commit dd97489
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions base/server/upgrade/10.7.0/04-AddPKIListener
@@ -0,0 +1,70 @@
# Authors:
# Endi S. Dewata <edewata@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2019 Red Hat, Inc.
# All rights reserved.

from __future__ import absolute_import
import logging
from lxml import etree

import pki


class AddPKIListener(pki.server.upgrade.PKIServerUpgradeScriptlet):

def __init__(self):
super(AddPKIListener, self).__init__()
self.message = 'Add PKIListener in server.xml'

def upgrade_instance(self, instance):

self.backup(instance.server_xml)

document = etree.parse(instance.server_xml, pki.server.parser)
server = document.getroot()

# find existing PKIListener
class_name = 'com.netscape.cms.tomcat.PKIListener'
pki_listener = server.find('Listener[@className=\'%s\']' % class_name)

if pki_listener is None:
logging.debug('Creating new PKIListener')
pki_listener = etree.Element('Listener')
pki_listener.set('className', class_name)

else:
logging.debug('Detaching existing PKIListener')
server.remove(pki_listener)

# find the last Listener
last_listener = server.find('Listener[last()]')

if last_listener is None:
logging.debug('No other Listeners found')
# (re)insert PKIListener at the top
index = 0

else:
logging.debug('Found last Listener: %s', last_listener.get('className'))
# (re)insert PKIListener after the last listener
index = list(server).index(last_listener) + 1

logging.debug('Inserting PKIListener at index %d', index)
server.insert(index, pki_listener)

with open(instance.server_xml, 'wb') as f:
document.write(f, pretty_print=True, encoding='utf-8')

0 comments on commit dd97489

Please sign in to comment.