def _test_destroy(self): self.mox.StubOutWithMock(db, 'service_destroy') db.service_destroy(self.context, 123) self.mox.ReplayAll() service_obj = service.Service(context=self.context) service_obj.id = 123 service_obj.destroy()
def test_save(self): self.mox.StubOutWithMock(db, 'service_update') db.service_update(self.context, 123, {'host': 'fake-host'}).AndReturn( fake_service) self.mox.ReplayAll() service_obj = service.Service(context=self.context) service_obj.id = 123 service_obj.host = 'fake-host' service_obj.save()
def test_recreate_fails(self): self.mox.StubOutWithMock(db, 'service_create') db.service_create(self.context, {'host': 'fake-host'}).AndReturn( fake_service) self.mox.ReplayAll() service_obj = service.Service(context=self.context) service_obj.host = 'fake-host' service_obj.create() self.assertRaises(exception.ObjectActionError, service_obj.create)
def test_create(self): self.mox.StubOutWithMock(db, 'service_create') db.service_create(self.context, {'host': 'fake-host'}).AndReturn( fake_service) self.mox.ReplayAll() service_obj = service.Service(context=self.context) service_obj.host = 'fake-host' service_obj.create() self.assertEqual(fake_service['id'], service_obj.id)
def test_get_by_service(self, cn_get_by_svc_id): cn_get_by_svc_id.return_value = [fake_compute_node] fake_service = service.Service(id=123) computes = compute_node.ComputeNodeList.get_by_service( self.context, fake_service) self.assertEqual(1, len(computes)) self.compare_obj(computes[0], fake_compute_node, subs=self.subs(), comparators=self.comparators())
def test_get_by_id_with_host_field_not_in_db(self, mock_cn_get, mock_obj_svc_get): fake_compute_node_with_no_host = fake_compute_node.copy() host = fake_compute_node_with_no_host.pop('host') fake_service = service.Service(id=123) fake_service.host = host mock_cn_get.return_value = fake_compute_node_with_no_host mock_obj_svc_get.return_value = fake_service compute = compute_node.ComputeNode.get_by_id(self.context, 123) self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators())
def test_compute_node(self): fake_compute_node = objects.ComputeNode._from_db_object( self.context, objects.ComputeNode(), test_compute_node.fake_compute_node) self.mox.StubOutWithMock(objects.ComputeNodeList, 'get_all_by_host') objects.ComputeNodeList.get_all_by_host( self.context, 'fake-host').AndReturn( [fake_compute_node]) self.mox.ReplayAll() service_obj = service.Service(id=123, host="fake-host", binary="patron-compute") service_obj._context = self.context self.assertEqual(service_obj.compute_node, fake_compute_node) # Make sure it doesn't re-fetch this service_obj.compute_node
def test_get_by_host_and_nodename_not_found(self, cn_get_by_h_and_n, svc_get_by_ch, cn_get_by_svc_id, svc_get_by_id): cn_get_by_h_and_n.side_effect = exception.ComputeHostNotFound( host='fake') fake_service = service.Service(id=123) fake_service.host = 'fake' another_node = fake_old_compute_node.copy() another_node['hypervisor_hostname'] = 'elsewhere' svc_get_by_ch.return_value = fake_service cn_get_by_svc_id.return_value = [another_node] svc_get_by_id.return_value = fake_service self.assertRaises(exception.ComputeHostNotFound, compute_node.ComputeNode.get_by_host_and_nodename, self.context, 'fake', 'vm.danplanet.com')
def test_get_all_by_host_with_old_compute(self, cn_get_all_by_host, svc_get_by_ch, cn_get_by_svc_id, svc_get_by_id): cn_get_all_by_host.side_effect = exception.ComputeHostNotFound( host='fake') fake_service = service.Service(id=123) fake_service.host = 'fake' svc_get_by_ch.return_value = fake_service cn_get_by_svc_id.return_value = [fake_old_compute_node] svc_get_by_id.return_value = fake_service computes = compute_node.ComputeNodeList.get_all_by_host( self.context, 'fake') self.assertEqual(1, len(computes)) # NOTE(sbauza): Result is still converted to new style Compute self.compare_obj(computes[0], fake_compute_node, subs=self.subs(), comparators=self.comparators())
def test_get_by_host_and_nodename_with_old_compute(self, cn_get_by_h_and_n, svc_get_by_ch, cn_get_by_svc_id, svc_get_by_id): cn_get_by_h_and_n.side_effect = exception.ComputeHostNotFound( host='fake') fake_service = service.Service(id=123) fake_service.host = 'fake' svc_get_by_ch.return_value = fake_service cn_get_by_svc_id.return_value = [fake_old_compute_node] svc_get_by_id.return_value = fake_service compute = compute_node.ComputeNode.get_by_host_and_nodename( self.context, 'fake', 'vm.danplanet.com') # NOTE(sbauza): Result is still converted to new style Compute self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators())
def test_load_when_orphaned(self): service_obj = service.Service() service_obj.id = 123 self.assertRaises(exception.OrphanedObjectError, getattr, service_obj, 'compute_node')
def test_set_id_failure(self, db_mock): service_obj = service.Service(context=self.context) service_obj.create() self.assertRaises(exception.ReadOnlyFieldError, setattr, service_obj, 'id', 124)