BigSwitch: Fix certificate file helper functions

Fixes function definitions for file-system calls
in certificate functions for BigSwitch plugin.

Closes-Bug: #1289192
Change-Id: Ifea8506ea0d751e0d5b08511eafd04d2fa26be23
This commit is contained in:
Kevin Benton 2014-03-07 11:09:46 -08:00 committed by Gerrit Code Review
parent 12cbf72265
commit 288e312744
2 changed files with 31 additions and 2 deletions

View File

@ -317,7 +317,7 @@ class ServerPool(object):
self._combine_certs_to_file(certs, combined_cert)
return combined_cert
def _combine_certs_to_file(certs, cfile):
def _combine_certs_to_file(self, certs, cfile):
'''
Concatenates the contents of each certificate in a list of
certificate paths to one combined location for use with ssl
@ -366,7 +366,7 @@ class ServerPool(object):
return cert
def _file_put_contents(path, contents):
def _file_put_contents(self, path, contents):
# Simple method to write to file.
# Created for easy Mocking
with open(path, 'w') as handle:

View File

@ -68,3 +68,32 @@ class ServerManagerTests(test_rp.BigSwitchProxyPluginV2TestCase):
pl.servers.capabilities = ['consistency']
self.assertRaises(servermanager.RemoteRestError,
pl.servers._consistency_watchdog)
def test_file_put_contents(self):
pl = NeutronManager.get_plugin()
with mock.patch(SERVERMANAGER + '.open', create=True) as omock:
pl.servers._file_put_contents('somepath', 'contents')
omock.assert_has_calls([mock.call('somepath', 'w')])
omock.return_value.__enter__.return_value.assert_has_calls([
mock.call.write('contents')
])
def test_combine_certs_to_file(self):
pl = NeutronManager.get_plugin()
with mock.patch(SERVERMANAGER + '.open', create=True) as omock:
omock.return_value.__enter__().read.return_value = 'certdata'
pl.servers._combine_certs_to_file(['cert1.pem', 'cert2.pem'],
'combined.pem')
# mock shared between read and write file handles so the calls
# are mixed together
omock.assert_has_calls([
mock.call('combined.pem', 'w'),
mock.call('cert1.pem', 'r'),
mock.call('cert2.pem', 'r'),
], any_order=True)
omock.return_value.__enter__.return_value.assert_has_calls([
mock.call.read(),
mock.call.write('certdata'),
mock.call.read(),
mock.call.write('certdata')
])