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
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:
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')
+ ])