]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
BrcdFCSanLookupService should allow customize host key and policy
authorLynxzh <jmzhang@cn.ibm.com>
Mon, 19 May 2014 09:49:00 +0000 (17:49 +0800)
committerLynxzh <jmzhang@cn.ibm.com>
Mon, 19 May 2014 14:13:45 +0000 (22:13 +0800)
In BrcdFCSanLookupService, the initialization should allow the
customization of the known_hosts_file and missing_key_policy so that the
hosts key and missing policy can be customized according to the
different scenario and customer aspect. This will not change the default
behavior when no argument is given, but more flexible to allow the
caller to give more options according to different requirements.

Closes-Bug: #1320050
Change-Id: If5767f63ccd2cde5fbea30a6154acf4d28f662b6

cinder/tests/zonemanager/test_brcd_fc_san_lookup_service.py
cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py

index 5be6233208eb1c6c56323fbdf0e28b5c799b25ad..f18b440e2a675c001410e23bf48f6d6310bbc604 100644 (file)
@@ -76,6 +76,19 @@ class TestBrcdFCSanLookupService(brcd_lookup.BrcdFCSanLookupService,
         config = conf.Configuration(fc_fabric_opts, 'BRCD_FAB_2')
         self.fabric_configs = {'BRCD_FAB_2': config}
 
+    @mock.patch.object(paramiko.hostkeys.HostKeys, 'load')
+    def test_create_ssh_client(self, load_mock):
+        mock_args = {}
+        mock_args['known_hosts_file'] = 'dummy_host_key_file'
+        mock_args['missing_key_policy'] = paramiko.RejectPolicy()
+        ssh_client = self.create_ssh_client(**mock_args)
+        self.assertEqual(ssh_client._host_keys_filename, 'dummy_host_key_file')
+        self.assertTrue(isinstance(ssh_client._policy, paramiko.RejectPolicy))
+        mock_args = {}
+        ssh_client = self.create_ssh_client(**mock_args)
+        self.assertIsNone(ssh_client._host_keys_filename)
+        self.assertTrue(isinstance(ssh_client._policy, paramiko.WarningPolicy))
+
     @mock.patch.object(brcd_lookup.BrcdFCSanLookupService,
                        'get_nameserver_info')
     def test_get_device_mapping_from_network(self, get_nameserver_info_mock):
index 5c05b52b2ff2c9c59814011d6d5c981a81c9f186..d1f762e18dcfae89510948676c6d73d41e3ecefd 100644 (file)
@@ -45,9 +45,7 @@ class BrcdFCSanLookupService(FCSanLookupService):
         super(BrcdFCSanLookupService, self).__init__(**kwargs)
         self.configuration = kwargs.get('configuration', None)
         self.create_configuration()
-        self.client = paramiko.SSHClient()
-        self.client.load_system_host_keys()
-        self.client.set_missing_host_key_policy(paramiko.WarningPolicy())
+        self.client = self.create_ssh_client(**kwargs)
 
     def create_configuration(self):
         """Configuration specific to SAN context values."""
@@ -62,6 +60,19 @@ class BrcdFCSanLookupService(FCSanLookupService):
             self.fabric_configs = fabric_opts.load_fabric_configurations(
                 fabric_names)
 
+    def create_ssh_client(self, **kwargs):
+        ssh_client = paramiko.SSHClient()
+        known_hosts_file = kwargs.get('known_hosts_file', None)
+        if known_hosts_file is None:
+            ssh_client.load_system_host_keys()
+        else:
+            ssh_client.load_host_keys(known_hosts_file)
+        missing_key_policy = kwargs.get('missing_key_policy', None)
+        if missing_key_policy is None:
+            missing_key_policy = paramiko.WarningPolicy()
+        ssh_client.set_missing_host_key_policy(missing_key_policy)
+        return ssh_client
+
     def get_device_mapping_from_network(self,
                                         initiator_wwn_list,
                                         target_wwn_list):