def test_save_simple(self): values = self._get_default_values() db_result = self._create_instance_group(self.context, values) obj_result = instance_group.InstanceGroup.get_by_uuid( self.context, db_result.uuid) self.assertEqual(obj_result.name, 'fake_name') obj_result.name = 'new_name' obj_result.save() result = db.instance_group_get(self.context, db_result['uuid']) self.assertEqual(result['name'], 'new_name')
def test_save_policies(self): values = self._get_default_values() db_result = self._create_instance_group(self.context, values) obj_result = instance_group.InstanceGroup.get_by_uuid(self.context, db_result.uuid) policies = ['policy1', 'policy2'] obj_result.policies = policies obj_result.save() result = db.instance_group_get(self.context, db_result['uuid']) self.assertEqual(result['policies'], policies)
def test_save_policies(self): values = self._get_default_values() db_result = self._create_instance_group(self.context, values) obj_result = instance_group.InstanceGroup.get_by_uuid( self.context, db_result.uuid) policies = ['policy1', 'policy2'] obj_result.policies = policies obj_result.save() result = db.instance_group_get(self.context, db_result['uuid']) self.assertEqual(result['policies'], policies)
def test_save_simple(self): values = self._get_default_values() db_result = self._create_instance_group(self.context, values) obj_result = instance_group.InstanceGroup.get_by_uuid(self.context, db_result.uuid) self.assertEqual(obj_result.name, 'fake_name') obj_result.name = 'new_name' obj_result.save() result = db.instance_group_get(self.context, db_result['uuid']) self.assertEqual(result['name'], 'new_name')
def test_save_members(self): values = self._get_default_values() db_result = self._create_instance_group(self.context, values) obj_result = instance_group.InstanceGroup.get_by_uuid( self.context, db_result.uuid) members = ['instance1', 'instance2'] obj_result.members = members fake_notifier.NOTIFICATIONS = [] obj_result.save() self.assertEqual(1, len(fake_notifier.NOTIFICATIONS)) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual('servergroup.update', msg.event_type) self.assertEqual(members, msg.payload['members']) result = db.instance_group_get(self.context, db_result['uuid']) self.assertEqual(result['members'], members)
def save(self): """Save updates to this instance group.""" updates = self.obj_get_changes() if not updates: return payload = dict(updates) payload['server_group_id'] = self.uuid db.instance_group_update(self._context, self.uuid, updates) db_inst = db.instance_group_get(self._context, self.uuid) self._from_db_object(self._context, self, db_inst) compute_utils.notify_about_server_group_update(self._context, "update", payload)
def test_save_members(self): values = self._get_default_values() db_result = self._create_instance_group(self.context, values) obj_result = instance_group.InstanceGroup.get_by_uuid(self.context, db_result.uuid) members = ['instance1', 'instance2'] obj_result.members = members fake_notifier.NOTIFICATIONS = [] obj_result.save() self.assertEqual(1, len(fake_notifier.NOTIFICATIONS)) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual('servergroup.update', msg.event_type) self.assertEqual(members, msg.payload['members']) result = db.instance_group_get(self.context, db_result['uuid']) self.assertEqual(result['members'], members)
def test_create(self): group1 = instance_group.InstanceGroup(context=self.context) group1.uuid = 'fake-uuid' group1.name = 'fake-name' fake_notifier.NOTIFICATIONS = [] group1.create() self.assertEqual(1, len(fake_notifier.NOTIFICATIONS)) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual(group1.name, msg.payload['name']) self.assertEqual(group1.uuid, msg.payload['server_group_id']) self.assertEqual('servergroup.create', msg.event_type) group2 = instance_group.InstanceGroup.get_by_uuid( self.context, group1.uuid) self.assertEqual(group1.id, group2.id) self.assertEqual(group1.uuid, group2.uuid) self.assertEqual(group1.name, group2.name) result = db.instance_group_get(self.context, group1.uuid) self.assertEqual(group1.id, result.id) self.assertEqual(group1.uuid, result.uuid) self.assertEqual(group1.name, result.name)
def test_create(self): group1 = instance_group.InstanceGroup(context=self.context) group1.uuid = 'fake-uuid' group1.name = 'fake-name' fake_notifier.NOTIFICATIONS = [] group1.create() self.assertEqual(1, len(fake_notifier.NOTIFICATIONS)) msg = fake_notifier.NOTIFICATIONS[0] self.assertEqual(group1.name, msg.payload['name']) self.assertEqual(group1.uuid, msg.payload['server_group_id']) self.assertEqual('servergroup.create', msg.event_type) group2 = instance_group.InstanceGroup.get_by_uuid(self.context, group1.uuid) self.assertEqual(group1.id, group2.id) self.assertEqual(group1.uuid, group2.uuid) self.assertEqual(group1.name, group2.name) result = db.instance_group_get(self.context, group1.uuid) self.assertEqual(group1.id, result.id) self.assertEqual(group1.uuid, result.uuid) self.assertEqual(group1.name, result.name)
def get_by_uuid(cls, context, uuid): db_inst = db.instance_group_get(context, uuid) return cls._from_db_object(context, cls(), db_inst)