def setUp(self): super(TestNodeInfoOptions, self).setUp() node_cache.add_node(self.uuid, bmc_address='1.2.3.4', mac=self.macs) self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=3.14) with self.db: self.db.execute( 'insert into options(uuid, name, value) ' 'values(?, ?, ?)', (self.uuid, 'foo', '"bar"'))
def setUp(self): super(TestNodeInfoOptions, self).setUp() node_cache.add_node(self.uuid, bmc_address='1.2.3.4', mac=self.macs) self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=3.14) with self.db: self.db.execute('insert into options(uuid, name, value) ' 'values(?, ?, ?)', (self.uuid, 'foo', '"bar"'))
def test_add_node(self): # Ensure previous node information is cleared with self.db: self.db.execute("insert into nodes(uuid) values(?)", (self.node.uuid,)) self.db.execute("insert into nodes(uuid) values('uuid2')") self.db.execute("insert into attributes(name, value, uuid) " "values(?, ?, ?)", ('mac', '11:22:11:22:11:22', self.uuid)) res = node_cache.add_node(self.node.uuid, mac=self.macs, bmc_address='1.2.3.4', foo=None) self.assertEqual(self.uuid, res.uuid) self.assertTrue(time.time() - 60 < res.started_at < time.time() + 60) res = self.db.execute("select uuid, started_at " "from nodes order by uuid").fetchall() self.assertEqual(['uuid', 'uuid2'], [t[0] for t in res]) self.assertTrue(time.time() - 60 < res[0][1] < time.time() + 60) res = self.db.execute("select name, value, uuid from attributes " "order by name, value").fetchall() self.assertEqual([('bmc_address', '1.2.3.4', self.uuid), ('mac', self.macs[0], self.uuid), ('mac', self.macs[1], self.uuid)], [tuple(row) for row in res])
def test_add_node(self): # Ensure previous node information is cleared with self.db: self.db.execute("insert into nodes(uuid) values(?)", (self.node.uuid, )) self.db.execute("insert into nodes(uuid) values('uuid2')") self.db.execute( "insert into attributes(name, value, uuid) " "values(?, ?, ?)", ('mac', '11:22:11:22:11:22', self.uuid)) res = node_cache.add_node(self.node.uuid, mac=self.macs, bmc_address='1.2.3.4', foo=None) self.assertEqual(self.uuid, res.uuid) self.assertTrue(time.time() - 60 < res.started_at < time.time() + 60) res = self.db.execute("select uuid, started_at " "from nodes order by uuid").fetchall() self.assertEqual(['uuid', 'uuid2'], [t[0] for t in res]) self.assertTrue(time.time() - 60 < res[0][1] < time.time() + 60) res = self.db.execute("select name, value, uuid from attributes " "order by name, value").fetchall() self.assertEqual([('bmc_address', '1.2.3.4', self.uuid), ('mac', self.macs[0], self.uuid), ('mac', self.macs[1], self.uuid)], [tuple(row) for row in res])
def setUp(self): super(TestNodeCacheFind, self).setUp() self.macs2 = ['00:00:00:00:00:00'] node_cache.add_node(self.uuid, bmc_address='1.2.3.4', mac=self.macs)
def test_macs_multiple_found(self): node_cache.add_node('uuid2', mac=self.macs2) self.assertRaises(utils.Error, node_cache.find_node, mac=[self.macs[0], self.macs2[0]])