Esempio n. 1
0
 def test_with_security_groups(self):
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst['uuid']
     fake_inst['security_groups'] = [
         {'id': 1, 'name': 'secgroup1', 'description': 'fake-desc',
          'user_id': 'fake-user', 'project_id': 'fake_project',
          'created_at': None, 'updated_at': None, 'deleted_at': None,
          'deleted': False},
         {'id': 2, 'name': 'secgroup2', 'description': 'fake-desc',
          'user_id': 'fake-user', 'project_id': 'fake_project',
          'created_at': None, 'updated_at': None, 'deleted_at': None,
          'deleted': False},
         ]
     self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
     self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
     self.mox.StubOutWithMock(db, 'security_group_update')
     db.instance_get_by_uuid(self.context, fake_uuid, columns_to_join=[]
                             ).AndReturn(fake_inst)
     db.security_group_update(self.context, 1, {'description': 'changed'}
                              ).AndReturn(fake_inst['security_groups'][0])
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(self.context, fake_uuid)
     self.assertEqual(len(inst.security_groups), 2)
     for index, group in enumerate(fake_inst['security_groups']):
         for key in group:
             self.assertEqual(group[key],
                              inst.security_groups[index][key])
             self.assertTrue(isinstance(inst.security_groups[index],
                                        security_group.SecurityGroup))
     self.assertEqual(inst.security_groups.obj_what_changed(), set())
     inst.security_groups[0].description = 'changed'
     inst.save()
     self.assertEqual(inst.security_groups.obj_what_changed(), set())
Esempio n. 2
0
 def test_save(self):
     self.mox.StubOutWithMock(db, "security_group_update")
     updated_secgroup = dict(fake_secgroup, project_id="changed")
     db.security_group_update(self.context, 1, {"description": "foobar"}).AndReturn(updated_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(), fake_secgroup
     )
     secgroup.description = "foobar"
     secgroup.save()
     self.assertEqual(self._fix_deleted(updated_secgroup), dict(secgroup.items()))
     self.assertEqual(secgroup.obj_what_changed(), set())
     self.assertRemotes()
Esempio n. 3
0
 def test_save(self):
     self.mox.StubOutWithMock(db, 'security_group_update')
     updated_secgroup = dict(fake_secgroup, project_id='changed')
     db.security_group_update(self.context, 1,
                              {'description': 'foobar'}).AndReturn(
                                  updated_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup._from_db_object(
         self.context, security_group.SecurityGroup(),
         fake_secgroup)
     secgroup.description = 'foobar'
     secgroup.save()
     ovo_fixture.compare_obj(self, secgroup,
                             self._fix_deleted(updated_secgroup))
     self.assertEqual(secgroup.obj_what_changed(), set())
Esempio n. 4
0
 def save(self):
     updates = self.obj_get_changes()
     if updates:
         db_secgroup = db.security_group_update(self._context, self.id,
                                                updates)
         self._from_db_object(self._context, self, db_secgroup)
     self.obj_reset_changes()
Esempio n. 5
0
 def save(self):
     updates = self.obj_get_changes()
     if updates:
         db_secgroup = db.security_group_update(self._context, self.id,
                                                updates)
         self._from_db_object(self._context, self, db_secgroup)
     self.obj_reset_changes()
 def test_save(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'security_group_update')
     updated_secgroup = dict(fake_secgroup, project_id='changed')
     db.security_group_update(ctxt, 1,
                              {'description': 'foobar'}).AndReturn(
                                  updated_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup._from_db_object(
         security_group.SecurityGroup(), fake_secgroup)
     secgroup.description = 'foobar'
     secgroup.save(ctxt)
     self.assertEqual(self._fix_deleted(updated_secgroup),
                      dict(secgroup.items()))
     self.assertEqual(secgroup.obj_what_changed(), set())
     self.assertRemotes()
Esempio n. 7
0
 def test_save(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'security_group_update')
     updated_secgroup = dict(fake_secgroup, project_id='changed')
     db.security_group_update(ctxt, 1, {
         'description': 'foobar'
     }).AndReturn(updated_secgroup)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup._from_db_object(
         security_group.SecurityGroup(), fake_secgroup)
     secgroup.description = 'foobar'
     secgroup.save(ctxt)
     self.assertEqual(self._fix_deleted(updated_secgroup),
                      dict(secgroup.items()))
     self.assertEqual(secgroup.obj_what_changed(), set())
     self.assertRemotes()
Esempio n. 8
0
 def save(self, context):
     updates = {}
     for field in self.obj_what_changed():
         updates[field] = self[field]
     if updates:
         db_secgroup = db.security_group_update(context, self.id, updates)
         SecurityGroup._from_db_object(self, db_secgroup)
     self.obj_reset_changes()
 def save(self, context):
     updates = {}
     for field in self.obj_what_changed():
         updates[field] = self[field]
     if updates:
         db_secgroup = db.security_group_update(context, self.id, updates)
         SecurityGroup._from_db_object(self, db_secgroup)
     self.obj_reset_changes()
Esempio n. 10
0
 def test_with_security_groups(self):
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst["uuid"]
     fake_inst["security_groups"] = [
         {
             "id": 1,
             "name": "secgroup1",
             "description": "fake-desc",
             "user_id": "fake-user",
             "project_id": "fake_project",
             "created_at": None,
             "updated_at": None,
             "deleted_at": None,
             "deleted": False,
         },
         {
             "id": 2,
             "name": "secgroup2",
             "description": "fake-desc",
             "user_id": "fake-user",
             "project_id": "fake_project",
             "created_at": None,
             "updated_at": None,
             "deleted_at": None,
             "deleted": False,
         },
     ]
     self.mox.StubOutWithMock(db, "instance_get_by_uuid")
     self.mox.StubOutWithMock(db, "instance_update_and_get_original")
     self.mox.StubOutWithMock(db, "security_group_update")
     db.instance_get_by_uuid(
         self.context, fake_uuid, columns_to_join=["info_cache", "security_groups"], use_slave=False
     ).AndReturn(fake_inst)
     db.security_group_update(self.context, 1, {"description": "changed"}).AndReturn(fake_inst["security_groups"][0])
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(self.context, fake_uuid)
     self.assertEqual(len(inst.security_groups), 2)
     for index, group in enumerate(fake_inst["security_groups"]):
         for key in group:
             self.assertEqual(group[key], inst.security_groups[index][key])
             self.assertIsInstance(inst.security_groups[index], security_group.SecurityGroup)
     self.assertEqual(inst.security_groups.obj_what_changed(), set())
     inst.security_groups[0].description = "changed"
     inst.save()
     self.assertEqual(inst.security_groups.obj_what_changed(), set())
Esempio n. 11
0
 def save(self):
     updates = self.obj_get_changes()
     # We don't store uuid in the Nova database so remove it if someone
     # mistakenly tried to save a neutron security group object. We only
     # need the uuid in the object for obj_to_primitive() calls where this
     # object is serialized and stored in the RequestSpec object.
     updates.pop("uuid", None)
     if updates:
         db_secgroup = db.security_group_update(self._context, self.id, updates)
         self._from_db_object(self._context, self, db_secgroup)
     self.obj_reset_changes()
Esempio n. 12
0
 def save(self):
     updates = self.obj_get_changes()
     # We don't store uuid in the Nova database so remove it if someone
     # mistakenly tried to save a neutron security group object. We only
     # need the uuid in the object for obj_to_primitive() calls where this
     # object is serialized and stored in the RequestSpec object.
     updates.pop('uuid', None)
     if updates:
         db_secgroup = db.security_group_update(self._context, self.id,
                                                updates)
         self._from_db_object(self._context, self, db_secgroup)
     self.obj_reset_changes()
Esempio n. 13
0
 def test_with_security_groups(self):
     fake_inst = dict(self.fake_instance)
     fake_uuid = fake_inst['uuid']
     fake_inst['security_groups'] = [
         {'id': 1, 'name': 'secgroup1', 'description': 'fake-desc',
          'user_id': 'fake-user', 'project_id': 'fake_project',
          'created_at': None, 'updated_at': None, 'deleted_at': None,
          'deleted': False},
         {'id': 2, 'name': 'secgroup2', 'description': 'fake-desc',
          'user_id': 'fake-user', 'project_id': 'fake_project',
          'created_at': None, 'updated_at': None, 'deleted_at': None,
          'deleted': False},
         ]
     self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
     self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
     self.mox.StubOutWithMock(db, 'security_group_update')
     db.instance_get_by_uuid(self.context, fake_uuid,
                             columns_to_join=['info_cache',
                                              'security_groups'],
                             use_slave=False
                             ).AndReturn(fake_inst)
     db.security_group_update(self.context, 1, {'description': 'changed'}
                              ).AndReturn(fake_inst['security_groups'][0])
     self.mox.ReplayAll()
     inst = instance.Instance.get_by_uuid(self.context, fake_uuid)
     self.assertEqual(len(inst.security_groups), 2)
     for index, group in enumerate(fake_inst['security_groups']):
         for key in group:
             self.assertEqual(group[key],
                              inst.security_groups[index][key])
             self.assertIsInstance(inst.security_groups[index],
                                   security_group.SecurityGroup)
     self.assertEqual(inst.security_groups.obj_what_changed(), set())
     inst.security_groups[0].description = 'changed'
     inst.save()
     self.assertEqual(inst.security_groups.obj_what_changed(), set())