Dan Kenigsberg has uploaded a new change for review. Change subject: vdscli: make __getLocalVdsName more robust ......................................................................
vdscli: make __getLocalVdsName more robust vdscli attempts to guess the name of the local host by reading the "subject" of its openssl certificate. On Fedora 19, the order of the subject fields has changed. This patch makes __getLocalVdsName a bit more robust, and adds a unit test for it. Change-Id: I56bf79904cdf5d0dfcba773f096df1d3ec1670fe Signed-off-by: Dan Kenigsberg <[email protected]> --- M lib/vdsm/vdscli.py.in M tests/vdsClientTests.py 2 files changed, 27 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/59/16059/1 diff --git a/lib/vdsm/vdscli.py.in b/lib/vdsm/vdscli.py.in index f888e83..a26ca3c 100644 --- a/lib/vdsm/vdscli.py.in +++ b/lib/vdsm/vdscli.py.in @@ -77,15 +77,23 @@ pass -def __getLocalVdsName(tsPath): - p = subprocess.Popen(['openssl', 'x509', '-noout', '-subject', '-in', - '%s/certs/vdsmcert.pem' % tsPath], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - close_fds=True) - out, err = p.communicate() - if p.returncode != 0: - return '0' - return out.split('=')[-1].strip() +def __getLocalVdsName(tsPath, out=None): + if not out: + p = subprocess.Popen(['openssl', 'x509', '-noout', '-subject', '-in', + '%s/certs/vdsmcert.pem' % tsPath], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + close_fds=True) + out, err = p.communicate() + if p.returncode != 0: + return '0' + + for keyval in out[:-1].split('/'): + key, val = keyval.split('=') + if key == 'CN': + return val + + return '0' + __guessDefaults() diff --git a/tests/vdsClientTests.py b/tests/vdsClientTests.py index abf3242..fb8e4ef 100644 --- a/tests/vdsClientTests.py +++ b/tests/vdsClientTests.py @@ -24,6 +24,7 @@ from testrunner import VdsmTestCase as TestCaseBase import vdsClient +from vdsm.vdscli import __getLocalVdsName as getLocalVdsName @contextmanager @@ -118,3 +119,12 @@ allArgs[-1] = 'cpuPinning={0:1,1:0}' r4 = serv.do_create(['/dev/null'] + allArgs) self.assertNotEquals(r4, expectResult) + +class vdscliTests(TestCaseBase): + def test__getLocalVdsName(self): + cn = getLocalVdsName('fake', + "subject= /O=VDSM Certificate/CN=myhost\n") + self.assertEquals('myhost', cn) + cn = getLocalVdsName('fake', + "subject= /CN=myhost/O=VDSM Certificate\n") + self.assertEquals('myhost', cn) -- To view, visit http://gerrit.ovirt.org/16059 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I56bf79904cdf5d0dfcba773f096df1d3ec1670fe Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Dan Kenigsberg <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
