]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
BigSwitch: Fix certificate file helper functions
authorKevin Benton <blak111@gmail.com>
Fri, 7 Mar 2014 19:09:46 +0000 (11:09 -0800)
committerGerrit Code Review <review@openstack.org>
Tue, 11 Mar 2014 16:52:48 +0000 (16:52 +0000)
Fixes function definitions for file-system calls
in certificate functions for BigSwitch plugin.

Closes-Bug: #1289192
Change-Id: Ifea8506ea0d751e0d5b08511eafd04d2fa26be23

neutron/plugins/bigswitch/servermanager.py
neutron/tests/unit/bigswitch/test_servermanager.py

index e482466eda6ca20ad14b35da11af4dbd4ab32864..5efafed7e5f4f208269d286d59b57b6100b91d0d 100644 (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:
index f7dc48116d75d69c7db02be1ef3ad89ccc06b76d..e09858cdc2e29c81fbe48faab19e5371ff44377c 100644 (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')
+            ])