Commit 89459ae9 authored by Maiken's avatar Maiken
Browse files

Merge branch 'arcctl-testca-consistent-hostname' into 'master'

arcctl: Consistent with other ARC services handling of hostname in TestCA

See merge request nordugrid/arc!282
parents 26fd8f21 48732e06
......@@ -3,6 +3,7 @@ from __future__ import absolute_import
from .ControlCommon import *
from .CertificateGenerator import CertificateGenerator, CertificateKeyPair
import subprocess
import socket
import sys
import stat
......@@ -26,6 +27,9 @@ class TestCAControl(ComponentControl):
def __init__(self, arcconfig):
self.logger = logging.getLogger('ARCCTL.TestCA')
self.x509_cert_dir = '/etc/grid-security/certificates'
self.hostname = None
# Use values from arc.conf if possible
self.arcconfig = arcconfig
if arcconfig is None:'Failed to parse arc.conf, using default CA certificates directory')
......@@ -33,7 +37,22 @@ class TestCAControl(ComponentControl):
x509_cert_dir = arcconfig.get_value('x509_cert_dir', 'common')
if x509_cert_dir:
self.x509_cert_dir = x509_cert_dir
self.hostname = socket.gethostname()
self.hostname = arcconfig.get_value('hostname', 'common')
self.logger.debug('Using hostname from arc.conf: {0}', self.hostname)
# if hostname is not defined via arc.conf
if self.hostname is None:
# try to get it from hostname -f
hostname_f = subprocess.Popen(['hostname', '-f'], stdout=subprocess.PIPE)
self.hostname = hostname_f.stdout.readline().strip()
self.logger.debug('Using hostname from \'hostname -f\': {0}', self.hostname)
except OSError:
# fallback
self.hostname = socket.gethostname()
self.logger.warning('Cannot get hostname from \'hostname -f\'. '
'Using {0} that comes from name services.', self.hostname)
self.caName = 'ARC {0} TestCA'.format(self.hostname)
self.caKey = os.path.join(self.x509_cert_dir, self.caName.replace(' ', '-') + '-key.pem')
self.caCert = os.path.join(self.x509_cert_dir, self.caName.replace(' ', '-') + '.pem')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment