def test_netdevice_get_all(self): dbapi.netdevices_create(self.context, device1) filters = {} res = dbapi.netdevices_get_by_region(self.context, device1['region_id'], filters) self.assertEqual(len(res), 1) self.assertEqual(res[0]['hostname'], 'switch1')
def test_netdevices_update(self): device = dbapi.netdevices_create(self.context, device1) res = dbapi.netdevices_get_by_id(self.context, device.id) self.assertEqual(res.hostname, 'switch1') new_name = 'switch2' res = dbapi.netdevices_update(self.context, res.id, {'name': 'switch2'}) self.assertEqual(res.name, new_name)
def test_netdevices_delete(self): device = dbapi.netdevices_create(self.context, device1) # First make sure we have the device res = dbapi.netdevices_get_by_id(self.context, device.id) self.assertEqual(res.id, device.id) # Delete the device dbapi.netdevices_delete(self.context, res.id) self.assertRaises(exceptions.NotFound, dbapi.netdevices_get_by_id, self.context, res.id)
def test_netdevice_data_delete(self): device = dbapi.netdevices_create(self.context, device1) _data = {"hello": "hi", "a": "b"} dbapi.netdevices_data_update(self.context, device.id, _data) ndevice = dbapi.netdevices_get_by_id(self.context, device.id) self.assertEqual(ndevice.variables, _data) _del_data = {"key": "a"} dbapi.netdevices_data_delete(self.context, device.id, _del_data) ndevice = dbapi.netdevices_get_by_id(self.context, device.id) self.assertEqual(ndevice.variables, {"hello": "hi"})
def test_netdevice_labels_delete(self): device = dbapi.netdevices_create(self.context, device1) _labels = {"labels": ["tom", "jerry"]} dbapi.netdevices_labels_update(self.context, device.id, _labels) ndevice = dbapi.netdevices_get_by_id(self.context, device.id) self.assertEqual(sorted(ndevice.labels), sorted(_labels["labels"])) _dlabels = {"labels": ["tom"]} dbapi.netdevices_labels_delete(self.context, ndevice.id, _dlabels) ndevice = dbapi.netdevices_get_by_id(self.context, ndevice.id) self.assertEqual(ndevice.labels, {"jerry"})
def test_netdevices_create(self): try: dbapi.netdevices_create(self.context, device1) except Exception: self.fail("Network device create raised unexpected exception")
def test_netdevice_labels_create(self): device = dbapi.netdevices_create(self.context, device1) labels = {"labels": ["tom", "jerry"]} dbapi.netdevices_labels_update(self.context, device.id, labels)
def test_netdevices_get_by_id(self): device = dbapi.netdevices_create(self.context, device1) res = dbapi.netdevices_get_by_id(self.context, device.id) self.assertEqual(res.hostname, 'switch1')