From 4acff1c9382583691d9781eedccd74f060738247 Mon Sep 17 00:00:00 2001 From: Devananda van der Veen Date: Thu, 6 Jun 2013 17:40:31 -0700 Subject: [PATCH] SSH driver doesn't need to query database. Don't fetch the nodes' ports from the database inside ssh._get_nodes_mac_addresses() when we already have that information in the NodeManager. Change-Id: I6fd3f8de8e4eebfb5f5e47de11d688a863d900c5 --- ironic/drivers/modules/ssh.py | 6 +++--- ironic/tests/drivers/test_ssh.py | 36 +++++++++++++------------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/ironic/drivers/modules/ssh.py b/ironic/drivers/modules/ssh.py index 765a86d131..08349e59aa 100644 --- a/ironic/drivers/modules/ssh.py +++ b/ironic/drivers/modules/ssh.py @@ -248,9 +248,9 @@ def _power_off(ssh_obj, driver_info): def _get_nodes_mac_addresses(task, node): """Get all mac addresses for a node.""" - interface_ports = task.dbapi.get_ports_by_node(node.get('id')) - macs = [p.address for p in interface_ports] - return macs + for r in task.resources: + if r.node.id == node['id']: + return [p.address for p in r.ports] class SSHPower(base.PowerInterface): diff --git a/ironic/tests/drivers/test_ssh.py b/ironic/tests/drivers/test_ssh.py index 9f2378b5ea..e443a12105 100644 --- a/ironic/tests/drivers/test_ssh.py +++ b/ironic/tests/drivers/test_ssh.py @@ -366,29 +366,23 @@ class SSHDriverTestCase(db_base.DbTestCase): self.sshclient = paramiko.SSHClient() def test__get_nodes_mac_addresses(self): - class task(object): - dbapi = self.dbapi + ports = [] + ports.append( + self.dbapi.create_port( + db_utils.get_test_port( + id=6, + address='aa:bb:cc', + uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53'))) + ports.append( + self.dbapi.create_port( + db_utils.get_test_port( + id=7, + address='dd:ee:ff', + uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234'))) - ports = [ - db_utils.get_test_port( - id=6, - address='aa:bb:cc', - uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53'), - db_utils.get_test_port( - id=7, - address='dd:ee:ff', - uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234')] - ports[0] = self.dbapi.create_port(ports[0]) - ports[1] = self.dbapi.create_port(ports[1]) - - self.mox.StubOutWithMock(self.dbapi, 'get_ports_by_node') - self.dbapi.get_ports_by_node(self.node.get('id')).\ - AndReturn(ports) - self.mox.ReplayAll() - - node_macs = ssh._get_nodes_mac_addresses(task(), self.node) + with task_manager.acquire([self.node['uuid']]) as task: + node_macs = ssh._get_nodes_mac_addresses(task, self.node) self.assertEqual(node_macs, ['aa:bb:cc', 'dd:ee:ff']) - self.mox.VerifyAll() def test_reboot_good(self): info = ssh._parse_driver_info(self.node)