From 288e3127440158f177beaae1972236def4916251 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Fri, 7 Mar 2014 11:09:46 -0800 Subject: [PATCH] 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 --- neutron/plugins/bigswitch/servermanager.py | 4 +-- .../unit/bigswitch/test_servermanager.py | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/neutron/plugins/bigswitch/servermanager.py b/neutron/plugins/bigswitch/servermanager.py index e482466eda6..5efafed7e5f 100644 --- a/neutron/plugins/bigswitch/servermanager.py +++ b/neutron/plugins/bigswitch/servermanager.py @@ -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: diff --git a/neutron/tests/unit/bigswitch/test_servermanager.py b/neutron/tests/unit/bigswitch/test_servermanager.py index f7dc48116d7..e09858cdc2e 100644 --- a/neutron/tests/unit/bigswitch/test_servermanager.py +++ b/neutron/tests/unit/bigswitch/test_servermanager.py @@ -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') + ])